blob: 06557beeadd52419561f31913ac6a50bdf08d3c0 [file] [log] [blame]
Shawn Willden815e8962020-12-11 13:05:27 +00001/*
2 * Copyright 2020, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <aidl/android/hardware/security/keymint/BnKeyMintDevice.h>
20#include <aidl/android/hardware/security/keymint/BnKeyMintOperation.h>
21#include <aidl/android/hardware/security/keymint/HardwareAuthToken.h>
22
23namespace keymaster {
24class AndroidKeymaster;
25}
26
27namespace aidl::android::hardware::security::keymint {
Shawn Willden815e8962020-12-11 13:05:27 +000028using ::ndk::ScopedAStatus;
Shawn Willden5c4f5702022-02-17 15:48:35 -070029using std::array;
Shawn Willden44c38882020-12-21 18:35:13 -070030using std::optional;
Shawn Willden815e8962020-12-11 13:05:27 +000031using std::shared_ptr;
32using std::vector;
33
Shawn Willden55929692021-02-19 14:53:02 -070034using secureclock::TimeStampToken;
35
Shawn Willden815e8962020-12-11 13:05:27 +000036class AndroidKeyMintDevice : public BnKeyMintDevice {
37 public:
38 explicit AndroidKeyMintDevice(SecurityLevel securityLevel);
39 virtual ~AndroidKeyMintDevice();
40
41 ScopedAStatus getHardwareInfo(KeyMintHardwareInfo* info) override;
42
Shawn Willden815e8962020-12-11 13:05:27 +000043 ScopedAStatus addRngEntropy(const vector<uint8_t>& data) override;
44
Shawn Willden763166c2021-01-10 19:45:01 -070045 ScopedAStatus generateKey(const vector<KeyParameter>& keyParams,
Shawn Willden44c38882020-12-21 18:35:13 -070046 const optional<AttestationKey>& attestationKey,
Shawn Willden763166c2021-01-10 19:45:01 -070047 KeyCreationResult* creationResult) override;
Shawn Willden815e8962020-12-11 13:05:27 +000048
49 ScopedAStatus importKey(const vector<KeyParameter>& keyParams, KeyFormat keyFormat,
Shawn Willden763166c2021-01-10 19:45:01 -070050 const vector<uint8_t>& keyData,
Shawn Willden44c38882020-12-21 18:35:13 -070051 const optional<AttestationKey>& attestationKey,
Shawn Willden763166c2021-01-10 19:45:01 -070052 KeyCreationResult* creationResult) override;
Shawn Willden815e8962020-12-11 13:05:27 +000053
54 ScopedAStatus importWrappedKey(const vector<uint8_t>& wrappedKeyData,
55 const vector<uint8_t>& wrappingKeyBlob,
56 const vector<uint8_t>& maskingKey,
57 const vector<KeyParameter>& unwrappingParams,
58 int64_t passwordSid, int64_t biometricSid,
Shawn Willden763166c2021-01-10 19:45:01 -070059 KeyCreationResult* creationResult) override;
Shawn Willden815e8962020-12-11 13:05:27 +000060
61 ScopedAStatus upgradeKey(const vector<uint8_t>& keyBlobToUpgrade,
62 const vector<KeyParameter>& upgradeParams,
63 vector<uint8_t>* keyBlob) override;
64
65 ScopedAStatus deleteKey(const vector<uint8_t>& keyBlob) override;
66 ScopedAStatus deleteAllKeys() override;
67 ScopedAStatus destroyAttestationIds() override;
68
69 ScopedAStatus begin(KeyPurpose purpose, const vector<uint8_t>& keyBlob,
David Drysdale81815912021-04-19 19:11:41 +010070 const vector<KeyParameter>& params,
71 const optional<HardwareAuthToken>& authToken, BeginResult* result) override;
Shawn Willden55929692021-02-19 14:53:02 -070072
73 ScopedAStatus deviceLocked(bool passwordOnly,
74 const optional<TimeStampToken>& timestampToken) override;
Chirag Pathakb292e9a2021-02-02 07:28:09 +000075 ScopedAStatus earlyBootEnded() override;
Shawn Willden815e8962020-12-11 13:05:27 +000076
Shawn Willden5c4f5702022-02-17 15:48:35 -070077 ScopedAStatus convertStorageKeyToEphemeral(const vector<uint8_t>& storageKeyBlob,
78 vector<uint8_t>* ephemeralKeyBlob) override;
Satya Tangirala86d25402021-03-05 16:33:50 -080079
Shawn Willden5c4f5702022-02-17 15:48:35 -070080 ScopedAStatus getKeyCharacteristics(const vector<uint8_t>& keyBlob,
81 const vector<uint8_t>& appId,
82 const vector<uint8_t>& appData,
83 vector<KeyCharacteristics>* keyCharacteristics) override;
84
85 ScopedAStatus getRootOfTrustChallenge(array<uint8_t, 16>* challenge) override;
86 ScopedAStatus getRootOfTrust(const array<uint8_t, 16>& challenge,
87 vector<uint8_t>* rootOfTrust) override;
88 ScopedAStatus sendRootOfTrust(const vector<uint8_t>& rootOfTrust) override;
Paul Crowley08641bf2021-04-29 12:46:49 -070089
Shawn Willden55929692021-02-19 14:53:02 -070090 shared_ptr<::keymaster::AndroidKeymaster>& getKeymasterImpl() { return impl_; }
Chirag Pathak7a079942021-01-25 20:16:30 +000091
Shawn Willden815e8962020-12-11 13:05:27 +000092 protected:
93 std::shared_ptr<::keymaster::AndroidKeymaster> impl_;
94 SecurityLevel securityLevel_;
95};
96
Janis Danisevskis99e4a382022-02-15 13:27:44 -080097std::shared_ptr<IKeyMintDevice> CreateKeyMintDevice(SecurityLevel securityLevel);
Shawn Willden815e8962020-12-11 13:05:27 +000098
99} // namespace aidl::android::hardware::security::keymint