|
22 | 22 | #include <credentials/DeviceAttestationCredsProvider.h>
|
23 | 23 | #include <credentials/attestation_verifier/DefaultDeviceAttestationVerifier.h>
|
24 | 24 | #include <credentials/attestation_verifier/DeviceAttestationVerifier.h>
|
| 25 | +#include <credentials/attestation_verifier/TestDACRevocationDelegateImpl.h> |
25 | 26 | #include <credentials/attestation_verifier/TestPAAStore.h>
|
26 | 27 | #include <credentials/examples/DeviceAttestationCredsExample.h>
|
27 | 28 | #include <credentials/examples/ExampleDACs.h>
|
|
35 | 36 |
|
36 | 37 | #include "CHIPAttCert_test_vectors.h"
|
37 | 38 |
|
| 39 | +#include <fstream> |
| 40 | + |
38 | 41 | using namespace chip;
|
39 | 42 | using namespace chip::Crypto;
|
40 | 43 | using namespace chip::Credentials;
|
@@ -411,3 +414,158 @@ TEST_F(TestDeviceAttestationCredentials, TestAttestationTrustStore)
|
411 | 414 | }
|
412 | 415 | }
|
413 | 416 | }
|
| 417 | + |
| 418 | +static void WriteTestRevokedData(const char * jsonData, const char * fileName) |
| 419 | +{ |
| 420 | + // write data to /tmp/sample_revoked_set.json using fstream APIs |
| 421 | + std::ofstream file; |
| 422 | + file.open(fileName, std::ofstream::out | std::ofstream::trunc); |
| 423 | + file << jsonData; |
| 424 | + file.close(); |
| 425 | +} |
| 426 | + |
| 427 | +TEST_F(TestDeviceAttestationCredentials, TestDACRevocationDelegateImpl) |
| 428 | +{ |
| 429 | + uint8_t attestationElementsTestVector[] = { 0 }; |
| 430 | + uint8_t attestationChallengeTestVector[] = { 0 }; |
| 431 | + uint8_t attestationSignatureTestVector[] = { 0 }; |
| 432 | + uint8_t attestationNonceTestVector[] = { 0 }; |
| 433 | + |
| 434 | + // Details for TestCerts::sTestCert_DAC_FFF1_8000_0004_Cert |
| 435 | + // Issuer: MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw |
| 436 | + // AKID: AF42B7094DEBD515EC6ECF33B81115225F325288 |
| 437 | + // Serial Number: 0C694F7F866067B2 |
| 438 | + // |
| 439 | + // Details for TestCerts::sTestCert_PAI_FFF1_8000_Cert |
| 440 | + // Issuer: MDAxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBQTEUMBIGCisGAQQBgqJ8AgEMBEZGRjE= |
| 441 | + // AKID: 6AFD22771F511FECBF1641976710DCDC31A1717E |
| 442 | + // Serial Number: 3E6CE6509AD840CD1 |
| 443 | + Credentials::DeviceAttestationVerifier::AttestationInfo info( |
| 444 | + ByteSpan(attestationElementsTestVector), ByteSpan(attestationChallengeTestVector), ByteSpan(attestationSignatureTestVector), |
| 445 | + TestCerts::sTestCert_PAI_FFF1_8000_Cert, TestCerts::sTestCert_DAC_FFF1_8000_0004_Cert, ByteSpan(attestationNonceTestVector), |
| 446 | + static_cast<VendorId>(0xFFF1), 0x8000); |
| 447 | + |
| 448 | + AttestationVerificationResult attestationResult = AttestationVerificationResult::kNotImplemented; |
| 449 | + |
| 450 | + Callback::Callback<DeviceAttestationVerifier::OnAttestationInformationVerification> attestationInformationVerificationCallback( |
| 451 | + OnAttestationInformationVerificationCallback, &attestationResult); |
| 452 | + |
| 453 | + TestDACRevocationDelegateImpl revocationDelegateImpl; |
| 454 | + |
| 455 | + // Test without revocation set |
| 456 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 457 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 458 | + |
| 459 | + const char * tmpJsonFile = "/tmp/sample_revoked_set.json"; |
| 460 | + revocationDelegateImpl.SetDeviceAttestationRevocationSetPath(tmpJsonFile); |
| 461 | + |
| 462 | + // Test empty json |
| 463 | + WriteTestRevokedData("", tmpJsonFile); |
| 464 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 465 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 466 | + |
| 467 | + // Test DAC is revoked |
| 468 | + const char * jsonData = R"( |
| 469 | + [{ |
| 470 | + "type": "revocation_set", |
| 471 | + "issuer_subject_key_id": "AF42B7094DEBD515EC6ECF33B81115225F325288", |
| 472 | + "issuer_name": "MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw", |
| 473 | + "revoked_serial_numbers": ["0C694F7F866067B2"] |
| 474 | + }] |
| 475 | + )"; |
| 476 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 477 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 478 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kDacRevoked); |
| 479 | + |
| 480 | + // Test PAI is revoked |
| 481 | + jsonData = R"( |
| 482 | + [{ |
| 483 | + "type": "revocation_set", |
| 484 | + "issuer_subject_key_id": "6AFD22771F511FECBF1641976710DCDC31A1717E", |
| 485 | + "issuer_name": "MDAxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBQTEUMBIGCisGAQQBgqJ8AgEMBEZGRjE=", |
| 486 | + "revoked_serial_numbers": ["3E6CE6509AD840CD"] |
| 487 | + }] |
| 488 | + )"; |
| 489 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 490 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 491 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kPaiRevoked); |
| 492 | + |
| 493 | + // Test DAC and PAI both revoked |
| 494 | + jsonData = R"( |
| 495 | + [{ |
| 496 | + "type": "revocation_set", |
| 497 | + "issuer_subject_key_id": "AF42B7094DEBD515EC6ECF33B81115225F325288", |
| 498 | + "issuer_name": "MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw", |
| 499 | + "revoked_serial_numbers": ["0C694F7F866067B2"] |
| 500 | + }, |
| 501 | + { |
| 502 | + "type": "revocation_set", |
| 503 | + "issuer_subject_key_id": "6AFD22771F511FECBF1641976710DCDC31A1717E", |
| 504 | + "issuer_name": "MDAxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBQTEUMBIGCisGAQQBgqJ8AgEMBEZGRjE=", |
| 505 | + "revoked_serial_numbers": ["3E6CE6509AD840CD"] |
| 506 | + }] |
| 507 | + )"; |
| 508 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 509 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 510 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kPaiAndDacRevoked); |
| 511 | + |
| 512 | + // Test with another test DAC and PAI |
| 513 | + Credentials::DeviceAttestationVerifier::AttestationInfo FFF2_8001_info( |
| 514 | + ByteSpan(attestationElementsTestVector), ByteSpan(attestationChallengeTestVector), ByteSpan(attestationSignatureTestVector), |
| 515 | + TestCerts::sTestCert_PAI_FFF2_8001_Cert, TestCerts::sTestCert_DAC_FFF2_8001_0008_Cert, ByteSpan(attestationNonceTestVector), |
| 516 | + static_cast<VendorId>(0xFFF2), 0x8001); |
| 517 | + revocationDelegateImpl.CheckForRevokedDACChain(FFF2_8001_info, &attestationInformationVerificationCallback); |
| 518 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 519 | + |
| 520 | + // Test issuer does not match |
| 521 | + jsonData = R"( |
| 522 | + [{ |
| 523 | + "type": "revocation_set", |
| 524 | + "issuer_subject_key_id": "BF42B7094DEBD515EC6ECF33B81115225F325289", |
| 525 | + "issuer_name": "MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw", |
| 526 | + "revoked_serial_numbers": ["0C694F7F866067B2"] |
| 527 | + }] |
| 528 | + )"; |
| 529 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 530 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 531 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 532 | + |
| 533 | + // Test subject key ID does not match |
| 534 | + jsonData = R"( |
| 535 | + [{ |
| 536 | + "type": "revocation_set", |
| 537 | + "issuer_subject_key_id": "BF42B7094DEBD515EC6ECF33B81115225F325289", |
| 538 | + "issuer_name": "MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw", |
| 539 | + "revoked_serial_numbers": ["0C694F7F866067B2"] |
| 540 | + }] |
| 541 | + )"; |
| 542 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 543 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 544 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 545 | + |
| 546 | + // Test serial number does not match |
| 547 | + jsonData = R"( |
| 548 | + [{ |
| 549 | + "type": "revocation_set", |
| 550 | + "issuer_subject_key_id": "AF42B7094DEBD515EC6ECF33B81115225F325288", |
| 551 | + "issuer_name": "MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw", |
| 552 | + "revoked_serial_numbers": ["3E6CE6509AD840CD1", "BC694F7F866067B1"] |
| 553 | + }] |
| 554 | + )"; |
| 555 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 556 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 557 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 558 | + |
| 559 | + // Test starting serial number bytes match but not all |
| 560 | + jsonData = R"( |
| 561 | + [{ |
| 562 | + "type": "revocation_set", |
| 563 | + "issuer_subject_key_id": "AF42B7094DEBD515EC6ECF33B81115225F325288", |
| 564 | + "issuer_name": "MEYxGDAWBgNVBAMMD01hdHRlciBUZXN0IFBBSTEUMBIGCisGAQQBgqJ8AgEMBEZGRjExFDASBgorBgEEAYKifAICDAQ4MDAw", |
| 565 | + "revoked_serial_numbers": ["0C694F7F866067B21234"] |
| 566 | + }] |
| 567 | + )"; |
| 568 | + WriteTestRevokedData(jsonData, tmpJsonFile); |
| 569 | + revocationDelegateImpl.CheckForRevokedDACChain(info, &attestationInformationVerificationCallback); |
| 570 | + EXPECT_EQ(attestationResult, AttestationVerificationResult::kSuccess); |
| 571 | +} |
0 commit comments