Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / android / keystore.h
blobb79479901a4b7dcb4b1ab4cb2e66189040f72a6c
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.
5 #ifndef NET_ANDROID_KEYSTORE_H
6 #define NET_ANDROID_KEYSTORE_H
8 #include <jni.h>
9 #include <stdint.h>
11 #include <string>
12 #include <vector>
14 #include "base/android/scoped_java_ref.h"
15 #include "base/strings/string_piece.h"
16 #include "net/base/net_export.h"
17 #include "net/ssl/ssl_client_cert_type.h"
19 // Misc functions to access the Android platform KeyStore.
21 namespace net {
22 namespace android {
24 struct AndroidEVP_PKEY;
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.
30 // This enum is used as part of an RPC interface, so new values must be
31 // appended and not reused.
33 // A Java counterpart will be generated for this enum.
34 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
35 enum PrivateKeyType {
36 PRIVATE_KEY_TYPE_RSA = 0,
37 // Obsolete: PRIVATE_KEY_TYPE_DSA = 1,
38 PRIVATE_KEY_TYPE_ECDSA = 2,
39 PRIVATE_KEY_TYPE_INVALID = 255,
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.
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(jobject private_key,
51 std::vector<uint8_t>* modulus);
53 // 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 // with BN_bin2bn() to convert to an OpenSSL BIGNUM.
56 // |private_key| is a JNI reference for the private key.
57 // |order| will receive the result bytes on success.
58 // Returns true on success, or false on failure (e.g. if the key is
59 // not EC).
60 bool GetECKeyOrder(jobject private_key, std::vector<uint8_t>* order);
62 // 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
64 // rawSignDigestWithPrivateKey method in AndroidKeyStore.java.
66 // |private_key| is a JNI reference for the private key.
67 // |digest| is the input digest.
68 // |signature| will receive the signature on success.
69 // Returns true on success, false on failure.
71 NET_EXPORT bool RawSignDigestWithPrivateKey(jobject private_key,
72 const base::StringPiece& digest,
73 std::vector<uint8_t>* signature);
75 // Return the PrivateKeyType of a given private key.
76 // |private_key| is a JNI reference for the private key.
77 // Returns a PrivateKeyType, while will be CLIENT_CERT_INVALID_TYPE
78 // on error.
79 NET_EXPORT PrivateKeyType GetPrivateKeyType(jobject private_key);
81 // 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
83 // < 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
85 // + OpenSSL.
87 // |private_key| is a JNI reference for the private key.
88 // Returns an AndroidEVP_PKEY* handle, or NULL in case of error.
90 // Note: Despite its name and return type, this function doesn't know
91 // anything about OpenSSL, it just type-casts a system pointer that
92 // is passed as an int through JNI. As such, it never increments
93 // the returned key's reference count.
94 AndroidEVP_PKEY* GetOpenSSLSystemHandleForPrivateKey(jobject private_key);
96 // 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
98 // 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
100 // Harmony + OpenSSL.
101 base::android::ScopedJavaLocalRef<jobject> GetOpenSSLEngineForPrivateKey(
102 jobject private_key);
104 NET_EXPORT void ReleaseKey(jobject private_key);
106 // Register JNI methods
107 NET_EXPORT bool RegisterKeyStore(JNIEnv* env);
109 } // namespace android
110 } // namespace net
112 #endif // NET_ANDROID_KEYSTORE_H