From 242772269a4df08fd2071ffd7f9e65959723ffa4 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..08149bf6c44d26 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));