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.4
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  //Valid Serial Number attribute?
481  if(name->serialNumber.value != NULL && name->serialNumber.length > 0)
482  {
483  //Set attribute type and value
484  nameAttribute.oid.value = X509_SERIAL_NUMBER_OID;
485  nameAttribute.oid.length = sizeof(X509_SERIAL_NUMBER_OID);
486  nameAttribute.type = ASN1_TYPE_PRINTABLE_STRING;
487  nameAttribute.data.value = name->serialNumber.value;
488  nameAttribute.data.length = name->serialNumber.length;
489 
490  //Encode the attribute to ASN.1 format
491  error = x509FormatNameAttribute(&nameAttribute, p, &n);
492  //Any error to report?
493  if(error)
494  return error;
495 
496  //Advance data pointer
497  p += n;
498  length += n;
499  }
500 
501  //The Name structure is encapsulated within a sequence
502  tag.constructed = TRUE;
505  tag.length = length;
506  tag.value = output;
507 
508  //Write the corresponding ASN.1 tag
509  error = asn1WriteTag(&tag, FALSE, output, &n);
510  //Any error to report?
511  if(error)
512  return error;
513 
514  //Total number of bytes that have been written
515  *written = n;
516  }
517 
518  //Successful processing
519  return NO_ERROR;
520 }
521 
522 
523 /**
524  * @brief Format name attribute
525  * @param[in] nameAttribute Name attribute
526  * @param[out] output Buffer where to format the ASN.1 structure
527  * @param[out] written Length of the resulting ASN.1 structure
528  * @return Error code
529  **/
530 
532  uint8_t *output, size_t *written)
533 {
534  error_t error;
535  size_t n;
536  size_t length;
537  uint8_t *p;
538  Asn1Tag tag;
539 
540  //Point to the buffer where to write the ASN.1 structure
541  p = output;
542  //Length of the ASN.1 structure
543  length = 0;
544 
545  //Format AttributeType field
546  tag.constructed = FALSE;
549  tag.length = nameAttribute->oid.length;
550  tag.value = nameAttribute->oid.value;
551 
552  //Write the corresponding ASN.1 tag
553  error = asn1WriteTag(&tag, FALSE, p, &n);
554  //Any error to report?
555  if(error)
556  return error;
557 
558  //Advance data pointer
559  p += n;
560  length += n;
561 
562  //Format AttributeValue field
563  tag.constructed = FALSE;
565  tag.objType = nameAttribute->type;
566  tag.length = nameAttribute->data.length;
567  tag.value = (uint8_t *) nameAttribute->data.value;
568 
569  //Write the corresponding ASN.1 tag
570  error = asn1WriteTag(&tag, FALSE, p, &n);
571  //Any error to report?
572  if(error)
573  return error;
574 
575  //Advance data pointer
576  p += n;
577  length += n;
578 
579  //The attribute type and value are encapsulated within a sequence
580  tag.constructed = TRUE;
583  tag.length = length;
584  tag.value = output;
585 
586  //Write the corresponding ASN.1 tag
587  error = asn1WriteTag(&tag, FALSE, output, &n);
588  //Any error to report?
589  if(error)
590  return error;
591 
592  //The sequence is encapsulated within a set
593  tag.constructed = TRUE;
595  tag.objType = ASN1_TYPE_SET;
596  tag.length = n;
597  tag.value = output;
598 
599  //Write the corresponding ASN.1 tag
600  error = asn1WriteTag(&tag, FALSE, output, &n);
601  //Any error to report?
602  if(error)
603  return error;
604 
605  //Total number of bytes that have been written
606  *written = n;
607 
608  //Successful processing
609  return NO_ERROR;
610 }
611 
612 
613 /**
614  * @brief Format Validity structure
615  * @param[in] validity Validity period
616  * @param[out] output Buffer where to format the ASN.1 structure
617  * @param[out] written Length of the resulting ASN.1 structure
618  * @return Error code
619  **/
620 
621 error_t x509FormatValidity(const X509Validity *validity, uint8_t *output,
622  size_t *written)
623 {
624  error_t error;
625  size_t n;
626  size_t length;
627  uint8_t *p;
628  Asn1Tag tag;
629 
630  //Point to the buffer where to write the ASN.1 structure
631  p = output;
632  //Length of the ASN.1 structure
633  length = 0;
634 
635  //The NotBefore field may be encoded as UTCTime or GeneralizedTime
636  error = x509FormatTime(&validity->notBefore, p, &n);
637  //Any error to report?
638  if(error)
639  return error;
640 
641  //Advance data pointer
642  p += n;
643  length += n;
644 
645  //The NotAfter field may be encoded as UTCTime or GeneralizedTime
646  error = x509FormatTime(&validity->notAfter, p, &n);
647  //Any error to report?
648  if(error)
649  return error;
650 
651  //Advance data pointer
652  p += n;
653  length += n;
654 
655  //The Validity structure is encapsulated within a sequence
656  tag.constructed = TRUE;
659  tag.length = length;
660  tag.value = output;
661 
662  //Write the corresponding ASN.1 tag
663  error = asn1WriteTag(&tag, FALSE, output, &n);
664  //Any error to report?
665  if(error)
666  return error;
667 
668  //Total number of bytes that have been written
669  *written = n;
670 
671  //Successful processing
672  return NO_ERROR;
673 }
674 
675 
676 /**
677  * @brief Format UTCTime or GeneralizedTime field
678  * @param[in] dateTime Date to be encoded
679  * @param[out] output Buffer where to format the ASN.1 structure
680  * @param[out] written Length of the resulting ASN.1 structure
681  * @return Error code
682  **/
683 
684 error_t x509FormatTime(const DateTime *dateTime, uint8_t *output,
685  size_t *written)
686 {
687  error_t error;
688  uint_t type;
689  size_t n;
690  Asn1Tag tag;
691  char_t buffer[16];
692 
693  //UTCTime is limited to the period from 1950 to 2049
694  if(dateTime->year >= 1950 && dateTime->year <= 2049)
695  {
696  //Use UTCTime format
698 
699  //The UTCTime uses a 2-digit representation of the year. If YY is greater
700  //than or equal to 50, the year shall be interpreted as 19YY. If YY is
701  //less than 50, the year shall be interpreted as 20YY
702  osSprintf(buffer, "%02" PRIu16 "%02" PRIu8 "%02" PRIu8
703  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
704  dateTime->year % 100, dateTime->month, dateTime->day,
705  dateTime->hours, dateTime->minutes, dateTime->seconds);
706  }
707  else
708  {
709  //Use GeneralizedTime format
711 
712  //The GeneralizedTime uses a 4-digit representation of the year
713  osSprintf(buffer, "%04" PRIu16 "%02" PRIu8 "%02" PRIu8
714  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
715  dateTime->year, dateTime->month, dateTime->day,
716  dateTime->hours, dateTime->minutes, dateTime->seconds);
717  }
718 
719  //The date may be encoded as UTCTime or GeneralizedTime
720  tag.constructed = FALSE;
722  tag.objType = type;
723  tag.length = osStrlen(buffer);
724  tag.value = (uint8_t *) buffer;
725 
726  //Write the corresponding ASN.1 tag
727  error = asn1WriteTag(&tag, FALSE, output, &n);
728  //Any error to report?
729  if(error)
730  return error;
731 
732  //Total number of bytes that have been written
733  *written = n;
734 
735  //Successful processing
736  return NO_ERROR;
737 }
738 
739 #endif
const uint8_t X509_EMAIL_ADDRESS_OID[9]
Definition: x509_common.c:162
@ ASN1_TYPE_UTC_TIME
Definition: asn1.h:87
@ ASN1_TYPE_GENERALIZED_TIME
Definition: asn1.h:88
uint8_t extensions[]
Definition: ntp_common.h:207
const uint8_t * value
Definition: x509_common.h:665
error_t x509FormatExtensions(const X509Extensions *extensions, const X509SubjectKeyId *subjectKeyId, const X509AuthKeyId *authKeyId, uint8_t *output, size_t *written)
Format Extensions structure.
#define PrngAlgo
Definition: crypto.h:938
const uint8_t X509_ORGANIZATION_NAME_OID[3]
Definition: x509_common.c:58
SHA-1 (Secure Hash Algorithm 1)
uint8_t p
Definition: ndp.h:300
Validity.
Definition: x509_common.h:715
uint16_t year
Definition: date_time.h:48
error_t x509FormatNameAttribute(const X509NameAttribute *nameAttribute, uint8_t *output, size_t *written)
Format name attribute.
#define TRUE
Definition: os_port.h:50
@ ASN1_TYPE_UTF8_STRING
Definition: asn1.h:79
uint8_t type
Definition: coap_common.h:176
char_t name[]
@ ASN1_TYPE_IA5_STRING
Definition: asn1.h:86
#define osStrlen(s)
Definition: os_port.h:165
uint8_t version
Definition: coap_common.h:177
const uint8_t X509_COUNTRY_NAME_OID[3]
Definition: x509_common.c:52
size_t length
Definition: x509_common.h:644
Subject Key Identifier extension.
Definition: x509_common.h:884
X.509 certificate formatting.
error_t x509FormatValidity(const X509Validity *validity, uint8_t *output, size_t *written)
Format Validity structure.
uint8_t day
Definition: date_time.h:50
error_t x509FormatSubjectPublicKeyInfo(const X509SubjectPublicKeyInfo *publicKeyInfo, const void *publicKey, uint8_t *keyId, uint8_t *output, size_t *written)
Format SubjectPublicKeyInfo structure.
size_t length
Definition: asn1.h:106
DateTime notAfter
Definition: x509_common.h:717
#define FALSE
Definition: os_port.h:46
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
uint8_t minutes
Definition: date_time.h:53
error_t
Error codes.
Definition: error.h:43
#define osSprintf(dest,...)
Definition: os_port.h:231
error_t x509FormatTime(const DateTime *dateTime, uint8_t *output, size_t *written)
Format UTCTime or GeneralizedTime field.
Name attribute.
Definition: x509_common.h:703
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:52
X509Version
X.509 versions.
Definition: x509_common.h:465
ASN.1 tag.
Definition: asn1.h:102
const uint8_t X509_LOCALITY_NAME_OID[3]
Definition: x509_common.c:54
const uint8_t X509_SERIAL_NUMBER_OID[3]
Definition: x509_common.c:50
@ X509_VERSION_3
Definition: x509_common.h:468
Authority Key Identifier extension.
Definition: x509_common.h:896
const uint8_t X509_COMMON_NAME_OID[3]
Definition: x509_common.c:46
General definitions for cryptographic algorithms.
error_t asn1WriteTag(Asn1Tag *tag, bool_t reverse, uint8_t *data, size_t *written)
Write an ASN.1 tag.
Definition: asn1.c:334
error_t x509FormatSignatureAlgo(const X509SignAlgoId *signatureAlgo, uint8_t *output, size_t *written)
Format SignatureAlgorithm structure.
uint8_t hours
Definition: date_time.h:52
Date and time representation.
Definition: date_time.h:47
uint_t objClass
Definition: asn1.h:104
@ ASN1_TYPE_PRINTABLE_STRING
Definition: asn1.h:83
uint8_t length
Definition: tcp.h:368
uint8_t seconds
Definition: date_time.h:54
@ ASN1_TYPE_INTEGER
Definition: asn1.h:70
uint8_t month
Definition: date_time.h:49
char char_t
Definition: compiler_port.h:48
Formatting of ASN.1 encoded keys.
#define SHA1_DIGEST_SIZE
Definition: sha1.h:45
error_t x509FormatVersion(X509Version version, uint8_t *output, size_t *written)
Format Version field.
DateTime notBefore
Definition: x509_common.h:716
const char_t * value
Definition: x509_common.h:643
uint8_t n
Issuer or subject name.
Definition: x509_common.h:675
Subject Public Key Information extension.
Definition: x509_common.h:790
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.
#define ASN1_CLASS_CONTEXT_SPECIFIC
Definition: asn1.h:54
error_t x509FormatName(const X509Name *name, uint8_t *output, size_t *written)
Format Name structure.
#define X509_SERIAL_NUMBER_SIZE
Definition: x509_common.h:367
bool_t constructed
Definition: asn1.h:103
@ ASN1_TYPE_OBJECT_IDENTIFIER
Definition: asn1.h:74
const uint8_t X509_ORGANIZATIONAL_UNIT_NAME_OID[3]
Definition: x509_common.c:60
@ ASN1_TYPE_SEQUENCE
Definition: asn1.h:80
X.509 certificate extensions.
Definition: x509_common.h:1003
X509OctetString oid
Definition: x509_common.h:704
const uint8_t * value
Definition: x509_common.h:654
const uint8_t * value
Definition: x509_common.h:886
error_t x509FormatSerialNumber(const PrngAlgo *prngAlgo, void *prngContext, const X509SerialNumber *serialNumber, uint8_t *output, size_t *written)
Format SerialNumber field.
X.509 extension formatting.
Serial number.
Definition: x509_common.h:664
unsigned int uint_t
Definition: compiler_port.h:50
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
X509String data
Definition: x509_common.h:706
const uint8_t X509_STATE_OR_PROVINCE_NAME_OID[]
Definition: x509_common.c:56
@ ASN1_TYPE_SET
Definition: asn1.h:81
const uint8_t * value
Definition: asn1.h:107
Signature algorithm identifier.
Definition: x509_common.h:1040
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
uint_t objType
Definition: asn1.h:105
ASN.1 (Abstract Syntax Notation One)