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