1/* 2 ** 3 ** Copyright 2017, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18#ifndef HIDL_android_hardware_keymaster_V4_0_AndroidKeymaster4Device_H_ 19#define HIDL_android_hardware_keymaster_V4_0_AndroidKeymaster4Device_H_ 20 21#include <android/hardware/keymaster/4.0/IKeymasterDevice.h> 22 23#include <hidl/Status.h> 24 25namespace keymaster { 26class AndroidKeymaster; 27class KeymasterContext; 28 29namespace V4_0 { 30namespace ng { 31 32using ::android::sp; 33using ::android::hardware::hidl_vec; 34using ::android::hardware::Return; 35using ::android::hardware::Void; 36using ::android::hardware::keymaster::V4_0::ErrorCode; 37using ::android::hardware::keymaster::V4_0::HardwareAuthenticatorType; 38using ::android::hardware::keymaster::V4_0::HardwareAuthToken; 39using ::android::hardware::keymaster::V4_0::HmacSharingParameters; 40using ::android::hardware::keymaster::V4_0::IKeymasterDevice; 41using ::android::hardware::keymaster::V4_0::KeyCharacteristics; 42using ::android::hardware::keymaster::V4_0::KeyFormat; 43using ::android::hardware::keymaster::V4_0::KeyParameter; 44using ::android::hardware::keymaster::V4_0::KeyPurpose; 45using ::android::hardware::keymaster::V4_0::SecurityLevel; 46using ::android::hardware::keymaster::V4_0::Tag; 47using ::android::hardware::keymaster::V4_0::VerificationToken; 48 49class AndroidKeymaster4Device : public IKeymasterDevice { 50 public: 51 AndroidKeymaster4Device(SecurityLevel securityLevel); 52 virtual ~AndroidKeymaster4Device(); 53 54 Return<void> getHardwareInfo(getHardwareInfo_cb _hidl_cb) override; 55 Return<void> getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb) override; 56 Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>& params, 57 computeSharedHmac_cb) override; 58 Return<void> verifyAuthorization(uint64_t challenge, 59 const hidl_vec<KeyParameter>& parametersToVerify, 60 const HardwareAuthToken& authToken, 61 verifyAuthorization_cb _hidl_cb) override; 62 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override; 63 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams, 64 generateKey_cb _hidl_cb) override; 65 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob, 66 const hidl_vec<uint8_t>& clientId, 67 const hidl_vec<uint8_t>& appData, 68 getKeyCharacteristics_cb _hidl_cb) override; 69 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat, 70 const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override; 71 Return<void> importWrappedKey(const hidl_vec<uint8_t>& wrappedKeyData, 72 const hidl_vec<uint8_t>& wrappingKeyBlob, 73 const hidl_vec<uint8_t>& maskingKey, 74 const hidl_vec<KeyParameter>& unwrappingParams, 75 uint64_t passwordSid, uint64_t biometricSid, 76 importWrappedKey_cb _hidl_cb) override; 77 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob, 78 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData, 79 exportKey_cb _hidl_cb) override; 80 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest, 81 const hidl_vec<KeyParameter>& attestParams, 82 attestKey_cb _hidl_cb) override; 83 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade, 84 const hidl_vec<KeyParameter>& upgradeParams, 85 upgradeKey_cb _hidl_cb) override; 86 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override; 87 Return<ErrorCode> deleteAllKeys() override; 88 Return<ErrorCode> destroyAttestationIds() override; 89 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key, 90 const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken, 91 begin_cb _hidl_cb) override; 92 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, 93 const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken, 94 const VerificationToken& verificationToken, update_cb _hidl_cb) override; 95 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, 96 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature, 97 const HardwareAuthToken& authToken, 98 const VerificationToken& verificationToken, finish_cb _hidl_cb) override; 99 Return<ErrorCode> abort(uint64_t operationHandle) override; 100 101 private: 102 std::unique_ptr<::keymaster::AndroidKeymaster> impl_; 103 SecurityLevel securityLevel_; 104}; 105 106IKeymasterDevice* CreateKeymasterDevice(SecurityLevel securityLevel); 107 108} // namespace ng 109} // namespace V4_0 110} // namespace keymaster 111 112#endif // HIDL_android_hardware_keymaster_V4_0_AndroidKeymaster4Device_H_ 113