@@ -284,20 +284,29 @@ CHIP_ERROR ChipCertificateSet::FindValidCert(const ChipDN & subjectDN, const Cer
284
284
285
285
CHIP_ERROR ChipCertificateSet::VerifySignature (const ChipCertificateData * cert, const ChipCertificateData * caCert)
286
286
{
287
+ VerifyOrReturnError ((cert != nullptr ) && (caCert != nullptr ), CHIP_ERROR_INVALID_ARGUMENT);
288
+ return VerifyCertSignature (*cert, *caCert);
289
+ }
290
+
291
+ CHIP_ERROR VerifyCertSignature (const ChipCertificateData & cert, const ChipCertificateData & signer)
292
+ {
293
+ VerifyOrReturnError (cert.mCertFlags .Has (CertFlags::kTBSHashPresent ), CHIP_ERROR_INVALID_ARGUMENT);
294
+ VerifyOrReturnError (cert.mSigAlgoOID == kOID_SigAlgo_ECDSAWithSHA256 , CHIP_ERROR_UNSUPPORTED_SIGNATURE_TYPE);
295
+
287
296
#ifdef ENABLE_HSM_ECDSA_VERIFY
288
- P256PublicKeyHSM caPublicKey ;
297
+ P256PublicKeyHSM signerPublicKey ;
289
298
#else
290
- P256PublicKey caPublicKey ;
299
+ P256PublicKey signerPublicKey ;
291
300
#endif
292
301
P256ECDSASignature signature;
293
302
294
- VerifyOrReturnError ((cert != nullptr ) && (caCert != nullptr ), CHIP_ERROR_INVALID_ARGUMENT);
295
- ReturnErrorOnFailure (signature.SetLength (cert->mSignature .size ()));
296
- memcpy (signature.Bytes (), cert->mSignature .data (), cert->mSignature .size ());
303
+ ReturnErrorOnFailure (signature.SetLength (cert.mSignature .size ()));
304
+ memcpy (signature.Bytes (), cert.mSignature .data (), cert.mSignature .size ());
297
305
298
- memcpy (caPublicKey, caCert-> mPublicKey .data (), caCert-> mPublicKey .size ());
306
+ memcpy (signerPublicKey, signer. mPublicKey .data (), signer. mPublicKey .size ());
299
307
300
- ReturnErrorOnFailure (caPublicKey.ECDSA_validate_hash_signature (cert->mTBSHash , chip::Crypto::kSHA256_Hash_Length , signature));
308
+ ReturnErrorOnFailure (
309
+ signerPublicKey.ECDSA_validate_hash_signature (cert.mTBSHash , chip::Crypto::kSHA256_Hash_Length , signature));
301
310
302
311
return CHIP_NO_ERROR;
303
312
}
@@ -454,10 +463,6 @@ CHIP_ERROR ChipCertificateSet::ValidateCert(const ChipCertificateData * cert, Va
454
463
// recursion in such a case.
455
464
VerifyOrExit (depth < mCertCount , err = CHIP_ERROR_CERT_PATH_TOO_LONG);
456
465
457
- // Verify that a hash of the 'to-be-signed' portion of the certificate has been computed. We will need this to
458
- // verify the cert's signature below.
459
- VerifyOrExit (cert->mCertFlags .Has (CertFlags::kTBSHashPresent ), err = CHIP_ERROR_INVALID_ARGUMENT);
460
-
461
466
// Search for a valid CA certificate that matches the Issuer DN and Authority Key Id of the current certificate.
462
467
// Fail if no acceptable certificate is found.
463
468
err = FindValidCert (cert->mIssuerDN , cert->mAuthKeyId , context, static_cast <uint8_t >(depth + 1 ), &caCert);
@@ -468,7 +473,7 @@ CHIP_ERROR ChipCertificateSet::ValidateCert(const ChipCertificateData * cert, Va
468
473
469
474
// Verify signature of the current certificate against public key of the CA certificate. If signature verification
470
475
// succeeds, the current certificate is valid.
471
- err = VerifySignature ( cert, caCert);
476
+ err = VerifyCertSignature (* cert, * caCert);
472
477
SuccessOrExit (err);
473
478
474
479
exit :
@@ -1166,7 +1171,7 @@ CHIP_ERROR ValidateChipRCAC(const ByteSpan & rcac)
1166
1171
1167
1172
VerifyOrReturnError (certData.mKeyUsageFlags .Has (KeyUsageFlags::kKeyCertSign ), CHIP_ERROR_CERT_USAGE_NOT_ALLOWED);
1168
1173
1169
- return ChipCertificateSet::VerifySignature (& certData, & certData);
1174
+ return VerifyCertSignature ( certData, certData);
1170
1175
}
1171
1176
1172
1177
CHIP_ERROR ConvertIntegerDERToRaw (ByteSpan derInt, uint8_t * rawInt, const uint16_t rawIntLen)
0 commit comments