Skip to content

Commit

Permalink
Make test vectors ByteSpans (project-chip#29200)
Browse files Browse the repository at this point in the history
This gets rid off some boilerplate compared to separate array and length symbols.
  • Loading branch information
ksperling-apple authored Sep 13, 2023
1 parent 511aafb commit 9ebd18a
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 700 deletions.
634 changes: 210 additions & 424 deletions src/credentials/tests/CHIPCert_test_vectors.cpp

Large diffs are not rendered by default.

343 changes: 120 additions & 223 deletions src/credentials/tests/CHIPCert_test_vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,229 +81,126 @@ extern const size_t gNumTestCerts;

// ------------------------------ DECLARATIONS ----------------------------------------

extern const uint8_t sTestCert_Root01_Chip[];
extern const size_t sTestCert_Root01_Chip_Len;
extern const uint8_t sTestCert_Root01_DER[];
extern const size_t sTestCert_Root01_DER_Len;
extern const uint8_t sTestCert_Root01_PublicKey[];
extern const size_t sTestCert_Root01_PublicKey_Len;
extern const uint8_t sTestCert_Root01_PrivateKey[];
extern const size_t sTestCert_Root01_PrivateKey_Len;
extern const uint8_t sTestCert_Root01_SubjectKeyId[];
extern const size_t sTestCert_Root01_SubjectKeyId_Len;
extern const uint8_t sTestCert_Root01_AuthorityKeyId[];
extern const size_t sTestCert_Root01_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Root02_Chip[];
extern const size_t sTestCert_Root02_Chip_Len;
extern const uint8_t sTestCert_Root02_DER[];
extern const size_t sTestCert_Root02_DER_Len;
extern const uint8_t sTestCert_Root02_PublicKey[];
extern const size_t sTestCert_Root02_PublicKey_Len;
extern const uint8_t sTestCert_Root02_PrivateKey[];
extern const size_t sTestCert_Root02_PrivateKey_Len;
extern const uint8_t sTestCert_Root02_SubjectKeyId[];
extern const size_t sTestCert_Root02_SubjectKeyId_Len;
extern const uint8_t sTestCert_Root02_AuthorityKeyId[];
extern const size_t sTestCert_Root02_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Root03_Chip[];
extern const size_t sTestCert_Root03_Chip_Len;
extern const uint8_t sTestCert_Root03_DER[];
extern const size_t sTestCert_Root03_DER_Len;
extern const uint8_t sTestCert_Root03_PublicKey[];
extern const size_t sTestCert_Root03_PublicKey_Len;
extern const uint8_t sTestCert_Root03_PrivateKey[];
extern const size_t sTestCert_Root03_PrivateKey_Len;
extern const uint8_t sTestCert_Root03_SubjectKeyId[];
extern const size_t sTestCert_Root03_SubjectKeyId_Len;
extern const uint8_t sTestCert_Root03_AuthorityKeyId[];
extern const size_t sTestCert_Root03_AuthorityKeyId_Len;

extern const uint8_t sTestCert_ICA01_Chip[];
extern const size_t sTestCert_ICA01_Chip_Len;
extern const uint8_t sTestCert_ICA01_DER[];
extern const size_t sTestCert_ICA01_DER_Len;
extern const uint8_t sTestCert_ICA01_PublicKey[];
extern const size_t sTestCert_ICA01_PublicKey_Len;
extern const uint8_t sTestCert_ICA01_PrivateKey[];
extern const size_t sTestCert_ICA01_PrivateKey_Len;
extern const uint8_t sTestCert_ICA01_SubjectKeyId[];
extern const size_t sTestCert_ICA01_SubjectKeyId_Len;
extern const uint8_t sTestCert_ICA01_AuthorityKeyId[];
extern const size_t sTestCert_ICA01_AuthorityKeyId_Len;

extern const uint8_t sTestCert_ICA02_Chip[];
extern const size_t sTestCert_ICA02_Chip_Len;
extern const uint8_t sTestCert_ICA02_DER[];
extern const size_t sTestCert_ICA02_DER_Len;
extern const uint8_t sTestCert_ICA02_PublicKey[];
extern const size_t sTestCert_ICA02_PublicKey_Len;
extern const uint8_t sTestCert_ICA02_PrivateKey[];
extern const size_t sTestCert_ICA02_PrivateKey_Len;
extern const uint8_t sTestCert_ICA02_SubjectKeyId[];
extern const size_t sTestCert_ICA02_SubjectKeyId_Len;
extern const uint8_t sTestCert_ICA02_AuthorityKeyId[];
extern const size_t sTestCert_ICA02_AuthorityKeyId_Len;

extern const uint8_t sTestCert_ICA01_1_Chip[];
extern const size_t sTestCert_ICA01_1_Chip_Len;
extern const uint8_t sTestCert_ICA01_1_DER[];
extern const size_t sTestCert_ICA01_1_DER_Len;
extern const uint8_t sTestCert_ICA01_1_PublicKey[];
extern const size_t sTestCert_ICA01_1_PublicKey_Len;
extern const uint8_t sTestCert_ICA01_1_PrivateKey[];
extern const size_t sTestCert_ICA01_1_PrivateKey_Len;
extern const uint8_t sTestCert_ICA01_1_SubjectKeyId[];
extern const size_t sTestCert_ICA01_1_SubjectKeyId_Len;
extern const uint8_t sTestCert_ICA01_1_AuthorityKeyId[];
extern const size_t sTestCert_ICA01_1_AuthorityKeyId_Len;

extern const uint8_t sTestCert_FWSign01_Chip[];
extern const size_t sTestCert_FWSign01_Chip_Len;
extern const uint8_t sTestCert_FWSign01_DER[];
extern const size_t sTestCert_FWSign01_DER_Len;
extern const uint8_t sTestCert_FWSign01_PublicKey[];
extern const size_t sTestCert_FWSign01_PublicKey_Len;
extern const uint8_t sTestCert_FWSign01_PrivateKey[];
extern const size_t sTestCert_FWSign01_PrivateKey_Len;
extern const uint8_t sTestCert_FWSign01_SubjectKeyId[];
extern const size_t sTestCert_FWSign01_SubjectKeyId_Len;
extern const uint8_t sTestCert_FWSign01_AuthorityKeyId[];
extern const size_t sTestCert_FWSign01_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node01_01_Chip[];
extern const size_t sTestCert_Node01_01_Chip_Len;
extern const uint8_t sTestCert_Node01_01_DER[];
extern const size_t sTestCert_Node01_01_DER_Len;
extern const uint8_t sTestCert_Node01_01_PublicKey[];
extern const size_t sTestCert_Node01_01_PublicKey_Len;
extern const uint8_t sTestCert_Node01_01_PrivateKey[];
extern const size_t sTestCert_Node01_01_PrivateKey_Len;
extern const uint8_t sTestCert_Node01_01_SubjectKeyId[];
extern const size_t sTestCert_Node01_01_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node01_01_AuthorityKeyId[];
extern const size_t sTestCert_Node01_01_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node01_01_Err01_Chip[];
extern const size_t sTestCert_Node01_01_Err01_Chip_Len;

extern const uint8_t sTestCert_Node01_02_Chip[];
extern const size_t sTestCert_Node01_02_Chip_Len;
extern const uint8_t sTestCert_Node01_02_DER[];
extern const size_t sTestCert_Node01_02_DER_Len;
extern const uint8_t sTestCert_Node01_02_PublicKey[];
extern const size_t sTestCert_Node01_02_PublicKey_Len;
extern const uint8_t sTestCert_Node01_02_PrivateKey[];
extern const size_t sTestCert_Node01_02_PrivateKey_Len;
extern const uint8_t sTestCert_Node01_02_SubjectKeyId[];
extern const size_t sTestCert_Node01_02_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node01_02_AuthorityKeyId[];
extern const size_t sTestCert_Node01_02_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_01_Chip[];
extern const size_t sTestCert_Node02_01_Chip_Len;
extern const uint8_t sTestCert_Node02_01_DER[];
extern const size_t sTestCert_Node02_01_DER_Len;
extern const uint8_t sTestCert_Node02_01_PublicKey[];
extern const size_t sTestCert_Node02_01_PublicKey_Len;
extern const uint8_t sTestCert_Node02_01_PrivateKey[];
extern const size_t sTestCert_Node02_01_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_01_SubjectKeyId[];
extern const size_t sTestCert_Node02_01_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_01_AuthorityKeyId[];
extern const size_t sTestCert_Node02_01_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_02_Chip[];
extern const size_t sTestCert_Node02_02_Chip_Len;
extern const uint8_t sTestCert_Node02_02_DER[];
extern const size_t sTestCert_Node02_02_DER_Len;
extern const uint8_t sTestCert_Node02_02_PublicKey[];
extern const size_t sTestCert_Node02_02_PublicKey_Len;
extern const uint8_t sTestCert_Node02_02_PrivateKey[];
extern const size_t sTestCert_Node02_02_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_02_SubjectKeyId[];
extern const size_t sTestCert_Node02_02_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_02_AuthorityKeyId[];
extern const size_t sTestCert_Node02_02_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_03_Chip[];
extern const size_t sTestCert_Node02_03_Chip_Len;
extern const uint8_t sTestCert_Node02_03_DER[];
extern const size_t sTestCert_Node02_03_DER_Len;
extern const uint8_t sTestCert_Node02_03_PublicKey[];
extern const size_t sTestCert_Node02_03_PublicKey_Len;
extern const uint8_t sTestCert_Node02_03_PrivateKey[];
extern const size_t sTestCert_Node02_03_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_03_SubjectKeyId[];
extern const size_t sTestCert_Node02_03_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_03_AuthorityKeyId[];
extern const size_t sTestCert_Node02_03_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_04_Chip[];
extern const size_t sTestCert_Node02_04_Chip_Len;
extern const uint8_t sTestCert_Node02_04_DER[];
extern const size_t sTestCert_Node02_04_DER_Len;
extern const uint8_t sTestCert_Node02_04_PublicKey[];
extern const size_t sTestCert_Node02_04_PublicKey_Len;
extern const uint8_t sTestCert_Node02_04_PrivateKey[];
extern const size_t sTestCert_Node02_04_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_04_SubjectKeyId[];
extern const size_t sTestCert_Node02_04_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_04_AuthorityKeyId[];
extern const size_t sTestCert_Node02_04_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_05_Chip[];
extern const size_t sTestCert_Node02_05_Chip_Len;
extern const uint8_t sTestCert_Node02_05_DER[];
extern const size_t sTestCert_Node02_05_DER_Len;
extern const uint8_t sTestCert_Node02_05_PublicKey[];
extern const size_t sTestCert_Node02_05_PublicKey_Len;
extern const uint8_t sTestCert_Node02_05_PrivateKey[];
extern const size_t sTestCert_Node02_05_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_05_SubjectKeyId[];
extern const size_t sTestCert_Node02_05_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_05_AuthorityKeyId[];
extern const size_t sTestCert_Node02_05_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_06_Chip[];
extern const size_t sTestCert_Node02_06_Chip_Len;
extern const uint8_t sTestCert_Node02_06_DER[];
extern const size_t sTestCert_Node02_06_DER_Len;
extern const uint8_t sTestCert_Node02_06_PublicKey[];
extern const size_t sTestCert_Node02_06_PublicKey_Len;
extern const uint8_t sTestCert_Node02_06_PrivateKey[];
extern const size_t sTestCert_Node02_06_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_06_SubjectKeyId[];
extern const size_t sTestCert_Node02_06_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_06_AuthorityKeyId[];
extern const size_t sTestCert_Node02_06_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_07_Chip[];
extern const size_t sTestCert_Node02_07_Chip_Len;
extern const uint8_t sTestCert_Node02_07_DER[];
extern const size_t sTestCert_Node02_07_DER_Len;
extern const uint8_t sTestCert_Node02_07_PublicKey[];
extern const size_t sTestCert_Node02_07_PublicKey_Len;
extern const uint8_t sTestCert_Node02_07_PrivateKey[];
extern const size_t sTestCert_Node02_07_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_07_SubjectKeyId[];
extern const size_t sTestCert_Node02_07_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_07_AuthorityKeyId[];
extern const size_t sTestCert_Node02_07_AuthorityKeyId_Len;

extern const uint8_t sTestCert_Node02_08_Chip[];
extern const size_t sTestCert_Node02_08_Chip_Len;
extern const uint8_t sTestCert_Node02_08_DER[];
extern const size_t sTestCert_Node02_08_DER_Len;
extern const uint8_t sTestCert_Node02_08_PublicKey[];
extern const size_t sTestCert_Node02_08_PublicKey_Len;
extern const uint8_t sTestCert_Node02_08_PrivateKey[];
extern const size_t sTestCert_Node02_08_PrivateKey_Len;
extern const uint8_t sTestCert_Node02_08_SubjectKeyId[];
extern const size_t sTestCert_Node02_08_SubjectKeyId_Len;
extern const uint8_t sTestCert_Node02_08_AuthorityKeyId[];
extern const size_t sTestCert_Node02_08_AuthorityKeyId_Len;
extern const ByteSpan sTestCert_Root01_Chip;
extern const ByteSpan sTestCert_Root01_DER;
extern const ByteSpan sTestCert_Root01_PublicKey;
extern const ByteSpan sTestCert_Root01_PrivateKey;
extern const ByteSpan sTestCert_Root01_SubjectKeyId;
extern const ByteSpan sTestCert_Root01_AuthorityKeyId;

extern const ByteSpan sTestCert_Root02_Chip;
extern const ByteSpan sTestCert_Root02_DER;
extern const ByteSpan sTestCert_Root02_PublicKey;
extern const ByteSpan sTestCert_Root02_PrivateKey;
extern const ByteSpan sTestCert_Root02_SubjectKeyId;
extern const ByteSpan sTestCert_Root02_AuthorityKeyId;

extern const ByteSpan sTestCert_Root03_Chip;
extern const ByteSpan sTestCert_Root03_DER;
extern const ByteSpan sTestCert_Root03_PublicKey;
extern const ByteSpan sTestCert_Root03_PrivateKey;
extern const ByteSpan sTestCert_Root03_SubjectKeyId;
extern const ByteSpan sTestCert_Root03_AuthorityKeyId;

extern const ByteSpan sTestCert_ICA01_Chip;
extern const ByteSpan sTestCert_ICA01_DER;
extern const ByteSpan sTestCert_ICA01_PublicKey;
extern const ByteSpan sTestCert_ICA01_PrivateKey;
extern const ByteSpan sTestCert_ICA01_SubjectKeyId;
extern const ByteSpan sTestCert_ICA01_AuthorityKeyId;

extern const ByteSpan sTestCert_ICA02_Chip;
extern const ByteSpan sTestCert_ICA02_DER;
extern const ByteSpan sTestCert_ICA02_PublicKey;
extern const ByteSpan sTestCert_ICA02_PrivateKey;
extern const ByteSpan sTestCert_ICA02_SubjectKeyId;
extern const ByteSpan sTestCert_ICA02_AuthorityKeyId;

extern const ByteSpan sTestCert_ICA01_1_Chip;
extern const ByteSpan sTestCert_ICA01_1_DER;
extern const ByteSpan sTestCert_ICA01_1_PublicKey;
extern const ByteSpan sTestCert_ICA01_1_PrivateKey;
extern const ByteSpan sTestCert_ICA01_1_SubjectKeyId;
extern const ByteSpan sTestCert_ICA01_1_AuthorityKeyId;

extern const ByteSpan sTestCert_FWSign01_Chip;
extern const ByteSpan sTestCert_FWSign01_DER;
extern const ByteSpan sTestCert_FWSign01_PublicKey;
extern const ByteSpan sTestCert_FWSign01_PrivateKey;
extern const ByteSpan sTestCert_FWSign01_SubjectKeyId;
extern const ByteSpan sTestCert_FWSign01_AuthorityKeyId;

extern const ByteSpan sTestCert_Node01_01_Chip;
extern const ByteSpan sTestCert_Node01_01_DER;
extern const ByteSpan sTestCert_Node01_01_PublicKey;
extern const ByteSpan sTestCert_Node01_01_PrivateKey;
extern const ByteSpan sTestCert_Node01_01_SubjectKeyId;
extern const ByteSpan sTestCert_Node01_01_AuthorityKeyId;

extern const ByteSpan sTestCert_Node01_01_Err01_Chip;

extern const ByteSpan sTestCert_Node01_02_Chip;
extern const ByteSpan sTestCert_Node01_02_DER;
extern const ByteSpan sTestCert_Node01_02_PublicKey;
extern const ByteSpan sTestCert_Node01_02_PrivateKey;
extern const ByteSpan sTestCert_Node01_02_SubjectKeyId;
extern const ByteSpan sTestCert_Node01_02_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_01_Chip;
extern const ByteSpan sTestCert_Node02_01_DER;
extern const ByteSpan sTestCert_Node02_01_PublicKey;
extern const ByteSpan sTestCert_Node02_01_PrivateKey;
extern const ByteSpan sTestCert_Node02_01_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_01_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_02_Chip;
extern const ByteSpan sTestCert_Node02_02_DER;
extern const ByteSpan sTestCert_Node02_02_PublicKey;
extern const ByteSpan sTestCert_Node02_02_PrivateKey;
extern const ByteSpan sTestCert_Node02_02_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_02_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_03_Chip;
extern const ByteSpan sTestCert_Node02_03_DER;
extern const ByteSpan sTestCert_Node02_03_PublicKey;
extern const ByteSpan sTestCert_Node02_03_PrivateKey;
extern const ByteSpan sTestCert_Node02_03_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_03_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_04_Chip;
extern const ByteSpan sTestCert_Node02_04_DER;
extern const ByteSpan sTestCert_Node02_04_PublicKey;
extern const ByteSpan sTestCert_Node02_04_PrivateKey;
extern const ByteSpan sTestCert_Node02_04_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_04_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_05_Chip;
extern const ByteSpan sTestCert_Node02_05_DER;
extern const ByteSpan sTestCert_Node02_05_PublicKey;
extern const ByteSpan sTestCert_Node02_05_PrivateKey;
extern const ByteSpan sTestCert_Node02_05_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_05_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_06_Chip;
extern const ByteSpan sTestCert_Node02_06_DER;
extern const ByteSpan sTestCert_Node02_06_PublicKey;
extern const ByteSpan sTestCert_Node02_06_PrivateKey;
extern const ByteSpan sTestCert_Node02_06_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_06_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_07_Chip;
extern const ByteSpan sTestCert_Node02_07_DER;
extern const ByteSpan sTestCert_Node02_07_PublicKey;
extern const ByteSpan sTestCert_Node02_07_PrivateKey;
extern const ByteSpan sTestCert_Node02_07_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_07_AuthorityKeyId;

extern const ByteSpan sTestCert_Node02_08_Chip;
extern const ByteSpan sTestCert_Node02_08_DER;
extern const ByteSpan sTestCert_Node02_08_PublicKey;
extern const ByteSpan sTestCert_Node02_08_PrivateKey;
extern const ByteSpan sTestCert_Node02_08_SubjectKeyId;
extern const ByteSpan sTestCert_Node02_08_AuthorityKeyId;

} // namespace TestCerts
} // namespace chip
12 changes: 6 additions & 6 deletions src/credentials/tests/TestChipCert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static void TestChipCert_ChipToX509(nlTestSuite * inSuite, void * inContext)

// Error Case:
MutableByteSpan outCert(outCertBuf);
err = ConvertChipCertToX509Cert(ByteSpan(sTestCert_Node01_01_Err01_Chip, sTestCert_Node01_01_Err01_Chip_Len), outCert);
err = ConvertChipCertToX509Cert(sTestCert_Node01_01_Err01_Chip, outCert);
NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INVALID_TLV_TAG);
}

Expand Down Expand Up @@ -2059,12 +2059,12 @@ static void TestChipCert_ExtractPublicKeyAndSKID(nlTestSuite * inSuite, void * i
struct TestCase
{
uint8_t Cert;
const uint8_t * ExpectedPublicKey;
const uint8_t * ExpectedSKID;
ByteSpan ExpectedPublicKey;
ByteSpan ExpectedSKID;
};

// clang-format off
static constexpr TestCase sTestCases[] = {
static const TestCase sTestCases[] = {
// Cert ExpectedPublicKey ExpectedSKID
// =======================================================================================
{ TestCert::kRoot01, sTestCert_Root01_PublicKey, sTestCert_Root01_SubjectKeyId },
Expand Down Expand Up @@ -2094,12 +2094,12 @@ static void TestChipCert_ExtractPublicKeyAndSKID(nlTestSuite * inSuite, void * i
P256PublicKeySpan publicKey;
err = ExtractPublicKeyFromChipCert(cert, publicKey);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, publicKey.data_equal(P256PublicKeySpan(testCase.ExpectedPublicKey)));
NL_TEST_ASSERT(inSuite, publicKey.data_equal(testCase.ExpectedPublicKey));

CertificateKeyId skid;
err = ExtractSKIDFromChipCert(cert, skid);
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, skid.data_equal(CertificateKeyId(testCase.ExpectedSKID)));
NL_TEST_ASSERT(inSuite, skid.data_equal(testCase.ExpectedSKID));
}
}

Expand Down
Loading

0 comments on commit 9ebd18a

Please sign in to comment.