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