Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace keymaster { |
| 24 | class AndroidKeymaster; |
| 25 | } |
| 26 | |
| 27 | namespace aidl::android::hardware::security::keymint { |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 28 | using ::ndk::ScopedAStatus; |
Shawn Willden | 5c4f570 | 2022-02-17 15:48:35 -0700 | [diff] [blame] | 29 | using std::array; |
Shawn Willden | 44c3888 | 2020-12-21 18:35:13 -0700 | [diff] [blame] | 30 | using std::optional; |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 31 | using std::shared_ptr; |
| 32 | using std::vector; |
| 33 | |
Shawn Willden | 5592969 | 2021-02-19 14:53:02 -0700 | [diff] [blame] | 34 | using secureclock::TimeStampToken; |
| 35 | |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 36 | class AndroidKeyMintDevice : public BnKeyMintDevice { |
| 37 | public: |
| 38 | explicit AndroidKeyMintDevice(SecurityLevel securityLevel); |
| 39 | virtual ~AndroidKeyMintDevice(); |
| 40 | |
| 41 | ScopedAStatus getHardwareInfo(KeyMintHardwareInfo* info) override; |
| 42 | |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 43 | ScopedAStatus addRngEntropy(const vector<uint8_t>& data) override; |
| 44 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 45 | ScopedAStatus generateKey(const vector<KeyParameter>& keyParams, |
Shawn Willden | 44c3888 | 2020-12-21 18:35:13 -0700 | [diff] [blame] | 46 | const optional<AttestationKey>& attestationKey, |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 47 | KeyCreationResult* creationResult) override; |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 48 | |
| 49 | ScopedAStatus importKey(const vector<KeyParameter>& keyParams, KeyFormat keyFormat, |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 50 | const vector<uint8_t>& keyData, |
Shawn Willden | 44c3888 | 2020-12-21 18:35:13 -0700 | [diff] [blame] | 51 | const optional<AttestationKey>& attestationKey, |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 52 | KeyCreationResult* creationResult) override; |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 53 | |
| 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 Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 59 | KeyCreationResult* creationResult) override; |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 60 | |
| 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 Drysdale | 8181591 | 2021-04-19 19:11:41 +0100 | [diff] [blame] | 70 | const vector<KeyParameter>& params, |
| 71 | const optional<HardwareAuthToken>& authToken, BeginResult* result) override; |
Shawn Willden | 5592969 | 2021-02-19 14:53:02 -0700 | [diff] [blame] | 72 | |
| 73 | ScopedAStatus deviceLocked(bool passwordOnly, |
| 74 | const optional<TimeStampToken>& timestampToken) override; |
Chirag Pathak | b292e9a | 2021-02-02 07:28:09 +0000 | [diff] [blame] | 75 | ScopedAStatus earlyBootEnded() override; |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 76 | |
Shawn Willden | 5c4f570 | 2022-02-17 15:48:35 -0700 | [diff] [blame] | 77 | ScopedAStatus convertStorageKeyToEphemeral(const vector<uint8_t>& storageKeyBlob, |
| 78 | vector<uint8_t>* ephemeralKeyBlob) override; |
Satya Tangirala | 86d2540 | 2021-03-05 16:33:50 -0800 | [diff] [blame] | 79 | |
Shawn Willden | 5c4f570 | 2022-02-17 15:48:35 -0700 | [diff] [blame] | 80 | 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 Crowley | 08641bf | 2021-04-29 12:46:49 -0700 | [diff] [blame] | 89 | |
Shawn Willden | 5592969 | 2021-02-19 14:53:02 -0700 | [diff] [blame] | 90 | shared_ptr<::keymaster::AndroidKeymaster>& getKeymasterImpl() { return impl_; } |
Chirag Pathak | 7a07994 | 2021-01-25 20:16:30 +0000 | [diff] [blame] | 91 | |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 92 | protected: |
| 93 | std::shared_ptr<::keymaster::AndroidKeymaster> impl_; |
| 94 | SecurityLevel securityLevel_; |
| 95 | }; |
| 96 | |
Janis Danisevskis | 99e4a38 | 2022-02-15 13:27:44 -0800 | [diff] [blame] | 97 | std::shared_ptr<IKeyMintDevice> CreateKeyMintDevice(SecurityLevel securityLevel); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 98 | |
| 99 | } // namespace aidl::android::hardware::security::keymint |