16
16
*/
17
17
#include " JSONFileRevocationSet.h"
18
18
19
+ #include < lib/core/CHIPSafeCasts.h>
19
20
#include < lib/support/Base64.h>
20
21
#include < lib/support/BytesToHex.h>
21
22
#include < lib/support/ScopedBuffer.h>
22
23
23
24
#include < cstdlib>
24
25
#include < fstream>
25
- #include < iostream>
26
26
27
27
namespace chip {
28
28
namespace Credentials {
@@ -53,17 +53,16 @@ AttestationVerificationResult JSONFileRevocationSet::IsCertificateRevoked(bool i
53
53
ByteSpan issuer, ByteSpan authorityKeyId,
54
54
ByteSpan serialNumber) const
55
55
{
56
- for (size_t revocation_set_idx = 0 ; revocation_set_idx < mRevocationSet .size (); ++revocation_set_idx)
56
+ for (int revocation_set_idx = 0 ; revocation_set_idx < static_cast < int >( mRevocationSet .size () ); ++revocation_set_idx)
57
57
{
58
- Json::Value type = mRevocationSet [static_cast < int >( revocation_set_idx)][ " type " ];
58
+ Json::Value revocationSetEntry = mRevocationSet [revocation_set_idx];
59
59
60
60
// 1.
61
- if (type.asString ().compare (" revocation_set" ) == 0 )
61
+ if (revocationSetEntry[ " type" ] .asString ().compare (" revocation_set" ) == 0 )
62
62
{
63
- Json::Value jsonCrlIssuerSubjectKeyId = mRevocationSet [static_cast <int >(revocation_set_idx)][" issuer_subject_key_id" ];
64
- Json::Value jsonCrlIssuerName = mRevocationSet [static_cast <int >(revocation_set_idx)][" issuer_name" ];
65
- Json::Value jsonCrlRevokedSerialNumbers =
66
- mRevocationSet [static_cast <int >(revocation_set_idx)][" revoked_serial_numbers" ];
63
+ Json::Value jsonCrlIssuerSubjectKeyId = revocationSetEntry[" issuer_subject_key_id" ];
64
+ Json::Value jsonCrlIssuerName = revocationSetEntry[" issuer_name" ];
65
+ Json::Value jsonCrlRevokedSerialNumbers = revocationSetEntry[" revoked_serial_numbers" ];
67
66
68
67
uint8_t crlIssuerSubjectKeyIdBuf[Crypto::kAuthorityKeyIdentifierLength ] = { 0 };
69
68
ByteSpan crlIssuerSubjectKeyId (crlIssuerSubjectKeyIdBuf);
@@ -81,62 +80,46 @@ AttestationVerificationResult JSONFileRevocationSet::IsCertificateRevoked(bool i
81
80
82
81
// 2.
83
82
size_t crlSignerCertificateLength =
84
- Base64Decode (jsonCrlIssuerName.asString ().c_str (), jsonCrlIssuerName.asString ().size (), crlSignerCertificate.Get ());
83
+ Base64Decode (jsonCrlIssuerName.asString ().c_str (), static_cast <uint16_t >(jsonCrlIssuerName.asString ().size ()),
84
+ crlSignerCertificate.Get ());
85
85
VerifyOrReturnError (crlSignerCertificateLength > 0 && crlSignerCertificateLength != UINT16_MAX,
86
86
AttestationVerificationResult::kInternalError );
87
87
88
- // 3.
89
- if (isPaa)
90
- {
91
- Crypto::AttestationCertVidPid vid;
88
+ // 3. && 4.
89
+ Crypto::AttestationCertVidPid vidPid;
92
90
93
- Crypto::ExtractVIDPIDFromAttributeString (
94
- Crypto::DNAttrType::kCommonName , ByteSpan (crlSignerCertificate.Get (), crlSignerCertificateLength), vid, vid );
91
+ Crypto::ExtractVIDPIDFromAttributeString (
92
+ Crypto::DNAttrType::kCommonName , ByteSpan (crlSignerCertificate.Get (), crlSignerCertificateLength), vidPid, vidPid );
95
93
96
- if (vid.mVendorId .HasValue ())
94
+ if (vidPid.mVendorId .HasValue () && vidPid.mVendorId .Value () != vidPidUnderTest.mVendorId .Value ())
95
+ {
96
+ // VID does not match. Stop further processing and continue to next entry.
97
+ continue ;
98
+ }
99
+
100
+ if (isPaa)
101
+ {
102
+ if (vidPid.mProductId .HasValue ())
97
103
{
98
- if (vid.mVendorId .Value () != vidPidUnderTest.mVendorId .Value ())
99
- {
100
- // VID does not match. Stop further processing and continue to next entry.
101
- continue ;
102
- }
104
+ // PAA must not contain PID entry. Format wrong. Continuing to next entry.
105
+ continue ;
103
106
}
104
107
}
105
- // 4.
106
108
else
107
109
{
108
- Crypto::AttestationCertVidPid vidPid;
109
-
110
- Crypto::ExtractVIDPIDFromAttributeString (Crypto::DNAttrType::kCommonName ,
111
- ByteSpan (crlSignerCertificate.Get (), crlSignerCertificateLength), vidPid,
112
- vidPid);
113
-
114
- if (vidPid.mVendorId .HasValue () && vidPid.mVendorId .Value () != vidPidUnderTest.mVendorId .Value ())
110
+ if (vidPid.mProductId .HasValue () && vidPid.mProductId .Value () != vidPidUnderTest.mProductId .Value ())
115
111
{
116
- // VID does not match. Stop further processing and continue to next entry.
112
+ // PID does not match. Stop further processing and continue to next entry.
117
113
continue ;
118
114
}
119
-
120
- if (vidPid.mProductId .HasValue ())
121
- {
122
- if (vidPid.mProductId .Value () != vidPidUnderTest.mProductId .Value ())
123
- {
124
- // PID does not match. Stop further processing and continue to next entry.
125
- continue ;
126
- }
127
- }
128
115
}
129
116
130
- // 7.a Perform CRLFile validation
117
+ // 7. Perform CRLFile validation
131
118
if (authorityKeyId.data_equal (crlIssuerSubjectKeyId) == false )
132
119
{
133
120
continue ;
134
121
}
135
122
136
- // TODO: 7.b
137
-
138
- // TODO: 8.
139
-
140
123
// 9. && 10.
141
124
for (int serial_number_idx = 0 ; serial_number_idx < static_cast <int >(jsonCrlRevokedSerialNumbers.size ());
142
125
++serial_number_idx)
@@ -151,15 +134,16 @@ AttestationVerificationResult JSONFileRevocationSet::IsCertificateRevoked(bool i
151
134
152
135
size_t revokedSerialNumberLength =
153
136
Base64Decode (jsonCrlRevokedSerialNumbers[serial_number_idx].asString ().c_str (),
154
- jsonCrlRevokedSerialNumbers[serial_number_idx].asString ().size (), revokedSerialNumber.Get ());
137
+ static_cast <uint16_t >(jsonCrlRevokedSerialNumbers[serial_number_idx].asString ().size ()),
138
+ revokedSerialNumber.Get ());
155
139
VerifyOrReturnError (revokedSerialNumberLength > 0 && revokedSerialNumberLength != UINT16_MAX,
156
140
AttestationVerificationResult::kInternalError );
157
141
158
142
uint8_t crlRevokedSerialNumberBuf[Crypto::kMaxCertificateSerialNumberLength ] = { 0 };
159
143
ByteSpan crlSerialNumber (crlRevokedSerialNumberBuf);
160
144
161
- VerifyOrReturnError (Encoding::HexToBytes (reinterpret_cast < char *> (revokedSerialNumber.Get ()),
162
- revokedSerialNumberLength, crlRevokedSerialNumberBuf,
145
+ VerifyOrReturnError (Encoding::HexToBytes (Uint8::to_char (revokedSerialNumber.Get ()), revokedSerialNumberLength ,
146
+ crlRevokedSerialNumberBuf,
163
147
sizeof (crlRevokedSerialNumberBuf)) == sizeof (crlRevokedSerialNumberBuf),
164
148
AttestationVerificationResult::kInvalidArgument );
165
149
0 commit comments