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