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 
18 #ifndef keymaster_V4_0_TrustyKeymaster4Device_H_
19 #define keymaster_V4_0_TrustyKeymaster4Device_H_
20 
21 #include <android/hardware/keymaster/4.0/IKeymasterDevice.h>
22 #include <hidl/Status.h>
23 #include <trusty_keymaster/TrustyKeymaster.h>
24 
25 namespace keymaster {
26 
27 namespace V4_0 {
28 
29 using ::android::sp;
30 using ::android::hardware::hidl_vec;
31 using ::android::hardware::Return;
32 using ::android::hardware::Void;
33 using ::android::hardware::keymaster::V4_0::ErrorCode;
34 using ::android::hardware::keymaster::V4_0::HardwareAuthenticatorType;
35 using ::android::hardware::keymaster::V4_0::HardwareAuthToken;
36 using ::android::hardware::keymaster::V4_0::HmacSharingParameters;
37 using ::android::hardware::keymaster::V4_0::IKeymasterDevice;
38 using ::android::hardware::keymaster::V4_0::KeyCharacteristics;
39 using ::android::hardware::keymaster::V4_0::KeyFormat;
40 using ::android::hardware::keymaster::V4_0::KeyParameter;
41 using ::android::hardware::keymaster::V4_0::KeyPurpose;
42 using ::android::hardware::keymaster::V4_0::SecurityLevel;
43 using ::android::hardware::keymaster::V4_0::Tag;
44 using ::android::hardware::keymaster::V4_0::VerificationToken;
45 
46 class TrustyKeymaster4Device : public IKeymasterDevice {
47   public:
48     explicit TrustyKeymaster4Device(TrustyKeymaster* impl);
49     virtual ~TrustyKeymaster4Device();
50 
51     Return<void> getHardwareInfo(getHardwareInfo_cb _hidl_cb) override;
52     Return<void> getHmacSharingParameters(getHmacSharingParameters_cb _hidl_cb) override;
53     Return<void> computeSharedHmac(const hidl_vec<HmacSharingParameters>& params,
54                                    computeSharedHmac_cb) override;
55     Return<void> verifyAuthorization(uint64_t challenge,
56                                      const hidl_vec<KeyParameter>& parametersToVerify,
57                                      const HardwareAuthToken& authToken,
58                                      verifyAuthorization_cb _hidl_cb) override;
59     Return<ErrorCode> addRngEntropy(const hidl_vec<uint8_t>& data) override;
60     Return<void> generateKey(const hidl_vec<KeyParameter>& keyParams,
61                              generateKey_cb _hidl_cb) override;
62     Return<void> getKeyCharacteristics(const hidl_vec<uint8_t>& keyBlob,
63                                        const hidl_vec<uint8_t>& clientId,
64                                        const hidl_vec<uint8_t>& appData,
65                                        getKeyCharacteristics_cb _hidl_cb) override;
66     Return<void> importKey(const hidl_vec<KeyParameter>& params, KeyFormat keyFormat,
67                            const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) override;
68     Return<void> importWrappedKey(const hidl_vec<uint8_t>& wrappedKeyData,
69                                   const hidl_vec<uint8_t>& wrappingKeyBlob,
70                                   const hidl_vec<uint8_t>& maskingKey,
71                                   const hidl_vec<KeyParameter>& unwrappingParams,
72                                   uint64_t passwordSid, uint64_t biometricSid,
73                                   importWrappedKey_cb _hidl_cb) override;
74     Return<void> exportKey(KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob,
75                            const hidl_vec<uint8_t>& clientId, const hidl_vec<uint8_t>& appData,
76                            exportKey_cb _hidl_cb) override;
77     Return<void> attestKey(const hidl_vec<uint8_t>& keyToAttest,
78                            const hidl_vec<KeyParameter>& attestParams,
79                            attestKey_cb _hidl_cb) override;
80     Return<void> upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade,
81                             const hidl_vec<KeyParameter>& upgradeParams,
82                             upgradeKey_cb _hidl_cb) override;
83     Return<ErrorCode> deleteKey(const hidl_vec<uint8_t>& keyBlob) override;
84     Return<ErrorCode> deleteAllKeys() override;
85     Return<ErrorCode> destroyAttestationIds() override;
86     Return<void> begin(KeyPurpose purpose, const hidl_vec<uint8_t>& key,
87                        const hidl_vec<KeyParameter>& inParams, const HardwareAuthToken& authToken,
88                        begin_cb _hidl_cb) override;
89     Return<void> update(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
90                         const hidl_vec<uint8_t>& input, const HardwareAuthToken& authToken,
91                         const VerificationToken& verificationToken, update_cb _hidl_cb) override;
92     Return<void> finish(uint64_t operationHandle, const hidl_vec<KeyParameter>& inParams,
93                         const hidl_vec<uint8_t>& input, const hidl_vec<uint8_t>& signature,
94                         const HardwareAuthToken& authToken,
95                         const VerificationToken& verificationToken, finish_cb _hidl_cb) override;
96     Return<ErrorCode> abort(uint64_t operationHandle) override;
97 
98   private:
99     std::unique_ptr<::keymaster::TrustyKeymaster> impl_;
100 };
101 
102 }  // namespace V4_0
103 }  // namespace keymaster
104 
105 #endif  // keymaster_V4_0_TrustyKeymaster4Device_H_
106