OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_ANDROID_KEYSTORE_H | 5 #ifndef NET_ANDROID_KEYSTORE_H |
6 #define NET_ANDROID_KEYSTORE_H | 6 #define NET_ANDROID_KEYSTORE_H |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 // Returns the modulus of a given RSAPrivateKey platform object, | 42 // Returns the modulus of a given RSAPrivateKey platform object, |
43 // as a series of bytes, in big-endian representation. This can be | 43 // as a series of bytes, in big-endian representation. This can be |
44 // used with BN_bin2bn() to convert to an OpenSSL BIGNUM. | 44 // used with BN_bin2bn() to convert to an OpenSSL BIGNUM. |
45 // | 45 // |
46 // |private_key| is a JNI reference for the private key. | 46 // |private_key| is a JNI reference for the private key. |
47 // |modulus| will receive the modulus bytes on success. | 47 // |modulus| will receive the modulus bytes on success. |
48 // Returns true on success, or false on failure (e.g. if the key | 48 // Returns true on success, or false on failure (e.g. if the key |
49 // is not RSA). | 49 // is not RSA). |
50 NET_EXPORT bool GetRSAKeyModulus(jobject private_key, | 50 NET_EXPORT bool GetRSAKeyModulus( |
51 std::vector<uint8_t>* modulus); | 51 const base::android::JavaRef<jobject>& private_key, |
| 52 std::vector<uint8_t>* modulus); |
52 | 53 |
53 // Returns the order parameter of a given ECPrivateKey platform object, | 54 // Returns the order parameter of a given ECPrivateKey platform object, |
54 // as a series of bytes, in big-endian representation. This can be used | 55 // as a series of bytes, in big-endian representation. This can be used |
55 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. | 56 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. |
56 // |private_key| is a JNI reference for the private key. | 57 // |private_key| is a JNI reference for the private key. |
57 // |order| will receive the result bytes on success. | 58 // |order| will receive the result bytes on success. |
58 // Returns true on success, or false on failure (e.g. if the key is | 59 // Returns true on success, or false on failure (e.g. if the key is |
59 // not EC). | 60 // not EC). |
60 bool GetECKeyOrder(jobject private_key, std::vector<uint8_t>* order); | 61 bool GetECKeyOrder(const base::android::JavaRef<jobject>& private_key, |
| 62 std::vector<uint8_t>* order); |
61 | 63 |
62 // Compute the signature of a given message, which is actually a hash, | 64 // Compute the signature of a given message, which is actually a hash, |
63 // using a private key. For more details, please read the comments for the | 65 // using a private key. For more details, please read the comments for the |
64 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. | 66 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. |
65 // | 67 // |
66 // |private_key| is a JNI reference for the private key. | 68 // |private_key| is a JNI reference for the private key. |
67 // |digest| is the input digest. | 69 // |digest| is the input digest. |
68 // |signature| will receive the signature on success. | 70 // |signature| will receive the signature on success. |
69 // Returns true on success, false on failure. | 71 // Returns true on success, false on failure. |
70 // | 72 // |
71 NET_EXPORT bool RawSignDigestWithPrivateKey(jobject private_key, | 73 NET_EXPORT bool RawSignDigestWithPrivateKey( |
72 const base::StringPiece& digest, | 74 const base::android::JavaRef<jobject>& private_key, |
73 std::vector<uint8_t>* signature); | 75 const base::StringPiece& digest, |
| 76 std::vector<uint8_t>* signature); |
74 | 77 |
75 // Return the PrivateKeyType of a given private key. | 78 // Return the PrivateKeyType of a given private key. |
76 // |private_key| is a JNI reference for the private key. | 79 // |private_key| is a JNI reference for the private key. |
77 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE | 80 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE |
78 // on error. | 81 // on error. |
79 NET_EXPORT PrivateKeyType GetPrivateKeyType(jobject private_key); | 82 NET_EXPORT PrivateKeyType |
| 83 GetPrivateKeyType(const base::android::JavaRef<jobject>& private_key); |
80 | 84 |
81 // Returns a handle to the system AndroidEVP_PKEY object used to back a given | 85 // Returns a handle to the system AndroidEVP_PKEY object used to back a given |
82 // private_key object. This must *only* be used for RSA private keys on Android | 86 // private_key object. This must *only* be used for RSA private keys on Android |
83 // < 4.2. Technically, this is only guaranteed to work if the system image | 87 // < 4.2. Technically, this is only guaranteed to work if the system image |
84 // contains a vanilla implementation of the Java API frameworks based on Harmony | 88 // contains a vanilla implementation of the Java API frameworks based on Harmony |
85 // + OpenSSL. | 89 // + OpenSSL. |
86 // | 90 // |
87 // |private_key| is a JNI reference for the private key. | 91 // |private_key| is a JNI reference for the private key. |
88 // Returns an AndroidEVP_PKEY* handle, or NULL in case of error. | 92 // Returns an AndroidEVP_PKEY* handle, or NULL in case of error. |
89 // | 93 // |
90 // Note: Despite its name and return type, this function doesn't know | 94 // Note: Despite its name and return type, this function doesn't know |
91 // anything about OpenSSL, it just type-casts a system pointer that | 95 // anything about OpenSSL, it just type-casts a system pointer that |
92 // is passed as an int through JNI. As such, it never increments | 96 // is passed as an int through JNI. As such, it never increments |
93 // the returned key's reference count. | 97 // the returned key's reference count. |
94 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key); | 98 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey( |
| 99 const base::android::JavaRef<jobject>& private_key); |
95 | 100 |
96 // Returns a JNI reference to the OpenSSLEngine object which is used to back a | 101 // Returns a JNI reference to the OpenSSLEngine object which is used to back a |
97 // given private_key object. This must *only* be used for RSA private keys on | 102 // given private_key object. This must *only* be used for RSA private keys on |
98 // Android < 4.2. Technically, this is only guaranteed to work if the system | 103 // Android < 4.2. Technically, this is only guaranteed to work if the system |
99 // image contains a vanilla implementation of the Java API frameworks based on | 104 // image contains a vanilla implementation of the Java API frameworks based on |
100 // Harmony + OpenSSL. | 105 // Harmony + OpenSSL. |
101 base::android::ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey( | 106 base::android::ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey( |
102 jobject private_key); | 107 const base::android::JavaRef<jobject>& private_key); |
103 | 108 |
104 } // namespace android | 109 } // namespace android |
105 } // namespace net | 110 } // namespace net |
106 | 111 |
107 #endif // NET_ANDROID_KEYSTORE_H | 112 #endif // NET_ANDROID_KEYSTORE_H |
OLD | NEW |