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