1 /* 2 * Copyright 2021, 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 #include <trusty_keymaster/TrustyKeymaster.h> 24 25 namespace aidl::android::hardware::security::keymint::trusty { 26 27 using ::keymaster::TrustyKeymaster; 28 using ::ndk::ScopedAStatus; 29 using secureclock::TimeStampToken; 30 using ::std::array; 31 using ::std::optional; 32 using ::std::shared_ptr; 33 using ::std::vector; 34 35 class TrustyKeyMintDevice : public BnKeyMintDevice { 36 public: TrustyKeyMintDevice(shared_ptr<TrustyKeymaster> impl)37 explicit TrustyKeyMintDevice(shared_ptr<TrustyKeymaster> impl) : impl_(std::move(impl)) {} 38 virtual ~TrustyKeyMintDevice() = default; 39 40 ScopedAStatus getHardwareInfo(KeyMintHardwareInfo* info) override; 41 42 ScopedAStatus addRngEntropy(const vector<uint8_t>& data) override; 43 44 ScopedAStatus generateKey(const vector<KeyParameter>& keyParams, 45 const optional<AttestationKey>& attestationKey, 46 KeyCreationResult* creationResult) override; 47 48 ScopedAStatus getKeyCharacteristics(const vector<uint8_t>& keyBlob, 49 const vector<uint8_t>& clientId, 50 const vector<uint8_t>& appData, 51 vector<KeyCharacteristics>* characteristics) override; 52 53 ScopedAStatus importKey(const vector<KeyParameter>& keyParams, KeyFormat keyFormat, 54 const vector<uint8_t>& keyData, 55 const optional<AttestationKey>& attestationKey, 56 KeyCreationResult* creationResult) override; 57 58 ScopedAStatus importWrappedKey(const vector<uint8_t>& wrappedKeyData, 59 const vector<uint8_t>& wrappingKeyBlob, 60 const vector<uint8_t>& maskingKey, 61 const vector<KeyParameter>& unwrappingParams, 62 int64_t passwordSid, int64_t biometricSid, 63 KeyCreationResult* creationResult) override; 64 65 ScopedAStatus upgradeKey(const vector<uint8_t>& keyBlobToUpgrade, 66 const vector<KeyParameter>& upgradeParams, 67 vector<uint8_t>* keyBlob) override; 68 69 ScopedAStatus deleteKey(const vector<uint8_t>& keyBlob) override; 70 ScopedAStatus deleteAllKeys() override; 71 ScopedAStatus destroyAttestationIds() override; 72 73 ScopedAStatus begin(KeyPurpose purpose, const vector<uint8_t>& keyBlob, 74 const vector<KeyParameter>& params, 75 const optional<HardwareAuthToken>& authToken, BeginResult* result) override; 76 77 ScopedAStatus deviceLocked(bool passwordOnly, 78 const optional<TimeStampToken>& timestampToken) override; 79 ScopedAStatus earlyBootEnded() override; 80 81 ScopedAStatus convertStorageKeyToEphemeral(const vector<uint8_t>& storageKeyBlob, 82 vector<uint8_t>* ephemeralKeyBlob) override; 83 84 ScopedAStatus getRootOfTrustChallenge(array<uint8_t, 16>* challenge) override; 85 ScopedAStatus getRootOfTrust(const array<uint8_t, 16>& challenge, 86 vector<uint8_t>* rootOfTrust) override; 87 ScopedAStatus sendRootOfTrust(const vector<uint8_t>& rootOfTrust) override; 88 89 protected: 90 std::shared_ptr<TrustyKeymaster> impl_; 91 SecurityLevel securityLevel_; 92 }; 93 94 } // namespace aidl::android::hardware::security::keymint::trusty 95