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.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
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->generate(prngContext, output,
278 
279  //Check status code
280  if(!error)
281  {
282  //CAs must force the serial number to be a non-negative integer
283  output[0] = (output[0] & 0x3F) | 0x40;
284  }
285  }
286 
287  //Check status code
288  if(!error)
289  {
290  //The serial number is a unique integer assigned by the CA to each
291  //certificate
292  tag.constructed = FALSE;
296 
297  //Write the corresponding ASN.1 tag
298  error = asn1InsertHeader(&tag, output, &n);
299  }
300  }
301 
302  //Check status code
303  if(!error)
304  {
305  //Total number of bytes that have been written
306  *written = tag.totalLength;
307  }
308 
309  //Return status code
310  return error;
311 }
312 
313 
314 /**
315  * @brief Format Name structure
316  * @param[in] name Information about the name to be encoded
317  * @param[out] output Buffer where to format the ASN.1 structure
318  * @param[out] written Length of the resulting ASN.1 structure
319  * @return Error code
320  **/
321 
322 error_t x509FormatName(const X509Name *name, uint8_t *output, size_t *written)
323 {
324  error_t error;
325  size_t n;
326  size_t length;
327  uint8_t *p;
328  Asn1Tag tag;
329  X509NameAttribute nameAttribute;
330 
331  //Initialize status code
332  error = NO_ERROR;
333 
334  //Raw ASN.1 sequence?
335  if(name->raw.value != NULL && name->raw.length > 0)
336  {
337  //Copy raw ASN.1 sequence
338  if(output != NULL)
339  {
340  osMemcpy(output, name->raw.value, name->raw.length);
341  }
342 
343  //Total number of bytes that have been written
344  *written = name->raw.length;
345  }
346  else
347  {
348  //Point to the buffer where to write the Name structure
349  p = output;
350  //Length of the Name structure
351  length = 0;
352 
353  //Valid Country Name attribute?
354  if(name->countryName.value != NULL && name->countryName.length > 0)
355  {
356  //Set attribute type and value
357  nameAttribute.oid.value = X509_COUNTRY_NAME_OID;
358  nameAttribute.oid.length = sizeof(X509_COUNTRY_NAME_OID);
359  nameAttribute.type = ASN1_TYPE_PRINTABLE_STRING;
360  nameAttribute.data.value = name->countryName.value;
361  nameAttribute.data.length = name->countryName.length;
362 
363  //Encode the attribute to ASN.1 format
364  error = x509FormatNameAttribute(&nameAttribute, p, &n);
365  //Any error to report?
366  if(error)
367  return error;
368 
369  //Advance data pointer
370  ASN1_INC_POINTER(p, n);
371  length += n;
372  }
373 
374  //Valid State Or Province Name attribute?
375  if(name->stateOrProvinceName.value != NULL && name->stateOrProvinceName.length > 0)
376  {
377  //Set attribute type and value
378  nameAttribute.oid.value = X509_STATE_OR_PROVINCE_NAME_OID;
379  nameAttribute.oid.length = sizeof(X509_STATE_OR_PROVINCE_NAME_OID);
380  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
381  nameAttribute.data.value = name->stateOrProvinceName.value;
382  nameAttribute.data.length = name->stateOrProvinceName.length;
383 
384  //Encode the attribute to ASN.1 format
385  error = x509FormatNameAttribute(&nameAttribute, p, &n);
386  //Any error to report?
387  if(error)
388  return error;
389 
390  //Advance data pointer
391  ASN1_INC_POINTER(p, n);
392  length += n;
393  }
394 
395  //Valid Locality Name attribute?
396  if(name->localityName.value != NULL && name->localityName.length > 0)
397  {
398  //Set attribute type and value
399  nameAttribute.oid.value = X509_LOCALITY_NAME_OID;
400  nameAttribute.oid.length = sizeof(X509_LOCALITY_NAME_OID);
401  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
402  nameAttribute.data.value = name->localityName.value;
403  nameAttribute.data.length = name->localityName.length;
404 
405  //Encode the attribute to ASN.1 format
406  error = x509FormatNameAttribute(&nameAttribute, p, &n);
407  //Any error to report?
408  if(error)
409  return error;
410 
411  //Advance data pointer
412  ASN1_INC_POINTER(p, n);
413  length += n;
414  }
415 
416  //Valid Organization Name attribute?
417  if(name->organizationName.value != NULL && name->organizationName.length > 0)
418  {
419  //Set attribute type and value
420  nameAttribute.oid.value = X509_ORGANIZATION_NAME_OID;
421  nameAttribute.oid.length = sizeof(X509_ORGANIZATION_NAME_OID);
422  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
423  nameAttribute.data.value = name->organizationName.value;
424  nameAttribute.data.length = name->organizationName.length;
425 
426  //Encode the attribute to ASN.1 format
427  error = x509FormatNameAttribute(&nameAttribute, p, &n);
428  //Any error to report?
429  if(error)
430  return error;
431 
432  //Advance data pointer
433  ASN1_INC_POINTER(p, n);
434  length += n;
435  }
436 
437  //Valid Organizational Unit Name attribute?
438  if(name->organizationalUnitName.value != NULL && name->organizationalUnitName.length > 0)
439  {
440  //Set attribute type and value
442  nameAttribute.oid.length = sizeof(X509_ORGANIZATIONAL_UNIT_NAME_OID);
443  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
444  nameAttribute.data.value = name->organizationalUnitName.value;
445  nameAttribute.data.length = name->organizationalUnitName.length;
446 
447  //Encode the attribute to ASN.1 format
448  error = x509FormatNameAttribute(&nameAttribute, p, &n);
449  //Any error to report?
450  if(error)
451  return error;
452 
453  //Advance data pointer
454  ASN1_INC_POINTER(p, n);
455  length += n;
456  }
457 
458  //Valid Common Name attribute?
459  if(name->commonName.value != NULL && name->commonName.length > 0)
460  {
461  //Set attribute type and value
462  nameAttribute.oid.value = X509_COMMON_NAME_OID;
463  nameAttribute.oid.length = sizeof(X509_COMMON_NAME_OID);
464  nameAttribute.type = ASN1_TYPE_UTF8_STRING;
465  nameAttribute.data.value = name->commonName.value;
466  nameAttribute.data.length = name->commonName.length;
467 
468  //Encode the attribute to ASN.1 format
469  error = x509FormatNameAttribute(&nameAttribute, p, &n);
470  //Any error to report?
471  if(error)
472  return error;
473 
474  //Advance data pointer
475  ASN1_INC_POINTER(p, n);
476  length += n;
477  }
478 
479  //Valid E-mail Address attribute?
480  if(name->emailAddress.value != NULL && name->emailAddress.length > 0)
481  {
482  //Set attribute type and value
483  nameAttribute.oid.value = PKCS9_EMAIL_ADDR_OID;
484  nameAttribute.oid.length = sizeof(PKCS9_EMAIL_ADDR_OID);
485  nameAttribute.type = ASN1_TYPE_IA5_STRING;
486  nameAttribute.data.value = name->emailAddress.value;
487  nameAttribute.data.length = name->emailAddress.length;
488 
489  //Encode the attribute to ASN.1 format
490  error = x509FormatNameAttribute(&nameAttribute, p, &n);
491  //Any error to report?
492  if(error)
493  return error;
494 
495  //Advance data pointer
496  ASN1_INC_POINTER(p, n);
497  length += n;
498  }
499 
500  //Valid Serial Number attribute?
501  if(name->serialNumber.value != NULL && name->serialNumber.length > 0)
502  {
503  //Set attribute type and value
504  nameAttribute.oid.value = X509_SERIAL_NUMBER_OID;
505  nameAttribute.oid.length = sizeof(X509_SERIAL_NUMBER_OID);
506  nameAttribute.type = ASN1_TYPE_PRINTABLE_STRING;
507  nameAttribute.data.value = name->serialNumber.value;
508  nameAttribute.data.length = name->serialNumber.length;
509 
510  //Encode the attribute to ASN.1 format
511  error = x509FormatNameAttribute(&nameAttribute, p, &n);
512  //Any error to report?
513  if(error)
514  return error;
515 
516  //Advance data pointer
517  ASN1_INC_POINTER(p, n);
518  length += n;
519  }
520 
521  //The Name structure is encapsulated within a sequence
522  tag.constructed = TRUE;
525  tag.length = length;
526 
527  //Write the corresponding ASN.1 tag
528  error = asn1InsertHeader(&tag, output, &n);
529  //Any error to report?
530  if(error)
531  return error;
532 
533  //Total number of bytes that have been written
534  *written = tag.totalLength;
535  }
536 
537  //Successful processing
538  return NO_ERROR;
539 }
540 
541 
542 /**
543  * @brief Format name attribute
544  * @param[in] nameAttribute Name attribute
545  * @param[out] output Buffer where to format the ASN.1 structure
546  * @param[out] written Length of the resulting ASN.1 structure
547  * @return Error code
548  **/
549 
551  uint8_t *output, size_t *written)
552 {
553  error_t error;
554  size_t n;
555  size_t length;
556  uint8_t *p;
557  Asn1Tag tag;
558 
559  //Point to the buffer where to write the ASN.1 structure
560  p = output;
561  //Length of the ASN.1 structure
562  length = 0;
563 
564  //Format AttributeType field
565  tag.constructed = FALSE;
568  tag.length = nameAttribute->oid.length;
569  tag.value = nameAttribute->oid.value;
570 
571  //Write the corresponding ASN.1 tag
572  error = asn1WriteTag(&tag, FALSE, p, &n);
573  //Any error to report?
574  if(error)
575  return error;
576 
577  //Advance data pointer
578  ASN1_INC_POINTER(p, n);
579  length += n;
580 
581  //Format AttributeValue field
582  tag.constructed = FALSE;
584  tag.objType = nameAttribute->type;
585  tag.length = nameAttribute->data.length;
586  tag.value = (uint8_t *) nameAttribute->data.value;
587 
588  //Write the corresponding ASN.1 tag
589  error = asn1WriteTag(&tag, FALSE, p, &n);
590  //Any error to report?
591  if(error)
592  return error;
593 
594  //Advance data pointer
595  ASN1_INC_POINTER(p, n);
596  length += n;
597 
598  //The attribute type and value are encapsulated within a sequence
599  tag.constructed = TRUE;
602  tag.length = length;
603 
604  //Write the corresponding ASN.1 tag
605  error = asn1InsertHeader(&tag, output, &n);
606  //Any error to report?
607  if(error)
608  return error;
609 
610  //The sequence is encapsulated within a set
611  tag.constructed = TRUE;
613  tag.objType = ASN1_TYPE_SET;
614  tag.length = length + n;
615 
616  //Write the corresponding ASN.1 tag
617  error = asn1InsertHeader(&tag, output, &n);
618  //Any error to report?
619  if(error)
620  return error;
621 
622  //Total number of bytes that have been written
623  *written = tag.totalLength;
624 
625  //Successful processing
626  return NO_ERROR;
627 }
628 
629 
630 /**
631  * @brief Format Validity structure
632  * @param[in] validity Validity period
633  * @param[out] output Buffer where to format the ASN.1 structure
634  * @param[out] written Length of the resulting ASN.1 structure
635  * @return Error code
636  **/
637 
638 error_t x509FormatValidity(const X509Validity *validity, uint8_t *output,
639  size_t *written)
640 {
641  error_t error;
642  size_t n;
643  size_t length;
644  uint8_t *p;
645  Asn1Tag tag;
646 
647  //Point to the buffer where to write the ASN.1 structure
648  p = output;
649  //Length of the ASN.1 structure
650  length = 0;
651 
652  //The NotBefore field may be encoded as UTCTime or GeneralizedTime
653  error = x509FormatTime(&validity->notBefore, p, &n);
654  //Any error to report?
655  if(error)
656  return error;
657 
658  //Advance data pointer
659  ASN1_INC_POINTER(p, n);
660  length += n;
661 
662  //The NotAfter field may be encoded as UTCTime or GeneralizedTime
663  error = x509FormatTime(&validity->notAfter, p, &n);
664  //Any error to report?
665  if(error)
666  return error;
667 
668  //Advance data pointer
669  ASN1_INC_POINTER(p, n);
670  length += n;
671 
672  //The Validity structure is encapsulated within a sequence
673  tag.constructed = TRUE;
676  tag.length = length;
677 
678  //Write the corresponding ASN.1 tag
679  error = asn1InsertHeader(&tag, output, &n);
680  //Any error to report?
681  if(error)
682  return error;
683 
684  //Total number of bytes that have been written
685  *written = tag.totalLength;
686 
687  //Successful processing
688  return NO_ERROR;
689 }
690 
691 
692 /**
693  * @brief Format UTCTime or GeneralizedTime field
694  * @param[in] dateTime Date to be encoded
695  * @param[out] output Buffer where to format the ASN.1 structure
696  * @param[out] written Length of the resulting ASN.1 structure
697  * @return Error code
698  **/
699 
700 error_t x509FormatTime(const DateTime *dateTime, uint8_t *output,
701  size_t *written)
702 {
703  error_t error;
704  uint_t type;
705  size_t n;
706  Asn1Tag tag;
707  char_t buffer[24];
708 
709  //UTCTime is limited to the period from 1950 to 2049
710  if(dateTime->year >= 1950 && dateTime->year <= 2049)
711  {
712  //Use UTCTime format
714  }
715  else
716  {
717  //Use GeneralizedTime format
719  }
720 
721  //Format UTCTime or GeneralizedTime string
722  error = x509FormatTimeString(dateTime, type, buffer);
723  //Any error to report?
724  if(error)
725  return error;
726 
727  //The date may be encoded as UTCTime or GeneralizedTime
728  tag.constructed = FALSE;
730  tag.objType = type;
731  tag.length = osStrlen(buffer);
732  tag.value = (uint8_t *) buffer;
733 
734  //Write the corresponding ASN.1 tag
735  error = asn1WriteTag(&tag, FALSE, output, &n);
736  //Any error to report?
737  if(error)
738  return error;
739 
740  //Total number of bytes that have been written
741  *written = n;
742 
743  //Successful processing
744  return NO_ERROR;
745 }
746 
747 
748 /**
749  * @brief Format UTCTime or GeneralizedTime string
750  * @param[in] dateTime Date to be encoded
751  * @param[in] type Time format (UTCTime or GeneralizedTime)
752  * @param[out] output Buffer where to format the string
753  * @return Error code
754  **/
755 
757  char_t *output)
758 {
759  error_t error;
760 
761  //Initialize status code
762  error = NO_ERROR;
763 
764  //The date may be encoded as UTCTime or GeneralizedTime
765  if(type == ASN1_TYPE_UTC_TIME)
766  {
767  //UTCTime is limited to the period from 1950 to 2049
768  if(dateTime->year >= 1950 && dateTime->year <= 2049)
769  {
770  //The UTCTime uses a 2-digit representation of the year. If YY is
771  //greater than or equal to 50, the year shall be interpreted as 19YY.
772  //If YY is less than 50, the year shall be interpreted as 20YY
773  osSprintf(output, "%02" PRIu16 "%02" PRIu8 "%02" PRIu8
774  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
775  dateTime->year % 100, dateTime->month, dateTime->day,
776  dateTime->hours, dateTime->minutes, dateTime->seconds);
777  }
778  else
779  {
780  //Report an error
781  error = ERROR_OUT_OF_RANGE;
782  }
783  }
784  else if(type == ASN1_TYPE_GENERALIZED_TIME)
785  {
786  //The GeneralizedTime uses a 4-digit representation of the year
787  osSprintf(output, "%04" PRIu16 "%02" PRIu8 "%02" PRIu8
788  "%02" PRIu8 "%02" PRIu8 "%02" PRIu8 "Z",
789  dateTime->year, dateTime->month, dateTime->day,
790  dateTime->hours, dateTime->minutes, dateTime->seconds);
791  }
792  else
793  {
794  //Report an error
795  error = ERROR_INVALID_TYPE;
796  }
797 
798  //Return status code
799  return error;
800 }
801 
802 #endif
@ ASN1_TYPE_UTC_TIME
Definition: asn1.h:90
@ ASN1_TYPE_GENERALIZED_TIME
Definition: asn1.h:91
uint8_t extensions[]
Definition: ntp_common.h:213
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:715
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:1008
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:765
uint16_t year
Definition: date_time.h:55
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:694
Subject Key Identifier extension.
Definition: x509_common.h:934
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:57
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:767
#define FALSE
Definition: os_port.h:46
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
uint8_t minutes
Definition: date_time.h:60
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:753
#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:946
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:59
@ ERROR_INVALID_TYPE
Definition: error.h:115
Date and time representation.
Definition: date_time.h:54
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:61
const uint8_t PKCS9_EMAIL_ADDR_OID[9]
Definition: x509_common.c:166
@ ASN1_TYPE_INTEGER
Definition: asn1.h:73
uint8_t month
Definition: date_time.h:56
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:766
const char_t * value
Definition: x509_common.h:693
uint8_t n
Issuer or subject name.
Definition: x509_common.h:725
Subject Public Key Information extension.
Definition: x509_common.h:840
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:1053
X509OctetString oid
Definition: x509_common.h:754
const uint8_t * value
Definition: x509_common.h:704
const uint8_t * value
Definition: x509_common.h:936
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:714
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:756
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:1090
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
uint_t objType
Definition: asn1.h:108
ASN.1 (Abstract Syntax Notation One)