Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -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 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 18 | #ifndef KEYMASTER_3_DEVICE_WRAPPER_H_ |
| 19 | #define KEYMASTER_3_DEVICE_WRAPPER_H_ |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 20 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 21 | #include <android/hardware/keymaster/3.0/IKeymasterDevice.h> |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 22 | #include <keystore/keymaster_types.h> |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 23 | |
| 24 | #include "Keymaster.h" |
| 25 | |
| 26 | namespace keystore { |
| 27 | |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 28 | using IKeymaster3Device = ::android::hardware::keymaster::V3_0::IKeymasterDevice; |
| 29 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 30 | using ::android::sp; |
| 31 | using ::android::hardware::hidl_string; |
| 32 | using ::android::hardware::hidl_vec; |
| 33 | using ::android::hardware::Return; |
| 34 | using ::android::hardware::Void; |
| 35 | using ::android::hardware::details::return_status; |
| 36 | |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 37 | class Keymaster3 : public Keymaster { |
| 38 | public: |
Janis Danisevskis | c146014 | 2017-12-18 16:48:46 -0800 | [diff] [blame] | 39 | using WrappedIKeymasterDevice = IKeymaster3Device; |
| 40 | Keymaster3(sp<IKeymaster3Device> km3_dev) : km3_dev_(km3_dev), haveVersion_(false) {} |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 41 | |
| 42 | VersionResult halVersion() override; |
| 43 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 44 | Return<void> getHardwareInfo(getHardwareInfo_cb _hidl_cb); |
| 45 | |
| 46 | Return<void> getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb) override { |
| 47 | _hidl_cb(ErrorCode::UNIMPLEMENTED, {}); |
| 48 | return Void(); |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 51 | Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>&, |
| 52 | computeSharedHmac_cb _hidl_cb) override { |
| 53 | _hidl_cb(ErrorCode::UNIMPLEMENTED, {}); |
| 54 | return Void(); |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 57 | Return<void> verifyAuthorization(uint64_t, const hidl_vec<KeyParameter>&, |
| 58 | const HardwareAuthToken&, |
| 59 | verifyAuthorization_cb _hidl_cb) override { |
| 60 | _hidl_cb(ErrorCode::UNIMPLEMENTED, {}); |
| 61 | return Void(); |
| 62 | } |
| 63 | |
| 64 | Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 65 | Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 66 | generateKey_cb _hidl_cb) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 67 | Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob, |
| 68 | const hidl_vec<uint8_t>& clientId, |
| 69 | const hidl_vec<uint8_t>& appData, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 70 | getKeyCharacteristics_cb _hidl_cb) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 71 | Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 72 | const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override; |
| 73 | |
| 74 | Return<void> importWrappedKey(const hidl_vec<uint8_t>&, const hidl_vec<uint8_t>&, |
| 75 | const hidl_vec<uint8_t>&, importWrappedKey_cb _hidl_cb) { |
| 76 | _hidl_cb(ErrorCode::UNIMPLEMENTED, {}, {}); |
| 77 | return Void(); |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob, |
| 81 | const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 82 | exportKey_cb _hidl_cb) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 83 | Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest, |
| 84 | const hidl_vec<KeyParameter>& attestParams, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 85 | attestKey_cb _hidl_cb) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 86 | Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade, |
| 87 | const hidl_vec<KeyParameter>& upgradeParams, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 88 | upgradeKey_cb _hidl_cb) override; |
| 89 | Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override; |
| 90 | Return<ErrorCode> deleteAllKeys() override; |
| 91 | Return<ErrorCode> destroyAttestationIds() override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 92 | Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 93 | const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken, |
| 94 | begin_cb _hidl_cb) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 95 | Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 96 | const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken, |
| 97 | const VerificationToken& verificationToken, update_cb _hidl_cb) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 98 | Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams, |
| 99 | const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature, |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 100 | const HardwareAuthToken& authToken, |
| 101 | const VerificationToken& verificationToken, finish_cb _hidl_cb) override; |
| 102 | Return<ErrorCode> abort(uint64_t operationHandle) override; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 103 | |
| 104 | private: |
| 105 | void getVersionIfNeeded(); |
| 106 | |
| 107 | sp<IKeymaster3Device> km3_dev_; |
| 108 | |
Janis Danisevskis | c146014 | 2017-12-18 16:48:46 -0800 | [diff] [blame] | 109 | bool haveVersion_; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 110 | uint8_t majorVersion_; |
Janis Danisevskis | c146014 | 2017-12-18 16:48:46 -0800 | [diff] [blame] | 111 | SecurityLevel securityLevel_; |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 112 | bool supportsEllipticCurve_; |
| 113 | bool supportsSymmetricCryptography_; |
| 114 | bool supportsAttestation_; |
| 115 | bool supportsAllDigests_; |
| 116 | std::string keymasterName_; |
| 117 | std::string authorName_; |
| 118 | }; |
| 119 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 120 | sp<IKeymaster3Device> makeSoftwareKeymasterDevice(); |
| 121 | |
Shawn Willden | c67a8aa | 2017-12-03 17:51:29 -0700 | [diff] [blame] | 122 | } // namespace keystore |
| 123 | |
Shawn Willden | 0329a82 | 2017-12-04 13:55:14 -0700 | [diff] [blame] | 124 | #endif // KEYMASTER_3_DEVICE_WRAPPER_H_ |