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 | 10 |
10 #include <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
14 #include "base/basictypes.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; |
(...skipping 13 matching lines...) Expand all Loading... |
38 | 38 |
39 // Returns the modulus of a given RSAPrivateKey platform object, | 39 // Returns the modulus of a given RSAPrivateKey platform object, |
40 // as a series of bytes, in big-endian representation. This can be | 40 // as a series of bytes, in big-endian representation. This can be |
41 // used with BN_bin2bn() to convert to an OpenSSL BIGNUM. | 41 // used with BN_bin2bn() to convert to an OpenSSL BIGNUM. |
42 // | 42 // |
43 // |private_key| is a JNI reference for the private key. | 43 // |private_key| is a JNI reference for the private key. |
44 // |modulus| will receive the modulus bytes on success. | 44 // |modulus| will receive the modulus bytes on success. |
45 // Returns true on success, or false on failure (e.g. if the key | 45 // Returns true on success, or false on failure (e.g. if the key |
46 // is not RSA). | 46 // is not RSA). |
47 NET_EXPORT bool GetRSAKeyModulus(jobject private_key, | 47 NET_EXPORT bool GetRSAKeyModulus(jobject private_key, |
48 std::vector<uint8>* modulus); | 48 std::vector<uint8_t>* modulus); |
49 | 49 |
50 // Returns the Q parameter of a given DSAPrivateKey platform object, | 50 // Returns the Q parameter of a given DSAPrivateKey platform object, |
51 // as a series of bytes, in big-endian representation. This can be used | 51 // as a series of bytes, in big-endian representation. This can be used |
52 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. | 52 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. |
53 // |private_key| is a JNI reference for the private key. | 53 // |private_key| is a JNI reference for the private key. |
54 // |q| will receive the result bytes on success. | 54 // |q| will receive the result bytes on success. |
55 // Returns true on success, or false on failure (e.g. if the key is | 55 // Returns true on success, or false on failure (e.g. if the key is |
56 // not DSA). | 56 // not DSA). |
57 NET_EXPORT bool GetDSAKeyParamQ(jobject private_key, | 57 NET_EXPORT bool GetDSAKeyParamQ(jobject private_key, std::vector<uint8_t>* q); |
58 std::vector<uint8>* q); | |
59 | 58 |
60 // Returns the order parameter of a given ECPrivateKey platform object, | 59 // Returns the order parameter of a given ECPrivateKey platform object, |
61 // as a series of bytes, in big-endian representation. This can be used | 60 // as a series of bytes, in big-endian representation. This can be used |
62 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. | 61 // with BN_bin2bn() to convert to an OpenSSL BIGNUM. |
63 // |private_key| is a JNI reference for the private key. | 62 // |private_key| is a JNI reference for the private key. |
64 // |order| will receive the result bytes on success. | 63 // |order| will receive the result bytes on success. |
65 // Returns true on success, or false on failure (e.g. if the key is | 64 // Returns true on success, or false on failure (e.g. if the key is |
66 // not EC). | 65 // not EC). |
67 bool GetECKeyOrder(jobject private_key, | 66 bool GetECKeyOrder(jobject private_key, std::vector<uint8_t>* order); |
68 std::vector<uint8>* order); | |
69 | 67 |
70 // Returns the encoded PKCS#8 representation of a private key. | 68 // Returns the encoded PKCS#8 representation of a private key. |
71 // This only works on Android 4.0.3 and older releases for platform keys | 69 // This only works on Android 4.0.3 and older releases for platform keys |
72 // (i.e. all keys except those explicitely generated by the application). | 70 // (i.e. all keys except those explicitely generated by the application). |
73 // |private_key| is a JNI reference for the private key. | 71 // |private_key| is a JNI reference for the private key. |
74 // |encoded| will receive the encoded data on success. | 72 // |encoded| will receive the encoded data on success. |
75 // Returns true on success, or false on failure (e.g. on 4.0.4 or higher). | 73 // Returns true on success, or false on failure (e.g. on 4.0.4 or higher). |
76 bool GetPrivateKeyEncodedBytes(jobject private_key, | 74 bool GetPrivateKeyEncodedBytes(jobject private_key, |
77 std::vector<uint8>* encoded); | 75 std::vector<uint8_t>* encoded); |
78 | 76 |
79 // Compute the signature of a given message, which is actually a hash, | 77 // Compute the signature of a given message, which is actually a hash, |
80 // using a private key. For more details, please read the comments for the | 78 // using a private key. For more details, please read the comments for the |
81 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. | 79 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java. |
82 // | 80 // |
83 // |private_key| is a JNI reference for the private key. | 81 // |private_key| is a JNI reference for the private key. |
84 // |digest| is the input digest. | 82 // |digest| is the input digest. |
85 // |signature| will receive the signature on success. | 83 // |signature| will receive the signature on success. |
86 // Returns true on success, false on failure. | 84 // Returns true on success, false on failure. |
87 // | 85 // |
88 NET_EXPORT bool RawSignDigestWithPrivateKey( | 86 NET_EXPORT bool RawSignDigestWithPrivateKey(jobject private_key, |
89 jobject private_key, | 87 const base::StringPiece& digest, |
90 const base::StringPiece& digest, | 88 std::vector<uint8_t>* signature); |
91 std::vector<uint8>* signature); | |
92 | |
93 | 89 |
94 // Return the PrivateKeyType of a given private key. | 90 // Return the PrivateKeyType of a given private key. |
95 // |private_key| is a JNI reference for the private key. | 91 // |private_key| is a JNI reference for the private key. |
96 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE | 92 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE |
97 // on error. | 93 // on error. |
98 NET_EXPORT PrivateKeyType GetPrivateKeyType(jobject private_key); | 94 NET_EXPORT PrivateKeyType GetPrivateKeyType(jobject private_key); |
99 | 95 |
100 // Returns a handle to the system AndroidEVP_PKEY object used to back a given | 96 // Returns a handle to the system AndroidEVP_PKEY object used to back a given |
101 // private_key object. This must *only* be used for RSA private keys on Android | 97 // private_key object. This must *only* be used for RSA private keys on Android |
102 // < 4.2. Technically, this is only guaranteed to work if the system image | 98 // < 4.2. Technically, this is only guaranteed to work if the system image |
(...skipping 19 matching lines...) Expand all Loading... |
122 | 118 |
123 NET_EXPORT void ReleaseKey(jobject private_key); | 119 NET_EXPORT void ReleaseKey(jobject private_key); |
124 | 120 |
125 // Register JNI methods | 121 // Register JNI methods |
126 NET_EXPORT bool RegisterKeyStore(JNIEnv* env); | 122 NET_EXPORT bool RegisterKeyStore(JNIEnv* env); |
127 | 123 |
128 } // namespace android | 124 } // namespace android |
129 } // namespace net | 125 } // namespace net |
130 | 126 |
131 #endif // NET_ANDROID_KEYSTORE_H | 127 #endif // NET_ANDROID_KEYSTORE_H |
OLD | NEW |