From 9d67ff1cb244fadd757cb096e94f45d92078df6b Mon Sep 17 00:00:00 2001 From: Robert Szewczyk Date: Mon, 9 Oct 2023 10:55:05 -0700 Subject: [PATCH] Impove CD validation We currently peform validation against PAA checks in encoding. In decoding, we check for cryptographic validity, but do not perform the same checks againts the data. This commit brings the encoding and decoding into parity. --- src/credentials/CertificationDeclaration.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/credentials/CertificationDeclaration.cpp b/src/credentials/CertificationDeclaration.cpp index 45b4831f43fb4f..aa080b77ca05de 100644 --- a/src/credentials/CertificationDeclaration.cpp +++ b/src/credentials/CertificationDeclaration.cpp @@ -143,6 +143,7 @@ CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, Cer certElements.ProductIdsCount = 0; while ((err = reader.Next(AnonymousTag())) == CHIP_NO_ERROR) { + VerifyOrReturnError(certElements.ProductIdsCount < kMaxProductIdsCount,CHIP_ERROR_INVALID_ARGUMENT); ReturnErrorOnFailure(reader.Get(certElements.ProductIds[certElements.ProductIdsCount++])); } VerifyOrReturnError(err == CHIP_END_OF_TLV, err); @@ -194,6 +195,7 @@ CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, Cer while ((err = reader.Next(kTLVType_ByteString, AnonymousTag())) == CHIP_NO_ERROR) { VerifyOrReturnError(reader.GetLength() == kKeyIdentifierLength, CHIP_ERROR_UNEXPECTED_TLV_ELEMENT); + VerifyOrReturnError(certElements.AuthorizedPAAListCount < kMaxAuthorizedPAAListCount, CHIP_ERROR_INVALID_ARGUMENT); ReturnErrorOnFailure( reader.GetBytes(certElements.AuthorizedPAAList[certElements.AuthorizedPAAListCount++], kKeyIdentifierLength));