blob: 7279c9569249a7c38df3b8fe09642250f79c12f7 [file] [log] [blame]
Selene Huang31ab4042020-04-29 04:22:39 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Selene Huang31ab4042020-04-29 04:22:39 -070017#pragma once
18
David Drysdaleadfe6112021-05-27 12:00:53 +010019#include <functional>
David Drysdale300b5552021-05-20 12:05:26 +010020#include <string_view>
21
Selene Huang31ab4042020-04-29 04:22:39 -070022#include <aidl/Gtest.h>
23#include <aidl/Vintf.h>
David Drysdalea676c3b2021-06-14 14:46:02 +010024#include <android-base/properties.h>
Selene Huang31ab4042020-04-29 04:22:39 -070025#include <binder/IServiceManager.h>
26#include <binder/ProcessState.h>
27#include <gtest/gtest.h>
Shawn Willden7c130392020-12-21 09:58:22 -070028#include <openssl/x509.h>
Selene Huang31ab4042020-04-29 04:22:39 -070029
Janis Danisevskis24c04702020-12-16 18:28:39 -080030#include <aidl/android/hardware/security/keymint/ErrorCode.h>
31#include <aidl/android/hardware/security/keymint/IKeyMintDevice.h>
David Drysdale4dc01072021-04-01 12:17:35 +010032#include <aidl/android/hardware/security/keymint/MacedPublicKey.h>
Shawn Willden1d3f85e2020-12-09 14:18:44 -070033
Shawn Willden08a7e432020-12-11 13:05:27 +000034#include <keymint_support/authorization_set.h>
Shawn Willden7c130392020-12-21 09:58:22 -070035#include <keymint_support/openssl_utils.h>
Selene Huang31ab4042020-04-29 04:22:39 -070036
Shawn Willden0e80b5d2020-12-17 09:07:27 -070037namespace aidl::android::hardware::security::keymint {
38
39::std::ostream& operator<<(::std::ostream& os, const AuthorizationSet& set);
40
Shawn Willden7c130392020-12-21 09:58:22 -070041inline bool operator==(const keymint::AuthorizationSet& a, const keymint::AuthorizationSet& b) {
42 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
43}
44
Shawn Willden0e80b5d2020-12-17 09:07:27 -070045namespace test {
Selene Huang31ab4042020-04-29 04:22:39 -070046
47using ::android::sp;
Janis Danisevskis24c04702020-12-16 18:28:39 -080048using Status = ::ndk::ScopedAStatus;
Shawn Willden7c130392020-12-21 09:58:22 -070049using ::std::optional;
Selene Huang31ab4042020-04-29 04:22:39 -070050using ::std::shared_ptr;
51using ::std::string;
52using ::std::vector;
53
54constexpr uint64_t kOpHandleSentinel = 0xFFFFFFFFFFFFFFFF;
55
Selene Huang31ab4042020-04-29 04:22:39 -070056class KeyMintAidlTestBase : public ::testing::TestWithParam<string> {
57 public:
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +000058 struct KeyData {
59 vector<uint8_t> blob;
60 vector<KeyCharacteristics> characteristics;
61 };
62
Shawn Willden7c130392020-12-21 09:58:22 -070063 static bool arm_deleteAllKeys;
64 static bool dump_Attestations;
65
Selene Huang31ab4042020-04-29 04:22:39 -070066 void SetUp() override;
67 void TearDown() override {
68 if (key_blob_.size()) {
69 CheckedDeleteKey();
70 }
71 AbortIfNeeded();
72 }
73
Janis Danisevskis24c04702020-12-16 18:28:39 -080074 void InitializeKeyMint(std::shared_ptr<IKeyMintDevice> keyMint);
Selene Huang31ab4042020-04-29 04:22:39 -070075 IKeyMintDevice& keyMint() { return *keymint_; }
David Drysdale7dff4fc2021-12-10 10:10:52 +000076 int32_t AidlVersion();
Selene Huang31ab4042020-04-29 04:22:39 -070077 uint32_t os_version() { return os_version_; }
78 uint32_t os_patch_level() { return os_patch_level_; }
David Drysdalebb3d85e2021-04-13 11:15:51 +010079 uint32_t vendor_patch_level() { return vendor_patch_level_; }
David Drysdale37af4b32021-05-14 16:46:59 +010080 uint32_t boot_patch_level(const vector<KeyCharacteristics>& key_characteristics);
81 uint32_t boot_patch_level();
Prashant Patil88ad1892022-03-15 16:31:02 +000082 bool isDeviceIdAttestationRequired();
Selene Huang31ab4042020-04-29 04:22:39 -070083
David Drysdale42fe1892021-10-14 14:43:46 +010084 bool Curve25519Supported();
85
Janis Danisevskis24c04702020-12-16 18:28:39 -080086 ErrorCode GetReturnErrorCode(const Status& result);
Selene Huang31ab4042020-04-29 04:22:39 -070087
Shawn Willden7c130392020-12-21 09:58:22 -070088 ErrorCode GenerateKey(const AuthorizationSet& key_desc, vector<uint8_t>* key_blob,
89 vector<KeyCharacteristics>* key_characteristics) {
90 return GenerateKey(key_desc, std::nullopt /* attest_key */, key_blob, key_characteristics,
91 &cert_chain_);
92 }
93 ErrorCode GenerateKey(const AuthorizationSet& key_desc,
94 const optional<AttestationKey>& attest_key, vector<uint8_t>* key_blob,
95 vector<KeyCharacteristics>* key_characteristics,
96 vector<Certificate>* cert_chain);
97 ErrorCode GenerateKey(const AuthorizationSet& key_desc,
98 const optional<AttestationKey>& attest_key = std::nullopt);
99
subrahmanyaman7d9bc462022-03-16 01:40:39 +0000100 // Generate key for implementations which do not support factory attestation.
101 ErrorCode GenerateKeyWithSelfSignedAttestKey(const AuthorizationSet& attest_key_desc,
102 const AuthorizationSet& key_desc,
103 vector<uint8_t>* key_blob,
104 vector<KeyCharacteristics>* key_characteristics,
105 vector<Certificate>* cert_chain);
106
107 ErrorCode GenerateKeyWithSelfSignedAttestKey(const AuthorizationSet& attest_key_desc,
108 const AuthorizationSet& key_desc,
109 vector<uint8_t>* key_blob,
110 vector<KeyCharacteristics>* key_characteristics) {
111 return GenerateKeyWithSelfSignedAttestKey(attest_key_desc, key_desc, key_blob,
112 key_characteristics, &cert_chain_);
113 }
114
Selene Huang31ab4042020-04-29 04:22:39 -0700115 ErrorCode ImportKey(const AuthorizationSet& key_desc, KeyFormat format,
116 const string& key_material, vector<uint8_t>* key_blob,
Shawn Willden7f424372021-01-10 18:06:50 -0700117 vector<KeyCharacteristics>* key_characteristics);
Selene Huang31ab4042020-04-29 04:22:39 -0700118 ErrorCode ImportKey(const AuthorizationSet& key_desc, KeyFormat format,
119 const string& key_material);
120
121 ErrorCode ImportWrappedKey(string wrapped_key, string wrapping_key,
122 const AuthorizationSet& wrapping_key_desc, string masking_key,
David Drysdaled2cc8c22021-04-15 13:29:45 +0100123 const AuthorizationSet& unwrapping_params, int64_t password_sid,
124 int64_t biometric_sid);
125 ErrorCode ImportWrappedKey(string wrapped_key, string wrapping_key,
126 const AuthorizationSet& wrapping_key_desc, string masking_key,
127 const AuthorizationSet& unwrapping_params) {
128 return ImportWrappedKey(wrapped_key, wrapping_key, wrapping_key_desc, masking_key,
129 unwrapping_params, 0 /* password_sid */, 0 /* biometric_sid */);
130 }
Selene Huang31ab4042020-04-29 04:22:39 -0700131
David Drysdale300b5552021-05-20 12:05:26 +0100132 ErrorCode GetCharacteristics(const vector<uint8_t>& key_blob, const vector<uint8_t>& app_id,
133 const vector<uint8_t>& app_data,
134 vector<KeyCharacteristics>* key_characteristics);
135 ErrorCode GetCharacteristics(const vector<uint8_t>& key_blob,
136 vector<KeyCharacteristics>* key_characteristics);
137
138 void CheckCharacteristics(const vector<uint8_t>& key_blob,
139 const vector<KeyCharacteristics>& generate_characteristics);
140 void CheckAppIdCharacteristics(const vector<uint8_t>& key_blob, std::string_view app_id_string,
141 std::string_view app_data_string,
142 const vector<KeyCharacteristics>& generate_characteristics);
143
Selene Huang31ab4042020-04-29 04:22:39 -0700144 ErrorCode DeleteKey(vector<uint8_t>* key_blob, bool keep_key_blob = false);
145 ErrorCode DeleteKey(bool keep_key_blob = false);
146
147 ErrorCode DeleteAllKeys();
148
David Drysdaled2cc8c22021-04-15 13:29:45 +0100149 ErrorCode DestroyAttestationIds();
150
Selene Huang31ab4042020-04-29 04:22:39 -0700151 void CheckedDeleteKey(vector<uint8_t>* key_blob, bool keep_key_blob = false);
152 void CheckedDeleteKey();
153
154 ErrorCode Begin(KeyPurpose purpose, const vector<uint8_t>& key_blob,
155 const AuthorizationSet& in_params, AuthorizationSet* out_params,
Janis Danisevskis24c04702020-12-16 18:28:39 -0800156 std::shared_ptr<IKeyMintOperation>& op);
Selene Huang31ab4042020-04-29 04:22:39 -0700157 ErrorCode Begin(KeyPurpose purpose, const vector<uint8_t>& key_blob,
158 const AuthorizationSet& in_params, AuthorizationSet* out_params);
159 ErrorCode Begin(KeyPurpose purpose, const AuthorizationSet& in_params,
160 AuthorizationSet* out_params);
161 ErrorCode Begin(KeyPurpose purpose, const AuthorizationSet& in_params);
162
Shawn Willden92d79c02021-02-19 07:31:55 -0700163 ErrorCode UpdateAad(const string& input);
164 ErrorCode Update(const string& input, string* output);
Selene Huang31ab4042020-04-29 04:22:39 -0700165
Selene Huang31ab4042020-04-29 04:22:39 -0700166 ErrorCode Finish(const string& message, const string& signature, string* output);
Shawn Willden92d79c02021-02-19 07:31:55 -0700167 ErrorCode Finish(const string& message, string* output) {
168 return Finish(message, {} /* signature */, output);
169 }
170 ErrorCode Finish(string* output) { return Finish({} /* message */, output); }
Selene Huang31ab4042020-04-29 04:22:39 -0700171
172 ErrorCode Abort();
Janis Danisevskis24c04702020-12-16 18:28:39 -0800173 ErrorCode Abort(const shared_ptr<IKeyMintOperation>& op);
Selene Huang31ab4042020-04-29 04:22:39 -0700174 void AbortIfNeeded();
175
176 string ProcessMessage(const vector<uint8_t>& key_blob, KeyPurpose operation,
177 const string& message, const AuthorizationSet& in_params,
178 AuthorizationSet* out_params);
Shawn Willden92d79c02021-02-19 07:31:55 -0700179 std::tuple<ErrorCode, std::string /* processedMessage */> ProcessMessage(
180 const vector<uint8_t>& key_blob, KeyPurpose operation, const std::string& message,
181 const AuthorizationSet& in_params);
Selene Huang31ab4042020-04-29 04:22:39 -0700182 string SignMessage(const vector<uint8_t>& key_blob, const string& message,
183 const AuthorizationSet& params);
184 string SignMessage(const string& message, const AuthorizationSet& params);
185
186 string MacMessage(const string& message, Digest digest, size_t mac_length);
187
anil.hiranniah19a4ca12022-03-03 17:39:30 +0530188 void CheckAesIncrementalEncryptOperation(BlockMode block_mode, int message_size);
189
Selene Huang31ab4042020-04-29 04:22:39 -0700190 void CheckHmacTestVector(const string& key, const string& message, Digest digest,
191 const string& expected_mac);
192
193 void CheckAesCtrTestVector(const string& key, const string& nonce, const string& message,
194 const string& expected_ciphertext);
195
196 void CheckTripleDesTestVector(KeyPurpose purpose, BlockMode block_mode,
197 PaddingMode padding_mode, const string& key, const string& iv,
198 const string& input, const string& expected_output);
199
200 void VerifyMessage(const vector<uint8_t>& key_blob, const string& message,
201 const string& signature, const AuthorizationSet& params);
202 void VerifyMessage(const string& message, const string& signature,
203 const AuthorizationSet& params);
David Drysdaledf8f52e2021-05-06 08:10:58 +0100204 void LocalVerifyMessage(const string& message, const string& signature,
205 const AuthorizationSet& params);
Selene Huang31ab4042020-04-29 04:22:39 -0700206
David Drysdale59cae642021-05-12 13:52:03 +0100207 string LocalRsaEncryptMessage(const string& message, const AuthorizationSet& params);
Selene Huang31ab4042020-04-29 04:22:39 -0700208 string EncryptMessage(const vector<uint8_t>& key_blob, const string& message,
209 const AuthorizationSet& in_params, AuthorizationSet* out_params);
210 string EncryptMessage(const string& message, const AuthorizationSet& params,
211 AuthorizationSet* out_params);
212 string EncryptMessage(const string& message, const AuthorizationSet& params);
213 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding);
214 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
215 vector<uint8_t>* iv_out);
216 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
217 const vector<uint8_t>& iv_in);
218 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
219 uint8_t mac_length_bits, const vector<uint8_t>& iv_in);
David Drysdaled2cc8c22021-04-15 13:29:45 +0100220 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
221 uint8_t mac_length_bits);
Selene Huang31ab4042020-04-29 04:22:39 -0700222
223 string DecryptMessage(const vector<uint8_t>& key_blob, const string& ciphertext,
224 const AuthorizationSet& params);
225 string DecryptMessage(const string& ciphertext, const AuthorizationSet& params);
226 string DecryptMessage(const string& ciphertext, BlockMode block_mode, PaddingMode padding_mode,
227 const vector<uint8_t>& iv);
228
229 std::pair<ErrorCode, vector<uint8_t>> UpgradeKey(const vector<uint8_t>& key_blob);
230
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000231 template <typename TagType>
232 std::tuple<KeyData /* aesKey */, KeyData /* hmacKey */, KeyData /* rsaKey */,
233 KeyData /* ecdsaKey */>
David Drysdaleadfe6112021-05-27 12:00:53 +0100234 CreateTestKeys(
235 TagType tagToTest, ErrorCode expectedReturn,
236 std::function<void(AuthorizationSetBuilder*)> tagModifier =
237 [](AuthorizationSetBuilder*) {}) {
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000238 /* AES */
239 KeyData aesKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100240 AuthorizationSetBuilder aesBuilder = AuthorizationSetBuilder()
241 .AesEncryptionKey(128)
242 .Authorization(tagToTest)
243 .BlockMode(BlockMode::ECB)
244 .Padding(PaddingMode::NONE)
245 .Authorization(TAG_NO_AUTH_REQUIRED);
246 tagModifier(&aesBuilder);
247 ErrorCode errorCode =
248 GenerateKey(aesBuilder, &aesKeyData.blob, &aesKeyData.characteristics);
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000249 EXPECT_EQ(expectedReturn, errorCode);
250
251 /* HMAC */
252 KeyData hmacKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100253 AuthorizationSetBuilder hmacBuilder = AuthorizationSetBuilder()
254 .HmacKey(128)
255 .Authorization(tagToTest)
256 .Digest(Digest::SHA_2_256)
257 .Authorization(TAG_MIN_MAC_LENGTH, 128)
258 .Authorization(TAG_NO_AUTH_REQUIRED);
259 tagModifier(&hmacBuilder);
260 errorCode = GenerateKey(hmacBuilder, &hmacKeyData.blob, &hmacKeyData.characteristics);
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000261 EXPECT_EQ(expectedReturn, errorCode);
262
263 /* RSA */
264 KeyData rsaKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100265 AuthorizationSetBuilder rsaBuilder = AuthorizationSetBuilder()
266 .RsaSigningKey(2048, 65537)
267 .Authorization(tagToTest)
268 .Digest(Digest::NONE)
269 .Padding(PaddingMode::NONE)
270 .Authorization(TAG_NO_AUTH_REQUIRED)
271 .SetDefaultValidity();
272 tagModifier(&rsaBuilder);
273 errorCode = GenerateKey(rsaBuilder, &rsaKeyData.blob, &rsaKeyData.characteristics);
subrahmanyaman05642492022-02-05 07:10:56 +0000274 if (!(SecLevel() == SecurityLevel::STRONGBOX &&
275 ErrorCode::ATTESTATION_KEYS_NOT_PROVISIONED == errorCode)) {
276 EXPECT_EQ(expectedReturn, errorCode);
277 }
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000278
279 /* ECDSA */
280 KeyData ecdsaKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100281 AuthorizationSetBuilder ecdsaBuilder = AuthorizationSetBuilder()
David Drysdaledf09e542021-06-08 15:46:11 +0100282 .EcdsaSigningKey(EcCurve::P_256)
David Drysdaleadfe6112021-05-27 12:00:53 +0100283 .Authorization(tagToTest)
284 .Digest(Digest::SHA_2_256)
285 .Authorization(TAG_NO_AUTH_REQUIRED)
286 .SetDefaultValidity();
287 tagModifier(&ecdsaBuilder);
288 errorCode = GenerateKey(ecdsaBuilder, &ecdsaKeyData.blob, &ecdsaKeyData.characteristics);
subrahmanyaman05642492022-02-05 07:10:56 +0000289 if (!(SecLevel() == SecurityLevel::STRONGBOX &&
290 ErrorCode::ATTESTATION_KEYS_NOT_PROVISIONED == errorCode)) {
291 EXPECT_EQ(expectedReturn, errorCode);
292 }
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000293 return {aesKeyData, hmacKeyData, rsaKeyData, ecdsaKeyData};
294 }
Shawn Willden7f424372021-01-10 18:06:50 -0700295 bool IsSecure() const { return securityLevel_ != SecurityLevel::SOFTWARE; }
296 SecurityLevel SecLevel() const { return securityLevel_; }
Selene Huang31ab4042020-04-29 04:22:39 -0700297
298 vector<uint32_t> ValidKeySizes(Algorithm algorithm);
299 vector<uint32_t> InvalidKeySizes(Algorithm algorithm);
300
David Drysdale7de9feb2021-03-05 14:56:19 +0000301 vector<BlockMode> ValidBlockModes(Algorithm algorithm);
302 vector<PaddingMode> ValidPaddingModes(Algorithm algorithm, BlockMode blockMode);
303 vector<PaddingMode> InvalidPaddingModes(Algorithm algorithm, BlockMode blockMode);
304
Selene Huang31ab4042020-04-29 04:22:39 -0700305 vector<EcCurve> ValidCurves();
306 vector<EcCurve> InvalidCurves();
307
308 vector<Digest> ValidDigests(bool withNone, bool withMD5);
subrahmanyaman05642492022-02-05 07:10:56 +0000309 vector<uint64_t> ValidExponents();
Selene Huang31ab4042020-04-29 04:22:39 -0700310
311 static vector<string> build_params() {
Janis Danisevskis24c04702020-12-16 18:28:39 -0800312 auto params = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor);
Selene Huang31ab4042020-04-29 04:22:39 -0700313 return params;
314 }
315
Janis Danisevskis24c04702020-12-16 18:28:39 -0800316 std::shared_ptr<IKeyMintOperation> op_;
Shawn Willden7f424372021-01-10 18:06:50 -0700317 vector<Certificate> cert_chain_;
Selene Huang31ab4042020-04-29 04:22:39 -0700318 vector<uint8_t> key_blob_;
Shawn Willden7f424372021-01-10 18:06:50 -0700319 vector<KeyCharacteristics> key_characteristics_;
320
321 const vector<KeyParameter>& SecLevelAuthorizations(
322 const vector<KeyCharacteristics>& key_characteristics);
323 inline const vector<KeyParameter>& SecLevelAuthorizations() {
324 return SecLevelAuthorizations(key_characteristics_);
325 }
Qi Wubeefae42021-01-28 23:16:37 +0800326 const vector<KeyParameter>& SecLevelAuthorizations(
327 const vector<KeyCharacteristics>& key_characteristics, SecurityLevel securityLevel);
328
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000329 ErrorCode UseAesKey(const vector<uint8_t>& aesKeyBlob);
330 ErrorCode UseHmacKey(const vector<uint8_t>& hmacKeyBlob);
331 ErrorCode UseRsaKey(const vector<uint8_t>& rsaKeyBlob);
332 ErrorCode UseEcdsaKey(const vector<uint8_t>& ecdsaKeyBlob);
Selene Huang31ab4042020-04-29 04:22:39 -0700333
Shawn Willdend659c7c2021-02-19 14:51:51 -0700334 protected:
Janis Danisevskis24c04702020-12-16 18:28:39 -0800335 std::shared_ptr<IKeyMintDevice> keymint_;
Selene Huang31ab4042020-04-29 04:22:39 -0700336 uint32_t os_version_;
337 uint32_t os_patch_level_;
David Drysdalebb3d85e2021-04-13 11:15:51 +0100338 uint32_t vendor_patch_level_;
David Drysdaled2cc8c22021-04-15 13:29:45 +0100339 bool timestamp_token_required_;
Selene Huang31ab4042020-04-29 04:22:39 -0700340
341 SecurityLevel securityLevel_;
342 string name_;
343 string author_;
344 long challenge_;
345};
346
David Drysdalea676c3b2021-06-14 14:46:02 +0100347// If the given property is available, add it to the tag set under the given tag ID.
348template <Tag tag>
349void add_tag_from_prop(AuthorizationSetBuilder* tags, TypedTag<TagType::BYTES, tag> ttag,
350 const char* prop) {
351 std::string prop_value = ::android::base::GetProperty(prop, /* default= */ "");
352 if (!prop_value.empty()) {
353 tags->Authorization(ttag, prop_value.data(), prop_value.size());
354 }
355}
356
Selene Huang6e46f142021-04-20 19:20:11 -0700357vector<uint8_t> build_serial_blob(const uint64_t serial_int);
358void verify_subject(const X509* cert, const string& subject, bool self_signed);
359void verify_serial(X509* cert, const uint64_t expected_serial);
360void verify_subject_and_serial(const Certificate& certificate, //
361 const uint64_t expected_serial, //
362 const string& subject, bool self_signed);
363
David Drysdale7dff4fc2021-12-10 10:10:52 +0000364bool verify_attestation_record(int aidl_version, //
365 const string& challenge, //
Shawn Willden7c130392020-12-21 09:58:22 -0700366 const string& app_id, //
367 AuthorizationSet expected_sw_enforced, //
368 AuthorizationSet expected_hw_enforced, //
369 SecurityLevel security_level,
David Drysdale565ccc72021-10-11 12:49:50 +0100370 const vector<uint8_t>& attestation_cert,
371 vector<uint8_t>* unique_id = nullptr);
Selene Huang6e46f142021-04-20 19:20:11 -0700372
Shawn Willden7c130392020-12-21 09:58:22 -0700373string bin2hex(const vector<uint8_t>& data);
374X509_Ptr parse_cert_blob(const vector<uint8_t>& blob);
David Drysdalef0d516d2021-03-22 07:51:43 +0000375vector<uint8_t> make_name_from_str(const string& name);
David Drysdale4dc01072021-04-01 12:17:35 +0100376void check_maced_pubkey(const MacedPublicKey& macedPubKey, bool testMode,
377 vector<uint8_t>* payload_value);
378void p256_pub_key(const vector<uint8_t>& coseKeyData, EVP_PKEY_Ptr* signingKey);
379
David Drysdalef0d516d2021-03-22 07:51:43 +0000380AuthorizationSet HwEnforcedAuthorizations(const vector<KeyCharacteristics>& key_characteristics);
381AuthorizationSet SwEnforcedAuthorizations(const vector<KeyCharacteristics>& key_characteristics);
Eran Messeri03d7a1a2021-07-06 12:07:57 +0100382::testing::AssertionResult ChainSignaturesAreValid(const vector<Certificate>& chain,
383 bool strict_issuer_check = true);
Shawn Willden7c130392020-12-21 09:58:22 -0700384
Selene Huang31ab4042020-04-29 04:22:39 -0700385#define INSTANTIATE_KEYMINT_AIDL_TEST(name) \
386 INSTANTIATE_TEST_SUITE_P(PerInstance, name, \
387 testing::ValuesIn(KeyMintAidlTestBase::build_params()), \
Shawn Willden7e71f1e2021-04-01 16:44:22 -0600388 ::android::PrintInstanceNameToString); \
389 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(name);
Selene Huang31ab4042020-04-29 04:22:39 -0700390
Shawn Willden0e80b5d2020-12-17 09:07:27 -0700391} // namespace test
392
393} // namespace aidl::android::hardware::security::keymint