/* ** Copyright 2020, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ #pragma once #include "Keymaster.h" namespace android::hardware::keymaster::V4_1::support { using android::sp; /** * This class can wrap either a V4_0 or V4_1 IKeymasterDevice. */ class Keymaster4 : public Keymaster { public: // This definition is used for device enumeration; enumerating 4.0 devices will also // enumerate 4.1. devices. using WrappedIKeymasterDevice = V4_0::IKeymasterDevice; Keymaster4(sp km4_0_dev, const hidl_string& instanceName) : Keymaster(V4_1::IKeymasterDevice::descriptor, instanceName), haveVersion_(false), km4_0_dev_(km4_0_dev), km4_1_dev_(V4_1::IKeymasterDevice::castFrom(km4_0_dev)) {} const VersionResult& halVersion() const override { const_cast(this)->getVersionIfNeeded(); return version_; } /********************************** * V4_0::IKeymasterDevice methods * *********************************/ Return getHardwareInfo(getHardwareInfo_cb _hidl_cb) override { return km4_0_dev_->getHardwareInfo(_hidl_cb); } Return getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb) override { return km4_0_dev_->getHmacSharingParameters(_hidl_cb); } Return computeSharedHmac(const hidl_vec& params, computeSharedHmac_cb _hidl_cb) override { return km4_0_dev_->computeSharedHmac(params, _hidl_cb); } Return verifyAuthorization(uint64_t operationHandle, const hidl_vec& params, const HardwareAuthToken& authToken, verifyAuthorization_cb _hidl_cb) override { return km4_0_dev_->verifyAuthorization(operationHandle, params, authToken, _hidl_cb); } Return addRngEntropy(const hidl_vec& data) override { return km4_0_dev_->addRngEntropy(data); } Return generateKey(const hidl_vec& keyParams, generateKey_cb _hidl_cb) override { return km4_0_dev_->generateKey(keyParams, _hidl_cb); } Return getKeyCharacteristics(const hidl_vec& keyBlob, const hidl_vec& clientId, const hidl_vec& appData, getKeyCharacteristics_cb _hidl_cb) override { return km4_0_dev_->getKeyCharacteristics(keyBlob, clientId, appData, _hidl_cb); } Return importKey(const hidl_vec& params, KeyFormat keyFormat, const hidl_vec& keyData, importKey_cb _hidl_cb) override { return km4_0_dev_->importKey(params, keyFormat, keyData, _hidl_cb); } Return importWrappedKey(const hidl_vec& wrappedKeyData, const hidl_vec& wrappingKeyBlob, const hidl_vec& maskingKey, const hidl_vec& unwrappingParams, uint64_t passwordSid, uint64_t biometricSid, importWrappedKey_cb _hidl_cb) { return km4_0_dev_->importWrappedKey(wrappedKeyData, wrappingKeyBlob, maskingKey, unwrappingParams, passwordSid, biometricSid, _hidl_cb); } Return exportKey(KeyFormat exportFormat, const hidl_vec& keyBlob, const hidl_vec& clientId, const hidl_vec& appData, exportKey_cb _hidl_cb) override { return km4_0_dev_->exportKey(exportFormat, keyBlob, clientId, appData, _hidl_cb); } Return attestKey(const hidl_vec& keyToAttest, const hidl_vec& attestParams, attestKey_cb _hidl_cb) override { return km4_0_dev_->attestKey(keyToAttest, attestParams, _hidl_cb); } Return upgradeKey(const hidl_vec& keyBlobToUpgrade, const hidl_vec& upgradeParams, upgradeKey_cb _hidl_cb) override { return km4_0_dev_->upgradeKey(keyBlobToUpgrade, upgradeParams, _hidl_cb); } Return deleteKey(const hidl_vec& keyBlob) override { return km4_0_dev_->deleteKey(keyBlob); } Return deleteAllKeys() override { return km4_0_dev_->deleteAllKeys(); } Return destroyAttestationIds() override { return km4_0_dev_->destroyAttestationIds(); } Return begin(KeyPurpose purpose, const hidl_vec& key, const hidl_vec& inParams, const HardwareAuthToken& authToken, begin_cb _hidl_cb) override { return km4_0_dev_->begin(purpose, key, inParams, authToken, _hidl_cb); } Return update(uint64_t operationHandle, const hidl_vec& inParams, const hidl_vec& input, const HardwareAuthToken& authToken, const VerificationToken& verificationToken, update_cb _hidl_cb) override { return km4_0_dev_->update(operationHandle, inParams, input, authToken, verificationToken, _hidl_cb); } Return finish(uint64_t operationHandle, const hidl_vec& inParams, const hidl_vec& input, const hidl_vec& signature, const HardwareAuthToken& authToken, const VerificationToken& verificationToken, finish_cb _hidl_cb) override { return km4_0_dev_->finish(operationHandle, inParams, input, signature, authToken, verificationToken, _hidl_cb); } Return abort(uint64_t operationHandle) override { return km4_0_dev_->abort(operationHandle); } /********************************** * V4_1::IKeymasterDevice methods * *********************************/ Return deviceLocked(bool passwordOnly, const VerificationToken& verificationToken) override { if (km4_1_dev_) return km4_1_dev_->deviceLocked(passwordOnly, verificationToken); return ErrorCode::UNIMPLEMENTED; } Return earlyBootEnded() override { if (km4_1_dev_) return km4_1_dev_->earlyBootEnded(); return ErrorCode::UNIMPLEMENTED; } private: void getVersionIfNeeded(); bool haveVersion_; VersionResult version_; sp km4_0_dev_; sp km4_1_dev_; }; // namespace android::hardware::keymaster::V4_1::support } // namespace android::hardware::keymaster::V4_1::support