|
26 | 26 |
|
27 | 27 | #include <lib/core/CHIPError.h>
|
28 | 28 | #include <lib/core/Global.h>
|
29 |
| -#include <lib/support/Base64.h> |
30 |
| -#include <lib/support/BytesToHex.h> |
31 | 29 | #include <lib/support/CodeUtils.h>
|
32 | 30 | #include <lib/support/ScopedBuffer.h>
|
33 | 31 | #include <lib/support/Span.h>
|
34 | 32 |
|
35 |
| -#include <fstream> |
36 |
| -#include <json/json.h> |
37 |
| -#include <string.h> |
38 |
| - |
39 | 33 | using namespace chip::Crypto;
|
40 | 34 | using chip::TestCerts::GetTestPaaRootStore;
|
41 | 35 |
|
@@ -613,149 +607,17 @@ CHIP_ERROR DefaultDACVerifier::VerifyNodeOperationalCSRInformation(const ByteSpa
|
613 | 607 | return CHIP_NO_ERROR;
|
614 | 608 | }
|
615 | 609 |
|
616 |
| -// This method parses the below JSON Scheme |
617 |
| -// [ |
618 |
| -// { |
619 |
| -// "type": "revocation_set", |
620 |
| -// "issuer_subject_key_id": "63540E47F64B1C38D13884A462D16C195D8FFB3C", |
621 |
| -// "issuer_name": "MD0xJTAjBgNVBAMMHE1hdHRlciBEZXYgUEFJIDB4RkZGMSBubyBQSUQxFDASBgorBgEEAYKifAIBDARGRkYx", |
622 |
| -// "revoked_serial_numbers": [ |
623 |
| -// "69CDF10DE9E54ED1" |
624 |
| -// ] |
625 |
| -// } |
626 |
| -// ] |
627 |
| -// |
628 |
| -bool DefaultDACVerifier::IsEntryExistsInRevocationSet(const CharSpan & akidHexStr, const CharSpan & issuerNameBase64Str, |
629 |
| - const CharSpan & serialNumberHexStr) |
630 |
| -{ |
631 |
| - std::ifstream file(mDeviceAttestationRevocationSetPath); |
632 |
| - if (!file.is_open()) |
633 |
| - { |
634 |
| - return false; |
635 |
| - } |
636 |
| - |
637 |
| - // Parse the JSON data incrementally |
638 |
| - Json::CharReaderBuilder readerBuilder; |
639 |
| - Json::Value jsonData; |
640 |
| - std::string errs; |
641 |
| - |
642 |
| - bool parsingSuccessful = Json::parseFromStream(readerBuilder, file, &jsonData, &errs); |
643 |
| - |
644 |
| - // Close the file as it's no longer needed |
645 |
| - file.close(); |
646 |
| - |
647 |
| - if (!parsingSuccessful) |
648 |
| - { |
649 |
| - return false; |
650 |
| - } |
651 |
| - |
652 |
| - for (const auto & revokedSet : jsonData) |
653 |
| - { |
654 |
| - if (strncmp(revokedSet["issuer_name"].asCString(), issuerNameBase64Str.data(), issuerNameBase64Str.size()) == 0 && |
655 |
| - strncmp(revokedSet["issuer_subject_key_id"].asCString(), akidHexStr.data(), akidHexStr.size()) == 0) |
656 |
| - { |
657 |
| - for (const auto & revokedSerialNumber : revokedSet["revoked_serial_numbers"]) |
658 |
| - { |
659 |
| - if (strncmp(revokedSerialNumber.asCString(), serialNumberHexStr.data(), serialNumberHexStr.size()) == 0) |
660 |
| - { |
661 |
| - return true; |
662 |
| - } |
663 |
| - } |
664 |
| - } |
665 |
| - } |
666 |
| - return false; |
667 |
| -} |
668 |
| - |
669 |
| -CHIP_ERROR DefaultDACVerifier::GetAKIDHexStr(const ByteSpan & certDer, MutableCharSpan & outAKIDHexStr) |
670 |
| -{ |
671 |
| - uint8_t akidBuf[kAuthorityKeyIdentifierLength]; |
672 |
| - MutableByteSpan akid(akidBuf); |
673 |
| - |
674 |
| - CHIP_ERROR err = ExtractAKIDFromX509Cert(certDer, akid); |
675 |
| - VerifyOrReturnError(err == CHIP_NO_ERROR, err); |
676 |
| - VerifyOrReturnError(outAKIDHexStr.size() > akid.size() * 2, CHIP_ERROR_BUFFER_TOO_SMALL); |
677 |
| - |
678 |
| - Encoding::HexFlags flags = Encoding::HexFlags::kUppercaseAndNullTerminate; |
679 |
| - err = BytesToHex(akid.data(), akid.size(), outAKIDHexStr.data(), outAKIDHexStr.size(), flags); |
680 |
| - VerifyOrReturnError(err == CHIP_NO_ERROR, err); |
681 |
| - |
682 |
| - outAKIDHexStr.reduce_size(strlen(outAKIDHexStr.data())); |
683 |
| - return CHIP_NO_ERROR; |
684 |
| -} |
685 |
| - |
686 |
| -CHIP_ERROR DefaultDACVerifier::GetSerialNumberHexStr(const ByteSpan & certDer, MutableCharSpan & outSerialNumberHexStr) |
687 |
| -{ |
688 |
| - uint8_t serialNumberBuf[kMaxCertificateSerialNumberLength] = { 0 }; |
689 |
| - MutableByteSpan serialNumber(serialNumberBuf); |
690 |
| - |
691 |
| - CHIP_ERROR err = ExtractSerialNumberFromX509Cert(certDer, serialNumber); |
692 |
| - VerifyOrReturnError(err == CHIP_NO_ERROR, err); |
693 |
| - VerifyOrReturnError(outSerialNumberHexStr.size() > serialNumber.size() * 2, CHIP_ERROR_BUFFER_TOO_SMALL); |
694 |
| - |
695 |
| - Encoding::HexFlags flags = Encoding::HexFlags::kUppercaseAndNullTerminate; |
696 |
| - err = BytesToHex(serialNumber.data(), serialNumber.size(), outSerialNumberHexStr.data(), outSerialNumberHexStr.size(), flags); |
697 |
| - VerifyOrReturnError(err == CHIP_NO_ERROR, err); |
698 |
| - |
699 |
| - outSerialNumberHexStr.reduce_size(strlen(outSerialNumberHexStr.data())); |
700 |
| - return CHIP_NO_ERROR; |
701 |
| -} |
702 |
| - |
703 |
| -CHIP_ERROR DefaultDACVerifier::GetIssuerNameBase64Str(const ByteSpan & certDer, MutableCharSpan & outIssuerNameBase64String) |
704 |
| -{ |
705 |
| - uint8_t issuerBuf[kMaxCertificateDistinguishedNameLength] = { 0 }; |
706 |
| - MutableByteSpan issuer(issuerBuf); |
707 |
| - |
708 |
| - CHIP_ERROR err = ExtractIssuerFromX509Cert(certDer, issuer); |
709 |
| - VerifyOrReturnError(CHIP_NO_ERROR == err, err); |
710 |
| - VerifyOrReturnError(outIssuerNameBase64String.size() > BASE64_ENCODED_LEN(issuer.size()), CHIP_ERROR_BUFFER_TOO_SMALL); |
711 |
| - |
712 |
| - uint32_t encodedLen = Base64Encode32(issuer.data(), static_cast<uint32_t>(issuer.size()), outIssuerNameBase64String.data()); |
713 |
| - outIssuerNameBase64String.reduce_size(encodedLen); |
714 |
| - return CHIP_NO_ERROR; |
715 |
| -} |
716 |
| - |
717 |
| -bool DefaultDACVerifier::IsCertificateRevoked(const ByteSpan & certDer) |
718 |
| -{ |
719 |
| - static constexpr uint32_t maxIssuerBase64Len = BASE64_ENCODED_LEN(kMaxCertificateDistinguishedNameLength) + 1; |
720 |
| - |
721 |
| - char issuerNameBuffer[maxIssuerBase64Len] = { 0 }; |
722 |
| - char serialNumberHexStrBuffer[2 * kMaxCertificateSerialNumberLength + 1] = { 0 }; |
723 |
| - char akidHexStrBuffer[2 * kAuthorityKeyIdentifierLength + 1] = { 0 }; |
724 |
| - |
725 |
| - MutableCharSpan issuerName(issuerNameBuffer); |
726 |
| - MutableCharSpan serialNumber(serialNumberHexStrBuffer); |
727 |
| - MutableCharSpan akid(akidHexStrBuffer); |
728 |
| - |
729 |
| - CHIP_ERROR err = GetIssuerNameBase64Str(certDer, issuerName); |
730 |
| - VerifyOrReturnValue(err == CHIP_NO_ERROR, false); |
731 |
| - |
732 |
| - err = GetSerialNumberHexStr(certDer, serialNumber); |
733 |
| - VerifyOrReturnValue(err == CHIP_NO_ERROR, false); |
734 |
| - |
735 |
| - err = GetAKIDHexStr(certDer, akid); |
736 |
| - VerifyOrReturnValue(err == CHIP_NO_ERROR, false); |
737 |
| - |
738 |
| - return IsEntryExistsInRevocationSet(akid, issuerName, serialNumber); |
739 |
| -} |
740 |
| - |
741 | 610 | void DefaultDACVerifier::CheckForRevokedDACChain(const AttestationInfo & info,
|
742 | 611 | Callback::Callback<OnAttestationInformationVerification> * onCompletion)
|
743 | 612 | {
|
744 |
| - AttestationVerificationResult attestationError = AttestationVerificationResult::kSuccess; |
745 |
| - |
746 |
| - if (mDeviceAttestationRevocationSetPath != nullptr) |
| 613 | + if (mRevocationDelegate != nullptr) |
747 | 614 | {
|
748 |
| - if (IsCertificateRevoked(info.dacDerBuffer)) |
749 |
| - { |
750 |
| - attestationError = AttestationVerificationResult::kDacRevoked; |
751 |
| - } |
752 |
| - if (IsCertificateRevoked(info.paiDerBuffer)) |
753 |
| - { |
754 |
| - attestationError = AttestationVerificationResult::kPaiRevoked; |
755 |
| - } |
| 615 | + mRevocationDelegate->CheckForRevokedDACChain(info, onCompletion); |
| 616 | + } |
| 617 | + else |
| 618 | + { |
| 619 | + onCompletion->mCall(onCompletion->mContext, info, AttestationVerificationResult::kSuccess); |
756 | 620 | }
|
757 |
| - |
758 |
| - onCompletion->mCall(onCompletion->mContext, info, attestationError); |
759 | 621 | }
|
760 | 622 |
|
761 | 623 | bool CsaCdKeysTrustStore::IsCdTestKey(const ByteSpan & kid) const
|
|
0 commit comments