@@ -73,6 +73,7 @@ ECCX08CertClass::ECCX08CertClass() :
73
73
_keySlot(-1 ),
74
74
_compressedCertSlot(-1 ),
75
75
_serialNumberSlot(-1 ),
76
+ _authorityKeyIdentifier(NULL ),
76
77
_bytes(NULL ),
77
78
_length(0 )
78
79
{
@@ -334,10 +335,19 @@ int ECCX08CertClass::endReconstruction()
334
335
335
336
int publicKeyLen = publicKeyLength ();
336
337
338
+ int authorityKeyIdentifierLen = authorityKeyIdentifierLength (_authorityKeyIdentifier);
339
+
337
340
int signatureLen = signatureLength (compressedCert.signature );
338
341
339
342
int certInfoLen = 5 + serialNumberLen + 12 + issuerHeaderLen + issuerLen + 32 +
340
- subjectHeaderLen + subjectLen + publicKeyLen + 4 ;
343
+ subjectHeaderLen + subjectLen + publicKeyLen;
344
+
345
+ if (authorityKeyIdentifierLen) {
346
+ certInfoLen += authorityKeyIdentifierLen;
347
+ } else {
348
+ certInfoLen += 4 ;
349
+ }
350
+
341
351
int certInfoHeaderLen = sequenceHeaderLength (certInfoLen);
342
352
343
353
int certDataLen = certInfoLen + certInfoHeaderLen + signatureLen;
@@ -411,11 +421,16 @@ int ECCX08CertClass::endReconstruction()
411
421
appendPublicKey (publicKey, out);
412
422
out += publicKeyLen;
413
423
414
- // null sequence
415
- *out++ = 0xA3 ;
416
- *out++ = 0x02 ;
417
- *out++ = 0x30 ;
418
- *out++ = 0x00 ;
424
+ if (authorityKeyIdentifierLen) {
425
+ appendAuthorityKeyIdentifier (_authorityKeyIdentifier, out);
426
+ out += authorityKeyIdentifierLen;
427
+ } else {
428
+ // null sequence
429
+ *out++ = 0xA3 ;
430
+ *out++ = 0x02 ;
431
+ *out++ = 0x30 ;
432
+ *out++ = 0x00 ;
433
+ }
419
434
420
435
// signature
421
436
appendSignature (compressedCert.signature , out);
@@ -494,6 +509,11 @@ void ECCX08CertClass::setSubjectCommonName(const String& commonName)
494
509
_subjectCommonName = commonName;
495
510
}
496
511
512
+ void ECCX08CertClass::setAuthorityKeyIdentifier (const byte authorityKeyIdentifier[])
513
+ {
514
+ _authorityKeyIdentifier = authorityKeyIdentifier;
515
+ }
516
+
497
517
int ECCX08CertClass::versionLength ()
498
518
{
499
519
return 3 ;
@@ -546,6 +566,11 @@ int ECCX08CertClass::publicKeyLength()
546
566
return (2 + 2 + 9 + 10 + 4 + 64 );
547
567
}
548
568
569
+ int ECCX08CertClass::authorityKeyIdentifierLength (const byte authorityKeyIdentifier[])
570
+ {
571
+ return (authorityKeyIdentifier == NULL ) ? 0 : 37 ;
572
+ }
573
+
549
574
int ECCX08CertClass::signatureLength (const byte signature[])
550
575
{
551
576
const byte* r = &signature[0 ];
@@ -684,6 +709,41 @@ void ECCX08CertClass::appendPublicKey(const byte publicKey[], byte out[])
684
709
memcpy (out, publicKey, 64 );
685
710
}
686
711
712
+ void ECCX08CertClass::appendAuthorityKeyIdentifier (const byte authorityKeyIdentifier[], byte out[])
713
+ {
714
+ // [3]
715
+ *out++ = 0xa3 ;
716
+ *out++ = 0x23 ;
717
+
718
+ // sequence
719
+ *out++ = ASN1_SEQUENCE;
720
+ *out++ = 0x21 ;
721
+
722
+ // sequence
723
+ *out++ = ASN1_SEQUENCE;
724
+ *out++ = 0x1f ;
725
+
726
+ // 2.5.29.35 authorityKeyIdentifier(X.509 extension)
727
+ *out++ = 0x06 ;
728
+ *out++ = 0x03 ;
729
+ *out++ = 0x55 ;
730
+ *out++ = 0x1d ;
731
+ *out++ = 0x23 ;
732
+
733
+ // octet string
734
+ *out++ = 0x04 ;
735
+ *out++ = 0x18 ;
736
+
737
+ // sequence
738
+ *out++ = ASN1_SEQUENCE;
739
+ *out++ = 0x16 ;
740
+
741
+ *out++ = 0x80 ;
742
+ *out++ = 0x14 ;
743
+
744
+ memcpy (out, authorityKeyIdentifier, 20 );
745
+ }
746
+
687
747
void ECCX08CertClass::appendSignature (const byte signature[], byte out[])
688
748
{
689
749
// signature algorithm
0 commit comments