Skip to content

Commit 1138076

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Fix generation of certificates without an expiration date. (#26402)
* Fix generation of certificates without an expiration date. Since Matter encodes "no expiration" as 0, we can't just check that notAfter >= notBefore; we have to check for the case when notAfter is "no expiration" separately. * Add unit test for no defined notAfter time. * Add unit tests for conversion of certs with no defined notAfter time.
1 parent f093fa0 commit 1138076

File tree

5 files changed

+174
-2
lines changed

5 files changed

+174
-2
lines changed

src/credentials/CHIPCert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ DLL_EXPORT CHIP_ERROR ChipEpochToASN1Time(uint32_t epochTime, chip::ASN1::ASN1Un
11231123
// times, which in consuming code can create a conversion from CHIP epoch 0 seconds to 99991231235959Z
11241124
// for NotBefore, which is not conventional.
11251125
//
1126-
// If an original X509 certificate encloses a NotBefore time that this the CHIP Epoch itself, 2000-01-01
1126+
// If an original X509 certificate encloses a NotBefore time that is the CHIP Epoch itself, 2000-01-01
11271127
// 00:00:00, the resultant X509 certificate in a conversion back from CHIP TLV format using this time
11281128
// conversion method will instead enclose the NotBefore time 99991231235959Z, which will invalidiate the
11291129
// TBS signature. Thus, certificates with this specific attribute are not usable with this code.

src/credentials/GenerateChipX509Cert.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ CHIP_ERROR EncodeTBSCert(const X509CertRequestParams & requestParams, const Cryp
330330
bool isCA;
331331

332332
VerifyOrReturnError(requestParams.SerialNumber >= 0, CHIP_ERROR_INVALID_ARGUMENT);
333-
VerifyOrReturnError(requestParams.ValidityEnd >= requestParams.ValidityStart, CHIP_ERROR_INVALID_ARGUMENT);
333+
VerifyOrReturnError(requestParams.ValidityEnd == kNullCertTime || requestParams.ValidityEnd >= requestParams.ValidityStart,
334+
CHIP_ERROR_INVALID_ARGUMENT);
334335

335336
ReturnErrorOnFailure(requestParams.SubjectDN.GetCertType(certType));
336337
isCA = (certType == kCertType_ICA || certType == kCertType_Root);

src/credentials/tests/CHIPCert_test_vectors.cpp

+140
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace TestCerts {
3535
extern const uint8_t gTestCerts[] = {
3636
TestCert::kRoot01,
3737
TestCert::kRoot02,
38+
TestCert::kRoot03,
3839
TestCert::kICA01,
3940
TestCert::kICA02,
4041
TestCert::kICA01_1,
@@ -78,6 +79,7 @@ CHIP_ERROR GetTestCert(uint8_t certType, BitFlags<TestCertLoadFlags> certLoadFla
7879

7980
SELECT_CERT(Root01);
8081
SELECT_CERT(Root02);
82+
SELECT_CERT(Root03);
8183
SELECT_CERT(ICA01);
8284
SELECT_CERT(ICA02);
8385
SELECT_CERT(ICA01_1);
@@ -114,6 +116,7 @@ const char * GetTestCertName(uint8_t certType)
114116

115117
NAME_CERT(Root01);
116118
NAME_CERT(Root02);
119+
NAME_CERT(Root03);
117120
NAME_CERT(ICA01);
118121
NAME_CERT(ICA02);
119122
NAME_CERT(ICA01_1);
@@ -150,6 +153,7 @@ CHIP_ERROR GetTestCertPubkey(uint8_t certType, ByteSpan & pubkey)
150153

151154
SELECT_PUBKEY(Root01);
152155
SELECT_PUBKEY(Root02);
156+
SELECT_PUBKEY(Root03);
153157
SELECT_PUBKEY(ICA01);
154158
SELECT_PUBKEY(ICA02);
155159
SELECT_PUBKEY(ICA01_1);
@@ -189,6 +193,7 @@ CHIP_ERROR GetTestCertSKID(uint8_t certType, ByteSpan & skid)
189193

190194
SELECT_SKID(Root01);
191195
SELECT_SKID(Root02);
196+
SELECT_SKID(Root03);
192197
SELECT_SKID(ICA01);
193198
SELECT_SKID(ICA02);
194199
SELECT_SKID(ICA01_1);
@@ -228,6 +233,7 @@ CHIP_ERROR GetTestCertAKID(uint8_t certType, ByteSpan & akid)
228233

229234
SELECT_AKID(Root01);
230235
SELECT_AKID(Root02);
236+
SELECT_AKID(Root03);
231237
SELECT_AKID(ICA01);
232238
SELECT_AKID(ICA02);
233239
SELECT_AKID(ICA01_1);
@@ -557,6 +563,140 @@ extern const uint8_t sTestCert_Root02_AuthorityKeyId[] = {
557563

558564
extern const size_t sTestCert_Root02_AuthorityKeyId_Len = sizeof(sTestCert_Root02_AuthorityKeyId);
559565

566+
/************** Test Root03 Certificate **************
567+
Certificate:
568+
Data:
569+
Version: 3 (0x2)
570+
Serial Number: 7744074172075392897 (0x6b787a6dfcd4bf81)
571+
Signature Algorithm: ecdsa-with-SHA256
572+
Issuer: 1.3.6.1.4.1.37244.1.4 = CACACACA00000002, 1.3.6.1.4.1.37244.1.5 = FAB000000000001D
573+
Validity
574+
Not Before: Oct 15 14:23:43 2020 GMT
575+
Not After : Dec 31 23:59:59 9999 GMT
576+
Subject: 1.3.6.1.4.1.37244.1.4 = CACACACA00000002, 1.3.6.1.4.1.37244.1.5 = FAB000000000001D
577+
Subject Public Key Info:
578+
Public Key Algorithm: id-ecPublicKey
579+
Public-Key: (256 bit)
580+
pub:
581+
04:71:05:40:8a:85:a9:d9:a0:8a:f8:b7:70:77:db:
582+
38:8b:7e:a4:38:97:dc:df:d3:16:f2:4f:0a:7e:71:
583+
de:69:a5:0c:44:55:0c:0c:9d:a2:36:1c:d8:29:e5:
584+
5f:dd:63:cc:f5:79:ed:44:e0:22:08:b4:f8:25:fc:
585+
d6:f0:68:2c:02
586+
ASN1 OID: prime256v1
587+
NIST CURVE: P-256
588+
X509v3 extensions:
589+
X509v3 Basic Constraints: critical
590+
CA:TRUE, pathlen:1
591+
X509v3 Key Usage: critical
592+
Certificate Sign, CRL Sign
593+
X509v3 Subject Key Identifier:
594+
FF:87:F3:CD:D2:06:9A:EF:8D:5D:32:EB:A3:16:3B:9E:B0:0A:00:29
595+
X509v3 Authority Key Identifier:
596+
keyid:FF:87:F3:CD:D2:06:9A:EF:8D:5D:32:EB:A3:16:3B:9E:B0:0A:00:29
597+
598+
Signature Algorithm: ecdsa-with-SHA256
599+
30:44:02:20:75:f6:70:eb:35:45:b9:97:86:46:67:99:eb:ea:
600+
40:51:a3:41:af:2a:9b:67:7f:d7:1b:4c:3d:4e:68:09:3b:66:
601+
02:20:5f:28:42:cb:7e:d3:19:9c:9a:d7:c9:62:79:47:a1:8a:
602+
92:16:8a:fc:d6:5f:3e:9c:af:6e:ed:fa:9e:60:c5:2f
603+
604+
-----BEGIN CERTIFICATE-----
605+
MIIB5TCCAYygAwIBAgIIa3h6bfzUv4EwCgYIKoZIzj0EAwIwRDEgMB4GCisGAQQB
606+
gqJ8AQQMEENBQ0FDQUNBMDAwMDAwMDIxIDAeBgorBgEEAYKifAEFDBBGQUIwMDAw
607+
MDAwMDAwMDFEMCAXDTIwMTAxNTE0MjM0M1oYDzk5OTkxMjMxMjM1OTU5WjBEMSAw
608+
HgYKKwYBBAGConwBBAwQQ0FDQUNBQ0EwMDAwMDAwMjEgMB4GCisGAQQBgqJ8AQUM
609+
EEZBQjAwMDAwMDAwMDAwMUQwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARxBUCK
610+
hanZoIr4t3B32ziLfqQ4l9zf0xbyTwp+cd5ppQxEVQwMnaI2HNgp5V/dY8z1ee1E
611+
4CIItPgl/NbwaCwCo2YwZDASBgNVHRMBAf8ECDAGAQH/AgEBMA4GA1UdDwEB/wQE
612+
AwIBBjAdBgNVHQ4EFgQU/4fzzdIGmu+NXTLroxY7nrAKACkwHwYDVR0jBBgwFoAU
613+
/4fzzdIGmu+NXTLroxY7nrAKACkwCgYIKoZIzj0EAwIDRwAwRAIgdfZw6zVFuZeG
614+
RmeZ6+pAUaNBryqbZ3/XG0w9TmgJO2YCIF8oQst+0xmcmtfJYnlHoYqSFor81l8+
615+
nK9u7fqeYMUv
616+
-----END CERTIFICATE-----
617+
618+
-----BEGIN EC PRIVATE KEY-----
619+
MHcCAQEEIHDnbQApKIHktaW8tOzQL/XkdbwUid5uw+jWPFo/LlqHoAoGCCqGSM49
620+
AwEHoUQDQgAEcQVAioWp2aCK+Ldwd9s4i36kOJfc39MW8k8KfnHeaaUMRFUMDJ2i
621+
NhzYKeVf3WPM9XntROAiCLT4JfzW8GgsAg==
622+
-----END EC PRIVATE KEY-----
623+
*/
624+
625+
extern const uint8_t sTestCert_Root03_Chip[] = {
626+
0x15, 0x30, 0x01, 0x08, 0x6b, 0x78, 0x7a, 0x6d, 0xfc, 0xd4, 0xbf, 0x81, 0x24, 0x02, 0x01, 0x37, 0x03, 0x27, 0x14, 0x02, 0x00,
627+
0x00, 0x00, 0xca, 0xca, 0xca, 0xca, 0x27, 0x15, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0xfa, 0x18, 0x26, 0x04, 0xef, 0x17,
628+
0x1b, 0x27, 0x24, 0x05, 0x00, 0x37, 0x06, 0x27, 0x14, 0x02, 0x00, 0x00, 0x00, 0xca, 0xca, 0xca, 0xca, 0x27, 0x15, 0x1d, 0x00,
629+
0x00, 0x00, 0x00, 0x00, 0xb0, 0xfa, 0x18, 0x24, 0x07, 0x01, 0x24, 0x08, 0x01, 0x30, 0x09, 0x41, 0x04, 0x71, 0x05, 0x40, 0x8a,
630+
0x85, 0xa9, 0xd9, 0xa0, 0x8a, 0xf8, 0xb7, 0x70, 0x77, 0xdb, 0x38, 0x8b, 0x7e, 0xa4, 0x38, 0x97, 0xdc, 0xdf, 0xd3, 0x16, 0xf2,
631+
0x4f, 0x0a, 0x7e, 0x71, 0xde, 0x69, 0xa5, 0x0c, 0x44, 0x55, 0x0c, 0x0c, 0x9d, 0xa2, 0x36, 0x1c, 0xd8, 0x29, 0xe5, 0x5f, 0xdd,
632+
0x63, 0xcc, 0xf5, 0x79, 0xed, 0x44, 0xe0, 0x22, 0x08, 0xb4, 0xf8, 0x25, 0xfc, 0xd6, 0xf0, 0x68, 0x2c, 0x02, 0x37, 0x0a, 0x35,
633+
0x01, 0x29, 0x01, 0x24, 0x02, 0x01, 0x18, 0x24, 0x02, 0x60, 0x30, 0x04, 0x14, 0xff, 0x87, 0xf3, 0xcd, 0xd2, 0x06, 0x9a, 0xef,
634+
0x8d, 0x5d, 0x32, 0xeb, 0xa3, 0x16, 0x3b, 0x9e, 0xb0, 0x0a, 0x00, 0x29, 0x30, 0x05, 0x14, 0xff, 0x87, 0xf3, 0xcd, 0xd2, 0x06,
635+
0x9a, 0xef, 0x8d, 0x5d, 0x32, 0xeb, 0xa3, 0x16, 0x3b, 0x9e, 0xb0, 0x0a, 0x00, 0x29, 0x18, 0x30, 0x0b, 0x40, 0x75, 0xf6, 0x70,
636+
0xeb, 0x35, 0x45, 0xb9, 0x97, 0x86, 0x46, 0x67, 0x99, 0xeb, 0xea, 0x40, 0x51, 0xa3, 0x41, 0xaf, 0x2a, 0x9b, 0x67, 0x7f, 0xd7,
637+
0x1b, 0x4c, 0x3d, 0x4e, 0x68, 0x09, 0x3b, 0x66, 0x5f, 0x28, 0x42, 0xcb, 0x7e, 0xd3, 0x19, 0x9c, 0x9a, 0xd7, 0xc9, 0x62, 0x79,
638+
0x47, 0xa1, 0x8a, 0x92, 0x16, 0x8a, 0xfc, 0xd6, 0x5f, 0x3e, 0x9c, 0xaf, 0x6e, 0xed, 0xfa, 0x9e, 0x60, 0xc5, 0x2f, 0x18,
639+
};
640+
641+
extern const size_t sTestCert_Root03_Chip_Len = sizeof(sTestCert_Root03_Chip);
642+
643+
extern const uint8_t sTestCert_Root03_DER[] = {
644+
0x30, 0x82, 0x01, 0xe5, 0x30, 0x82, 0x01, 0x8c, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x08, 0x6b, 0x78, 0x7a, 0x6d, 0xfc, 0xd4,
645+
0xbf, 0x81, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x44, 0x31, 0x20, 0x30, 0x1e, 0x06,
646+
0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x01, 0x04, 0x0c, 0x10, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41,
647+
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2,
648+
0x7c, 0x01, 0x05, 0x0c, 0x10, 0x46, 0x41, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x44,
649+
0x30, 0x20, 0x17, 0x0d, 0x32, 0x30, 0x31, 0x30, 0x31, 0x35, 0x31, 0x34, 0x32, 0x33, 0x34, 0x33, 0x5a, 0x18, 0x0f, 0x39, 0x39,
650+
0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x44, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x0a,
651+
0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x01, 0x04, 0x0c, 0x10, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x30,
652+
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c,
653+
0x01, 0x05, 0x0c, 0x10, 0x46, 0x41, 0x42, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x44, 0x30,
654+
0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01,
655+
0x07, 0x03, 0x42, 0x00, 0x04, 0x71, 0x05, 0x40, 0x8a, 0x85, 0xa9, 0xd9, 0xa0, 0x8a, 0xf8, 0xb7, 0x70, 0x77, 0xdb, 0x38, 0x8b,
656+
0x7e, 0xa4, 0x38, 0x97, 0xdc, 0xdf, 0xd3, 0x16, 0xf2, 0x4f, 0x0a, 0x7e, 0x71, 0xde, 0x69, 0xa5, 0x0c, 0x44, 0x55, 0x0c, 0x0c,
657+
0x9d, 0xa2, 0x36, 0x1c, 0xd8, 0x29, 0xe5, 0x5f, 0xdd, 0x63, 0xcc, 0xf5, 0x79, 0xed, 0x44, 0xe0, 0x22, 0x08, 0xb4, 0xf8, 0x25,
658+
0xfc, 0xd6, 0xf0, 0x68, 0x2c, 0x02, 0xa3, 0x66, 0x30, 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04,
659+
0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,
660+
0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xff, 0x87, 0xf3, 0xcd, 0xd2, 0x06,
661+
0x9a, 0xef, 0x8d, 0x5d, 0x32, 0xeb, 0xa3, 0x16, 0x3b, 0x9e, 0xb0, 0x0a, 0x00, 0x29, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23,
662+
0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xff, 0x87, 0xf3, 0xcd, 0xd2, 0x06, 0x9a, 0xef, 0x8d, 0x5d, 0x32, 0xeb, 0xa3, 0x16, 0x3b,
663+
0x9e, 0xb0, 0x0a, 0x00, 0x29, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x47, 0x00, 0x30,
664+
0x44, 0x02, 0x20, 0x75, 0xf6, 0x70, 0xeb, 0x35, 0x45, 0xb9, 0x97, 0x86, 0x46, 0x67, 0x99, 0xeb, 0xea, 0x40, 0x51, 0xa3, 0x41,
665+
0xaf, 0x2a, 0x9b, 0x67, 0x7f, 0xd7, 0x1b, 0x4c, 0x3d, 0x4e, 0x68, 0x09, 0x3b, 0x66, 0x02, 0x20, 0x5f, 0x28, 0x42, 0xcb, 0x7e,
666+
0xd3, 0x19, 0x9c, 0x9a, 0xd7, 0xc9, 0x62, 0x79, 0x47, 0xa1, 0x8a, 0x92, 0x16, 0x8a, 0xfc, 0xd6, 0x5f, 0x3e, 0x9c, 0xaf, 0x6e,
667+
0xed, 0xfa, 0x9e, 0x60, 0xc5, 0x2f,
668+
};
669+
670+
extern const size_t sTestCert_Root03_DER_Len = sizeof(sTestCert_Root03_DER);
671+
672+
extern const uint8_t sTestCert_Root03_PublicKey[] = {
673+
0x04, 0x71, 0x05, 0x40, 0x8a, 0x85, 0xa9, 0xd9, 0xa0, 0x8a, 0xf8, 0xb7, 0x70, 0x77, 0xdb, 0x38, 0x8b,
674+
0x7e, 0xa4, 0x38, 0x97, 0xdc, 0xdf, 0xd3, 0x16, 0xf2, 0x4f, 0x0a, 0x7e, 0x71, 0xde, 0x69, 0xa5, 0x0c,
675+
0x44, 0x55, 0x0c, 0x0c, 0x9d, 0xa2, 0x36, 0x1c, 0xd8, 0x29, 0xe5, 0x5f, 0xdd, 0x63, 0xcc, 0xf5, 0x79,
676+
0xed, 0x44, 0xe0, 0x22, 0x08, 0xb4, 0xf8, 0x25, 0xfc, 0xd6, 0xf0, 0x68, 0x2c, 0x02,
677+
};
678+
679+
extern const size_t sTestCert_Root03_PublicKey_Len = sizeof(sTestCert_Root03_PublicKey);
680+
681+
extern const uint8_t sTestCert_Root03_PrivateKey[] = {
682+
0x70, 0xe7, 0x6d, 0x00, 0x29, 0x28, 0x81, 0xe4, 0xb5, 0xa5, 0xbc, 0xb4, 0xec, 0xd0, 0x2f, 0xf5,
683+
0xe4, 0x75, 0xbc, 0x14, 0x89, 0xde, 0x6e, 0xc3, 0xe8, 0xd6, 0x3c, 0x5a, 0x3f, 0x2e, 0x5a, 0x87,
684+
};
685+
686+
extern const size_t sTestCert_Root03_PrivateKey_Len = sizeof(sTestCert_Root03_PrivateKey);
687+
688+
extern const uint8_t sTestCert_Root03_SubjectKeyId[] = {
689+
0xFF, 0x87, 0xF3, 0xCD, 0xD2, 0x06, 0x9A, 0xEF, 0x8D, 0x5D, 0x32, 0xEB, 0xA3, 0x16, 0x3B, 0x9E, 0xB0, 0x0A, 0x00, 0x29,
690+
};
691+
692+
extern const size_t sTestCert_Root03_SubjectKeyId_Len = sizeof(sTestCert_Root03_SubjectKeyId);
693+
694+
extern const uint8_t sTestCert_Root03_AuthorityKeyId[] = {
695+
0xFF, 0x87, 0xF3, 0xCD, 0xD2, 0x06, 0x9A, 0xEF, 0x8D, 0x5D, 0x32, 0xEB, 0xA3, 0x16, 0x3B, 0x9E, 0xB0, 0x0A, 0x00, 0x29,
696+
};
697+
698+
extern const size_t sTestCert_Root03_AuthorityKeyId_Len = sizeof(sTestCert_Root03_AuthorityKeyId);
699+
560700
/************** Test ICA01 Certificate **************
561701
Certificate:
562702
Data:

src/credentials/tests/CHIPCert_test_vectors.h

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum TestCert
5454
kNode02_06 = 14,
5555
kNode02_07 = 15,
5656
kNode02_08 = 16,
57+
kRoot03 = 17,
5758
};
5859

5960
// Special flags to alter how certificates are fetched/loaded.
@@ -106,6 +107,19 @@ extern const size_t sTestCert_Root02_SubjectKeyId_Len;
106107
extern const uint8_t sTestCert_Root02_AuthorityKeyId[];
107108
extern const size_t sTestCert_Root02_AuthorityKeyId_Len;
108109

110+
extern const uint8_t sTestCert_Root03_Chip[];
111+
extern const size_t sTestCert_Root03_Chip_Len;
112+
extern const uint8_t sTestCert_Root03_DER[];
113+
extern const size_t sTestCert_Root03_DER_Len;
114+
extern const uint8_t sTestCert_Root03_PublicKey[];
115+
extern const size_t sTestCert_Root03_PublicKey_Len;
116+
extern const uint8_t sTestCert_Root03_PrivateKey[];
117+
extern const size_t sTestCert_Root03_PrivateKey_Len;
118+
extern const uint8_t sTestCert_Root03_SubjectKeyId[];
119+
extern const size_t sTestCert_Root03_SubjectKeyId_Len;
120+
extern const uint8_t sTestCert_Root03_AuthorityKeyId[];
121+
extern const size_t sTestCert_Root03_AuthorityKeyId_Len;
122+
109123
extern const uint8_t sTestCert_ICA01_Chip[];
110124
extern const size_t sTestCert_ICA01_Chip_Len;
111125
extern const uint8_t sTestCert_ICA01_DER[];

src/credentials/tests/TestChipCert.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,23 @@ static void TestChipCert_GenerateRootCert(nlTestSuite * inSuite, void * inContex
13451345
NL_TEST_ASSERT(inSuite, ConvertX509CertToChipCert(signed_cert_span2, outCert) == CHIP_NO_ERROR);
13461346
NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR);
13471347

1348+
// Test with no defined notAfter time.
1349+
{
1350+
X509CertRequestParams root_params3 = { .SerialNumber = 1234,
1351+
.ValidityStart = 631161876,
1352+
.ValidityEnd = kNullCertTime,
1353+
.SubjectDN = root_dn,
1354+
.IssuerDN = root_dn };
1355+
MutableByteSpan signed_cert_span_no_expiry(signed_cert);
1356+
1357+
NL_TEST_ASSERT(inSuite, NewRootX509Cert(root_params3, keypair, signed_cert_span_no_expiry) == CHIP_NO_ERROR);
1358+
outCert = MutableByteSpan(outCertBuf);
1359+
1360+
NL_TEST_ASSERT(inSuite, ConvertX509CertToChipCert(signed_cert_span_no_expiry, outCert) == CHIP_NO_ERROR);
1361+
NL_TEST_ASSERT(inSuite, DecodeChipCert(outCert, certData) == CHIP_NO_ERROR);
1362+
NL_TEST_ASSERT(inSuite, certData.mNotAfterTime == kNullCertTime);
1363+
}
1364+
13481365
// Test error case: root cert subject provided ICA OID Attribute.
13491366
root_params.SubjectDN.Clear();
13501367
NL_TEST_ASSERT(inSuite, root_params.SubjectDN.AddAttribute_MatterICACId(0xabcdabcd) == CHIP_NO_ERROR);

0 commit comments

Comments
 (0)