OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_ANDROID_KEYSTORE_H |
| 6 #define NET_ANDROID_KEYSTORE_H |
| 7 |
| 8 #include <jni.h> |
| 9 |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "base/string_piece.h" |
| 15 #include "net/base/net_export.h" |
| 16 #include "net/base/ssl_client_cert_type.h" |
| 17 |
| 18 // Avoid including OpenSSL headers here. |
| 19 typedef struct evp_pkey_st EVP_PKEY; |
| 20 |
| 21 // Misc classes to access the Android platform KeyStore. |
| 22 |
| 23 namespace net { |
| 24 namespace android { |
| 25 |
| 26 // Define a list of constants describing private key types. The |
| 27 // values are shared with Java through org.chromium.net.PrivateKeyType. |
| 28 // Example: PRIVATE_KEY_TYPE_RSA. |
| 29 enum PrivateKeyType { |
| 30 #define DEFINE_PRIVATE_KEY_TYPE(name,value) PRIVATE_KEY_TYPE_ ## name = value, |
| 31 #include "net/android/private_key_type_list.h" |
| 32 #undef DEFINE_PRIVATE_KEY_TYPE |
| 33 }; |
| 34 |
| 35 // Returns the modulus of a given RSAPrivateKey platform object, |
| 36 // as a series of bytes, in big-endian representation. This can be |
| 37 // used with BN_bin2bn() to convert to an OpenSSL object |
| 38 // |
| 39 // |private_key| is a JNI reference for the private key. |
| 40 // |modulus| will receive the modulus bytes on success. |
| 41 // Returns true on success, or false on failure (e.g. if the key |
| 42 // is not RSA). |
| 43 // |
| 44 bool GetRSAKeyModulus(jobject private_key, |
| 45 std::vector<uint8>* modulus); |
| 46 |
| 47 bool GetDSAKeyParamQ(jobject private_key, |
| 48 std::vector<uint8>* q); |
| 49 |
| 50 // Returns the encoded PKCS#8 representation of a private key. |
| 51 // This only works on Android 4.0.3 and older releases for platform keys |
| 52 // (i.e. all keys except those explicitely generated by the application). |
| 53 // |private_key| is a JNI reference for the private key. |
| 54 // |encoded| will receive the encoded data on success. |
| 55 // Returns true on success, or false on failure (e.g. on 4.0.4 or higher). |
| 56 bool GetPrivateKeyEncodedBytes(jobject private_key, |
| 57 std::vector<uint8>* encoded); |
| 58 |
| 59 // Compute the signature of a given message, which is actually a hash, |
| 60 // using a private key. For more details, please read the comments for the |
| 61 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. |
| 62 // |
| 63 // |private_key| is a JNI reference for the private key. |
| 64 // |digest| is the input digest. |
| 65 // |signature| will receive the signature on success. |
| 66 // Returns true on success, false on failure. |
| 67 // |
| 68 bool RawSignDigestWithPrivateKey( |
| 69 jobject private_key, |
| 70 const base::StringPiece& digest, |
| 71 std::vector<uint8>* signature); |
| 72 |
| 73 |
| 74 // Return the PrivateKeyType of a given private key. |
| 75 // |private_key| is a JNI reference for the private key. |
| 76 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE |
| 77 // on error. |
| 78 PrivateKeyType GetPrivateKeyType(jobject private_key); |
| 79 |
| 80 // Returns a handle to the system EVP_PKEY object used to back a given |
| 81 // private_key object. This must *only* be used for RSA private keys |
| 82 // on Android < 4.2. Technically, this is only guaranteed to work if |
| 83 // the system image contains a vanilla implementation of the Java |
| 84 // API frameworks based on Harmony + OpenSSL. |
| 85 // |
| 86 // |private_key| is a JNI reference for the private key. |
| 87 // Returns an EVP_PKEY* handle, or NULL in case of error. |
| 88 // |
| 89 // Note: Despite its name and return type, this function doesn't know |
| 90 // anything about OpenSSL, it just type-casts a system pointer that |
| 91 // is passed as an int through JNI. As such, it never increments |
| 92 // the returned key's reference count. |
| 93 EVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key); |
| 94 |
| 95 // Register JNI methods |
| 96 NET_EXPORT bool RegisterKeyStore(JNIEnv* env); |
| 97 |
| 98 } // namespace android |
| 99 } // namespace net |
| 100 |
| 101 #endif // NET_ANDROID_KEYSTORE_H |
OLD | NEW |