Chromium Code Reviews| 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 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/android/scoped_java_ref.h" | |
| 13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 15 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 16 #include "net/ssl/ssl_client_cert_type.h" | 17 #include "net/ssl/ssl_client_cert_type.h" |
| 17 | 18 |
| 18 // Avoid including <openssl/evp.h> here. | |
| 19 typedef struct evp_pkey_st EVP_PKEY; | |
| 20 | |
| 21 // Misc functions to access the Android platform KeyStore. | 19 // Misc functions to access the Android platform KeyStore. |
| 22 | 20 |
| 23 namespace net { | 21 namespace net { |
| 24 namespace android { | 22 namespace android { |
| 25 | 23 |
| 24 struct AndroidEVP_PKEY; | |
| 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 enum PrivateKeyType { | 29 enum PrivateKeyType { |
| 30 #define DEFINE_PRIVATE_KEY_TYPE(name,value) PRIVATE_KEY_TYPE_ ## name = value, | 30 #define DEFINE_PRIVATE_KEY_TYPE(name,value) PRIVATE_KEY_TYPE_ ## name = value, |
| 31 #include "net/android/private_key_type_list.h" | 31 #include "net/android/private_key_type_list.h" |
| 32 #undef DEFINE_PRIVATE_KEY_TYPE | 32 #undef DEFINE_PRIVATE_KEY_TYPE |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // Returns the modulus of a given RSAPrivateKey platform object, | 35 // Returns the modulus of a given RSAPrivateKey platform object, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 const base::StringPiece& digest, | 86 const base::StringPiece& digest, |
| 87 std::vector<uint8>* signature); | 87 std::vector<uint8>* signature); |
| 88 | 88 |
| 89 | 89 |
| 90 // Return the PrivateKeyType of a given private key. | 90 // Return the PrivateKeyType of a given private key. |
| 91 // |private_key| is a JNI reference for the private key. | 91 // |private_key| is a JNI reference for the private key. |
| 92 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE | 92 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE |
| 93 // on error. | 93 // on error. |
| 94 NET_EXPORT PrivateKeyType GetPrivateKeyType(jobject private_key); | 94 NET_EXPORT PrivateKeyType GetPrivateKeyType(jobject private_key); |
| 95 | 95 |
| 96 // Returns a handle to the system EVP_PKEY object used to back a given | 96 // Returns a handle to the system AndroidEVP_PKEY object used to back a given |
| 97 // private_key object. This must *only* be used for RSA private keys | 97 // private_key object. This must *only* be used for RSA private keys on Android |
| 98 // on Android < 4.2. Technically, this is only guaranteed to work if | 98 // < 4.2. Technically, this is only guaranteed to work if the system image |
| 99 // the system image contains a vanilla implementation of the Java | 99 // contains a vanilla implementation of the Java API frameworks based on Harmony |
| 100 // API frameworks based on Harmony + OpenSSL. | 100 // + OpenSSL. |
| 101 // | 101 // |
| 102 // |private_key| is a JNI reference for the private key. | 102 // |private_key| is a JNI reference for the private key. |
| 103 // Returns an EVP_PKEY* handle, or NULL in case of error. | 103 // Returns an AndroidEVP_PKEY* handle, or NULL in case of error. |
| 104 // | 104 // |
| 105 // Note: Despite its name and return type, this function doesn't know | 105 // Note: Despite its name and return type, this function doesn't know |
| 106 // anything about OpenSSL, it just type-casts a system pointer that | 106 // anything about OpenSSL, it just type-casts a system pointer that |
| 107 // is passed as an int through JNI. As such, it never increments | 107 // is passed as an int through JNI. As such, it never increments |
| 108 // the returned key's reference count. | 108 // the returned key's reference count. |
| 109 EVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key); | 109 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key); |
| 110 | |
| 111 // Returns a JNI reference to the OpenSSLEngine object which used to back a | |
|
agl
2014/07/10 16:33:44
verb needed after "which".
davidben
2014/07/10 21:47:07
Done.
| |
| 112 // given private_key object. This must *only* be used for RSA private keys | |
| 113 // on Android < 4.2. Technically, this is only guaranteed to work if | |
| 114 // the system image contains a vanilla implementation of the Java | |
| 115 // API frameworks based on Harmony + OpenSSL. | |
| 116 base::android::ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey( | |
| 117 jobject private_key); | |
| 110 | 118 |
| 111 NET_EXPORT void ReleaseKey(jobject private_key); | 119 NET_EXPORT void ReleaseKey(jobject private_key); |
| 112 | 120 |
| 113 // Register JNI methods | 121 // Register JNI methods |
| 114 NET_EXPORT bool RegisterKeyStore(JNIEnv* env); | 122 NET_EXPORT bool RegisterKeyStore(JNIEnv* env); |
| 115 | 123 |
| 116 } // namespace android | 124 } // namespace android |
| 117 } // namespace net | 125 } // namespace net |
| 118 | 126 |
| 119 #endif // NET_ANDROID_KEYSTORE_H | 127 #endif // NET_ANDROID_KEYSTORE_H |
| OLD | NEW |