x509_cert_parse.h
Go to the documentation of this file.
1 /**
2  * @file x509_cert_parse.h
3  * @brief X.509 certificate parsing
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
29  **/
30 
31 #ifndef _X509_CERT_PARSE_H
32 #define _X509_CERT_PARSE_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkix/x509_common.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 //X.509 related functions
44 error_t x509ParseCertificate(const uint8_t *data, size_t length,
45  X509CertificateInfo *certInfo);
46 
47 error_t x509ParseTbsCertificate(const uint8_t *data, size_t length,
48  size_t *totalLength, X509TbsCertificate *tbsCert);
49 
50 error_t x509ParseVersion(const uint8_t *data, size_t length,
51  size_t *totalLength, X509Version *version);
52 
53 error_t x509ParseSerialNumber(const uint8_t *data, size_t length,
54  size_t *totalLength, X509SerialNumber *serialNumber);
55 
56 error_t x509ParseName(const uint8_t *data, size_t length,
57  size_t *totalLength, X509Name *name);
58 
59 error_t x509ParseNameAttribute(const uint8_t *data, size_t length,
60  size_t *totalLength, X509NameAttribute *nameAttribute);
61 
62 error_t x509ParseValidity(const uint8_t *data, size_t length,
63  size_t *totalLength, X509Validity *validity);
64 
65 error_t x509ParseTime(const uint8_t *data, size_t length,
66  size_t *totalLength, DateTime *dateTime);
67 
68 error_t x509ParseIssuerUniqueId(const uint8_t *data, size_t length,
69  size_t *totalLength);
70 
71 error_t x509ParseSubjectUniqueId(const uint8_t *data, size_t length,
72  size_t *totalLength);
73 
74 error_t x509ParseExtensions(const uint8_t *data, size_t length,
75  size_t *totalLength, X509Extensions *extensions);
76 
77 error_t x509ParseExtension(const uint8_t *data, size_t length,
78  size_t *totalLength, X509Extension *extension);
79 
80 error_t x509ParseBasicConstraints(bool_t critical, const uint8_t *data,
81  size_t length, X509BasicConstraints *basicConstraints);
82 
83 error_t x509ParseNameConstraints(bool_t critical, const uint8_t *data,
84  size_t length, X509NameConstraints *nameConstraints);
85 
86 error_t x509ParsePolicyConstraints(bool_t critical, const uint8_t *data,
87  size_t length);
88 
89 error_t x509ParsePolicyMappings(bool_t critical, const uint8_t *data,
90  size_t length);
91 
92 error_t x509ParseInhibitAnyPolicy(bool_t critical, const uint8_t *data,
93  size_t length);
94 
95 error_t x509ParseKeyUsage(bool_t critical, const uint8_t *data,
96  size_t length, X509KeyUsage *keyUsage);
97 
98 error_t x509ParseExtendedKeyUsage(bool_t critical, const uint8_t *data,
99  size_t length, X509ExtendedKeyUsage *extKeyUsage);
100 
101 error_t x509ParseSubjectAltName(bool_t critical, const uint8_t *data,
102  size_t length, X509SubjectAltName *subjectAltName);
103 
104 error_t x509ParseGeneralSubtrees(const uint8_t *data, size_t length);
105 
106 error_t x509ParseGeneralSubtree(const uint8_t *data, size_t length,
107  size_t *totalLength, X509GeneralName *generalName);
108 
109 error_t x509ParseGeneralName(const uint8_t *data, size_t length,
110  size_t *totalLength, X509GeneralName *generalName);
111 
112 error_t x509ParseSubjectKeyId(bool_t critical, const uint8_t *data,
113  size_t length, X509SubjectKeyId *subjectKeyId);
114 
115 error_t x509ParseAuthorityKeyId(bool_t critical, const uint8_t *data,
116  size_t length, X509AuthorityKeyId *authKeyId);
117 
118 error_t x509ParseNsCertType(bool_t critical, const uint8_t *data,
119  size_t length, X509NsCertType *nsCertType);
120 
121 error_t x509ParseSignatureAlgo(const uint8_t *data, size_t length,
122  size_t *totalLength, X509SignatureAlgoId *signatureAlgo);
123 
124 error_t x509ParseSignatureValue(const uint8_t *data, size_t length,
125  size_t *totalLength, X509SignatureValue *signatureValue);
126 
127 error_t x509ParseInt(const uint8_t *data, size_t length, uint_t *value);
128 
129 //C++ guard
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif
X.509 common definitions.
uint8_t length
Definition: dtls_misc.h:149
error_t x509ParseVersion(const uint8_t *data, size_t length, size_t *totalLength, X509Version *version)
Parse Version field.
int bool_t
Definition: compiler_port.h:49
TBSCertificate structure.
Definition: x509_common.h:901
Signature algorithm identifier.
Definition: x509_common.h:876
Validity.
Definition: x509_common.h:622
error_t x509ParsePolicyMappings(bool_t critical, const uint8_t *data, size_t length)
Parse PolicyMappings extension.
error_t x509ParseTime(const uint8_t *data, size_t length, size_t *totalLength, DateTime *dateTime)
Parse UTCTime or GeneralizedTime field.
error_t x509ParseIssuerUniqueId(const uint8_t *data, size_t length, size_t *totalLength)
Parse IssuerUniqueID structure.
X.509 certificate.
Definition: x509_common.h:920
uint16_t version
Definition: dtls_misc.h:172
error_t x509ParseAuthorityKeyId(bool_t critical, const uint8_t *data, size_t length, X509AuthorityKeyId *authKeyId)
Parse AuthorityKeyIdentifier extension.
char_t name[]
error_t x509ParseSignatureValue(const uint8_t *data, size_t length, size_t *totalLength, X509SignatureValue *signatureValue)
Parse SignatureValue field.
Subject key identifier.
Definition: x509_common.h:792
error_t x509ParseNsCertType(bool_t critical, const uint8_t *data, size_t length, X509NsCertType *nsCertType)
Parse NetscapeCertType extension.
error_t x509ParseExtension(const uint8_t *data, size_t length, size_t *totalLength, X509Extension *extension)
Parse X.509 certificate extension.
error_t x509ParseNameConstraints(bool_t critical, const uint8_t *data, size_t length, X509NameConstraints *nameConstraints)
Parse NameConstraints extension.
General name.
Definition: x509_common.h:766
error_t x509ParseInhibitAnyPolicy(bool_t critical, const uint8_t *data, size_t length)
Parse InhibitAnyPolicy extension.
error_t
Error codes.
Definition: error.h:42
Name attribute.
Definition: x509_common.h:609
Extended key usage.
Definition: x509_common.h:755
X509Version
X.509 versions.
Definition: x509_common.h:390
error_t x509ParseExtendedKeyUsage(bool_t critical, const uint8_t *data, size_t length, X509ExtendedKeyUsage *extKeyUsage)
Parse ExtendedKeyUsage extension.
error_t x509ParseBasicConstraints(bool_t critical, const uint8_t *data, size_t length, X509BasicConstraints *basicConstraints)
Parse BasicConstraints extension.
error_t x509ParseExtensions(const uint8_t *data, size_t length, size_t *totalLength, X509Extensions *extensions)
Parse X.509 certificate extensions.
error_t x509ParseSerialNumber(const uint8_t *data, size_t length, size_t *totalLength, X509SerialNumber *serialNumber)
Parse SerialNumber field.
X.509 certificate extension.
Definition: x509_common.h:827
error_t x509ParseGeneralSubtree(const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
Parse GeneralSubtree field.
error_t x509ParseSubjectUniqueId(const uint8_t *data, size_t length, size_t *totalLength)
Parse SubjectUniqueID structure.
General definitions for cryptographic algorithms.
error_t x509ParseGeneralSubtrees(const uint8_t *data, size_t length)
Parse GeneralSubtrees field.
Date and time representation.
Definition: date_time.h:46
error_t x509ParseName(const uint8_t *data, size_t length, size_t *totalLength, X509Name *name)
Parse Name structure.
error_t x509ParsePolicyConstraints(bool_t critical, const uint8_t *data, size_t length)
Parse PolicyConstraints extension.
Signature value.
Definition: x509_common.h:890
error_t x509ParseSubjectKeyId(bool_t critical, const uint8_t *data, size_t length, X509SubjectKeyId *subjectKeyId)
Parse SubjectKeyIdentifier extension.
Subject alternative name.
Definition: x509_common.h:778
error_t x509ParseNameAttribute(const uint8_t *data, size_t length, size_t *totalLength, X509NameAttribute *nameAttribute)
Parse name attribute.
error_t x509ParseValidity(const uint8_t *data, size_t length, size_t *totalLength, X509Validity *validity)
Parse Validity structure.
error_t x509ParseKeyUsage(bool_t critical, const uint8_t *data, size_t length, X509KeyUsage *keyUsage)
Parse KeyUsage extension.
Netscape certificate type.
Definition: x509_common.h:816
error_t x509ParseTbsCertificate(const uint8_t *data, size_t length, size_t *totalLength, X509TbsCertificate *tbsCert)
Parse TBSCertificate structure.
error_t x509ParseCertificate(const uint8_t *data, size_t length, X509CertificateInfo *certInfo)
Parse a X.509 certificate.
Issuer or subject name.
Definition: x509_common.h:568
uint8_t extensions[]
Definition: tls13_misc.h:327
Basic constraints.
Definition: x509_common.h:718
Name constraints.
Definition: x509_common.h:730
X.509 certificate extensions.
Definition: x509_common.h:841
error_t x509ParseGeneralName(const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
Parse GeneralName field.
Serial number.
Definition: x509_common.h:557
uint8_t value[]
Definition: dtls_misc.h:150
unsigned int uint_t
Definition: compiler_port.h:45
uint8_t data[]
Definition: dtls_misc.h:176
Authority key identifier.
Definition: x509_common.h:804
error_t x509ParseSubjectAltName(bool_t critical, const uint8_t *data, size_t length, X509SubjectAltName *subjectAltName)
Parse SubjectAltName extension.
error_t x509ParseSignatureAlgo(const uint8_t *data, size_t length, size_t *totalLength, X509SignatureAlgoId *signatureAlgo)
Parse SignatureAlgorithm structure.
Key usage.
Definition: x509_common.h:744
error_t x509ParseInt(const uint8_t *data, size_t length, uint_t *value)
Convert string to integer.