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 HARDWARE_INTERFACES_KEYMASTER_40_SUPPORT_KEYMASTER_4_H_ 19 #define HARDWARE_INTERFACES_KEYMASTER_40_SUPPORT_KEYMASTER_4_H_ 20 21 #include "Keymaster.h" 22 23 namespace android { 24 namespace hardware { 25 namespace keymaster { 26 namespace V4_0 { 27 namespace support { 28 29 using android::sp; 30 using IKeymaster4Device = ::android::hardware::keymaster::V4_0::IKeymasterDevice; 31 32 class Keymaster4 : public Keymaster { 33 public: 34 using WrappedIKeymasterDevice = IKeymaster4Device; Keymaster4(sp<IKeymasterDevice> km4_dev,const hidl_string & instanceName)35 Keymaster4(sp<IKeymasterDevice> km4_dev, const hidl_string& instanceName) 36 : Keymaster(IKeymaster4Device::descriptor, instanceName), 37 haveVersion_(false), 38 dev_(km4_dev) {} 39 halVersion()40 const VersionResult& halVersion() const override { 41 const_cast<Keymaster4*>(this)->getVersionIfNeeded(); 42 return version_; 43 } 44 getHardwareInfo(getHardwareInfo_cb _hidl_cb)45 Return<void> getHardwareInfo(getHardwareInfo_cb _hidl_cb) override { 46 return dev_->getHardwareInfo(_hidl_cb); 47 } 48 getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb)49 Return<void> getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb) override { 50 return dev_->getHmacSharingParameters(_hidl_cb); 51 } 52 computeSharedHmac(const hidl_vec<HmacSharingParameters> & params,computeSharedHmac_cb _hidl_cb)53 Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>& params, 54 computeSharedHmac_cb _hidl_cb) override { 55 return dev_->computeSharedHmac(params, _hidl_cb); 56 } 57 verifyAuthorization(uint64_t operationHandle,const hidl_vec<KeyParameter> & params,const HardwareAuthToken & authToken,verifyAuthorization_cb _hidl_cb)58 Return<void> verifyAuthorization(uint64_t operationHandle, const hidl_vec<KeyParameter>& params, 59 const HardwareAuthToken& authToken, 60 verifyAuthorization_cb _hidl_cb) override { 61 return dev_->verifyAuthorization(operationHandle, params, authToken, _hidl_cb); 62 } 63 addRngEntropy(const hidl_vec<uint8_t> & data)64 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override { 65 return dev_->addRngEntropy(data); 66 } 67 generateKey(const hidl_vec<KeyParameter> & keyParams,generateKey_cb _hidl_cb)68 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams, 69 generateKey_cb _hidl_cb) override { 70 return dev_->generateKey(keyParams, _hidl_cb); 71 } 72 getKeyCharacteristics(const hidl_vec<uint8_t> & keyBlob,const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,getKeyCharacteristics_cb _hidl_cb)73 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob, 74 const hidl_vec<uint8_t>& clientId, 75 const hidl_vec<uint8_t>& appData, 76 getKeyCharacteristics_cb _hidl_cb) override { 77 return dev_->getKeyCharacteristics(keyBlob, clientId, appData, _hidl_cb); 78 } 79 importKey(const hidl_vec<KeyParameter> & params,KeyFormat keyFormat,const hidl_vec<uint8_t> & keyData,importKey_cb _hidl_cb)80 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat, 81 const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override { 82 return dev_->importKey(params, keyFormat, keyData, _hidl_cb); 83 } 84 importWrappedKey(const hidl_vec<uint8_t> & wrappedKeyData,const hidl_vec<uint8_t> & wrappingKeyBlob,const hidl_vec<uint8_t> & maskingKey,const hidl_vec<KeyParameter> & unwrappingParams,uint64_t passwordSid,uint64_t biometricSid,importWrappedKey_cb _hidl_cb)85 Return<void> importWrappedKey(const hidl_vec<uint8_t>& wrappedKeyData, 86 const hidl_vec<uint8_t>& wrappingKeyBlob, 87 const hidl_vec<uint8_t>& maskingKey, 88 const hidl_vec<KeyParameter>& unwrappingParams, 89 uint64_t passwordSid, uint64_t biometricSid, 90 importWrappedKey_cb _hidl_cb) { 91 return dev_->importWrappedKey(wrappedKeyData, wrappingKeyBlob, maskingKey, unwrappingParams, 92 passwordSid, biometricSid, _hidl_cb); 93 } 94 exportKey(KeyFormat exportFormat,const hidl_vec<uint8_t> & keyBlob,const hidl_vec<uint8_t> & clientId,const hidl_vec<uint8_t> & appData,exportKey_cb _hidl_cb)95 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob, 96 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData, 97 exportKey_cb _hidl_cb) override { 98 return dev_->exportKey(exportFormat, keyBlob, clientId, appData, _hidl_cb); 99 } 100 attestKey(const hidl_vec<uint8_t> & keyToAttest,const hidl_vec<KeyParameter> & attestParams,attestKey_cb _hidl_cb)101 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest, 102 const hidl_vec<KeyParameter>& attestParams, 103 attestKey_cb _hidl_cb) override { 104 return dev_->attestKey(keyToAttest, attestParams, _hidl_cb); 105 } 106 upgradeKey(const hidl_vec<uint8_t> & keyBlobToUpgrade,const hidl_vec<KeyParameter> & upgradeParams,upgradeKey_cb _hidl_cb)107 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade, 108 const hidl_vec<KeyParameter>& upgradeParams, 109 upgradeKey_cb _hidl_cb) override { 110 return dev_->upgradeKey(keyBlobToUpgrade, upgradeParams, _hidl_cb); 111 } 112 deleteKey(const hidl_vec<uint8_t> & keyBlob)113 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override { 114 return dev_->deleteKey(keyBlob); 115 } 116 deleteAllKeys()117 Return<ErrorCode> deleteAllKeys() override { return dev_->deleteAllKeys(); } 118 destroyAttestationIds()119 Return<ErrorCode> destroyAttestationIds() override { return dev_->destroyAttestationIds(); } 120 begin(KeyPurpose purpose,const hidl_vec<uint8_t> & key,const hidl_vec<KeyParameter> & inParams,const HardwareAuthToken & authToken,begin_cb _hidl_cb)121 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key, 122 const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken, 123 begin_cb _hidl_cb) override { 124 return dev_->begin(purpose, key, inParams, authToken, _hidl_cb); 125 } 126 update(uint64_t operationHandle,const hidl_vec<KeyParameter> & inParams,const hidl_vec<uint8_t> & input,const HardwareAuthToken & authToken,const VerificationToken & verificationToken,update_cb _hidl_cb)127 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, 128 const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken, 129 const VerificationToken& verificationToken, update_cb _hidl_cb) override { 130 return dev_->update(operationHandle, inParams, input, authToken, verificationToken, 131 _hidl_cb); 132 } 133 finish(uint64_t operationHandle,const hidl_vec<KeyParameter> & inParams,const hidl_vec<uint8_t> & input,const hidl_vec<uint8_t> & signature,const HardwareAuthToken & authToken,const VerificationToken & verificationToken,finish_cb _hidl_cb)134 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, 135 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature, 136 const HardwareAuthToken& authToken, 137 const VerificationToken& verificationToken, finish_cb _hidl_cb) override { 138 return dev_->finish(operationHandle, inParams, input, signature, authToken, 139 verificationToken, _hidl_cb); 140 } 141 abort(uint64_t operationHandle)142 Return<ErrorCode> abort(uint64_t operationHandle) override { 143 return dev_->abort(operationHandle); 144 } 145 146 private: 147 void getVersionIfNeeded(); 148 149 bool haveVersion_; 150 VersionResult version_; 151 sp<IKeymaster4Device> dev_; 152 }; 153 154 } // namespace support 155 } // namespace V4_0 156 } // namespace keymaster 157 } // namespace hardware 158 } // namespace android 159 160 #endif // HARDWARE_INTERFACES_KEYMASTER_40_SUPPORT_KEYMASTER_4_H_ 161