Skip to content

Commit

Permalink
Added default constructor for CertificationElementsWithoutPIDs struct
Browse files Browse the repository at this point in the history
  • Loading branch information
vijs committed Nov 22, 2021
1 parent 9cddb31 commit b5f45aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
13 changes: 5 additions & 8 deletions src/credentials/CertificationDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, Cer
return CHIP_NO_ERROR;
}

CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, CertificationDeclarationContent & certDeclContent)
CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, CertificationElementsWithoutPIDs & certDeclContent)
{
CHIP_ERROR err;
TLVReader reader;
TLVType outerContainer1, outerContainer2;
TLVType outerContainer;

VerifyOrReturnError(encodedCertElements.size() <= kMaxCMSSignedCDMessage, CHIP_ERROR_INVALID_ARGUMENT);

reader.Init(encodedCertElements);

ReturnErrorOnFailure(reader.Next(kTLVType_Structure, AnonymousTag));

ReturnErrorOnFailure(reader.EnterContainer(outerContainer1));
ReturnErrorOnFailure(reader.EnterContainer(outerContainer));

ReturnErrorOnFailure(reader.Next(ContextTag(kTag_FormatVersion)));
ReturnErrorOnFailure(reader.Get(certDeclContent.formatVersion));
Expand All @@ -197,11 +197,8 @@ CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, Cer
ReturnErrorOnFailure(reader.Get(certDeclContent.vendorId));

ReturnErrorOnFailure(reader.Next(kTLVType_Array, ContextTag(kTag_ProductIdArray)));
ReturnErrorOnFailure(reader.EnterContainer(outerContainer2));

certDeclContent.containsPID = true;

ReturnErrorOnFailure(reader.ExitContainer(outerContainer2));
// skip PID Array

ReturnErrorOnFailure(reader.Next(ContextTag(kTag_DeviceTypeId)));
ReturnErrorOnFailure(reader.Get(certDeclContent.deviceTypeId));
Expand Down Expand Up @@ -238,7 +235,7 @@ CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, Cer
}
VerifyOrReturnError(err == CHIP_END_OF_TLV || err == CHIP_ERROR_UNEXPECTED_TLV_ELEMENT || err == CHIP_NO_ERROR, err);

ReturnErrorOnFailure(reader.ExitContainer(outerContainer1));
ReturnErrorOnFailure(reader.ExitContainer(outerContainer));

ReturnErrorOnFailure(reader.VerifyEndOfContainer());

Expand Down
27 changes: 13 additions & 14 deletions src/credentials/CertificationDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,19 @@ struct CertificationElements
bool DACOriginVIDandPIDPresent;
};

struct CertificationDeclarationContent
struct CertificationElementsWithoutPIDs
{
uint16_t formatVersion;
uint16_t vendorId;
bool containsPID;
uint32_t deviceTypeId;
char certificateId[kCertificateIdLength + 1];
uint8_t securityLevel;
uint16_t securityInformation;
uint16_t versionNumber;
uint8_t certificationType;
uint16_t dacOriginVendorId;
uint16_t dacOriginProductId;
bool dacOriginVIDandPIDPresent;
uint16_t formatVersion = 0;
uint16_t vendorId = VendorId::NotSpecified;
uint32_t deviceTypeId = 0;
uint8_t securityLevel = 0;
uint16_t securityInformation = 0;
uint16_t versionNumber = 0;
uint8_t certificationType = 0;
uint16_t dacOriginVendorId = VendorId::NotSpecified;
uint16_t dacOriginProductId = 0;
bool dacOriginVIDandPIDPresent = false;
char certificateId[kCertificateIdLength + 1] = { 0 };
};

class CertificationElementsDecoder
Expand Down Expand Up @@ -123,7 +122,7 @@ CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, Cer
*
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
**/
CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, CertificationDeclarationContent & certDeclContent);
CHIP_ERROR DecodeCertificationElements(const ByteSpan & encodedCertElements, CertificationElementsWithoutPIDs & certDeclContent);

/**
* @brief Generate CMS signed message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ AttestationVerificationResult ExampleDACVerifier::ValidateCertificateDeclaration
const ByteSpan & firmwareInfo,
const DeviceInfoForAttestation & deviceInfo)
{
CertificationDeclarationContent cdContent;
CertificationElementsWithoutPIDs cdContent;
CertificationElementsDecoder cdElementsDecoder;
VerifyOrReturnError(DecodeCertificationElements(certDeclBuffer, cdContent) == CHIP_NO_ERROR,
AttestationVerificationResult::kCertificationDeclarationInvalidFormat);
Expand Down
3 changes: 1 addition & 2 deletions src/credentials/tests/TestCertificationDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,12 @@ static void TestCD_CertificationElementsDecoder(nlTestSuite * inSuite, void * in
NL_TEST_ASSERT(inSuite, EncodeCertificationElements(testCase.cdElements, encodedCDPayload) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, testCase.cdContent.data_equal(encodedCDPayload));

CertificationDeclarationContent certificationDeclarationContent;
CertificationElementsWithoutPIDs certificationDeclarationContent;
CertificationElementsDecoder certificationElementsDecoder;
NL_TEST_ASSERT(inSuite, DecodeCertificationElements(encodedCDPayload, certificationDeclarationContent) == CHIP_NO_ERROR);

NL_TEST_ASSERT(inSuite, certificationDeclarationContent.formatVersion == testCase.cdElements.FormatVersion);
NL_TEST_ASSERT(inSuite, certificationDeclarationContent.vendorId == testCase.cdElements.VendorId);
NL_TEST_ASSERT(inSuite, certificationDeclarationContent.containsPID == true);
for (uint8_t j = 0; j < testCase.cdElements.ProductIdsCount; j++)
{
NL_TEST_ASSERT(inSuite,
Expand Down

0 comments on commit b5f45aa

Please sign in to comment.