blob: 172ab23bec228021a72820cf542ccdd103b48fbb [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:
Shawn Willden0329a822017-12-04 13:55:14 -070039 Keymaster3(sp<IKeymaster3Device> km3_dev) : km3_dev_(km3_dev) {}
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070040
41 VersionResult halVersion() override;
42
Shawn Willden0329a822017-12-04 13:55:14 -070043 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 Willdenc67a8aa2017-12-03 17:51:29 -070048 }
49
Shawn Willden0329a822017-12-04 13:55:14 -070050 Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>&,
51 computeSharedHmac_cb _hidl_cb) override {
52 _hidl_cb(ErrorCode::UNIMPLEMENTED, {});
53 return Void();
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070054 }
55
Shawn Willden0329a822017-12-04 13:55:14 -070056 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 Willdenc67a8aa2017-12-03 17:51:29 -070064 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
Shawn Willden0329a822017-12-04 13:55:14 -070065 generateKey_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070066 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
67 const hidl_vec<uint8_t>& clientId,
68 const hidl_vec<uint8_t>& appData,
Shawn Willden0329a822017-12-04 13:55:14 -070069 getKeyCharacteristics_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070070 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
Shawn Willden0329a822017-12-04 13:55:14 -070071 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 Willdenc67a8aa2017-12-03 17:51:29 -070077 }
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 Willden0329a822017-12-04 13:55:14 -070081 exportKey_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070082 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
83 const hidl_vec<KeyParameter>& attestParams,
Shawn Willden0329a822017-12-04 13:55:14 -070084 attestKey_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070085 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
86 const hidl_vec<KeyParameter>& upgradeParams,
Shawn Willden0329a822017-12-04 13:55:14 -070087 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 Willdenc67a8aa2017-12-03 17:51:29 -070091 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
Shawn Willden0329a822017-12-04 13:55:14 -070092 const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken,
93 begin_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070094 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
Shawn Willden0329a822017-12-04 13:55:14 -070095 const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken,
96 const VerificationToken& verificationToken, update_cb _hidl_cb) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -070097 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 Willden0329a822017-12-04 13:55:14 -070099 const HardwareAuthToken& authToken,
100 const VerificationToken& verificationToken, finish_cb _hidl_cb) override;
101 Return<ErrorCode> abort(uint64_t operationHandle) override;
Shawn Willdenc67a8aa2017-12-03 17:51:29 -0700102
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 Willden0329a822017-12-04 13:55:14 -0700119sp<IKeymaster3Device> makeSoftwareKeymasterDevice();
120
Shawn Willdenc67a8aa2017-12-03 17:51:29 -0700121} // namespace keystore
122
Shawn Willden0329a822017-12-04 13:55:14 -0700123#endif // KEYMASTER_3_DEVICE_WRAPPER_H_