David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | |
| 17 | #define LOG_TAG "FakeSecureHardwareProxy" |
| 18 | |
| 19 | #include "FakeSecureHardwareProxy.h" |
| 20 | |
| 21 | #include <android/hardware/identity/support/IdentityCredentialSupport.h> |
| 22 | |
| 23 | #include <android-base/logging.h> |
| 24 | #include <android-base/stringprintf.h> |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include <openssl/sha.h> |
| 28 | |
| 29 | #include <openssl/aes.h> |
| 30 | #include <openssl/bn.h> |
| 31 | #include <openssl/crypto.h> |
| 32 | #include <openssl/ec.h> |
| 33 | #include <openssl/err.h> |
| 34 | #include <openssl/evp.h> |
| 35 | #include <openssl/hkdf.h> |
| 36 | #include <openssl/hmac.h> |
| 37 | #include <openssl/objects.h> |
| 38 | #include <openssl/pem.h> |
| 39 | #include <openssl/pkcs12.h> |
| 40 | #include <openssl/rand.h> |
| 41 | #include <openssl/x509.h> |
| 42 | #include <openssl/x509_vfy.h> |
| 43 | |
| 44 | #include <libeic.h> |
| 45 | |
| 46 | using ::std::optional; |
| 47 | using ::std::string; |
| 48 | using ::std::tuple; |
| 49 | using ::std::vector; |
| 50 | |
| 51 | namespace android::hardware::identity { |
| 52 | |
| 53 | // ---------------------------------------------------------------------- |
| 54 | |
| 55 | FakeSecureHardwareProvisioningProxy::FakeSecureHardwareProvisioningProxy() {} |
| 56 | |
| 57 | FakeSecureHardwareProvisioningProxy::~FakeSecureHardwareProvisioningProxy() {} |
| 58 | |
| 59 | bool FakeSecureHardwareProvisioningProxy::shutdown() { |
| 60 | LOG(INFO) << "FakeSecureHardwarePresentationProxy shutdown"; |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | bool FakeSecureHardwareProvisioningProxy::initialize(bool testCredential) { |
| 65 | LOG(INFO) << "FakeSecureHardwareProvisioningProxy created, sizeof(EicProvisioning): " |
| 66 | << sizeof(EicProvisioning); |
| 67 | return eicProvisioningInit(&ctx_, testCredential); |
| 68 | } |
| 69 | |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 70 | bool FakeSecureHardwareProvisioningProxy::initializeForUpdate( |
| 71 | bool testCredential, string docType, vector<uint8_t> encryptedCredentialKeys) { |
| 72 | return eicProvisioningInitForUpdate(&ctx_, testCredential, docType.c_str(), |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 73 | docType.size(), |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 74 | encryptedCredentialKeys.data(), |
| 75 | encryptedCredentialKeys.size()); |
| 76 | } |
| 77 | |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 78 | // Returns public key certificate. |
| 79 | optional<vector<uint8_t>> FakeSecureHardwareProvisioningProxy::createCredentialKey( |
| 80 | const vector<uint8_t>& challenge, const vector<uint8_t>& applicationId) { |
| 81 | uint8_t publicKeyCert[4096]; |
| 82 | size_t publicKeyCertSize = sizeof publicKeyCert; |
| 83 | if (!eicProvisioningCreateCredentialKey(&ctx_, challenge.data(), challenge.size(), |
| 84 | applicationId.data(), applicationId.size(), |
| 85 | publicKeyCert, &publicKeyCertSize)) { |
| 86 | return {}; |
| 87 | } |
| 88 | vector<uint8_t> pubKeyCert(publicKeyCertSize); |
| 89 | memcpy(pubKeyCert.data(), publicKeyCert, publicKeyCertSize); |
| 90 | return pubKeyCert; |
| 91 | } |
| 92 | |
| 93 | bool FakeSecureHardwareProvisioningProxy::startPersonalization( |
| 94 | int accessControlProfileCount, vector<int> entryCounts, const string& docType, |
| 95 | size_t expectedProofOfProvisioningSize) { |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 96 | |
| 97 | if (!eicProvisioningStartPersonalization(&ctx_, accessControlProfileCount, |
| 98 | entryCounts.data(), |
| 99 | entryCounts.size(), |
| 100 | docType.c_str(), docType.size(), |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 101 | expectedProofOfProvisioningSize)) { |
| 102 | return false; |
| 103 | } |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | // Returns MAC (28 bytes). |
| 108 | optional<vector<uint8_t>> FakeSecureHardwareProvisioningProxy::addAccessControlProfile( |
| 109 | int id, const vector<uint8_t>& readerCertificate, bool userAuthenticationRequired, |
| 110 | uint64_t timeoutMillis, uint64_t secureUserId) { |
| 111 | vector<uint8_t> mac(28); |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 112 | uint8_t scratchSpace[512]; |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 113 | if (!eicProvisioningAddAccessControlProfile( |
| 114 | &ctx_, id, readerCertificate.data(), readerCertificate.size(), |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 115 | userAuthenticationRequired, timeoutMillis, secureUserId, mac.data(), |
| 116 | scratchSpace, sizeof(scratchSpace))) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 117 | return {}; |
| 118 | } |
| 119 | return mac; |
| 120 | } |
| 121 | |
| 122 | bool FakeSecureHardwareProvisioningProxy::beginAddEntry(const vector<int>& accessControlProfileIds, |
| 123 | const string& nameSpace, const string& name, |
| 124 | uint64_t entrySize) { |
| 125 | uint8_t scratchSpace[512]; |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 126 | vector<uint8_t> uint8AccessControlProfileIds; |
| 127 | for (size_t i = 0; i < accessControlProfileIds.size(); i++) { |
| 128 | uint8AccessControlProfileIds.push_back(accessControlProfileIds[i] & 0xFF); |
| 129 | } |
| 130 | |
| 131 | return eicProvisioningBeginAddEntry(&ctx_, uint8AccessControlProfileIds.data(), |
| 132 | uint8AccessControlProfileIds.size(), nameSpace.c_str(), |
| 133 | nameSpace.size(), name.c_str(), name.size(), entrySize, |
| 134 | scratchSpace, sizeof(scratchSpace)); |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // Returns encryptedContent. |
| 138 | optional<vector<uint8_t>> FakeSecureHardwareProvisioningProxy::addEntryValue( |
| 139 | const vector<int>& accessControlProfileIds, const string& nameSpace, const string& name, |
| 140 | const vector<uint8_t>& content) { |
| 141 | vector<uint8_t> eicEncryptedContent; |
| 142 | uint8_t scratchSpace[512]; |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 143 | vector<uint8_t> uint8AccessControlProfileIds; |
| 144 | for (size_t i = 0; i < accessControlProfileIds.size(); i++) { |
| 145 | uint8AccessControlProfileIds.push_back(accessControlProfileIds[i] & 0xFF); |
| 146 | } |
| 147 | |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 148 | eicEncryptedContent.resize(content.size() + 28); |
| 149 | if (!eicProvisioningAddEntryValue( |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 150 | &ctx_, uint8AccessControlProfileIds.data(), uint8AccessControlProfileIds.size(), |
| 151 | nameSpace.c_str(), nameSpace.size(), name.c_str(), name.size(), content.data(), |
| 152 | content.size(), eicEncryptedContent.data(), scratchSpace, sizeof(scratchSpace))) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 153 | return {}; |
| 154 | } |
| 155 | return eicEncryptedContent; |
| 156 | } |
| 157 | |
| 158 | // Returns signatureOfToBeSigned (EIC_ECDSA_P256_SIGNATURE_SIZE bytes). |
| 159 | optional<vector<uint8_t>> FakeSecureHardwareProvisioningProxy::finishAddingEntries() { |
| 160 | vector<uint8_t> signatureOfToBeSigned(EIC_ECDSA_P256_SIGNATURE_SIZE); |
| 161 | if (!eicProvisioningFinishAddingEntries(&ctx_, signatureOfToBeSigned.data())) { |
| 162 | return {}; |
| 163 | } |
| 164 | return signatureOfToBeSigned; |
| 165 | } |
| 166 | |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 167 | // Returns encryptedCredentialKeys. |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 168 | optional<vector<uint8_t>> FakeSecureHardwareProvisioningProxy::finishGetCredentialData( |
| 169 | const string& docType) { |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 170 | vector<uint8_t> encryptedCredentialKeys(116); |
| 171 | size_t size = encryptedCredentialKeys.size(); |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 172 | if (!eicProvisioningFinishGetCredentialData(&ctx_, docType.c_str(), docType.size(), |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 173 | encryptedCredentialKeys.data(), &size)) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 174 | return {}; |
| 175 | } |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 176 | encryptedCredentialKeys.resize(size); |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 177 | return encryptedCredentialKeys; |
| 178 | } |
| 179 | |
| 180 | // ---------------------------------------------------------------------- |
| 181 | |
| 182 | FakeSecureHardwarePresentationProxy::FakeSecureHardwarePresentationProxy() {} |
| 183 | |
| 184 | FakeSecureHardwarePresentationProxy::~FakeSecureHardwarePresentationProxy() {} |
| 185 | |
| 186 | bool FakeSecureHardwarePresentationProxy::initialize(bool testCredential, string docType, |
| 187 | vector<uint8_t> encryptedCredentialKeys) { |
| 188 | LOG(INFO) << "FakeSecureHardwarePresentationProxy created, sizeof(EicPresentation): " |
| 189 | << sizeof(EicPresentation); |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 190 | return eicPresentationInit(&ctx_, testCredential, docType.c_str(), docType.size(), |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 191 | encryptedCredentialKeys.data(), encryptedCredentialKeys.size()); |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Returns publicKeyCert (1st component) and signingKeyBlob (2nd component) |
| 195 | optional<pair<vector<uint8_t>, vector<uint8_t>>> |
| 196 | FakeSecureHardwarePresentationProxy::generateSigningKeyPair(string docType, time_t now) { |
| 197 | uint8_t publicKeyCert[512]; |
| 198 | size_t publicKeyCertSize = sizeof(publicKeyCert); |
| 199 | vector<uint8_t> signingKeyBlob(60); |
| 200 | |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 201 | if (!eicPresentationGenerateSigningKeyPair(&ctx_, docType.c_str(), docType.size(), now, |
| 202 | publicKeyCert, &publicKeyCertSize, |
| 203 | signingKeyBlob.data())) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 204 | return {}; |
| 205 | } |
| 206 | |
| 207 | vector<uint8_t> cert; |
| 208 | cert.resize(publicKeyCertSize); |
| 209 | memcpy(cert.data(), publicKeyCert, publicKeyCertSize); |
| 210 | |
| 211 | return std::make_pair(cert, signingKeyBlob); |
| 212 | } |
| 213 | |
| 214 | // Returns private key |
| 215 | optional<vector<uint8_t>> FakeSecureHardwarePresentationProxy::createEphemeralKeyPair() { |
| 216 | vector<uint8_t> priv(EIC_P256_PRIV_KEY_SIZE); |
| 217 | if (!eicPresentationCreateEphemeralKeyPair(&ctx_, priv.data())) { |
| 218 | return {}; |
| 219 | } |
| 220 | return priv; |
| 221 | } |
| 222 | |
| 223 | optional<uint64_t> FakeSecureHardwarePresentationProxy::createAuthChallenge() { |
| 224 | uint64_t challenge; |
| 225 | if (!eicPresentationCreateAuthChallenge(&ctx_, &challenge)) { |
| 226 | return {}; |
| 227 | } |
| 228 | return challenge; |
| 229 | } |
| 230 | |
| 231 | bool FakeSecureHardwarePresentationProxy::shutdown() { |
| 232 | LOG(INFO) << "FakeSecureHardwarePresentationProxy shutdown"; |
| 233 | return true; |
| 234 | } |
| 235 | |
| 236 | bool FakeSecureHardwarePresentationProxy::pushReaderCert(const vector<uint8_t>& certX509) { |
| 237 | return eicPresentationPushReaderCert(&ctx_, certX509.data(), certX509.size()); |
| 238 | } |
| 239 | |
| 240 | bool FakeSecureHardwarePresentationProxy::validateRequestMessage( |
| 241 | const vector<uint8_t>& sessionTranscript, const vector<uint8_t>& requestMessage, |
| 242 | int coseSignAlg, const vector<uint8_t>& readerSignatureOfToBeSigned) { |
| 243 | return eicPresentationValidateRequestMessage( |
| 244 | &ctx_, sessionTranscript.data(), sessionTranscript.size(), requestMessage.data(), |
| 245 | requestMessage.size(), coseSignAlg, readerSignatureOfToBeSigned.data(), |
| 246 | readerSignatureOfToBeSigned.size()); |
| 247 | } |
| 248 | |
| 249 | bool FakeSecureHardwarePresentationProxy::setAuthToken( |
| 250 | uint64_t challenge, uint64_t secureUserId, uint64_t authenticatorId, |
| 251 | int hardwareAuthenticatorType, uint64_t timeStamp, const vector<uint8_t>& mac, |
| 252 | uint64_t verificationTokenChallenge, uint64_t verificationTokenTimestamp, |
| 253 | int verificationTokenSecurityLevel, const vector<uint8_t>& verificationTokenMac) { |
| 254 | return eicPresentationSetAuthToken(&ctx_, challenge, secureUserId, authenticatorId, |
| 255 | hardwareAuthenticatorType, timeStamp, mac.data(), mac.size(), |
| 256 | verificationTokenChallenge, verificationTokenTimestamp, |
| 257 | verificationTokenSecurityLevel, verificationTokenMac.data(), |
| 258 | verificationTokenMac.size()); |
| 259 | } |
| 260 | |
| 261 | optional<bool> FakeSecureHardwarePresentationProxy::validateAccessControlProfile( |
| 262 | int id, const vector<uint8_t>& readerCertificate, bool userAuthenticationRequired, |
| 263 | int timeoutMillis, uint64_t secureUserId, const vector<uint8_t>& mac) { |
| 264 | bool accessGranted = false; |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 265 | uint8_t scratchSpace[512]; |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 266 | if (!eicPresentationValidateAccessControlProfile(&ctx_, id, readerCertificate.data(), |
| 267 | readerCertificate.size(), |
| 268 | userAuthenticationRequired, timeoutMillis, |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 269 | secureUserId, mac.data(), &accessGranted, |
| 270 | scratchSpace, sizeof(scratchSpace))) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 271 | return {}; |
| 272 | } |
| 273 | return accessGranted; |
| 274 | } |
| 275 | |
| 276 | bool FakeSecureHardwarePresentationProxy::startRetrieveEntries() { |
| 277 | return eicPresentationStartRetrieveEntries(&ctx_); |
| 278 | } |
| 279 | |
| 280 | bool FakeSecureHardwarePresentationProxy::calcMacKey( |
| 281 | const vector<uint8_t>& sessionTranscript, const vector<uint8_t>& readerEphemeralPublicKey, |
| 282 | const vector<uint8_t>& signingKeyBlob, const string& docType, |
| 283 | unsigned int numNamespacesWithValues, size_t expectedProofOfProvisioningSize) { |
| 284 | if (signingKeyBlob.size() != 60) { |
| 285 | eicDebug("Unexpected size %zd of signingKeyBlob, expected 60", signingKeyBlob.size()); |
| 286 | return false; |
| 287 | } |
| 288 | return eicPresentationCalcMacKey(&ctx_, sessionTranscript.data(), sessionTranscript.size(), |
| 289 | readerEphemeralPublicKey.data(), signingKeyBlob.data(), |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 290 | docType.c_str(), docType.size(), numNamespacesWithValues, |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 291 | expectedProofOfProvisioningSize); |
| 292 | } |
| 293 | |
| 294 | AccessCheckResult FakeSecureHardwarePresentationProxy::startRetrieveEntryValue( |
| 295 | const string& nameSpace, const string& name, unsigned int newNamespaceNumEntries, |
| 296 | int32_t entrySize, const vector<int32_t>& accessControlProfileIds) { |
| 297 | uint8_t scratchSpace[512]; |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 298 | vector<uint8_t> uint8AccessControlProfileIds; |
| 299 | for (size_t i = 0; i < accessControlProfileIds.size(); i++) { |
| 300 | uint8AccessControlProfileIds.push_back(accessControlProfileIds[i] & 0xFF); |
| 301 | } |
| 302 | |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 303 | EicAccessCheckResult result = eicPresentationStartRetrieveEntryValue( |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 304 | &ctx_, nameSpace.c_str(), nameSpace.size(), name.c_str(), name.size(), |
| 305 | newNamespaceNumEntries, entrySize, uint8AccessControlProfileIds.data(), |
| 306 | uint8AccessControlProfileIds.size(), scratchSpace, |
| 307 | sizeof(scratchSpace)); |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 308 | switch (result) { |
| 309 | case EIC_ACCESS_CHECK_RESULT_OK: |
| 310 | return AccessCheckResult::kOk; |
| 311 | case EIC_ACCESS_CHECK_RESULT_NO_ACCESS_CONTROL_PROFILES: |
| 312 | return AccessCheckResult::kNoAccessControlProfiles; |
| 313 | case EIC_ACCESS_CHECK_RESULT_FAILED: |
| 314 | return AccessCheckResult::kFailed; |
| 315 | case EIC_ACCESS_CHECK_RESULT_USER_AUTHENTICATION_FAILED: |
| 316 | return AccessCheckResult::kUserAuthenticationFailed; |
| 317 | case EIC_ACCESS_CHECK_RESULT_READER_AUTHENTICATION_FAILED: |
| 318 | return AccessCheckResult::kReaderAuthenticationFailed; |
| 319 | } |
| 320 | eicDebug("Unknown result with code %d, returning kFailed", (int)result); |
| 321 | return AccessCheckResult::kFailed; |
| 322 | } |
| 323 | |
| 324 | optional<vector<uint8_t>> FakeSecureHardwarePresentationProxy::retrieveEntryValue( |
| 325 | const vector<uint8_t>& encryptedContent, const string& nameSpace, const string& name, |
| 326 | const vector<int32_t>& accessControlProfileIds) { |
| 327 | uint8_t scratchSpace[512]; |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 328 | vector<uint8_t> uint8AccessControlProfileIds; |
| 329 | for (size_t i = 0; i < accessControlProfileIds.size(); i++) { |
| 330 | uint8AccessControlProfileIds.push_back(accessControlProfileIds[i] & 0xFF); |
| 331 | } |
| 332 | |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 333 | vector<uint8_t> content; |
| 334 | content.resize(encryptedContent.size() - 28); |
| 335 | if (!eicPresentationRetrieveEntryValue( |
| 336 | &ctx_, encryptedContent.data(), encryptedContent.size(), content.data(), |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 337 | nameSpace.c_str(), nameSpace.size(), name.c_str(), name.size(), |
| 338 | uint8AccessControlProfileIds.data(), uint8AccessControlProfileIds.size(), |
| 339 | scratchSpace, sizeof(scratchSpace))) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 340 | return {}; |
| 341 | } |
| 342 | return content; |
| 343 | } |
| 344 | |
| 345 | optional<vector<uint8_t>> FakeSecureHardwarePresentationProxy::finishRetrieval() { |
| 346 | vector<uint8_t> mac(32); |
| 347 | size_t macSize = 32; |
| 348 | if (!eicPresentationFinishRetrieval(&ctx_, mac.data(), &macSize)) { |
| 349 | return {}; |
| 350 | } |
| 351 | mac.resize(macSize); |
| 352 | return mac; |
| 353 | } |
| 354 | |
| 355 | optional<vector<uint8_t>> FakeSecureHardwarePresentationProxy::deleteCredential( |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 356 | const string& docType, const vector<uint8_t>& challenge, bool includeChallenge, |
| 357 | size_t proofOfDeletionCborSize) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 358 | vector<uint8_t> signatureOfToBeSigned(EIC_ECDSA_P256_SIGNATURE_SIZE); |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 359 | if (!eicPresentationDeleteCredential(&ctx_, docType.c_str(), docType.size(), challenge.data(), |
| 360 | challenge.size(), includeChallenge, |
| 361 | proofOfDeletionCborSize, signatureOfToBeSigned.data())) { |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 362 | return {}; |
| 363 | } |
| 364 | return signatureOfToBeSigned; |
| 365 | } |
| 366 | |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 367 | optional<vector<uint8_t>> FakeSecureHardwarePresentationProxy::proveOwnership( |
| 368 | const string& docType, bool testCredential, const vector<uint8_t>& challenge, |
| 369 | size_t proofOfOwnershipCborSize) { |
| 370 | vector<uint8_t> signatureOfToBeSigned(EIC_ECDSA_P256_SIGNATURE_SIZE); |
Joseph Jang | dabb3c5 | 2021-09-01 16:50:09 +0800 | [diff] [blame] | 371 | if (!eicPresentationProveOwnership(&ctx_, docType.c_str(), docType.size(), testCredential, |
| 372 | challenge.data(), challenge.size(), proofOfOwnershipCborSize, |
David Zeuthen | 49f2d25 | 2020-10-16 11:27:24 -0400 | [diff] [blame] | 373 | signatureOfToBeSigned.data())) { |
| 374 | return {}; |
| 375 | } |
| 376 | return signatureOfToBeSigned; |
| 377 | } |
| 378 | |
David Zeuthen | 630de2a | 2020-05-11 14:04:54 -0400 | [diff] [blame] | 379 | } // namespace android::hardware::identity |