Skip to content

Commit 1c204ec

Browse files
TestChipCert: Test TLV to DER for compact PDC test vector (project-chip#43660)
Also update the PDC Identity test vector to the example given in the latest spec version. (The updated test vector was generated using Deterministic ECDSA, which will become relevant to future tests / code but makes no practical difference for now.)
1 parent ee9fd12 commit 1c204ec

2 files changed

Lines changed: 34 additions & 22 deletions

File tree

src/credentials/tests/CHIPCert_test_vectors.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,11 +2344,12 @@ extern constexpr ByteSpan sTestCert_Node02_08_AuthorityKeyId((const uint8_t[]){
23442344
});
23452345

23462346
/************** Test PDCID01 Certificate **************
2347+
Example Network Identity from the spec, signed using Deterministic ECDSA
23472348
Certificate:
23482349
Data:
23492350
Version: 3 (0x2)
23502351
Serial Number: 1 (0x1)
2351-
Signature Algorithm: ecdsa-with-SHA256
2352+
Signature Algorithm: ecdsa-with-SHA256
23522353
Issuer: CN=*
23532354
Validity
23542355
Not Before: Jan 1 00:00:01 2000 GMT
@@ -2373,19 +2374,19 @@ extern constexpr ByteSpan sTestCert_Node02_08_AuthorityKeyId((const uint8_t[]){
23732374
X509v3 Extended Key Usage: critical
23742375
TLS Web Client Authentication, TLS Web Server Authentication
23752376
Signature Algorithm: ecdsa-with-SHA256
2376-
30:45:02:21:00:e9:43:b6:16:f3:1a:f3:81:52:e7:37:41:f7:
2377-
47:28:db:7d:56:87:b5:94:c0:2e:0f:5f:ee:3a:60:bf:36:44:
2378-
a9:02:20:1c:85:2c:fd:6b:15:d8:f8:fe:19:93:4d:af:2f:91:
2379-
93:fd:2c:bc:4e:23:50:0a:31:7d:a4:a0:79:b2:db:69:42
2377+
30:45:02:20:38:4c:1b:d0:8f:e4:ca:a0:46:07:91:66:0d:82:
2378+
14:5d:fb:fe:97:d3:14:d1:5e:00:0d:75:c0:73:af:5d:7c:7e:
2379+
02:21:00:cc:1a:01:85:21:26:18:4a:d9:eb:ec:80:9b:4c:78:
2380+
ff:f3:81:fe:32:4b:af:88:1c:c8:24:9e:16:92:59:bd:5a
23802381
23812382
-----BEGIN CERTIFICATE-----
23822383
MIIBSjCB8aADAgECAgEBMAoGCCqGSM49BAMCMAwxCjAIBgNVBAMMASowIBcNMDAw
23832384
MTAxMDAwMDAxWhgPOTk5OTEyMzEyMzU5NTlaMAwxCjAIBgNVBAMMASowWTATBgcq
23842385
hkjOPQIBBggqhkjOPQMBBwNCAAQ5zNSsfllovfGwgBEdklNklPxRYkxwqm1zCNrt
23852386
86FeOGkXexvz0JBH6/Br6N0XviPy+z1jkMbPgoAvYtBTYsAIo0IwQDAMBgNVHRMB
23862387
Af8EAjAAMA4GA1UdDwEB/wQEAwIHgDAgBgNVHSUBAf8EFjAUBggrBgEFBQcDAgYI
2387-
KwYBBQUHAwEwCgYIKoZIzj0EAwIDSAAwRQIhAOlDthbzGvOBUuc3QfdHKNt9Voe1
2388-
lMAuD1/uOmC/NkSpAiAchSz9axXY+P4Zk02vL5GT/Sy8TiNQCjF9pKB5sttpQg==
2388+
KwYBBQUHAwEwCgYIKoZIzj0EAwIDSAAwRQIgOEwb0I/kyqBGB5FmDYIUXfv+l9MU
2389+
0V4ADXXAc69dfH4CIQDMGgGFISYYStnr7ICbTHj/84H+MkuviBzIJJ4Wklm9Wg==
23892390
-----END CERTIFICATE-----
23902391
23912392
-----BEGIN EC PRIVATE KEY-----
@@ -2395,26 +2396,27 @@ R+vwa+jdF74j8vs9Y5DGz4KAL2LQU2LACA==
23952396
-----END EC PRIVATE KEY-----
23962397
*/
23972398

2399+
// NOTE: This non-compact TLV version of the certificate is not given in the spec, it was created from DER via chip-cert convert
23982400
extern constexpr ByteSpan sTestCert_PDCID01_Chip((const uint8_t[]){
23992401
0x15, 0x30, 0x01, 0x01, 0x01, 0x24, 0x02, 0x01, 0x37, 0x03, 0x2c, 0x01, 0x01, 0x2a, 0x18, 0x24, 0x04, 0x01, 0x24, 0x05, 0x00,
24002402
0x37, 0x06, 0x2c, 0x01, 0x01, 0x2a, 0x18, 0x24, 0x07, 0x01, 0x24, 0x08, 0x01, 0x30, 0x09, 0x41, 0x04, 0x39, 0xcc, 0xd4, 0xac,
24012403
0x7e, 0x59, 0x68, 0xbd, 0xf1, 0xb0, 0x80, 0x11, 0x1d, 0x92, 0x53, 0x64, 0x94, 0xfc, 0x51, 0x62, 0x4c, 0x70, 0xaa, 0x6d, 0x73,
24022404
0x08, 0xda, 0xed, 0xf3, 0xa1, 0x5e, 0x38, 0x69, 0x17, 0x7b, 0x1b, 0xf3, 0xd0, 0x90, 0x47, 0xeb, 0xf0, 0x6b, 0xe8, 0xdd, 0x17,
24032405
0xbe, 0x23, 0xf2, 0xfb, 0x3d, 0x63, 0x90, 0xc6, 0xcf, 0x82, 0x80, 0x2f, 0x62, 0xd0, 0x53, 0x62, 0xc0, 0x08, 0x37, 0x0a, 0x35,
2404-
0x01, 0x28, 0x01, 0x18, 0x24, 0x02, 0x01, 0x36, 0x03, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x30, 0x0b, 0x40, 0xe9, 0x43, 0xb6,
2405-
0x16, 0xf3, 0x1a, 0xf3, 0x81, 0x52, 0xe7, 0x37, 0x41, 0xf7, 0x47, 0x28, 0xdb, 0x7d, 0x56, 0x87, 0xb5, 0x94, 0xc0, 0x2e, 0x0f,
2406-
0x5f, 0xee, 0x3a, 0x60, 0xbf, 0x36, 0x44, 0xa9, 0x1c, 0x85, 0x2c, 0xfd, 0x6b, 0x15, 0xd8, 0xf8, 0xfe, 0x19, 0x93, 0x4d, 0xaf,
2407-
0x2f, 0x91, 0x93, 0xfd, 0x2c, 0xbc, 0x4e, 0x23, 0x50, 0x0a, 0x31, 0x7d, 0xa4, 0xa0, 0x79, 0xb2, 0xdb, 0x69, 0x42, 0x18,
2406+
0x01, 0x28, 0x01, 0x18, 0x24, 0x02, 0x01, 0x36, 0x03, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x30, 0x0b, 0x40, 0x38, 0x4c, 0x1b,
2407+
0xd0, 0x8f, 0xe4, 0xca, 0xa0, 0x46, 0x07, 0x91, 0x66, 0x0d, 0x82, 0x14, 0x5d, 0xfb, 0xfe, 0x97, 0xd3, 0x14, 0xd1, 0x5e, 0x00,
2408+
0x0d, 0x75, 0xc0, 0x73, 0xaf, 0x5d, 0x7c, 0x7e, 0xcc, 0x1a, 0x01, 0x85, 0x21, 0x26, 0x18, 0x4a, 0xd9, 0xeb, 0xec, 0x80, 0x9b,
2409+
0x4c, 0x78, 0xff, 0xf3, 0x81, 0xfe, 0x32, 0x4b, 0xaf, 0x88, 0x1c, 0xc8, 0x24, 0x9e, 0x16, 0x92, 0x59, 0xbd, 0x5a, 0x18,
24082410
});
24092411

24102412
extern constexpr ByteSpan sTestCert_PDCID01_ChipCompact((const uint8_t[]){
24112413
0x15, 0x30, 0x09, 0x41, 0x04, 0x39, 0xcc, 0xd4, 0xac, 0x7e, 0x59, 0x68, 0xbd, 0xf1, 0xb0, 0x80, 0x11, 0x1d, 0x92, 0x53,
24122414
0x64, 0x94, 0xfc, 0x51, 0x62, 0x4c, 0x70, 0xaa, 0x6d, 0x73, 0x08, 0xda, 0xed, 0xf3, 0xa1, 0x5e, 0x38, 0x69, 0x17, 0x7b,
24132415
0x1b, 0xf3, 0xd0, 0x90, 0x47, 0xeb, 0xf0, 0x6b, 0xe8, 0xdd, 0x17, 0xbe, 0x23, 0xf2, 0xfb, 0x3d, 0x63, 0x90, 0xc6, 0xcf,
2414-
0x82, 0x80, 0x2f, 0x62, 0xd0, 0x53, 0x62, 0xc0, 0x08, 0x30, 0x0b, 0x40, 0xe9, 0x43, 0xb6, 0x16, 0xf3, 0x1a, 0xf3, 0x81,
2415-
0x52, 0xe7, 0x37, 0x41, 0xf7, 0x47, 0x28, 0xdb, 0x7d, 0x56, 0x87, 0xb5, 0x94, 0xc0, 0x2e, 0x0f, 0x5f, 0xee, 0x3a, 0x60,
2416-
0xbf, 0x36, 0x44, 0xa9, 0x1c, 0x85, 0x2c, 0xfd, 0x6b, 0x15, 0xd8, 0xf8, 0xfe, 0x19, 0x93, 0x4d, 0xaf, 0x2f, 0x91, 0x93,
2417-
0xfd, 0x2c, 0xbc, 0x4e, 0x23, 0x50, 0x0a, 0x31, 0x7d, 0xa4, 0xa0, 0x79, 0xb2, 0xdb, 0x69, 0x42, 0x18,
2416+
0x82, 0x80, 0x2f, 0x62, 0xd0, 0x53, 0x62, 0xc0, 0x08, 0x30, 0x0b, 0x40, 0x38, 0x4c, 0x1b, 0xd0, 0x8f, 0xe4, 0xca, 0xa0,
2417+
0x46, 0x07, 0x91, 0x66, 0x0d, 0x82, 0x14, 0x5d, 0xfb, 0xfe, 0x97, 0xd3, 0x14, 0xd1, 0x5e, 0x00, 0x0d, 0x75, 0xc0, 0x73,
2418+
0xaf, 0x5d, 0x7c, 0x7e, 0xcc, 0x1a, 0x01, 0x85, 0x21, 0x26, 0x18, 0x4a, 0xd9, 0xeb, 0xec, 0x80, 0x9b, 0x4c, 0x78, 0xff,
2419+
0xf3, 0x81, 0xfe, 0x32, 0x4b, 0xaf, 0x88, 0x1c, 0xc8, 0x24, 0x9e, 0x16, 0x92, 0x59, 0xbd, 0x5a, 0x18,
24182420
});
24192421

24202422
extern constexpr ByteSpan sTestCert_PDCID01_DER((const uint8_t[]){
@@ -2430,10 +2432,10 @@ extern constexpr ByteSpan sTestCert_PDCID01_DER((const uint8_t[]){
24302432
0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,
24312433
0x03, 0x02, 0x07, 0x80, 0x30, 0x20, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2b,
24322434
0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x30, 0x0a, 0x06, 0x08,
2433-
0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0xe9, 0x43, 0xb6, 0x16, 0xf3,
2434-
0x1a, 0xf3, 0x81, 0x52, 0xe7, 0x37, 0x41, 0xf7, 0x47, 0x28, 0xdb, 0x7d, 0x56, 0x87, 0xb5, 0x94, 0xc0, 0x2e, 0x0f, 0x5f, 0xee,
2435-
0x3a, 0x60, 0xbf, 0x36, 0x44, 0xa9, 0x02, 0x20, 0x1c, 0x85, 0x2c, 0xfd, 0x6b, 0x15, 0xd8, 0xf8, 0xfe, 0x19, 0x93, 0x4d, 0xaf,
2436-
0x2f, 0x91, 0x93, 0xfd, 0x2c, 0xbc, 0x4e, 0x23, 0x50, 0x0a, 0x31, 0x7d, 0xa4, 0xa0, 0x79, 0xb2, 0xdb, 0x69, 0x42,
2435+
0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x38, 0x4c, 0x1b, 0xd0, 0x8f, 0xe4,
2436+
0xca, 0xa0, 0x46, 0x07, 0x91, 0x66, 0x0d, 0x82, 0x14, 0x5d, 0xfb, 0xfe, 0x97, 0xd3, 0x14, 0xd1, 0x5e, 0x00, 0x0d, 0x75, 0xc0,
2437+
0x73, 0xaf, 0x5d, 0x7c, 0x7e, 0x02, 0x21, 0x00, 0xcc, 0x1a, 0x01, 0x85, 0x21, 0x26, 0x18, 0x4a, 0xd9, 0xeb, 0xec, 0x80, 0x9b,
2438+
0x4c, 0x78, 0xff, 0xf3, 0x81, 0xfe, 0x32, 0x4b, 0xaf, 0x88, 0x1c, 0xc8, 0x24, 0x9e, 0x16, 0x92, 0x59, 0xbd, 0x5a,
24372439
});
24382440

24392441
extern constexpr ByteSpan sTestCert_PDCID01_PublicKey((const uint8_t[]){

src/credentials/tests/TestChipCert.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,19 @@ TEST_F(TestChipCert, TestChipCert_ChipToX509)
191191
}
192192

193193
// Error Case:
194-
MutableByteSpan outCert(outCertBuf);
195-
err = ConvertChipCertToX509Cert(sTestCert_Node01_01_Err01_Chip, outCert);
196-
EXPECT_EQ(err, CHIP_ERROR_INVALID_TLV_TAG);
194+
{
195+
MutableByteSpan outCert(outCertBuf);
196+
err = ConvertChipCertToX509Cert(sTestCert_Node01_01_Err01_Chip, outCert);
197+
EXPECT_EQ(err, CHIP_ERROR_INVALID_TLV_TAG);
198+
}
199+
200+
// For a PDC Identity, converting from the compact form must work too
201+
{
202+
MutableByteSpan outCert(outCertBuf);
203+
err = ConvertChipCertToX509Cert(sTestCert_PDCID01_ChipCompact, outCert);
204+
EXPECT_EQ(err, CHIP_NO_ERROR);
205+
EXPECT_TRUE(sTestCert_PDCID01_DER.data_equal(outCert));
206+
}
197207
}
198208

199209
TEST_F(TestChipCert, TestChipCert_ChipToX509_ErrorCases)

0 commit comments

Comments
 (0)