@@ -53,7 +53,7 @@ FileAttestationTrustStore::FileAttestationTrustStore(const char * paaTrustStoreP
53
53
mIsInitialized = true ;
54
54
}
55
55
56
- std::vector<std::vector<uint8_t >> LoadAllX509DerCerts (const char * trustStorePath)
56
+ std::vector<std::vector<uint8_t >> LoadAllX509DerCerts (const char * trustStorePath, CertificateValidationMode validationMode )
57
57
{
58
58
std::vector<std::vector<uint8_t >> certs;
59
59
if (trustStorePath == nullptr )
@@ -89,21 +89,39 @@ std::vector<std::vector<uint8_t>> LoadAllX509DerCerts(const char * trustStorePat
89
89
if ((certificateLength > 0 ) && (certificateLength <= kMaxDERCertLength ))
90
90
{
91
91
certificate.resize (certificateLength);
92
- // Only accumulate certificate if it has a subject key ID extension
93
- {
94
- uint8_t kidBuf[Crypto::kSubjectKeyIdentifierLength ] = { 0 };
95
- MutableByteSpan kidSpan{ kidBuf };
96
- ByteSpan certSpan{ certificate.data (), certificate.size () };
92
+ ByteSpan certSpan{ certificate.data (), certificate.size () };
97
93
94
+ // Only accumulate certificate if it passes validation.
95
+ bool isValid = false ;
96
+ switch (validationMode)
97
+ {
98
+ case CertificateValidationMode::kPAA : {
98
99
if (CHIP_NO_ERROR != VerifyAttestationCertificateFormat (certSpan, Crypto::AttestationCertType::kPAA ))
99
100
{
100
- continue ;
101
+ break ;
101
102
}
102
103
104
+ uint8_t kidBuf[Crypto::kSubjectKeyIdentifierLength ] = { 0 };
105
+ MutableByteSpan kidSpan{ kidBuf };
103
106
if (CHIP_NO_ERROR == Crypto::ExtractSKIDFromX509Cert (certSpan, kidSpan))
104
107
{
105
- certs. push_back (certificate) ;
108
+ isValid = true ;
106
109
}
110
+ break ;
111
+ }
112
+ case CertificateValidationMode::kPublicKeyOnly : {
113
+ Crypto::P256PublicKey publicKey;
114
+ if (CHIP_NO_ERROR == Crypto::ExtractPubkeyFromX509Cert (certSpan, publicKey))
115
+ {
116
+ isValid = true ;
117
+ }
118
+ break ;
119
+ }
120
+ }
121
+
122
+ if (isValid)
123
+ {
124
+ certs.push_back (certificate);
107
125
}
108
126
}
109
127
fclose (file);
0 commit comments