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 <hardware/keymaster_defs.h> 24 #include <hidl/Status.h> 25 26 namespace keymaster { 27 class AndroidKeymaster; 28 class KeymasterContext; 29 30 namespace V4_0 { 31 namespace ng { 32 33 using ::android::sp; 34 using ::android::hardware::hidl_vec; 35 using ::android::hardware::Return; 36 using ::android::hardware::Void; 37 using ::android::hardware::keymaster::V4_0::ErrorCode; 38 using ::android::hardware::keymaster::V4_0::HardwareAuthenticatorType; 39 using ::android::hardware::keymaster::V4_0::HardwareAuthToken; 40 using ::android::hardware::keymaster::V4_0::HmacSharingParameters; 41 using ::android::hardware::keymaster::V4_0::IKeymasterDevice; 42 using ::android::hardware::keymaster::V4_0::KeyCharacteristics; 43 using ::android::hardware::keymaster::V4_0::KeyFormat; 44 using ::android::hardware::keymaster::V4_0::KeyParameter; 45 using ::android::hardware::keymaster::V4_0::KeyPurpose; 46 using ::android::hardware::keymaster::V4_0::SecurityLevel; 47 using ::android::hardware::keymaster::V4_0::Tag; 48 using ::android::hardware::keymaster::V4_0::VerificationToken; 49 50 class AndroidKeymaster4Device : public IKeymasterDevice { 51 public: 52 explicit AndroidKeymaster4Device(SecurityLevel securityLevel); 53 virtual ~AndroidKeymaster4Device(); 54 55 Return<void> getHardwareInfo(getHardwareInfo_cb _hidl_cb) override; 56 Return<void> getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb) override; 57 Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>& params, 58 computeSharedHmac_cb) override; 59 Return<void> verifyAuthorization(uint64_t challenge, 60 const hidl_vec<KeyParameter>& parametersToVerify, 61 const HardwareAuthToken& authToken, 62 verifyAuthorization_cb _hidl_cb) override; 63 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override; 64 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams, 65 generateKey_cb _hidl_cb) override; 66 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob, 67 const hidl_vec<uint8_t>& clientId, 68 const hidl_vec<uint8_t>& appData, 69 getKeyCharacteristics_cb _hidl_cb) override; 70 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat, 71 const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override; 72 Return<void> importWrappedKey(const hidl_vec<uint8_t>& wrappedKeyData, 73 const hidl_vec<uint8_t>& wrappingKeyBlob, 74 const hidl_vec<uint8_t>& maskingKey, 75 const hidl_vec<KeyParameter>& unwrappingParams, 76 uint64_t passwordSid, uint64_t biometricSid, 77 importWrappedKey_cb _hidl_cb) override; 78 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob, 79 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData, 80 exportKey_cb _hidl_cb) override; 81 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest, 82 const hidl_vec<KeyParameter>& attestParams, 83 attestKey_cb _hidl_cb) override; 84 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade, 85 const hidl_vec<KeyParameter>& upgradeParams, 86 upgradeKey_cb _hidl_cb) override; 87 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override; 88 Return<ErrorCode> deleteAllKeys() override; 89 Return<ErrorCode> destroyAttestationIds() override; 90 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key, 91 const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken, 92 begin_cb _hidl_cb) override; 93 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, 94 const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken, 95 const VerificationToken& verificationToken, update_cb _hidl_cb) override; 96 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, 97 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature, 98 const HardwareAuthToken& authToken, 99 const VerificationToken& verificationToken, finish_cb _hidl_cb) override; 100 Return<ErrorCode> abort(uint64_t operationHandle) override; 101 102 protected: 103 std::unique_ptr<::keymaster::AndroidKeymaster> impl_; 104 SecurityLevel securityLevel_; 105 }; 106 107 // Convert HIDL key parametes to old keymaster param set. Note that this does *not* copy the blobs 108 // from keyParams, only pointers to them. The keyParams instance retains ownership and must 109 // continue to exist. 110 keymaster_key_param_set_t hidlKeyParams2Km(const hidl_vec<KeyParameter>& keyParams); 111 112 IKeymasterDevice* CreateKeymasterDevice(SecurityLevel securityLevel); 113 114 } // namespace ng 115 } // namespace V4_0 116 } // namespace keymaster 117 118 #endif // HIDL_android_hardware_keymaster_V4_0_AndroidKeymaster4Device_H_ 119