blob: 6d74a126274ac9f1514bb78d52f9825ac8f79cbd [file] [log] [blame]
Shawn Willdenc67a8aa2017-12-03 17:51:29 -07001/*
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 Willden0329a822017-12-04 13:55:14 -070018#ifndef KEYMASTER_3_DEVICE_WRAPPER_H_
19#define KEYMASTER_3_DEVICE_WRAPPER_H_
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070020
Shawn Willden0329a822017-12-04 13:55:14 -070021#include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070022#include <keystore/keymaster_types.h>
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070023
24#include "Keymaster.h"
25
26namespace keystore {
27
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070028using IKeymaster3Device = ::android::hardware::keymaster::V3_0::IKeymasterDevice;
29
Shawn Willden0329a822017-12-04 13:55:14 -070030using ::android::sp;
31using ::android::hardware::hidl_string;
32using ::android::hardware::hidl_vec;
33using ::android::hardware::Return;
34using ::android::hardware::Void;
35using ::android::hardware::details::return_status;
36
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070037class Keymaster3 : public Keymaster {
38 public:
Janis Danisevskisc1460142017-12-18 16:48:46 -080039 using WrappedIKeymasterDevice = IKeymaster3Device;
40 Keymaster3(sp<IKeymaster3Device> km3_dev) : km3_dev_(km3_dev), haveVersion_(false) {}
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070041
42 VersionResult halVersion() override;
43
Shawn Willden0329a822017-12-04 13:55:14 -070044 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 Willdenc67a8aa2017-12-03 17:51:29 -070049 }
50
Shawn Willden0329a822017-12-04 13:55:14 -070051 Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>&,
52 computeSharedHmac_cb _hidl_cb) override {
53 _hidl_cb(ErrorCode::UNIMPLEMENTED, {});
54 return Void();
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070055 }
56
Shawn Willden0329a822017-12-04 13:55:14 -070057 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 Willdenc67a8aa2017-12-03 17:51:29 -070065 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
Shawn Willden0329a822017-12-04 13:55:14 -070066 generateKey_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070067 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
68 const hidl_vec<uint8_t>& clientId,
69 const hidl_vec<uint8_t>& appData,
Shawn Willden0329a822017-12-04 13:55:14 -070070 getKeyCharacteristics_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070071 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
Shawn Willden0329a822017-12-04 13:55:14 -070072 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 Willdenc67a8aa2017-12-03 17:51:29 -070078 }
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 Willden0329a822017-12-04 13:55:14 -070082 exportKey_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070083 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
84 const hidl_vec<KeyParameter>& attestParams,
Shawn Willden0329a822017-12-04 13:55:14 -070085 attestKey_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070086 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
87 const hidl_vec<KeyParameter>& upgradeParams,
Shawn Willden0329a822017-12-04 13:55:14 -070088 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 Willdenc67a8aa2017-12-03 17:51:29 -070092 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
Shawn Willden0329a822017-12-04 13:55:14 -070093 const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken,
94 begin_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070095 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
Shawn Willden0329a822017-12-04 13:55:14 -070096 const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken,
97 const VerificationToken& verificationToken, update_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070098 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 Willden0329a822017-12-04 13:55:14 -0700100 const HardwareAuthToken& authToken,
101 const VerificationToken& verificationToken, finish_cb _hidl_cb) override;
102 Return<ErrorCode> abort(uint64_t operationHandle) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -0700103
104 private:
105 void getVersionIfNeeded();
106
107 sp<IKeymaster3Device> km3_dev_;
108
Janis Danisevskisc1460142017-12-18 16:48:46 -0800109 bool haveVersion_;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -0700110 uint8_t majorVersion_;
Janis Danisevskisc1460142017-12-18 16:48:46 -0800111 SecurityLevel securityLevel_;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -0700112 bool supportsEllipticCurve_;
113 bool supportsSymmetricCryptography_;
114 bool supportsAttestation_;
115 bool supportsAllDigests_;
116 std::string keymasterName_;
117 std::string authorName_;
118};
119
Shawn Willden0329a822017-12-04 13:55:14 -0700120sp<IKeymaster3Device> makeSoftwareKeymasterDevice();
121
Shawn Willdenc67a8aa2017-12-03 17:51:29 -0700122} // namespace keystore
123
Shawn Willden0329a822017-12-04 13:55:14 -0700124#endif // KEYMASTER_3_DEVICE_WRAPPER_H_