| 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 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 17 #include "net/ssl/ssl_client_cert_type.h" | 17 #include "net/ssl/ssl_client_cert_type.h" |
| 18 | 18 |
| 19 // Misc functions to access the Android platform KeyStore. | 19 // Misc functions to access the Android platform KeyStore. |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 namespace android { | 22 namespace android { |
| 23 | 23 |
| 24 struct AndroidEVP_PKEY; | 24 struct AndroidEVP_PKEY; |
| 25 | 25 |
| 26 // Define a list of constants describing private key types. The | 26 // Define a list of constants describing private key types. The |
| 27 // values are shared with Java through org.chromium.net.PrivateKeyType. | 27 // values are shared with Java through org.chromium.net.PrivateKeyType. |
| 28 // Example: PRIVATE_KEY_TYPE_RSA. | 28 // Example: PRIVATE_KEY_TYPE_RSA. |
| 29 // | 29 // |
| 30 // This enum is used as part of an RPC interface, so new values must be | |
| 31 // appended and not reused. | |
| 32 // | |
| 33 // A Java counterpart will be generated for this enum. | 30 // A Java counterpart will be generated for this enum. |
| 34 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net | 31 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net |
| 35 enum PrivateKeyType { | 32 enum PrivateKeyType { |
| 36 PRIVATE_KEY_TYPE_RSA = 0, | 33 PRIVATE_KEY_TYPE_RSA = 0, |
| 37 // Obsolete: PRIVATE_KEY_TYPE_DSA = 1, | 34 // Obsolete: PRIVATE_KEY_TYPE_DSA = 1, |
| 38 PRIVATE_KEY_TYPE_ECDSA = 2, | 35 PRIVATE_KEY_TYPE_ECDSA = 2, |
| 39 PRIVATE_KEY_TYPE_INVALID = 255, | 36 PRIVATE_KEY_TYPE_INVALID = 255, |
| 40 }; | 37 }; |
| 41 | 38 |
| 42 // Returns the modulus of a given RSAPrivateKey platform object, | |
| 43 // as a series of bytes, in big-endian representation. This can be | |
| 44 // used with BN_bin2bn() to convert to an OpenSSL BIGNUM. | |
| 45 // | |
| 46 // |private_key| is a JNI reference for the private key. | |
| 47 // |modulus| will receive the modulus bytes on success. | |
| 48 // Returns true on success, or false on failure (e.g. if the key | |
| 49 // is not RSA). | |
| 50 NET_EXPORT bool GetRSAKeyModulus( | |
| 51 const base::android::JavaRef<jobject>& private_key, | |
| 52 std::vector<uint8_t>* modulus); | |
| 53 | |
| 54 // Returns the order parameter of a given ECPrivateKey platform object, | |
| 55 // as a series of bytes, in big-endian representation. This can be used | |
| 56 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. | |
| 57 // |private_key| is a JNI reference for the private key. | |
| 58 // |order| will receive the result bytes on success. | |
| 59 // Returns true on success, or false on failure (e.g. if the key is | |
| 60 // not EC). | |
| 61 bool GetECKeyOrder(const base::android::JavaRef<jobject>& private_key, | |
| 62 std::vector<uint8_t>* order); | |
| 63 | |
| 64 // Compute the signature of a given message, which is actually a hash, | 39 // Compute the signature of a given message, which is actually a hash, |
| 65 // using a private key. For more details, please read the comments for the | 40 // using a private key. For more details, please read the comments for the |
| 66 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. | 41 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. |
| 67 // | 42 // |
| 68 // |private_key| is a JNI reference for the private key. | 43 // |private_key| is a JNI reference for the private key. |
| 69 // |digest| is the input digest. | 44 // |digest| is the input digest. |
| 70 // |signature| will receive the signature on success. | 45 // |signature| will receive the signature on success. |
| 71 // Returns true on success, false on failure. | 46 // Returns true on success, false on failure. |
| 72 // | 47 // |
| 73 NET_EXPORT bool RawSignDigestWithPrivateKey( | 48 NET_EXPORT bool RawSignDigestWithPrivateKey( |
| 74 const base::android::JavaRef<jobject>& private_key, | 49 const base::android::JavaRef<jobject>& private_key, |
| 75 const base::StringPiece& digest, | 50 const base::StringPiece& digest, |
| 76 std::vector<uint8_t>* signature); | 51 std::vector<uint8_t>* signature); |
| 77 | 52 |
| 78 // Return the PrivateKeyType of a given private key. | |
| 79 // |private_key| is a JNI reference for the private key. | |
| 80 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE | |
| 81 // on error. | |
| 82 NET_EXPORT PrivateKeyType | |
| 83 GetPrivateKeyType(const base::android::JavaRef<jobject>& private_key); | |
| 84 | |
| 85 // Returns a handle to the system AndroidEVP_PKEY object used to back a given | 53 // Returns a handle to the system AndroidEVP_PKEY object used to back a given |
| 86 // private_key object. This must *only* be used for RSA private keys on Android | 54 // private_key object. This must *only* be used for RSA private keys on Android |
| 87 // < 4.2. Technically, this is only guaranteed to work if the system image | 55 // < 4.2. Technically, this is only guaranteed to work if the system image |
| 88 // contains a vanilla implementation of the Java API frameworks based on Harmony | 56 // contains a vanilla implementation of the Java API frameworks based on Harmony |
| 89 // + OpenSSL. | 57 // + OpenSSL. |
| 90 // | 58 // |
| 91 // |private_key| is a JNI reference for the private key. | 59 // |private_key| is a JNI reference for the private key. |
| 92 // Returns an AndroidEVP_PKEY* handle, or NULL in case of error. | 60 // Returns an AndroidEVP_PKEY* handle, or NULL in case of error. |
| 93 // | 61 // |
| 94 // Note: Despite its name and return type, this function doesn't know | 62 // Note: Despite its name and return type, this function doesn't know |
| 95 // anything about OpenSSL, it just type-casts a system pointer that | 63 // anything about OpenSSL, it just type-casts a system pointer that |
| 96 // is passed as an int through JNI. As such, it never increments | 64 // is passed as an int through JNI. As such, it never increments |
| 97 // the returned key's reference count. | 65 // the returned key's reference count. |
| 98 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey( | 66 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey( |
| 99 const base::android::JavaRef<jobject>& private_key); | 67 const base::android::JavaRef<jobject>& private_key); |
| 100 | 68 |
| 101 // Returns a JNI reference to the OpenSSLEngine object which is used to back a | 69 // Returns a JNI reference to the OpenSSLEngine object which is used to back a |
| 102 // given private_key object. This must *only* be used for RSA private keys on | 70 // given private_key object. This must *only* be used for RSA private keys on |
| 103 // Android < 4.2. Technically, this is only guaranteed to work if the system | 71 // Android < 4.2. Technically, this is only guaranteed to work if the system |
| 104 // image contains a vanilla implementation of the Java API frameworks based on | 72 // image contains a vanilla implementation of the Java API frameworks based on |
| 105 // Harmony + OpenSSL. | 73 // Harmony + OpenSSL. |
| 106 base::android::ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey( | 74 base::android::ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey( |
| 107 const base::android::JavaRef<jobject>& private_key); | 75 const base::android::JavaRef<jobject>& private_key); |
| 108 | 76 |
| 109 } // namespace android | 77 } // namespace android |
| 110 } // namespace net | 78 } // namespace net |
| 111 | 79 |
| 112 #endif // NET_ANDROID_KEYSTORE_H | 80 #endif // NET_ANDROID_KEYSTORE_H |
| OLD | NEW |