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