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-2025 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.5.2
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
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  ASN1_INC_POINTER(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  ASN1_INC_POINTER(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  ASN1_INC_POINTER(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  ASN1_INC_POINTER(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  ASN1_INC_POINTER(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  ASN1_INC_POINTER(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  ASN1_INC_POINTER(p, n);
171  length += n;
172 
173  //The TBSCertificate structure is encapsulated within a sequence
174  tag.constructed = TRUE;
177  tag.length = length;
178 
179  //Write the corresponding ASN.1 tag
180  error = asn1InsertHeader(&tag, output, &n);
181  //Any error to report?
182  if(error)
183  return error;
184 
185  //Total number of bytes that have been written
186  *written = tag.totalLength;
187 
188  //Successful processing
189  return NO_ERROR;
190 }
191 
192 
193 /**
194  * @brief Format Version field
195  * @param[in] version Version number
196  * @param[out] output Buffer where to format the ASN.1 structure
197  * @param[out] written Length of the resulting ASN.1 structure
198  * @return Error code
199  **/
200 
202  size_t *written)
203 {
204  error_t error;
205  size_t n;
206  Asn1Tag tag;
207 
208  //Encode the version number
209  error = asn1WriteInt32(version, FALSE, output, &n);
210  //Any error to report?
211  if(error)
212  return error;
213 
214  //Explicit tagging shall be used to encode version
215  tag.constructed = TRUE;
217  tag.objType = 0;
218  tag.length = n;
219 
220  //Write the corresponding ASN.1 tag
221  error = asn1InsertHeader(&tag, output, &n);
222  //Any error to report?
223  if(error)
224  return error;
225 
226  //Total number of bytes that have been written
227  *written = tag.totalLength;
228 
229  //Successful processing
230  return NO_ERROR;
231 }
232 
233 
234 /**
235  * @brief Format SerialNumber field
236  * @param[in] prngAlgo PRNG algorithm
237  * @param[in] prngContext Pointer to the PRNG context
238  * @param[in] serialNumber Pointer to the serial number (optional parameter)
239  * @param[out] output Buffer where to format the ASN.1 structure
240  * @param[out] written Length of the resulting ASN.1 structure
241  * @return Error code
242  **/
243 
244 error_t x509FormatSerialNumber(const PrngAlgo *prngAlgo, void *prngContext,
245  const X509SerialNumber *serialNumber, uint8_t *output, size_t *written)
246 {
247  error_t error;
248  size_t n;
249  Asn1Tag tag;
250 
251  //Initialize status code
252  error = NO_ERROR;
253 
254  //Valid serial number?
255  if(serialNumber != NULL)
256  {
257  //The serial number is a unique integer assigned by the CA to each
258  //certificate
259  tag.constructed = FALSE;
262  tag.length = serialNumber->length;
263  tag.value = serialNumber->value;
264 
265  //Write the corresponding ASN.1 tag
266  error = asn1WriteTag(&tag, FALSE, output, &n);
267  }
268  else
269  {
270  //If the output parameter is NULL, then the function calculates the
271  //length of the octet string without copying any data
272  if(output != NULL)
273  {
274  //Conforming CAs must not use serial number values longer than 20
275  //octets
276  error = prngAlgo->read(prngContext, output, X509_SERIAL_NUMBER_SIZE);
277 
278  //Check status code
279  if(!error)
280  {
281  //CAs must force the serial number to be a non-negative integer
282  output[0] = (output[0] & 0x3F) | 0x40;
283  }
284  }
285 
286  //Check status code
287  if(!error)
288  {
289  //The serial number is a unique integer assigned by the CA to each
290  //certificate
291  tag.constructed = FALSE;
295 
296  //Write the corresponding ASN.1 tag
297  error = asn1InsertHeader(&tag, output, &n);
298  }
299  }
300 
301  //Check status code
302  if(!error)
303  {
304  //Total number of bytes that have been written
305  *written = tag.totalLength;
306  }
307 
308  //Return status code
309  return error;
310 }
311 
312 
313 /**
314  * @brief Format Name structure
315  * @param[in] name Information about the name to be encoded
316  * @param[out] output Buffer where to format the ASN.1 structure
317  * @param[out] written Length of the resulting ASN.1 structure
318  * @return Error code
319  **/
320 
321 error_t x509FormatName(const X509Name *name, uint8_t *output, size_t *written)
322 {
323  error_t error;
324  size_t n;
325  size_t length;
326  uint8_t *p;
327  Asn1Tag tag;
328  X509NameAttribute nameAttribute;
329 
330  //Initialize status code
331  error = NO_ERROR;
332 
333  //Raw ASN.1 sequence?
334  if(name->raw.value != NULL && name->raw.length > 0)
335  {
336  //Copy raw ASN.1 sequence
337  if(output != NULL)
338  {
339  osMemcpy(output, name->raw.value, name->raw.length);
340  }
341 
342  //Total number of bytes that have been written
343  *written = name->raw.length;
344  }
345  else
346  {
347  //Point to the buffer where to write the Name structure
348  p = output;
349  //Length of the Name structure
350  length = 0;
351 
352  //Valid Country Name attribute?
353  if(name->countryName.value != NULL && name->countryName.length > 0)
354  {
355  //Set attribute type and value
356  nameAttribute.oid.value = X509_COUNTRY_NAME_OID;
357  nameAttribute.oid.length = sizeof(X509_COUNTRY_NAME_OID);
358  nameAttribute.type = ASN1_TYPE_PRINTABLE_STRING;
359  nameAttribute.data.value = name->countryName.value;
360  nameAttribute.data.length = name->countryName.length;
361 
362  //Encode the attribute to ASN.1 format
363  error = x509FormatNameAttribute(&nameAttribute, p, &n);
364  //Any error to report?
365  if(error)
366  return error;
367 
368  //Advance data pointer
369  ASN1_INC_POINTER(p, n);
370  length += n;
371  }
372 
373  //Valid State Or Province Name attribute?
374  if(name->stateOrProvinceName.value != NULL && name->stateOrProvinceName.length > 0)
375  {
376  //Set attribute type and value
377  nameAttribute.oid.value = X509_STATE_OR_PROVINCE_NAME_OID;
378  nameAttribute.oid.length = sizeof(X509_STATE_OR_PROVINCE_NAME_OID);
379  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
380  nameAttribute.data.value = name->stateOrProvinceName.value;
381  nameAttribute.data.length = name->stateOrProvinceName.length;
382 
383  //Encode the attribute to ASN.1 format
384  error = x509FormatNameAttribute(&nameAttribute, p, &n);
385  //Any error to report?
386  if(error)
387  return error;
388 
389  //Advance data pointer
390  ASN1_INC_POINTER(p, n);
391  length += n;
392  }
393 
394  //Valid Locality Name attribute?
395  if(name->localityName.value != NULL && name->localityName.length > 0)
396  {
397  //Set attribute type and value
398  nameAttribute.oid.value = X509_LOCALITY_NAME_OID;
399  nameAttribute.oid.length = sizeof(X509_LOCALITY_NAME_OID);
400  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
401  nameAttribute.data.value = name->localityName.value;
402  nameAttribute.data.length = name->localityName.length;
403 
404  //Encode the attribute to ASN.1 format
405  error = x509FormatNameAttribute(&nameAttribute, p, &n);
406  //Any error to report?
407  if(error)
408  return error;
409 
410  //Advance data pointer
411  ASN1_INC_POINTER(p, n);
412  length += n;
413  }
414 
415  //Valid Organization Name attribute?
416  if(name->organizationName.value != NULL && name->organizationName.length > 0)
417  {
418  //Set attribute type and value
419  nameAttribute.oid.value = X509_ORGANIZATION_NAME_OID;
420  nameAttribute.oid.length = sizeof(X509_ORGANIZATION_NAME_OID);
421  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
422  nameAttribute.data.value = name->organizationName.value;
423  nameAttribute.data.length = name->organizationName.length;
424 
425  //Encode the attribute to ASN.1 format
426  error = x509FormatNameAttribute(&nameAttribute, p, &n);
427  //Any error to report?
428  if(error)
429  return error;
430 
431  //Advance data pointer
432  ASN1_INC_POINTER(p, n);
433  length += n;
434  }
435 
436  //Valid Organizational Unit Name attribute?
437  if(name->organizationalUnitName.value != NULL && name->organizationalUnitName.length > 0)
438  {
439  //Set attribute type and value
441  nameAttribute.oid.length = sizeof(X509_ORGANIZATIONAL_UNIT_NAME_OID);
442  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
443  nameAttribute.data.value = name->organizationalUnitName.value;
444  nameAttribute.data.length = name->organizationalUnitName.length;
445 
446  //Encode the attribute to ASN.1 format
447  error = x509FormatNameAttribute(&nameAttribute, p, &n);
448  //Any error to report?
449  if(error)
450  return error;
451 
452  //Advance data pointer
453  ASN1_INC_POINTER(p, n);
454  length += n;
455  }
456 
457  //Valid Common Name attribute?
458  if(name->commonName.value != NULL && name->commonName.length > 0)
459  {
460  //Set attribute type and value
461  nameAttribute.oid.value = X509_COMMON_NAME_OID;
462  nameAttribute.oid.length = sizeof(X509_COMMON_NAME_OID);
463  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
464  nameAttribute.data.value = name->commonName.value;
465  nameAttribute.data.length = name->commonName.length;
466 
467  //Encode the attribute to ASN.1 format
468  error = x509FormatNameAttribute(&nameAttribute, p, &n);
469  //Any error to report?
470  if(error)
471  return error;
472 
473  //Advance data pointer
474  ASN1_INC_POINTER(p, n);
475  length += n;
476  }
477 
478  //Valid E-mail Address attribute?
479  if(name->emailAddress.value != NULL && name->emailAddress.length > 0)
480  {
481  //Set attribute type and value
482  nameAttribute.oid.value = PKCS9_EMAIL_ADDR_OID;
483  nameAttribute.oid.length = sizeof(PKCS9_EMAIL_ADDR_OID);
484  nameAttribute.type = ASN1_TYPE_IA5_STRING;
485  nameAttribute.data.value = name->emailAddress.value;
486  nameAttribute.data.length = name->emailAddress.length;
487 
488  //Encode the attribute to ASN.1 format
489  error = x509FormatNameAttribute(&nameAttribute, p, &n);
490  //Any error to report?
491  if(error)
492  return error;
493 
494  //Advance data pointer
495  ASN1_INC_POINTER(p, n);
496  length += n;
497  }
498 
499  //Valid Serial Number attribute?
500  if(name->serialNumber.value != NULL && name->serialNumber.length > 0)
501  {
502  //Set attribute type and value
503  nameAttribute.oid.value = X509_SERIAL_NUMBER_OID;
504  nameAttribute.oid.length = sizeof(X509_SERIAL_NUMBER_OID);
505  nameAttribute.type = ASN1_TYPE_PRINTABLE_STRING;
506  nameAttribute.data.value = name->serialNumber.value;
507  nameAttribute.data.length = name->serialNumber.length;
508 
509  //Encode the attribute to ASN.1 format
510  error = x509FormatNameAttribute(&nameAttribute, p, &n);
511  //Any error to report?
512  if(error)
513  return error;
514 
515  //Advance data pointer
516  ASN1_INC_POINTER(p, n);
517  length += n;
518  }
519 
520  //The Name structure is encapsulated within a sequence
521  tag.constructed = TRUE;
524  tag.length = length;
525 
526  //Write the corresponding ASN.1 tag
527  error = asn1InsertHeader(&tag, output, &n);
528  //Any error to report?
529  if(error)
530  return error;
531 
532  //Total number of bytes that have been written
533  *written = tag.totalLength;
534  }
535 
536  //Successful processing
537  return NO_ERROR;
538 }
539 
540 
541 /**
542  * @brief Format name attribute
543  * @param[in] nameAttribute Name attribute
544  * @param[out] output Buffer where to format the ASN.1 structure
545  * @param[out] written Length of the resulting ASN.1 structure
546  * @return Error code
547  **/
548 
550  uint8_t *output, size_t *written)
551 {
552  error_t error;
553  size_t n;
554  size_t length;
555  uint8_t *p;
556  Asn1Tag tag;
557 
558  //Point to the buffer where to write the ASN.1 structure
559  p = output;
560  //Length of the ASN.1 structure
561  length = 0;
562 
563  //Format AttributeType field
564  tag.constructed = FALSE;
567  tag.length = nameAttribute->oid.length;
568  tag.value = nameAttribute->oid.value;
569 
570  //Write the corresponding ASN.1 tag
571  error = asn1WriteTag(&tag, FALSE, p, &n);
572  //Any error to report?
573  if(error)
574  return error;
575 
576  //Advance data pointer
577  ASN1_INC_POINTER(p, n);
578  length += n;
579 
580  //Format AttributeValue field
581  tag.constructed = FALSE;
583  tag.objType = nameAttribute->type;
584  tag.length = nameAttribute->data.length;
585  tag.value = (uint8_t *) nameAttribute->data.value;
586 
587  //Write the corresponding ASN.1 tag
588  error = asn1WriteTag(&tag, FALSE, p, &n);
589  //Any error to report?
590  if(error)
591  return error;
592 
593  //Advance data pointer
594  ASN1_INC_POINTER(p, n);
595  length += n;
596 
597  //The attribute type and value are encapsulated within a sequence
598  tag.constructed = TRUE;
601  tag.length = length;
602 
603  //Write the corresponding ASN.1 tag
604  error = asn1InsertHeader(&tag, output, &n);
605  //Any error to report?
606  if(error)
607  return error;
608 
609  //The sequence is encapsulated within a set
610  tag.constructed = TRUE;
612  tag.objType = ASN1_TYPE_SET;
613  tag.length = length + n;
614 
615  //Write the corresponding ASN.1 tag
616  error = asn1InsertHeader(&tag, output, &n);
617  //Any error to report?
618  if(error)
619  return error;
620 
621  //Total number of bytes that have been written
622  *written = tag.totalLength;
623 
624  //Successful processing
625  return NO_ERROR;
626 }
627 
628 
629 /**
630  * @brief Format Validity structure
631  * @param[in] validity Validity period
632  * @param[out] output Buffer where to format the ASN.1 structure
633  * @param[out] written Length of the resulting ASN.1 structure
634  * @return Error code
635  **/
636 
637 error_t x509FormatValidity(const X509Validity *validity, uint8_t *output,
638  size_t *written)
639 {
640  error_t error;
641  size_t n;
642  size_t length;
643  uint8_t *p;
644  Asn1Tag tag;
645 
646  //Point to the buffer where to write the ASN.1 structure
647  p = output;
648  //Length of the ASN.1 structure
649  length = 0;
650 
651  //The NotBefore field may be encoded as UTCTime or GeneralizedTime
652  error = x509FormatTime(&validity->notBefore, p, &n);
653  //Any error to report?
654  if(error)
655  return error;
656 
657  //Advance data pointer
658  ASN1_INC_POINTER(p, n);
659  length += n;
660 
661  //The NotAfter field may be encoded as UTCTime or GeneralizedTime
662  error = x509FormatTime(&validity->notAfter, p, &n);
663  //Any error to report?
664  if(error)
665  return error;
666 
667  //Advance data pointer
668  ASN1_INC_POINTER(p, n);
669  length += n;
670 
671  //The Validity structure is encapsulated within a sequence
672  tag.constructed = TRUE;
675  tag.length = length;
676 
677  //Write the corresponding ASN.1 tag
678  error = asn1InsertHeader(&tag, output, &n);
679  //Any error to report?
680  if(error)
681  return error;
682 
683  //Total number of bytes that have been written
684  *written = tag.totalLength;
685 
686  //Successful processing
687  return NO_ERROR;
688 }
689 
690 
691 /**
692  * @brief Format UTCTime or GeneralizedTime field
693  * @param[in] dateTime Date to be encoded
694  * @param[out] output Buffer where to format the ASN.1 structure
695  * @param[out] written Length of the resulting ASN.1 structure
696  * @return Error code
697  **/
698 
699 error_t x509FormatTime(const DateTime *dateTime, uint8_t *output,
700  size_t *written)
701 {
702  error_t error;
703  uint_t type;
704  size_t n;
705  Asn1Tag tag;
706  char_t buffer[24];
707 
708  //UTCTime is limited to the period from 1950 to 2049
709  if(dateTime->year >= 1950 && dateTime->year <= 2049)
710  {
711  //Use UTCTime format
713  }
714  else
715  {
716  //Use GeneralizedTime format
718  }
719 
720  //Format UTCTime or GeneralizedTime string
721  error = x509FormatTimeString(dateTime, type, buffer);
722  //Any error to report?
723  if(error)
724  return error;
725 
726  //The date may be encoded as UTCTime or GeneralizedTime
727  tag.constructed = FALSE;
729  tag.objType = type;
730  tag.length = osStrlen(buffer);
731  tag.value = (uint8_t *) buffer;
732 
733  //Write the corresponding ASN.1 tag
734  error = asn1WriteTag(&tag, FALSE, output, &n);
735  //Any error to report?
736  if(error)
737  return error;
738 
739  //Total number of bytes that have been written
740  *written = n;
741 
742  //Successful processing
743  return NO_ERROR;
744 }
745 
746 
747 /**
748  * @brief Format UTCTime or GeneralizedTime string
749  * @param[in] dateTime Date to be encoded
750  * @param[in] type Time format (UTCTime or GeneralizedTime)
751  * @param[out] output Buffer where to format the string
752  * @return Error code
753  **/
754 
756  char_t *output)
757 {
758  error_t error;
759 
760  //Initialize status code
761  error = NO_ERROR;
762 
763  //The date may be encoded as UTCTime or GeneralizedTime
764  if(type == ASN1_TYPE_UTC_TIME)
765  {
766  //UTCTime is limited to the period from 1950 to 2049
767  if(dateTime->year >= 1950 && dateTime->year <= 2049)
768  {
769  //The UTCTime uses a 2-digit representation of the year. If YY is
770  //greater than or equal to 50, the year shall be interpreted as 19YY.
771  //If YY is less than 50, the year shall be interpreted as 20YY
772  osSprintf(output, "%02" PRIu16 "%02" PRIu8 "%02" PRIu8
773  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
774  dateTime->year % 100, dateTime->month, dateTime->day,
775  dateTime->hours, dateTime->minutes, dateTime->seconds);
776  }
777  else
778  {
779  //Report an error
780  error = ERROR_OUT_OF_RANGE;
781  }
782  }
783  else if(type == ASN1_TYPE_GENERALIZED_TIME)
784  {
785  //The GeneralizedTime uses a 4-digit representation of the year
786  osSprintf(output, "%04" PRIu16 "%02" PRIu8 "%02" PRIu8
787  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
788  dateTime->year, dateTime->month, dateTime->day,
789  dateTime->hours, dateTime->minutes, dateTime->seconds);
790  }
791  else
792  {
793  //Report an error
794  error = ERROR_INVALID_TYPE;
795  }
796 
797  //Return status code
798  return error;
799 }
800 
801 #endif
@ ASN1_TYPE_UTC_TIME
Definition: asn1.h:90
@ ASN1_TYPE_GENERALIZED_TIME
Definition: asn1.h:91
uint8_t extensions[]
Definition: ntp_common.h:207
error_t x509FormatTimeString(const DateTime *dateTime, uint_t type, char_t *output)
Format UTCTime or GeneralizedTime string.
@ ERROR_OUT_OF_RANGE
Definition: error.h:138
const uint8_t * value
Definition: x509_common.h:713
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:980
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:763
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
error_t asn1InsertHeader(Asn1Tag *tag, uint8_t *data, size_t *written)
Insert an ASN.1 tag header.
Definition: asn1.c:643
@ ASN1_TYPE_UTF8_STRING
Definition: asn1.h:82
uint8_t type
Definition: coap_common.h:176
char_t name[]
@ ASN1_TYPE_IA5_STRING
Definition: asn1.h:89
#define osStrlen(s)
Definition: os_port.h:168
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:692
Subject Key Identifier extension.
Definition: x509_common.h:932
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 totalLength
Definition: asn1.h:111
size_t length
Definition: asn1.h:109
DateTime notAfter
Definition: x509_common.h:765
#define FALSE
Definition: os_port.h:46
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
uint8_t minutes
Definition: date_time.h:53
error_t
Error codes.
Definition: error.h:43
#define osSprintf(dest,...)
Definition: os_port.h:234
error_t x509FormatTime(const DateTime *dateTime, uint8_t *output, size_t *written)
Format UTCTime or GeneralizedTime field.
Name attribute.
Definition: x509_common.h:751
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:52
X509Version
X.509 versions.
Definition: x509_common.h:513
ASN.1 tag.
Definition: asn1.h:105
#define ASN1_INC_POINTER(p, n)
Definition: asn1.h:58
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:516
Authority Key Identifier extension.
Definition: x509_common.h:944
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
@ ERROR_INVALID_TYPE
Definition: error.h:115
Date and time representation.
Definition: date_time.h:47
uint_t objClass
Definition: asn1.h:107
@ ASN1_TYPE_PRINTABLE_STRING
Definition: asn1.h:86
uint8_t length
Definition: tcp.h:375
uint8_t seconds
Definition: date_time.h:54
const uint8_t PKCS9_EMAIL_ADDR_OID[9]
Definition: x509_common.c:162
@ ASN1_TYPE_INTEGER
Definition: asn1.h:73
uint8_t month
Definition: date_time.h:49
char char_t
Definition: compiler_port.h:55
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:764
const char_t * value
Definition: x509_common.h:691
uint8_t n
Issuer or subject name.
Definition: x509_common.h:723
Subject Public Key Information extension.
Definition: x509_common.h:838
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:415
bool_t constructed
Definition: asn1.h:106
@ ASN1_TYPE_OBJECT_IDENTIFIER
Definition: asn1.h:77
const uint8_t X509_ORGANIZATIONAL_UNIT_NAME_OID[3]
Definition: x509_common.c:60
@ ASN1_TYPE_SEQUENCE
Definition: asn1.h:83
X.509 certificate extensions.
Definition: x509_common.h:1051
X509OctetString oid
Definition: x509_common.h:752
const uint8_t * value
Definition: x509_common.h:702
const uint8_t * value
Definition: x509_common.h:934
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:712
unsigned int uint_t
Definition: compiler_port.h:57
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:781
X509String data
Definition: x509_common.h:754
const uint8_t X509_STATE_OR_PROVINCE_NAME_OID[]
Definition: x509_common.c:56
@ ASN1_TYPE_SET
Definition: asn1.h:84
const uint8_t * value
Definition: asn1.h:110
Signature algorithm identifier.
Definition: x509_common.h:1088
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
uint_t objType
Definition: asn1.h:108
ASN.1 (Abstract Syntax Notation One)