x509_cert_format.c
Go to the documentation of this file.
1 /**
2  * @file x509_cert_format.c
3  * @brief X.509 certificate formatting
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_cert_format.h"
38 #include "pkix/x509_key_format.h"
39 #include "pkix/x509_sign_format.h"
40 #include "encoding/asn1.h"
41 #include "hash/sha1.h"
42 #include "debug.h"
43 
44 //Check crypto library configuration
45 #if (X509_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief Format TBSCertificate structure
50  * @param[in] prngAlgo PRNG algorithm
51  * @param[in] prngContext Pointer to the PRNG context
52  * @param[in] serialNumber Serial number
53  * @param[in] signatureAlgo Signature algorithm
54  * @param[in] issuer Issuer's name
55  * @param[in] validity Validity period
56  * @param[in] subject Subject's name
57  * @param[in] subjectPublicKeyInfo Subject's public key information
58  * @param[in] publicKey Subject's public key
59  * @param[in] extensions X.509 certificates extensions
60  * @param[in] authKeyId AuthorityKeyIdentifier extension
61  * @param[out] output Buffer where to format the ASN.1 structure
62  * @param[out] written Length of the resulting ASN.1 structure
63  * @return Error code
64  **/
65 
66 error_t x509FormatTbsCertificate(const PrngAlgo *prngAlgo, void *prngContext,
67  const X509SerialNumber *serialNumber, const X509SignAlgoId *signatureAlgo,
68  const X509Name *issuer, const X509Validity *validity, const X509Name *subject,
69  const X509SubjectPublicKeyInfo *subjectPublicKeyInfo, const void *publicKey,
70  const X509Extensions *extensions, const X509AuthKeyId *authKeyId,
71  uint8_t *output, size_t *written)
72 {
73  error_t error;
74  size_t n;
75  size_t length;
76  uint8_t *p;
77  Asn1Tag tag;
78  X509SubjectKeyId subjectKeyId;
79  uint8_t digest[SHA1_DIGEST_SIZE];
80 
81  //Point to the buffer where to write the ASN.1 structure
82  p = output;
83  //Length of the ASN.1 structure
84  length = 0;
85 
86  //Format Version field
87  error = x509FormatVersion(X509_VERSION_3, p, &n);
88  //Any error to report?
89  if(error)
90  return error;
91 
92  //Advance data pointer
93  p += n;
94  length += n;
95 
96  //Format SerialNumber field
97  error = x509FormatSerialNumber(prngAlgo, prngContext, serialNumber, p, &n);
98  //Any error to report?
99  if(error)
100  return error;
101 
102  //Advance data pointer
103  p += n;
104  length += n;
105 
106  //Format Signature field
107  error = x509FormatSignatureAlgo(signatureAlgo, p, &n);
108  //Any error to report?
109  if(error)
110  return error;
111 
112  //Advance data pointer
113  p += n;
114  length += n;
115 
116  //Format Issuer field
117  error = x509FormatName(issuer, p, &n);
118  //Any error to report?
119  if(error)
120  return error;
121 
122  //Advance data pointer
123  p += n;
124  length += n;
125 
126  //Format Validity field
127  error = x509FormatValidity(validity, p, &n);
128  //Any error to report?
129  if(error)
130  return error;
131 
132  //Advance data pointer
133  p += n;
134  length += n;
135 
136  //Format Subject field
137  error = x509FormatName(subject, p, &n);
138  //Any error to report?
139  if(error)
140  return error;
141 
142  //Advance data pointer
143  p += n;
144  length += n;
145 
146  //Format SubjectPublicKeyInfo field
147  error = x509FormatSubjectPublicKeyInfo(subjectPublicKeyInfo, publicKey,
148  digest, p, &n);
149  //Any error to report?
150  if(error)
151  return error;
152 
153  //Advance data pointer
154  p += n;
155  length += n;
156 
157  //The SubjectKeyIdentifier extension provides a means of identifying
158  //certificates that contain a particular public key
159  subjectKeyId.critical = FALSE;
160  subjectKeyId.value = digest;
161  subjectKeyId.length = SHA1_DIGEST_SIZE;
162 
163  //The Extensions field must only appear if the version is 3
164  error = x509FormatExtensions(extensions, &subjectKeyId, authKeyId, p, &n);
165  //Any error to report?
166  if(error)
167  return error;
168 
169  //Advance data pointer
170  p += n;
171  length += n;
172 
173  //The TBSCertificate structure is encapsulated within a sequence
174  tag.constructed = TRUE;
177  tag.length = length;
178  tag.value = output;
179 
180  //Write the corresponding ASN.1 tag
181  error = asn1WriteTag(&tag, FALSE, output, &n);
182  //Any error to report?
183  if(error)
184  return error;
185 
186  //Total number of bytes that have been written
187  *written = n;
188 
189  //Successful processing
190  return NO_ERROR;
191 }
192 
193 
194 /**
195  * @brief Format Version field
196  * @param[in] version Version number
197  * @param[out] output Buffer where to format the ASN.1 structure
198  * @param[out] written Length of the resulting ASN.1 structure
199  * @return Error code
200  **/
201 
203  size_t *written)
204 {
205  error_t error;
206  size_t n;
207  Asn1Tag tag;
208 
209  //Encode the version number
210  error = asn1WriteInt32(version, FALSE, output, &n);
211  //Any error to report?
212  if(error)
213  return error;
214 
215  //Explicit tagging shall be used to encode version
216  tag.constructed = TRUE;
218  tag.objType = 0;
219  tag.length = n;
220  tag.value = output;
221 
222  //Write the corresponding ASN.1 tag
223  error = asn1WriteTag(&tag, FALSE, output, &n);
224  //Any error to report?
225  if(error)
226  return error;
227 
228  //Total number of bytes that have been written
229  *written = n;
230 
231  //Successful processing
232  return NO_ERROR;
233 }
234 
235 
236 /**
237  * @brief Format SerialNumber field
238  * @param[in] prngAlgo PRNG algorithm
239  * @param[in] prngContext Pointer to the PRNG context
240  * @param[in] serialNumber Pointer to the serial number (optional parameter)
241  * @param[out] output Buffer where to format the ASN.1 structure
242  * @param[out] written Length of the resulting ASN.1 structure
243  * @return Error code
244  **/
245 
246 error_t x509FormatSerialNumber(const PrngAlgo *prngAlgo, void *prngContext,
247  const X509SerialNumber *serialNumber, uint8_t *output, size_t *written)
248 {
249  error_t error;
250  size_t n;
251  Asn1Tag tag;
252 
253  //Valid serial number?
254  if(serialNumber != NULL)
255  {
256  //The serial number is a unique integer assigned by the CA to each
257  //certificate
258  tag.constructed = FALSE;
261  tag.length = serialNumber->length;
262  tag.value = serialNumber->value;
263  }
264  else
265  {
266  //Conforming CAs must not use serial number values longer than 20 octets
267  error = prngAlgo->read(prngContext, output, X509_SERIAL_NUMBER_SIZE);
268  //Any error to report?
269  if(error)
270  return error;
271 
272  //CAs must force the serial number to be a non-negative integer
273  output[0] = (output[0] & 0x3F) | 0x40;
274 
275  //The serial number is a unique integer assigned by the CA to each
276  //certificate
277  tag.constructed = FALSE;
281  tag.value = output;
282  }
283 
284  //Write the corresponding ASN.1 tag
285  error = asn1WriteTag(&tag, FALSE, output, &n);
286  //Any error to report?
287  if(error)
288  return error;
289 
290  //Total number of bytes that have been written
291  *written = n;
292 
293  //Successful processing
294  return NO_ERROR;
295 }
296 
297 
298 /**
299  * @brief Format Name structure
300  * @param[in] name Information about the name to be encoded
301  * @param[out] output Buffer where to format the ASN.1 structure
302  * @param[out] written Length of the resulting ASN.1 structure
303  * @return Error code
304  **/
305 
306 error_t x509FormatName(const X509Name *name, uint8_t *output, size_t *written)
307 {
308  error_t error;
309  size_t n;
310  size_t length;
311  uint8_t *p;
312  Asn1Tag tag;
313  X509NameAttribute nameAttribute;
314 
315  //Initialize status code
316  error = NO_ERROR;
317 
318  //Raw ASN.1 sequence?
319  if(name->raw.value != NULL && name->raw.length > 0)
320  {
321  //Copy raw ASN.1 sequence
322  osMemcpy(output, name->raw.value, name->raw.length);
323  //Total number of bytes that have been written
324  *written = name->raw.length;
325  }
326  else
327  {
328  //Point to the buffer where to write the Name structure
329  p = output;
330  //Length of the Name structure
331  length = 0;
332 
333  //Valid Country Name attribute?
334  if(name->countryName.value != NULL && name->countryName.length > 0)
335  {
336  //Set attribute type and value
337  nameAttribute.oid.value = X509_COUNTRY_NAME_OID;
338  nameAttribute.oid.length = sizeof(X509_COUNTRY_NAME_OID);
339  nameAttribute.type = ASN1_TYPE_PRINTABLE_STRING;
340  nameAttribute.data.value = name->countryName.value;
341  nameAttribute.data.length = name->countryName.length;
342 
343  //Encode the attribute to ASN.1 format
344  error = x509FormatNameAttribute(&nameAttribute, p, &n);
345  //Any error to report?
346  if(error)
347  return error;
348 
349  //Advance data pointer
350  p += n;
351  length += n;
352  }
353 
354  //Valid State Or Province Name attribute?
355  if(name->stateOrProvinceName.value != NULL && name->stateOrProvinceName.length > 0)
356  {
357  //Set attribute type and value
358  nameAttribute.oid.value = X509_STATE_OR_PROVINCE_NAME_OID;
359  nameAttribute.oid.length = sizeof(X509_STATE_OR_PROVINCE_NAME_OID);
360  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
361  nameAttribute.data.value = name->stateOrProvinceName.value;
362  nameAttribute.data.length = name->stateOrProvinceName.length;
363 
364  //Encode the attribute to ASN.1 format
365  error = x509FormatNameAttribute(&nameAttribute, p, &n);
366  //Any error to report?
367  if(error)
368  return error;
369 
370  //Advance data pointer
371  p += n;
372  length += n;
373  }
374 
375  //Valid Locality Name attribute?
376  if(name->localityName.value != NULL && name->localityName.length> 0)
377  {
378  //Set attribute type and value
379  nameAttribute.oid.value = X509_LOCALITY_NAME_OID;
380  nameAttribute.oid.length = sizeof(X509_LOCALITY_NAME_OID);
381  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
382  nameAttribute.data.value = name->localityName.value;
383  nameAttribute.data.length = name->localityName.length;
384 
385  //Encode the attribute to ASN.1 format
386  error = x509FormatNameAttribute(&nameAttribute, p, &n);
387  //Any error to report?
388  if(error)
389  return error;
390 
391  //Advance data pointer
392  p += n;
393  length += n;
394  }
395 
396  //Valid Organization Name attribute?
397  if(name->organizationName.value != NULL && name->organizationName.length> 0)
398  {
399  //Set attribute type and value
400  nameAttribute.oid.value = X509_ORGANIZATION_NAME_OID;
401  nameAttribute.oid.length = sizeof(X509_ORGANIZATION_NAME_OID);
402  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
403  nameAttribute.data.value = name->organizationName.value;
404  nameAttribute.data.length = name->organizationName.length;
405 
406  //Encode the attribute to ASN.1 format
407  error = x509FormatNameAttribute(&nameAttribute, p, &n);
408  //Any error to report?
409  if(error)
410  return error;
411 
412  //Advance data pointer
413  p += n;
414  length += n;
415  }
416 
417  //Valid Organizational Unit Name attribute?
418  if(name->organizationalUnitName.value != NULL && name->organizationalUnitName.length> 0)
419  {
420  //Set attribute type and value
422  nameAttribute.oid.length = sizeof(X509_ORGANIZATIONAL_UNIT_NAME_OID);
423  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
424  nameAttribute.data.value = name->organizationalUnitName.value;
425  nameAttribute.data.length = name->organizationalUnitName.length;
426 
427  //Encode the attribute to ASN.1 format
428  error = x509FormatNameAttribute(&nameAttribute, p, &n);
429  //Any error to report?
430  if(error)
431  return error;
432 
433  //Advance data pointer
434  p += n;
435  length += n;
436  }
437 
438  //Valid Common Name attribute?
439  if(name->commonName.value != NULL && name->commonName.length > 0)
440  {
441  //Set attribute type and value
442  nameAttribute.oid.value = X509_COMMON_NAME_OID;
443  nameAttribute.oid.length = sizeof(X509_COMMON_NAME_OID);
444  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
445  nameAttribute.data.value = name->commonName.value;
446  nameAttribute.data.length = name->commonName.length;
447 
448  //Encode the attribute to ASN.1 format
449  error = x509FormatNameAttribute(&nameAttribute, p, &n);
450  //Any error to report?
451  if(error)
452  return error;
453 
454  //Advance data pointer
455  p += n;
456  length += n;
457  }
458 
459  //Valid E-mail Address attribute?
460  if(name->emailAddress.value != NULL && name->emailAddress.length > 0)
461  {
462  //Set attribute type and value
463  nameAttribute.oid.value = X509_EMAIL_ADDRESS_OID;
464  nameAttribute.oid.length = sizeof(X509_EMAIL_ADDRESS_OID);
465  nameAttribute.type = ASN1_TYPE_IA5_STRING;
466  nameAttribute.data.value = name->emailAddress.value;
467  nameAttribute.data.length = name->emailAddress.length;
468 
469  //Encode the attribute to ASN.1 format
470  error = x509FormatNameAttribute(&nameAttribute, p, &n);
471  //Any error to report?
472  if(error)
473  return error;
474 
475  //Advance data pointer
476  p += n;
477  length += n;
478  }
479 
480  //The Name structure is encapsulated within a sequence
481  tag.constructed = TRUE;
484  tag.length = length;
485  tag.value = output;
486 
487  //Write the corresponding ASN.1 tag
488  error = asn1WriteTag(&tag, FALSE, output, &n);
489  //Any error to report?
490  if(error)
491  return error;
492 
493  //Total number of bytes that have been written
494  *written = n;
495  }
496 
497  //Successful processing
498  return NO_ERROR;
499 }
500 
501 
502 /**
503  * @brief Format name attribute
504  * @param[in] nameAttribute Name attribute
505  * @param[out] output Buffer where to format the ASN.1 structure
506  * @param[out] written Length of the resulting ASN.1 structure
507  * @return Error code
508  **/
509 
511  uint8_t *output, size_t *written)
512 {
513  error_t error;
514  size_t n;
515  size_t length;
516  uint8_t *p;
517  Asn1Tag tag;
518 
519  //Point to the buffer where to write the ASN.1 structure
520  p = output;
521  //Length of the ASN.1 structure
522  length = 0;
523 
524  //Format AttributeType field
525  tag.constructed = FALSE;
528  tag.length = nameAttribute->oid.length;
529  tag.value = nameAttribute->oid.value;
530 
531  //Write the corresponding ASN.1 tag
532  error = asn1WriteTag(&tag, FALSE, p, &n);
533  //Any error to report?
534  if(error)
535  return error;
536 
537  //Advance data pointer
538  p += n;
539  length += n;
540 
541  //Format AttributeValue field
542  tag.constructed = FALSE;
544  tag.objType = nameAttribute->type;
545  tag.length = nameAttribute->data.length;
546  tag.value = (uint8_t *) nameAttribute->data.value;
547 
548  //Write the corresponding ASN.1 tag
549  error = asn1WriteTag(&tag, FALSE, p, &n);
550  //Any error to report?
551  if(error)
552  return error;
553 
554  //Advance data pointer
555  p += n;
556  length += n;
557 
558  //The attribute type and value are encapsulated within a sequence
559  tag.constructed = TRUE;
562  tag.length = length;
563  tag.value = output;
564 
565  //Write the corresponding ASN.1 tag
566  error = asn1WriteTag(&tag, FALSE, output, &n);
567  //Any error to report?
568  if(error)
569  return error;
570 
571  //The sequence is encapsulated within a set
572  tag.constructed = TRUE;
574  tag.objType = ASN1_TYPE_SET;
575  tag.length = n;
576  tag.value = output;
577 
578  //Write the corresponding ASN.1 tag
579  error = asn1WriteTag(&tag, FALSE, output, &n);
580  //Any error to report?
581  if(error)
582  return error;
583 
584  //Total number of bytes that have been written
585  *written = n;
586 
587  //Successful processing
588  return NO_ERROR;
589 }
590 
591 
592 /**
593  * @brief Format Validity structure
594  * @param[in] validity Validity period
595  * @param[out] output Buffer where to format the ASN.1 structure
596  * @param[out] written Length of the resulting ASN.1 structure
597  * @return Error code
598  **/
599 
600 error_t x509FormatValidity(const X509Validity *validity, uint8_t *output,
601  size_t *written)
602 {
603  error_t error;
604  size_t n;
605  size_t length;
606  uint8_t *p;
607  Asn1Tag tag;
608 
609  //Point to the buffer where to write the ASN.1 structure
610  p = output;
611  //Length of the ASN.1 structure
612  length = 0;
613 
614  //The NotBefore field may be encoded as UTCTime or GeneralizedTime
615  error = x509FormatTime(&validity->notBefore, p, &n);
616  //Any error to report?
617  if(error)
618  return error;
619 
620  //Advance data pointer
621  p += n;
622  length += n;
623 
624  //The NotAfter field may be encoded as UTCTime or GeneralizedTime
625  error = x509FormatTime(&validity->notAfter, p, &n);
626  //Any error to report?
627  if(error)
628  return error;
629 
630  //Advance data pointer
631  p += n;
632  length += n;
633 
634  //The Validity structure is encapsulated within a sequence
635  tag.constructed = TRUE;
638  tag.length = length;
639  tag.value = output;
640 
641  //Write the corresponding ASN.1 tag
642  error = asn1WriteTag(&tag, FALSE, output, &n);
643  //Any error to report?
644  if(error)
645  return error;
646 
647  //Total number of bytes that have been written
648  *written = n;
649 
650  //Successful processing
651  return NO_ERROR;
652 }
653 
654 
655 /**
656  * @brief Format UTCTime or GeneralizedTime field
657  * @param[in] dateTime Date to be encoded
658  * @param[out] output Buffer where to format the ASN.1 structure
659  * @param[out] written Length of the resulting ASN.1 structure
660  * @return Error code
661  **/
662 
663 error_t x509FormatTime(const DateTime *dateTime, uint8_t *output,
664  size_t *written)
665 {
666  error_t error;
667  uint_t type;
668  size_t n;
669  Asn1Tag tag;
670  char_t buffer[16];
671 
672  //UTCTime is limited to the period from 1950 to 2049
673  if(dateTime->year >= 1950 && dateTime->year <= 2049)
674  {
675  //Use UTCTime format
677 
678  //The UTCTime uses a 2-digit representation of the year. If YY is greater
679  //than or equal to 50, the year shall be interpreted as 19YY. If YY is
680  //less than 50, the year shall be interpreted as 20YY
681  osSprintf(buffer, "%02" PRIu16 "%02" PRIu8 "%02" PRIu8
682  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
683  dateTime->year % 100, dateTime->month, dateTime->day,
684  dateTime->hours, dateTime->minutes, dateTime->seconds);
685  }
686  else
687  {
688  //Use GeneralizedTime format
690 
691  //The GeneralizedTime uses a 4-digit representation of the year
692  osSprintf(buffer, "%04" PRIu16 "%02" PRIu8 "%02" PRIu8
693  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
694  dateTime->year, dateTime->month, dateTime->day,
695  dateTime->hours, dateTime->minutes, dateTime->seconds);
696  }
697 
698  //The date may be encoded as UTCTime or GeneralizedTime
699  tag.constructed = FALSE;
701  tag.objType = type;
702  tag.length = osStrlen(buffer);
703  tag.value = (uint8_t *) buffer;
704 
705  //Write the corresponding ASN.1 tag
706  error = asn1WriteTag(&tag, FALSE, output, &n);
707  //Any error to report?
708  if(error)
709  return error;
710 
711  //Total number of bytes that have been written
712  *written = n;
713 
714  //Successful processing
715  return NO_ERROR;
716 }
717 
718 #endif
error_t asn1WriteInt32(int32_t value, bool_t reverse, uint8_t *data, size_t *written)
Write a 32-bit integer to the output stream.
Definition: asn1.c:495
error_t asn1WriteTag(Asn1Tag *tag, bool_t reverse, uint8_t *data, size_t *written)
Write an ASN.1 tag.
Definition: asn1.c:334
ASN.1 (Abstract Syntax Notation One)
@ ASN1_TYPE_GENERALIZED_TIME
Definition: asn1.h:88
@ ASN1_TYPE_OBJECT_IDENTIFIER
Definition: asn1.h:74
@ ASN1_TYPE_SET
Definition: asn1.h:81
@ ASN1_TYPE_UTC_TIME
Definition: asn1.h:87
@ ASN1_TYPE_PRINTABLE_STRING
Definition: asn1.h:83
@ ASN1_TYPE_IA5_STRING
Definition: asn1.h:86
@ ASN1_TYPE_UTF8_STRING
Definition: asn1.h:79
@ ASN1_TYPE_INTEGER
Definition: asn1.h:70
@ ASN1_TYPE_SEQUENCE
Definition: asn1.h:80
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:52
#define ASN1_CLASS_CONTEXT_SPECIFIC
Definition: asn1.h:54
uint8_t type
Definition: coap_common.h:176
uint8_t version
Definition: coap_common.h:177
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
General definitions for cryptographic algorithms.
#define PrngAlgo
Definition: crypto.h:917
Debugging facilities.
uint8_t n
error_t
Error codes.
Definition: error.h:43
@ NO_ERROR
Success.
Definition: error.h:44
uint8_t p
Definition: ndp.h:300
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
#define osStrlen(s)
Definition: os_port.h:165
#define osSprintf(dest,...)
Definition: os_port.h:231
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
char_t name[]
SHA-1 (Secure Hash Algorithm 1)
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
ASN.1 tag.
Definition: asn1.h:102
const uint8_t * value
Definition: asn1.h:107
uint_t objClass
Definition: asn1.h:104
uint_t objType
Definition: asn1.h:105
bool_t constructed
Definition: asn1.h:103
size_t length
Definition: asn1.h:106
Date and time representation.
Definition: date_time.h:47
uint8_t hours
Definition: date_time.h:52
uint8_t month
Definition: date_time.h:49
uint8_t seconds
Definition: date_time.h:54
uint16_t year
Definition: date_time.h:48
uint8_t day
Definition: date_time.h:50
uint8_t minutes
Definition: date_time.h:53
Authority Key Identifier extension.
Definition: x509_common.h:889
X.509 certificate extensions.
Definition: x509_common.h:996
Name attribute.
Definition: x509_common.h:696
X509String data
Definition: x509_common.h:699
X509OctetString oid
Definition: x509_common.h:697
Issuer or subject name.
Definition: x509_common.h:668
const uint8_t * value
Definition: x509_common.h:647
Serial number.
Definition: x509_common.h:657
const uint8_t * value
Definition: x509_common.h:658
Signature algorithm identifier.
Definition: x509_common.h:1033
const char_t * value
Definition: x509_common.h:636
size_t length
Definition: x509_common.h:637
Subject Key Identifier extension.
Definition: x509_common.h:877
const uint8_t * value
Definition: x509_common.h:879
Subject Public Key Information extension.
Definition: x509_common.h:783
Validity.
Definition: x509_common.h:708
DateTime notAfter
Definition: x509_common.h:710
DateTime notBefore
Definition: x509_common.h:709
uint8_t length
Definition: tcp.h:368
uint8_t extensions[]
Definition: tls13_misc.h:300
error_t x509FormatExtensions(const X509Extensions *extensions, const X509SubjectKeyId *subjectKeyId, const X509AuthKeyId *authKeyId, uint8_t *output, size_t *written)
Format Extensions structure.
X.509 extension formatting.
error_t x509FormatVersion(X509Version version, uint8_t *output, size_t *written)
Format Version field.
error_t x509FormatTbsCertificate(const PrngAlgo *prngAlgo, void *prngContext, const X509SerialNumber *serialNumber, const X509SignAlgoId *signatureAlgo, const X509Name *issuer, const X509Validity *validity, const X509Name *subject, const X509SubjectPublicKeyInfo *subjectPublicKeyInfo, const void *publicKey, const X509Extensions *extensions, const X509AuthKeyId *authKeyId, uint8_t *output, size_t *written)
Format TBSCertificate structure.
error_t x509FormatNameAttribute(const X509NameAttribute *nameAttribute, uint8_t *output, size_t *written)
Format name attribute.
error_t x509FormatValidity(const X509Validity *validity, uint8_t *output, size_t *written)
Format Validity structure.
error_t x509FormatName(const X509Name *name, uint8_t *output, size_t *written)
Format Name structure.
error_t x509FormatSerialNumber(const PrngAlgo *prngAlgo, void *prngContext, const X509SerialNumber *serialNumber, uint8_t *output, size_t *written)
Format SerialNumber field.
error_t x509FormatTime(const DateTime *dateTime, uint8_t *output, size_t *written)
Format UTCTime or GeneralizedTime field.
X.509 certificate formatting.
const uint8_t X509_LOCALITY_NAME_OID[3]
Definition: x509_common.c:54
const uint8_t X509_STATE_OR_PROVINCE_NAME_OID[]
Definition: x509_common.c:56
const uint8_t X509_COMMON_NAME_OID[3]
Definition: x509_common.c:46
const uint8_t X509_COUNTRY_NAME_OID[3]
Definition: x509_common.c:52
const uint8_t X509_ORGANIZATIONAL_UNIT_NAME_OID[3]
Definition: x509_common.c:60
const uint8_t X509_ORGANIZATION_NAME_OID[3]
Definition: x509_common.c:58
const uint8_t X509_EMAIL_ADDRESS_OID[9]
Definition: x509_common.c:162
#define X509_SERIAL_NUMBER_SIZE
Definition: x509_common.h:360
X509Version
X.509 versions.
Definition: x509_common.h:458
@ X509_VERSION_3
Definition: x509_common.h:461
error_t x509FormatSubjectPublicKeyInfo(const X509SubjectPublicKeyInfo *publicKeyInfo, const void *publicKey, uint8_t *keyId, uint8_t *output, size_t *written)
Format SubjectPublicKeyInfo structure.
Formatting of ASN.1 encoded keys.
error_t x509FormatSignatureAlgo(const X509SignAlgoId *signatureAlgo, uint8_t *output, size_t *written)
Format SignatureAlgorithm structure.