11//! C509 certificate To Be Sign Certificate (TBS Certificate)
22
3- use minicbor:: { encode :: Write , Decode , Decoder , Encode , Encoder } ;
3+ use minicbor:: { Decode , Decoder , Encode , Encoder , encode :: Write } ;
44use serde:: { Deserialize , Serialize } ;
55
66use crate :: {
@@ -226,9 +226,9 @@ pub(crate) mod test_tbs_cert {
226226 extension:: { Extension , ExtensionValue } ,
227227 } ,
228228 general_names:: {
229+ GeneralNames ,
229230 general_name:: { GeneralName , GeneralNameTypeRegistry , GeneralNameValue } ,
230231 other_name_hw_module:: OtherNameHardwareModuleName ,
231- GeneralNames ,
232232 } ,
233233 name:: NameValue ,
234234 } ;
@@ -240,31 +240,31 @@ pub(crate) mod test_tbs_cert {
240240 // A.1. Example RFC 7925 profiled X.509 Certificate
241241 pub ( crate ) fn tbs_1 ( ) -> ( TbsCert , String ) {
242242 let tbs_certificate = (
243- 3 , // c509_certificate_type
244- 128_269 , // certificate_serial_number
245- oid ! ( 1.2 . 840 . 10045 . 4 . 3 . 2 ) , // issuer_signature_algorithm (ecdsa-with-SHA256)
243+ 3 , // c509_certificate_type
244+ 128_269 , // certificate_serial_number
245+ oid ! ( 1.2 . 840.10045 . 4.3 . 2 ) , // issuer_signature_algorithm (ecdsa-with-SHA256)
246246 (
247247 // issuer
248- oid ! ( 2.5 . 4 . 3 ) , // oid (commonName)
249- "RFC test CA" , // value
250- false , // critical
248+ oid ! ( 2.5 . 4.3 ) , // oid (commonName)
249+ "RFC test CA" , // value
250+ false , // critical
251251 ) ,
252252 1_672_531_200 , // validity_not_before
253253 1_767_225_600 , // validity_not_after
254254 (
255255 // subject
256- oid ! ( 2.5 . 4 . 3 ) , // oid (commonName)
256+ oid ! ( 2.5 . 4.3 ) , // oid (commonName)
257257 "01-23-45-FF-FE-67-89-AB" , // value
258258 false , // critical
259259 ) ,
260- oid ! ( 1.2 . 840 . 10045 . 2 . 1 ) , /* subject_public_key_algorithm (id-ecPublicKey
261- * prime256v1 P-256) */
260+ oid ! ( 1.2 . 840.10045 . 2 .1) , /* subject_public_key_algorithm (id-ecPublicKey
261+ * prime256v1 P-256) */
262262 PUBKEY , // subject_public_key (modified from the example)
263263 (
264264 // extensions
265- oid ! ( 2.5 . 29 . 15 ) , // oid (keyUsage)
266- 1 , // value
267- false , // critical
265+ oid ! ( 2.5 . 29.15 ) , // oid (keyUsage)
266+ 1 , // value
267+ false , // critical
268268 ) ,
269269 ) ;
270270
@@ -282,21 +282,21 @@ pub(crate) mod test_tbs_cert {
282282 ] ;
283283
284284 // Issuer
285- let mut attr1 = Attribute :: new ( tbs_certificate. 3 . 0 ) ;
286- attr1. add_value ( AttributeValue :: Text ( tbs_certificate. 3 . 1 . to_string ( ) ) ) ;
285+ let mut attr1 = Attribute :: new ( tbs_certificate. 3 . 0 ) ;
286+ attr1. add_value ( AttributeValue :: Text ( tbs_certificate. 3 . 1 . to_string ( ) ) ) ;
287287 let issuer = Name :: new ( NameValue :: Attribute ( vec ! [ attr1] ) ) ;
288288
289289 // Subject
290- let mut attr2 = Attribute :: new ( tbs_certificate. 6 . 0 ) ;
291- attr2. add_value ( AttributeValue :: Text ( tbs_certificate. 6 . 1 . to_string ( ) ) ) ;
290+ let mut attr2 = Attribute :: new ( tbs_certificate. 6 . 0 ) ;
291+ attr2. add_value ( AttributeValue :: Text ( tbs_certificate. 6 . 1 . to_string ( ) ) ) ;
292292 let subject = Name :: new ( NameValue :: Attribute ( vec ! [ attr2] ) ) ;
293293
294294 // Extensions
295295 let mut extensions = Extensions :: new ( ) ;
296296 extensions. add_extension ( Extension :: new (
297- tbs_certificate. 9 . 0 ,
298- ExtensionValue :: Int ( tbs_certificate. 9 . 1 ) ,
299- tbs_certificate. 9 . 2 ,
297+ tbs_certificate. 9 . 0 ,
298+ ExtensionValue :: Int ( tbs_certificate. 9 . 1 ) ,
299+ tbs_certificate. 9 . 2 ,
300300 ) ) ;
301301
302302 let data = TbsCert :: new (
@@ -340,118 +340,118 @@ pub(crate) mod test_tbs_cert {
340340 #[ allow( clippy:: too_many_lines) ]
341341 fn tbs_2 ( ) -> ( TbsCert , String ) {
342342 let tbs_certificate = (
343- 3 , // c509_certificate_type
344- 9_112_578_475_118_446_130 , // certificate_serial_number
345- oid ! ( 1.2 . 840 . 10045 . 4 . 3 . 2 ) , // issuer_signature_algorithm (ecdsa-with-SHA256)
343+ 3 , // c509_certificate_type
344+ 9_112_578_475_118_446_130 , // certificate_serial_number
345+ oid ! ( 1.2 . 840.10045 . 4.3 . 2 ) , // issuer_signature_algorithm (ecdsa-with-SHA256)
346346 [
347347 // issuer
348348 (
349- oid ! ( 2.5 . 4 . 6 ) , // oid (C: countryName)
350- "US" , // value
351- false , // critical
349+ oid ! ( 2.5 . 4.6 ) , // oid (C: countryName)
350+ "US" , // value
351+ false , // critical
352352 ) ,
353353 (
354- oid ! ( 2.5 . 4 . 8 ) , // oid (ST: stateOrProvinceName)
355- "CA" , // value
356- false , // critical
354+ oid ! ( 2.5 . 4.8 ) , // oid (ST: stateOrProvinceName)
355+ "CA" , // value
356+ false , // critical
357357 ) ,
358358 (
359- oid ! ( 2.5 . 4 . 10 ) , // oid (O: organizationName)
360- "Example Inc" , // value
361- false , // critical
359+ oid ! ( 2.5 . 4.10 ) , // oid (O: organizationName)
360+ "Example Inc" , // value
361+ false , // critical
362362 ) ,
363363 (
364- oid ! ( 2.5 . 4 . 11 ) , // oid (OU: organizationalUnitName)
364+ oid ! ( 2.5 . 4.11 ) , // oid (OU: organizationalUnitName)
365365 "certification" , // value
366366 false , // critical
367367 ) ,
368368 (
369- oid ! ( 2.5 . 4 . 3 ) , // oid (CN: commonName)
370- "802.1AR CA" , // value
371- false , // critical
369+ oid ! ( 2.5 . 4.3 ) , // oid (CN: commonName)
370+ "802.1AR CA" , // value
371+ false , // critical
372372 ) ,
373373 ] ,
374374 1_548_934_156 , // validity_not_before
375375 253_402_300_799 , // validity_not_after
376376 [
377377 // subject
378378 (
379- oid ! ( 2.5 . 4 . 6 ) , // oid (C: countryName)
380- "US" , // value
381- false , // critical
379+ oid ! ( 2.5 . 4.6 ) , // oid (C: countryName)
380+ "US" , // value
381+ false , // critical
382382 ) ,
383383 (
384- oid ! ( 2.5 . 4 . 8 ) , // oid (ST: stateOrProvinceName)
385- "CA" , // value
386- false , // critical
384+ oid ! ( 2.5 . 4.8 ) , // oid (ST: stateOrProvinceName)
385+ "CA" , // value
386+ false , // critical
387387 ) ,
388388 (
389- oid ! ( 2.5 . 4 . 7 ) , // oid (L: localityName)
390- "LA" , // value
391- false , // critical
389+ oid ! ( 2.5 . 4.7 ) , // oid (L: localityName)
390+ "LA" , // value
391+ false , // critical
392392 ) ,
393393 (
394- oid ! ( 2.5 . 4 . 10 ) , // oid (O: organizationName)
395- "example Inc" , // value
396- false , // critical
394+ oid ! ( 2.5 . 4.10 ) , // oid (O: organizationName)
395+ "example Inc" , // value
396+ false , // critical
397397 ) ,
398398 (
399- oid ! ( 2.5 . 4 . 11 ) , // oid (OU: organizationalUnitName)
400- "IoT" , // value
401- false , // critical
399+ oid ! ( 2.5 . 4.11 ) , // oid (OU: organizationalUnitName)
400+ "IoT" , // value
401+ false , // critical
402402 ) ,
403403 (
404- oid ! ( 2.5 . 4 . 5 ) , // oid (serialNumber)
405- "Wt1234" , // value
406- false , // critical
404+ oid ! ( 2.5 . 4.5 ) , // oid (serialNumber)
405+ "Wt1234" , // value
406+ false , // critical
407407 ) ,
408408 ] ,
409- oid ! ( 1.2 . 840 . 10045 . 2 . 1 ) , /* subject_public_key_algorithm (id-ecPublicKey
410- * prime256v1 P-256) */
409+ oid ! ( 1.2 . 840.10045 . 2 .1) , /* subject_public_key_algorithm (id-ecPublicKey
410+ * prime256v1 P-256) */
411411 PUBKEY , // subject_public_key (modified from the example)
412412 (
413413 // extensions
414414 (
415- oid ! ( 2.5 . 29 . 19 ) , // oid (basicConstraints)
416- -2 , // value
417- false , // critical
415+ oid ! ( 2.5 . 29.19 ) , // oid (basicConstraints)
416+ -2 , // value
417+ false , // critical
418418 ) ,
419419 (
420- oid ! ( 2.5 . 29 . 14 ) , // oid (subjectKeyIdentifier)
420+ oid ! ( 2.5 . 29.14 ) , // oid (subjectKeyIdentifier)
421421 [
422422 0x96 , 0x60 , 0x0D , 0x87 , 0x16 , 0xBF , 0x7F , 0xD0 , 0xE7 , 0x52 , 0xD0 , 0xAC ,
423423 0x76 , 0x07 , 0x77 , 0xAD , 0x66 , 0x5D , 0x02 , 0xA0 ,
424424 ] , // value
425- false , // critical
425+ false , // critical
426426 ) ,
427427 (
428- oid ! ( 2.5 . 29 . 15 ) , // oid (keyUsage)
429- 5 , // value
430- true , // critical
428+ oid ! ( 2.5 . 29.15 ) , // oid (keyUsage)
429+ 5 , // value
430+ true , // critical
431431 ) ,
432432 (
433- oid ! ( 2.5 . 29 . 17 ) , // oid (subjectAltName)
433+ oid ! ( 2.5 . 29.17 ) , // oid (subjectAltName)
434434 (
435- oid ! ( 1.3 . 6 . 1 . 4 . 1 . 6175 . 10 . 1 ) , // hwType
436- [ 0x01 , 0x02 , 0x03 , 0x04 ] , // hwSerialNum
435+ oid ! ( 1.3 . 6.1 . 4.1 . 6175.10 . 1 ) , // hwType
436+ [ 0x01 , 0x02 , 0x03 , 0x04 ] , // hwSerialNum
437437 ) ,
438438 false , // critical
439439 ) ,
440440 ) ,
441441 ) ;
442442
443443 let tbs_certificate_cbor = [
444- "03" , // c509_certificate_type
445- "487e7661d7b54e4632" , // certificate_serial_number
446- "00" , // issuer_signature_algorithm
447- "8a0462555306624341086b4578616d706c6520496e63096d63657274696669636174696f6e016a3830322e314152204341" , // issuer
448- "1a5c52dc0c" , // validity_not_before
449- "f6" , // validity_not_after
450- "8c046255530662434105624c41086b6578616d706c6520496e630963496f540366577431323334" , // subject
451- "01" , // subject_public_key_algorithm
452- "4888d0b6b0b37baa46" , // subject_public_key
453- "840421015496600d8716bf7fd0e752d0ac760777ad665d02a0210503822082492b06010401b01f0a014401020304" , // extensions
454- ] ;
444+ "03" , // c509_certificate_type
445+ "487e7661d7b54e4632" , // certificate_serial_number
446+ "00" , // issuer_signature_algorithm
447+ "8a0462555306624341086b4578616d706c6520496e63096d63657274696669636174696f6e016a3830322e314152204341" , /* issuer */
448+ "1a5c52dc0c" , // validity_not_before
449+ "f6" , // validity_not_after
450+ "8c046255530662434105624c41086b6578616d706c6520496e630963496f540366577431323334" , /* subject */
451+ "01" , // subject_public_key_algorithm
452+ "4888d0b6b0b37baa46" , // subject_public_key
453+ "840421015496600d8716bf7fd0e752d0ac760777ad665d02a0210503822082492b06010401b01f0a014401020304" , /* extensions */
454+ ] ;
455455
456456 // Issuer
457457 let mut attributes_1 = Vec :: new ( ) ;
@@ -478,32 +478,32 @@ pub(crate) mod test_tbs_cert {
478478 // Extensions
479479 let mut extensions = Extensions :: new ( ) ;
480480 extensions. add_extension ( Extension :: new (
481- tbs_certificate. 9 . 0 . 0 ,
482- ExtensionValue :: Int ( tbs_certificate. 9 . 0 . 1 ) ,
483- tbs_certificate. 9 . 0 . 2 ,
481+ tbs_certificate. 9 . 0 . 0 ,
482+ ExtensionValue :: Int ( tbs_certificate. 9 . 0 . 1 ) ,
483+ tbs_certificate. 9 . 0 . 2 ,
484484 ) ) ;
485485 extensions. add_extension ( Extension :: new (
486- tbs_certificate. 9 . 1 . 0 ,
487- ExtensionValue :: Bytes ( tbs_certificate. 9 . 1 . 1 . to_vec ( ) ) ,
488- tbs_certificate. 9 . 1 . 2 ,
486+ tbs_certificate. 9 . 1 . 0 ,
487+ ExtensionValue :: Bytes ( tbs_certificate. 9 . 1 . 1 . to_vec ( ) ) ,
488+ tbs_certificate. 9 . 1 . 2 ,
489489 ) ) ;
490490 extensions. add_extension ( Extension :: new (
491- tbs_certificate. 9 . 2 . 0 ,
492- ExtensionValue :: Int ( tbs_certificate. 9 . 2 . 1 ) ,
493- tbs_certificate. 9 . 2 . 2 ,
491+ tbs_certificate. 9 . 2 . 0 ,
492+ ExtensionValue :: Int ( tbs_certificate. 9 . 2 . 1 ) ,
493+ tbs_certificate. 9 . 2 . 2 ,
494494 ) ) ;
495495 let mut gns = GeneralNames :: new ( ) ;
496496 let hw = OtherNameHardwareModuleName :: new (
497- tbs_certificate. 9 . 3 . 1 . 0 ,
498- tbs_certificate. 9 . 3 . 1 . 1 . to_vec ( ) ,
497+ tbs_certificate. 9 . 3 . 1 . 0 ,
498+ tbs_certificate. 9 . 3 . 1 . 1 . to_vec ( ) ,
499499 ) ;
500500 gns. add_general_name ( GeneralName :: new (
501501 GeneralNameTypeRegistry :: OtherNameHardwareModuleName ,
502502 GeneralNameValue :: OtherNameHWModuleName ( hw) ,
503503 ) ) ;
504504
505505 extensions. add_extension ( Extension :: new (
506- tbs_certificate. 9 . 3 . 0 ,
506+ tbs_certificate. 9 . 3 . 0 ,
507507 ExtensionValue :: AlternativeName ( AlternativeName :: new (
508508 GeneralNamesOrText :: GeneralNames ( gns) ,
509509 ) ) ,
0 commit comments