blob: c8eb34bed911dedcfcdc5dfbbd7114d94602131b [file] [log] [blame]
[email protected]03a07b2e2013-02-11 20:13:451// 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
bnc3698b0a02016-12-09 23:36:505#ifndef NET_ANDROID_KEYSTORE_H_
6#define NET_ANDROID_KEYSTORE_H_
[email protected]03a07b2e2013-02-11 20:13:457
8#include <jni.h>
wtc69f8ea82015-06-04 00:08:139#include <stdint.h>
[email protected]03a07b2e2013-02-11 20:13:4510
11#include <string>
12#include <vector>
13
[email protected]eeff8532014-07-11 22:07:5914#include "base/android/scoped_java_ref.h"
David Benjamin9ba36b02017-11-10 19:01:5315#include "base/containers/span.h"
David Benjamin5b4410e2017-11-10 21:50:2316#include "base/strings/string_piece.h"
[email protected]536fd0b2013-03-14 17:41:5717#include "net/ssl/ssl_client_cert_type.h"
[email protected]03a07b2e2013-02-11 20:13:4518
[email protected]03a07b2e2013-02-11 20:13:4519// Misc functions to access the Android platform KeyStore.
20
21namespace net {
22namespace android {
23
24// Define a list of constants describing private key types. The
25// values are shared with Java through org.chromium.net.PrivateKeyType.
26// Example: PRIVATE_KEY_TYPE_RSA.
mkosibaf6ebbf6b2014-09-30 14:42:3927//
28// A Java counterpart will be generated for this enum.
29// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
[email protected]03a07b2e2013-02-11 20:13:4530enum PrivateKeyType {
mkosibaf6ebbf6b2014-09-30 14:42:3931 PRIVATE_KEY_TYPE_RSA = 0,
davidben370b6fa2015-06-09 18:34:2732 // Obsolete: PRIVATE_KEY_TYPE_DSA = 1,
mkosibaf6ebbf6b2014-09-30 14:42:3933 PRIVATE_KEY_TYPE_ECDSA = 2,
34 PRIVATE_KEY_TYPE_INVALID = 255,
[email protected]03a07b2e2013-02-11 20:13:4535};
36
David Benjaminb65b0732018-11-09 20:33:5337// Returns the name of the class which implements the private key.
38std::string GetPrivateKeyClassName(const base::android::JavaRef<jobject>& key);
39
David Benjamin08d50eb2019-04-03 21:05:3440// Returns whether |key| supports the signature algorithm |algorithm|.
41bool PrivateKeySupportsSignature(const base::android::JavaRef<jobject>& key,
42 base::StringPiece algorithm);
43
44// Returns whether |key| supports the encryption algorithm |algorithm|.
45bool PrivateKeySupportsCipher(const base::android::JavaRef<jobject>& key,
46 base::StringPiece algorithm);
47
David Benjamin5b4410e2017-11-10 21:50:2348// Compute the signature of a given input using a private key. For more
49// details, please read the comments for the signWithPrivateKey method in
50// AndroidKeyStore.java.
[email protected]03a07b2e2013-02-11 20:13:4551//
52// |private_key| is a JNI reference for the private key.
David Benjamin5b4410e2017-11-10 21:50:2353// |algorithm| is the name of the algorithm to sign.
54// |input| is the input to sign.
[email protected]03a07b2e2013-02-11 20:13:4555// |signature| will receive the signature on success.
56// Returns true on success, false on failure.
David Benjamin5b4410e2017-11-10 21:50:2357bool SignWithPrivateKey(const base::android::JavaRef<jobject>& private_key,
58 base::StringPiece algorithm,
59 base::span<const uint8_t> input,
60 std::vector<uint8_t>* signature);
[email protected]03a07b2e2013-02-11 20:13:4561
David Benjamin08d50eb2019-04-03 21:05:3462// Encrypts a given input using a private key. For more details, please read the
63// comments for the encryptWithPrivateKey method in AndroidKeyStore.java.
64//
65// |private_key| is a JNI reference for the private key.
66// |algorithm| is the name of the algorithm to use.
67// |input| is the input to encrypt.
68// |ciphertext| will receive the ciphertext on success.
69// Returns true on success, false on failure.
70bool EncryptWithPrivateKey(const base::android::JavaRef<jobject>& private_key,
71 base::StringPiece algorithm,
72 base::span<const uint8_t> input,
73 std::vector<uint8_t>* ciphertext);
74
[email protected]03a07b2e2013-02-11 20:13:4575} // namespace android
76} // namespace net
77
bnc3698b0a02016-12-09 23:36:5078#endif // NET_ANDROID_KEYSTORE_H_