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