blob: 602dcaf6a0e056c140cf7dc2c73ab77c72229f9a [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();
Selene Huang31ab4042020-04-29 04:22:39 -070082
David Drysdale42fe1892021-10-14 14:43:46 +010083 bool Curve25519Supported();
84
Janis Danisevskis24c04702020-12-16 18:28:39 -080085 ErrorCode GetReturnErrorCode(const Status& result);
Selene Huang31ab4042020-04-29 04:22:39 -070086
Shawn Willden7c130392020-12-21 09:58:22 -070087 ErrorCode GenerateKey(const AuthorizationSet& key_desc, vector<uint8_t>* key_blob,
88 vector<KeyCharacteristics>* key_characteristics) {
89 return GenerateKey(key_desc, std::nullopt /* attest_key */, key_blob, key_characteristics,
90 &cert_chain_);
91 }
92 ErrorCode GenerateKey(const AuthorizationSet& key_desc,
93 const optional<AttestationKey>& attest_key, vector<uint8_t>* key_blob,
94 vector<KeyCharacteristics>* key_characteristics,
95 vector<Certificate>* cert_chain);
96 ErrorCode GenerateKey(const AuthorizationSet& key_desc,
97 const optional<AttestationKey>& attest_key = std::nullopt);
98
subrahmanyaman7d9bc462022-03-16 01:40:39 +000099 // Generate key for implementations which do not support factory attestation.
100 ErrorCode GenerateKeyWithSelfSignedAttestKey(const AuthorizationSet& attest_key_desc,
101 const AuthorizationSet& key_desc,
102 vector<uint8_t>* key_blob,
103 vector<KeyCharacteristics>* key_characteristics,
104 vector<Certificate>* cert_chain);
105
106 ErrorCode GenerateKeyWithSelfSignedAttestKey(const AuthorizationSet& attest_key_desc,
107 const AuthorizationSet& key_desc,
108 vector<uint8_t>* key_blob,
109 vector<KeyCharacteristics>* key_characteristics) {
110 return GenerateKeyWithSelfSignedAttestKey(attest_key_desc, key_desc, key_blob,
111 key_characteristics, &cert_chain_);
112 }
113
Selene Huang31ab4042020-04-29 04:22:39 -0700114 ErrorCode ImportKey(const AuthorizationSet& key_desc, KeyFormat format,
115 const string& key_material, vector<uint8_t>* key_blob,
Shawn Willden7f424372021-01-10 18:06:50 -0700116 vector<KeyCharacteristics>* key_characteristics);
Selene Huang31ab4042020-04-29 04:22:39 -0700117 ErrorCode ImportKey(const AuthorizationSet& key_desc, KeyFormat format,
118 const string& key_material);
119
120 ErrorCode ImportWrappedKey(string wrapped_key, string wrapping_key,
121 const AuthorizationSet& wrapping_key_desc, string masking_key,
David Drysdaled2cc8c22021-04-15 13:29:45 +0100122 const AuthorizationSet& unwrapping_params, int64_t password_sid,
123 int64_t biometric_sid);
124 ErrorCode ImportWrappedKey(string wrapped_key, string wrapping_key,
125 const AuthorizationSet& wrapping_key_desc, string masking_key,
126 const AuthorizationSet& unwrapping_params) {
127 return ImportWrappedKey(wrapped_key, wrapping_key, wrapping_key_desc, masking_key,
128 unwrapping_params, 0 /* password_sid */, 0 /* biometric_sid */);
129 }
Selene Huang31ab4042020-04-29 04:22:39 -0700130
David Drysdale300b5552021-05-20 12:05:26 +0100131 ErrorCode GetCharacteristics(const vector<uint8_t>& key_blob, const vector<uint8_t>& app_id,
132 const vector<uint8_t>& app_data,
133 vector<KeyCharacteristics>* key_characteristics);
134 ErrorCode GetCharacteristics(const vector<uint8_t>& key_blob,
135 vector<KeyCharacteristics>* key_characteristics);
136
137 void CheckCharacteristics(const vector<uint8_t>& key_blob,
138 const vector<KeyCharacteristics>& generate_characteristics);
139 void CheckAppIdCharacteristics(const vector<uint8_t>& key_blob, std::string_view app_id_string,
140 std::string_view app_data_string,
141 const vector<KeyCharacteristics>& generate_characteristics);
142
Selene Huang31ab4042020-04-29 04:22:39 -0700143 ErrorCode DeleteKey(vector<uint8_t>* key_blob, bool keep_key_blob = false);
144 ErrorCode DeleteKey(bool keep_key_blob = false);
145
146 ErrorCode DeleteAllKeys();
147
David Drysdaled2cc8c22021-04-15 13:29:45 +0100148 ErrorCode DestroyAttestationIds();
149
Selene Huang31ab4042020-04-29 04:22:39 -0700150 void CheckedDeleteKey(vector<uint8_t>* key_blob, bool keep_key_blob = false);
151 void CheckedDeleteKey();
152
153 ErrorCode Begin(KeyPurpose purpose, const vector<uint8_t>& key_blob,
154 const AuthorizationSet& in_params, AuthorizationSet* out_params,
Janis Danisevskis24c04702020-12-16 18:28:39 -0800155 std::shared_ptr<IKeyMintOperation>& op);
Selene Huang31ab4042020-04-29 04:22:39 -0700156 ErrorCode Begin(KeyPurpose purpose, const vector<uint8_t>& key_blob,
157 const AuthorizationSet& in_params, AuthorizationSet* out_params);
158 ErrorCode Begin(KeyPurpose purpose, const AuthorizationSet& in_params,
159 AuthorizationSet* out_params);
160 ErrorCode Begin(KeyPurpose purpose, const AuthorizationSet& in_params);
161
Shawn Willden92d79c02021-02-19 07:31:55 -0700162 ErrorCode UpdateAad(const string& input);
163 ErrorCode Update(const string& input, string* output);
Selene Huang31ab4042020-04-29 04:22:39 -0700164
Selene Huang31ab4042020-04-29 04:22:39 -0700165 ErrorCode Finish(const string& message, const string& signature, string* output);
Shawn Willden92d79c02021-02-19 07:31:55 -0700166 ErrorCode Finish(const string& message, string* output) {
167 return Finish(message, {} /* signature */, output);
168 }
169 ErrorCode Finish(string* output) { return Finish({} /* message */, output); }
Selene Huang31ab4042020-04-29 04:22:39 -0700170
171 ErrorCode Abort();
Janis Danisevskis24c04702020-12-16 18:28:39 -0800172 ErrorCode Abort(const shared_ptr<IKeyMintOperation>& op);
Selene Huang31ab4042020-04-29 04:22:39 -0700173 void AbortIfNeeded();
174
175 string ProcessMessage(const vector<uint8_t>& key_blob, KeyPurpose operation,
176 const string& message, const AuthorizationSet& in_params,
177 AuthorizationSet* out_params);
Shawn Willden92d79c02021-02-19 07:31:55 -0700178 std::tuple<ErrorCode, std::string /* processedMessage */> ProcessMessage(
179 const vector<uint8_t>& key_blob, KeyPurpose operation, const std::string& message,
180 const AuthorizationSet& in_params);
Selene Huang31ab4042020-04-29 04:22:39 -0700181 string SignMessage(const vector<uint8_t>& key_blob, const string& message,
182 const AuthorizationSet& params);
183 string SignMessage(const string& message, const AuthorizationSet& params);
184
185 string MacMessage(const string& message, Digest digest, size_t mac_length);
186
anil.hiranniah19a4ca12022-03-03 17:39:30 +0530187 void CheckAesIncrementalEncryptOperation(BlockMode block_mode, int message_size);
188
Selene Huang31ab4042020-04-29 04:22:39 -0700189 void CheckHmacTestVector(const string& key, const string& message, Digest digest,
190 const string& expected_mac);
191
192 void CheckAesCtrTestVector(const string& key, const string& nonce, const string& message,
193 const string& expected_ciphertext);
194
195 void CheckTripleDesTestVector(KeyPurpose purpose, BlockMode block_mode,
196 PaddingMode padding_mode, const string& key, const string& iv,
197 const string& input, const string& expected_output);
198
199 void VerifyMessage(const vector<uint8_t>& key_blob, const string& message,
200 const string& signature, const AuthorizationSet& params);
201 void VerifyMessage(const string& message, const string& signature,
202 const AuthorizationSet& params);
David Drysdaledf8f52e2021-05-06 08:10:58 +0100203 void LocalVerifyMessage(const string& message, const string& signature,
204 const AuthorizationSet& params);
Selene Huang31ab4042020-04-29 04:22:39 -0700205
David Drysdale59cae642021-05-12 13:52:03 +0100206 string LocalRsaEncryptMessage(const string& message, const AuthorizationSet& params);
Selene Huang31ab4042020-04-29 04:22:39 -0700207 string EncryptMessage(const vector<uint8_t>& key_blob, const string& message,
208 const AuthorizationSet& in_params, AuthorizationSet* out_params);
209 string EncryptMessage(const string& message, const AuthorizationSet& params,
210 AuthorizationSet* out_params);
211 string EncryptMessage(const string& message, const AuthorizationSet& params);
212 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding);
213 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
214 vector<uint8_t>* iv_out);
215 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
216 const vector<uint8_t>& iv_in);
217 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
218 uint8_t mac_length_bits, const vector<uint8_t>& iv_in);
David Drysdaled2cc8c22021-04-15 13:29:45 +0100219 string EncryptMessage(const string& message, BlockMode block_mode, PaddingMode padding,
220 uint8_t mac_length_bits);
Selene Huang31ab4042020-04-29 04:22:39 -0700221
222 string DecryptMessage(const vector<uint8_t>& key_blob, const string& ciphertext,
223 const AuthorizationSet& params);
224 string DecryptMessage(const string& ciphertext, const AuthorizationSet& params);
225 string DecryptMessage(const string& ciphertext, BlockMode block_mode, PaddingMode padding_mode,
226 const vector<uint8_t>& iv);
227
228 std::pair<ErrorCode, vector<uint8_t>> UpgradeKey(const vector<uint8_t>& key_blob);
229
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000230 template <typename TagType>
231 std::tuple<KeyData /* aesKey */, KeyData /* hmacKey */, KeyData /* rsaKey */,
232 KeyData /* ecdsaKey */>
David Drysdaleadfe6112021-05-27 12:00:53 +0100233 CreateTestKeys(
234 TagType tagToTest, ErrorCode expectedReturn,
235 std::function<void(AuthorizationSetBuilder*)> tagModifier =
236 [](AuthorizationSetBuilder*) {}) {
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000237 /* AES */
238 KeyData aesKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100239 AuthorizationSetBuilder aesBuilder = AuthorizationSetBuilder()
240 .AesEncryptionKey(128)
241 .Authorization(tagToTest)
242 .BlockMode(BlockMode::ECB)
243 .Padding(PaddingMode::NONE)
244 .Authorization(TAG_NO_AUTH_REQUIRED);
245 tagModifier(&aesBuilder);
246 ErrorCode errorCode =
247 GenerateKey(aesBuilder, &aesKeyData.blob, &aesKeyData.characteristics);
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000248 EXPECT_EQ(expectedReturn, errorCode);
249
250 /* HMAC */
251 KeyData hmacKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100252 AuthorizationSetBuilder hmacBuilder = AuthorizationSetBuilder()
253 .HmacKey(128)
254 .Authorization(tagToTest)
255 .Digest(Digest::SHA_2_256)
256 .Authorization(TAG_MIN_MAC_LENGTH, 128)
257 .Authorization(TAG_NO_AUTH_REQUIRED);
258 tagModifier(&hmacBuilder);
259 errorCode = GenerateKey(hmacBuilder, &hmacKeyData.blob, &hmacKeyData.characteristics);
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000260 EXPECT_EQ(expectedReturn, errorCode);
261
262 /* RSA */
263 KeyData rsaKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100264 AuthorizationSetBuilder rsaBuilder = AuthorizationSetBuilder()
265 .RsaSigningKey(2048, 65537)
266 .Authorization(tagToTest)
267 .Digest(Digest::NONE)
268 .Padding(PaddingMode::NONE)
269 .Authorization(TAG_NO_AUTH_REQUIRED)
270 .SetDefaultValidity();
271 tagModifier(&rsaBuilder);
272 errorCode = GenerateKey(rsaBuilder, &rsaKeyData.blob, &rsaKeyData.characteristics);
subrahmanyaman05642492022-02-05 07:10:56 +0000273 if (!(SecLevel() == SecurityLevel::STRONGBOX &&
274 ErrorCode::ATTESTATION_KEYS_NOT_PROVISIONED == errorCode)) {
275 EXPECT_EQ(expectedReturn, errorCode);
276 }
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000277
278 /* ECDSA */
279 KeyData ecdsaKeyData;
David Drysdaleadfe6112021-05-27 12:00:53 +0100280 AuthorizationSetBuilder ecdsaBuilder = AuthorizationSetBuilder()
David Drysdaledf09e542021-06-08 15:46:11 +0100281 .EcdsaSigningKey(EcCurve::P_256)
David Drysdaleadfe6112021-05-27 12:00:53 +0100282 .Authorization(tagToTest)
283 .Digest(Digest::SHA_2_256)
284 .Authorization(TAG_NO_AUTH_REQUIRED)
285 .SetDefaultValidity();
286 tagModifier(&ecdsaBuilder);
287 errorCode = GenerateKey(ecdsaBuilder, &ecdsaKeyData.blob, &ecdsaKeyData.characteristics);
subrahmanyaman05642492022-02-05 07:10:56 +0000288 if (!(SecLevel() == SecurityLevel::STRONGBOX &&
289 ErrorCode::ATTESTATION_KEYS_NOT_PROVISIONED == errorCode)) {
290 EXPECT_EQ(expectedReturn, errorCode);
291 }
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000292 return {aesKeyData, hmacKeyData, rsaKeyData, ecdsaKeyData};
293 }
Shawn Willden7f424372021-01-10 18:06:50 -0700294 bool IsSecure() const { return securityLevel_ != SecurityLevel::SOFTWARE; }
295 SecurityLevel SecLevel() const { return securityLevel_; }
Selene Huang31ab4042020-04-29 04:22:39 -0700296
297 vector<uint32_t> ValidKeySizes(Algorithm algorithm);
298 vector<uint32_t> InvalidKeySizes(Algorithm algorithm);
299
David Drysdale7de9feb2021-03-05 14:56:19 +0000300 vector<BlockMode> ValidBlockModes(Algorithm algorithm);
301 vector<PaddingMode> ValidPaddingModes(Algorithm algorithm, BlockMode blockMode);
302 vector<PaddingMode> InvalidPaddingModes(Algorithm algorithm, BlockMode blockMode);
303
Selene Huang31ab4042020-04-29 04:22:39 -0700304 vector<EcCurve> ValidCurves();
305 vector<EcCurve> InvalidCurves();
306
307 vector<Digest> ValidDigests(bool withNone, bool withMD5);
subrahmanyaman05642492022-02-05 07:10:56 +0000308 vector<uint64_t> ValidExponents();
Selene Huang31ab4042020-04-29 04:22:39 -0700309
310 static vector<string> build_params() {
Janis Danisevskis24c04702020-12-16 18:28:39 -0800311 auto params = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor);
Selene Huang31ab4042020-04-29 04:22:39 -0700312 return params;
313 }
314
Janis Danisevskis24c04702020-12-16 18:28:39 -0800315 std::shared_ptr<IKeyMintOperation> op_;
Shawn Willden7f424372021-01-10 18:06:50 -0700316 vector<Certificate> cert_chain_;
Selene Huang31ab4042020-04-29 04:22:39 -0700317 vector<uint8_t> key_blob_;
Shawn Willden7f424372021-01-10 18:06:50 -0700318 vector<KeyCharacteristics> key_characteristics_;
319
320 const vector<KeyParameter>& SecLevelAuthorizations(
321 const vector<KeyCharacteristics>& key_characteristics);
322 inline const vector<KeyParameter>& SecLevelAuthorizations() {
323 return SecLevelAuthorizations(key_characteristics_);
324 }
Qi Wubeefae42021-01-28 23:16:37 +0800325 const vector<KeyParameter>& SecLevelAuthorizations(
326 const vector<KeyCharacteristics>& key_characteristics, SecurityLevel securityLevel);
327
Chirag Pathak9ea6a0a2021-02-01 23:54:27 +0000328 ErrorCode UseAesKey(const vector<uint8_t>& aesKeyBlob);
329 ErrorCode UseHmacKey(const vector<uint8_t>& hmacKeyBlob);
330 ErrorCode UseRsaKey(const vector<uint8_t>& rsaKeyBlob);
331 ErrorCode UseEcdsaKey(const vector<uint8_t>& ecdsaKeyBlob);
Selene Huang31ab4042020-04-29 04:22:39 -0700332
Shawn Willdend659c7c2021-02-19 14:51:51 -0700333 protected:
Janis Danisevskis24c04702020-12-16 18:28:39 -0800334 std::shared_ptr<IKeyMintDevice> keymint_;
Selene Huang31ab4042020-04-29 04:22:39 -0700335 uint32_t os_version_;
336 uint32_t os_patch_level_;
David Drysdalebb3d85e2021-04-13 11:15:51 +0100337 uint32_t vendor_patch_level_;
David Drysdaled2cc8c22021-04-15 13:29:45 +0100338 bool timestamp_token_required_;
Selene Huang31ab4042020-04-29 04:22:39 -0700339
340 SecurityLevel securityLevel_;
341 string name_;
342 string author_;
343 long challenge_;
344};
345
David Drysdalea676c3b2021-06-14 14:46:02 +0100346// If the given property is available, add it to the tag set under the given tag ID.
347template <Tag tag>
348void add_tag_from_prop(AuthorizationSetBuilder* tags, TypedTag<TagType::BYTES, tag> ttag,
349 const char* prop) {
350 std::string prop_value = ::android::base::GetProperty(prop, /* default= */ "");
351 if (!prop_value.empty()) {
352 tags->Authorization(ttag, prop_value.data(), prop_value.size());
353 }
354}
355
Selene Huang6e46f142021-04-20 19:20:11 -0700356vector<uint8_t> build_serial_blob(const uint64_t serial_int);
357void verify_subject(const X509* cert, const string& subject, bool self_signed);
358void verify_serial(X509* cert, const uint64_t expected_serial);
359void verify_subject_and_serial(const Certificate& certificate, //
360 const uint64_t expected_serial, //
361 const string& subject, bool self_signed);
362
David Drysdale7dff4fc2021-12-10 10:10:52 +0000363bool verify_attestation_record(int aidl_version, //
364 const string& challenge, //
Shawn Willden7c130392020-12-21 09:58:22 -0700365 const string& app_id, //
366 AuthorizationSet expected_sw_enforced, //
367 AuthorizationSet expected_hw_enforced, //
368 SecurityLevel security_level,
David Drysdale565ccc72021-10-11 12:49:50 +0100369 const vector<uint8_t>& attestation_cert,
370 vector<uint8_t>* unique_id = nullptr);
Selene Huang6e46f142021-04-20 19:20:11 -0700371
Shawn Willden7c130392020-12-21 09:58:22 -0700372string bin2hex(const vector<uint8_t>& data);
373X509_Ptr parse_cert_blob(const vector<uint8_t>& blob);
David Drysdalef0d516d2021-03-22 07:51:43 +0000374vector<uint8_t> make_name_from_str(const string& name);
David Drysdale4dc01072021-04-01 12:17:35 +0100375void check_maced_pubkey(const MacedPublicKey& macedPubKey, bool testMode,
376 vector<uint8_t>* payload_value);
377void p256_pub_key(const vector<uint8_t>& coseKeyData, EVP_PKEY_Ptr* signingKey);
378
David Drysdalef0d516d2021-03-22 07:51:43 +0000379AuthorizationSet HwEnforcedAuthorizations(const vector<KeyCharacteristics>& key_characteristics);
380AuthorizationSet SwEnforcedAuthorizations(const vector<KeyCharacteristics>& key_characteristics);
Eran Messeri03d7a1a2021-07-06 12:07:57 +0100381::testing::AssertionResult ChainSignaturesAreValid(const vector<Certificate>& chain,
382 bool strict_issuer_check = true);
Shawn Willden7c130392020-12-21 09:58:22 -0700383
Selene Huang31ab4042020-04-29 04:22:39 -0700384#define INSTANTIATE_KEYMINT_AIDL_TEST(name) \
385 INSTANTIATE_TEST_SUITE_P(PerInstance, name, \
386 testing::ValuesIn(KeyMintAidlTestBase::build_params()), \
Shawn Willden7e71f1e2021-04-01 16:44:22 -0600387 ::android::PrintInstanceNameToString); \
388 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(name);
Selene Huang31ab4042020-04-29 04:22:39 -0700389
Shawn Willden0e80b5d2020-12-17 09:07:27 -0700390} // namespace test
391
392} // namespace aidl::android::hardware::security::keymint