blob: 3be01d7934effabe99169ad92248b4fb799671a2 [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
18#ifndef KEYSTORE_KEYMASTER_3_H_
19#define KEYSTORE_KEYMASTER_3_H_
20
21#include <keystore/keymaster_types.h>
22#include <utils/StrongPointer.h>
23
24#include "Keymaster.h"
25
26namespace keystore {
27
28using android::sp;
29using IKeymaster3Device = ::android::hardware::keymaster::V3_0::IKeymasterDevice;
30
31class Keymaster3 : public Keymaster {
32 public:
33 Keymaster3(sp<IKeymasterDevice> km3_dev) : km3_dev_(km3_dev) {}
34
35 VersionResult halVersion() override;
36
37 Return<void> getHardwareFeatures(getHardwareFeatures_cb _hidl_cb) override {
38 getVersionIfNeeded();
39 _hidl_cb(isSecure_, supportsEllipticCurve_, supportsSymmetricCryptography_,
40 supportsAttestation_, supportsAllDigests_,
41 keymasterName_ + " (wrapped by keystore::Keymaster3)", authorName_);
42 return android::hardware::Void();
43 }
44
45 Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override {
46 return km3_dev_->addRngEntropy(data);
47 }
48
49 Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
50 generateKey_cb _hidl_cb) override {
51 return km3_dev_->generateKey(keyParams, _hidl_cb);
52 }
53
54 Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
55 const hidl_vec<uint8_t>& clientId,
56 const hidl_vec<uint8_t>& appData,
57 getKeyCharacteristics_cb _hidl_cb) override {
58 return km3_dev_->getKeyCharacteristics(keyBlob, clientId, appData, _hidl_cb);
59 }
60
61 Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
62 const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override {
63 return km3_dev_->importKey(params, keyFormat, keyData, _hidl_cb);
64 }
65
66 Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
67 const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
68 exportKey_cb _hidl_cb) override {
69 return km3_dev_->exportKey(exportFormat, keyBlob, clientId, appData, _hidl_cb);
70 }
71
72 Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
73 const hidl_vec<KeyParameter>& attestParams,
74 attestKey_cb _hidl_cb) override {
75 return km3_dev_->attestKey(keyToAttest, attestParams, _hidl_cb);
76 }
77
78 Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
79 const hidl_vec<KeyParameter>& upgradeParams,
80 upgradeKey_cb _hidl_cb) override {
81 return km3_dev_->upgradeKey(keyBlobToUpgrade, upgradeParams, _hidl_cb);
82 }
83
84 Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override {
85 return km3_dev_->deleteKey(keyBlob);
86 }
87
88 Return<ErrorCode> deleteAllKeys() override { return km3_dev_->deleteAllKeys(); }
89
90 Return<ErrorCode> destroyAttestationIds() override { return km3_dev_->destroyAttestationIds(); }
91
92 Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
93 const hidl_vec<KeyParameter>& inParams, begin_cb _hidl_cb) override {
94 return km3_dev_->begin(purpose, key, inParams, _hidl_cb);
95 }
96
97 Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
98 const hidl_vec<uint8_t>& input, update_cb _hidl_cb) override {
99 return km3_dev_->update(operationHandle, inParams, input, _hidl_cb);
100 }
101
102 Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
103 const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
104 finish_cb _hidl_cb) override {
105 return km3_dev_->finish(operationHandle, inParams, input, signature, _hidl_cb);
106 }
107
108 Return<ErrorCode> abort(uint64_t operationHandle) override {
109 return km3_dev_->abort(operationHandle);
110 }
111
112 private:
113 void getVersionIfNeeded();
114
115 sp<IKeymaster3Device> km3_dev_;
116
117 bool haveVersion_ = false;
118 uint8_t majorVersion_;
119 bool isSecure_;
120 bool supportsEllipticCurve_;
121 bool supportsSymmetricCryptography_;
122 bool supportsAttestation_;
123 bool supportsAllDigests_;
124 std::string keymasterName_;
125 std::string authorName_;
126};
127
128} // namespace keystore
129
130#endif // KEYSTORE_KEYMASTER_3_H_