blob: 471cc2feaeedebeb5e2bc44ab54b86ac9b12679c [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
Tsuyoshi Horo4f516be2022-06-14 11:53:1321namespace net::android {
[email protected]03a07b2e2013-02-11 20:13:4522
23// Define a list of constants describing private key types. The
24// values are shared with Java through org.chromium.net.PrivateKeyType.
25// Example: PRIVATE_KEY_TYPE_RSA.
mkosibaf6ebbf6b2014-09-30 14:42:3926//
27// A Java counterpart will be generated for this enum.
28// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
[email protected]03a07b2e2013-02-11 20:13:4529enum PrivateKeyType {
mkosibaf6ebbf6b2014-09-30 14:42:3930 PRIVATE_KEY_TYPE_RSA = 0,
davidben370b6fa2015-06-09 18:34:2731 // Obsolete: PRIVATE_KEY_TYPE_DSA = 1,
mkosibaf6ebbf6b2014-09-30 14:42:3932 PRIVATE_KEY_TYPE_ECDSA = 2,
33 PRIVATE_KEY_TYPE_INVALID = 255,
[email protected]03a07b2e2013-02-11 20:13:4534};
35
David Benjaminb65b0732018-11-09 20:33:5336// Returns the name of the class which implements the private key.
37std::string GetPrivateKeyClassName(const base::android::JavaRef<jobject>& key);
38
David Benjamin08d50eb2019-04-03 21:05:3439// Returns whether |key| supports the signature algorithm |algorithm|.
40bool PrivateKeySupportsSignature(const base::android::JavaRef<jobject>& key,
41 base::StringPiece algorithm);
42
43// Returns whether |key| supports the encryption algorithm |algorithm|.
44bool PrivateKeySupportsCipher(const base::android::JavaRef<jobject>& key,
45 base::StringPiece algorithm);
46
David Benjamin5b4410e2017-11-10 21:50:2347// Compute the signature of a given input using a private key. For more
48// details, please read the comments for the signWithPrivateKey method in
49// AndroidKeyStore.java.
[email protected]03a07b2e2013-02-11 20:13:4550//
51// |private_key| is a JNI reference for the private key.
David Benjamin5b4410e2017-11-10 21:50:2352// |algorithm| is the name of the algorithm to sign.
53// |input| is the input to sign.
[email protected]03a07b2e2013-02-11 20:13:4554// |signature| will receive the signature on success.
55// Returns true on success, false on failure.
David Benjamin5b4410e2017-11-10 21:50:2356bool SignWithPrivateKey(const base::android::JavaRef<jobject>& private_key,
57 base::StringPiece algorithm,
58 base::span<const uint8_t> input,
59 std::vector<uint8_t>* signature);
[email protected]03a07b2e2013-02-11 20:13:4560
David Benjamin08d50eb2019-04-03 21:05:3461// Encrypts a given input using a private key. For more details, please read the
62// comments for the encryptWithPrivateKey method in AndroidKeyStore.java.
63//
64// |private_key| is a JNI reference for the private key.
65// |algorithm| is the name of the algorithm to use.
66// |input| is the input to encrypt.
67// |ciphertext| will receive the ciphertext on success.
68// Returns true on success, false on failure.
69bool EncryptWithPrivateKey(const base::android::JavaRef<jobject>& private_key,
70 base::StringPiece algorithm,
71 base::span<const uint8_t> input,
72 std::vector<uint8_t>* ciphertext);
73
Tsuyoshi Horo4f516be2022-06-14 11:53:1374} // namespace net::android
[email protected]03a07b2e2013-02-11 20:13:4575
bnc3698b0a02016-12-09 23:36:5076#endif // NET_ANDROID_KEYSTORE_H_