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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneCrypto Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _X509_CERT_PARSE_H
30 #define _X509_CERT_PARSE_H
31 
32 //Dependencies
33 #include "core/crypto.h"
35 
36 //C++ guard
37 #ifdef __cplusplus
38  extern "C" {
39 #endif
40 
41 //X.509 related functions
42 error_t x509ParseCertificate(const uint8_t *data, size_t length,
43  X509CertificateInfo *certInfo);
44 
45 error_t x509ParseTbsCertificate(const uint8_t *data, size_t length,
46  size_t *totalLength, X509CertificateInfo *certInfo);
47 
48 error_t x509ParseVersion(const uint8_t *data, size_t length,
49  size_t *totalLength, X509Version *version);
50 
51 error_t x509ParseSerialNumber(const uint8_t *data, size_t length,
52  size_t *totalLength, X509SerialNumber *serialNumber);
53 
54 error_t x509ParseSignature(const uint8_t *data, size_t length,
55  size_t *totalLength, X509SignatureAlgoId *signature);
56 
57 error_t x509ParseRsaPssParameters(const uint8_t *data, size_t length,
58  X509RsaPssParameters *rsaPssParams);
59 
60 error_t x509ParseRsaPssHashAlgo(const uint8_t *data, size_t length,
61  X509RsaPssParameters *rsaPssParams);
62 
63 error_t x509ParseRsaPssSaltLength(const uint8_t *data, size_t length,
64  X509RsaPssParameters *rsaPssParams);
65 
66 error_t x509ParseName(const uint8_t *data, size_t length,
67  size_t *totalLength, X509Name *name);
68 
69 error_t x509ParseNameAttribute(const uint8_t *data, size_t length,
70  size_t *totalLength, X509NameAttribute *nameAttribute);
71 
72 error_t x509ParseValidity(const uint8_t *data, size_t length,
73  size_t *totalLength, X509Validity *validity);
74 
75 error_t x509ParseTime(const uint8_t *data, size_t length,
76  size_t *totalLength, DateTime *dateTime);
77 
78 error_t x509ParseSubjectPublicKeyInfo(const uint8_t *data, size_t length,
79  size_t *totalLength, X509SubjectPublicKeyInfo *subjectPublicKeyInfo);
80 
81 error_t x509ParseAlgorithmIdentifier(const uint8_t *data, size_t length,
82  size_t *totalLength, X509SubjectPublicKeyInfo *subjectPublicKeyInfo);
83 
84 error_t x509ParseRsaPublicKey(const uint8_t *data, size_t length,
85  X509RsaPublicKey *rsaPublicKey);
86 
87 error_t x509ParseDsaParameters(const uint8_t *data, size_t length,
88  X509DsaParameters *dsaParams);
89 
90 error_t x509ParseDsaPublicKey(const uint8_t *data, size_t length,
91  X509DsaPublicKey *dsaPublicKey);
92 
93 error_t x509ParseEcParameters(const uint8_t *data, size_t length,
94  X509EcParameters *ecParams);
95 
96 error_t x509ParseEcPublicKey(const uint8_t *data, size_t length,
97  X509EcPublicKey *ecPublicKey);
98 
99 error_t x509ParseIssuerUniqueId(const uint8_t *data, size_t length,
100  size_t *totalLength);
101 
102 error_t x509ParseSubjectUniqueId(const uint8_t *data, size_t length,
103  size_t *totalLength);
104 
105 error_t x509ParseExtensions(const uint8_t *data, size_t length,
106  size_t *totalLength, X509Extensions *extensions);
107 
108 error_t x509ParseBasicConstraints(const uint8_t *data, size_t length,
109  X509BasicConstraints *basicConstraints);
110 
111 error_t x509ParseNameConstraints(const uint8_t *data, size_t length,
112  X509NameConstraints *nameConstraints);
113 
114 error_t x509ParsePolicyConstraints(const uint8_t *data, size_t length);
115 error_t x509ParsePolicyMappings(const uint8_t *data, size_t length);
116 error_t x509ParseInhibitAnyPolicy(const uint8_t *data, size_t length);
117 
118 error_t x509ParseKeyUsage(const uint8_t *data, size_t length,
119  uint16_t *keyUsage);
120 
121 error_t x509ParseExtendedKeyUsage(const uint8_t *data, size_t length,
122  uint8_t *extKeyUsage);
123 
124 error_t x509ParseSubjectAltName(const uint8_t *data, size_t length,
125  X509SubjectAltName *subjectAltName);
126 
127 error_t x509ParseGeneralSubtrees(const uint8_t *data, size_t length);
128 
129 error_t x509ParseGeneralSubtree(const uint8_t *data, size_t length,
130  size_t *totalLength, X509GeneralName *generalName);
131 
132 error_t x509ParseGeneralName(const uint8_t *data, size_t length,
133  size_t *totalLength, X509GeneralName *generalName);
134 
135 error_t x509ParseSubjectKeyId(const uint8_t *data, size_t length,
136  X509SubjectKeyId *subjectKeyId);
137 
138 error_t x509ParseAuthorityKeyId(const uint8_t *data, size_t length,
139  X509AuthorityKeyId *authorityKeyId);
140 
141 error_t x509ParseNsCertType(const uint8_t *data, size_t length,
142  uint8_t *nsCertType);
143 
144 error_t x509ParseSignatureAlgo(const uint8_t *data, size_t length,
145  size_t *totalLength, X509SignatureAlgoId *signatureAlgo);
146 
147 error_t x509ParseSignatureValue(const uint8_t *data, size_t length,
148  size_t *totalLength, X509SignatureValue *signatureValue);
149 
150 //C++ guard
151 #ifdef __cplusplus
152  }
153 #endif
154 
155 #endif
uint16_t version
Definition: dtls_misc.h:163
error_t x509ParseRsaPssParameters(const uint8_t *data, size_t length, X509RsaPssParameters *rsaPssParams)
Parse RSASSA-PSS parameters.
error_t x509ParseSignature(const uint8_t *data, size_t length, size_t *totalLength, X509SignatureAlgoId *signature)
Parse Signature field.
error_t x509ParseNsCertType(const uint8_t *data, size_t length, uint8_t *nsCertType)
Parse NetscapeCertType extension.
Basic constraints.
Definition: x509_common.h:623
Serial number.
Definition: x509_common.h:462
EC parameters.
Definition: x509_common.h:577
General name.
Definition: x509_common.h:647
General definitions for cryptographic algorithms.
Issuer or subject name.
Definition: x509_common.h:473
Subject key identifier.
Definition: x509_common.h:672
error_t x509ParsePolicyConstraints(const uint8_t *data, size_t length)
Parse PolicyConstraints extension.
error_t x509ParseRsaPssHashAlgo(const uint8_t *data, size_t length, X509RsaPssParameters *rsaPssParams)
Parse RSASSA-PSS hash algorithm.
error_t x509ParseAlgorithmIdentifier(const uint8_t *data, size_t length, size_t *totalLength, X509SubjectPublicKeyInfo *subjectPublicKeyInfo)
Parse AlgorithmIdentifier structure.
error_t x509ParseEcParameters(const uint8_t *data, size_t length, X509EcParameters *ecParams)
Parse ECParameters structure.
Signature value.
Definition: x509_common.h:737
RSA public key.
Definition: x509_common.h:538
error_t x509ParseSignatureAlgo(const uint8_t *data, size_t length, size_t *totalLength, X509SignatureAlgoId *signatureAlgo)
Parse SignatureAlgorithm structure.
error_t x509ParseValidity(const uint8_t *data, size_t length, size_t *totalLength, X509Validity *validity)
Parse Validity structure.
error_t x509ParseEcPublicKey(const uint8_t *data, size_t length, X509EcPublicKey *ecPublicKey)
Parse ECPublicKey structure.
Name constraints.
Definition: x509_common.h:634
RSASSA-PSS parameters.
Definition: x509_common.h:711
error_t x509ParseGeneralSubtree(const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
Parse GeneralSubtree field.
error_t x509ParseName(const uint8_t *data, size_t length, size_t *totalLength, X509Name *name)
Parse Name structure.
X509Version
X.509 versions.
Definition: x509_common.h:350
Name attribute.
Definition: x509_common.h:514
error_t x509ParseSubjectAltName(const uint8_t *data, size_t length, X509SubjectAltName *subjectAltName)
Parse SubjectAltName extension.
error_t x509ParseCertificate(const uint8_t *data, size_t length, X509CertificateInfo *certInfo)
Parse a X.509 certificate.
error_t x509ParseExtendedKeyUsage(const uint8_t *data, size_t length, uint8_t *extKeyUsage)
Parse ExtendedKeyUsage extension.
Extensions.
Definition: x509_common.h:694
error_t x509ParseSubjectUniqueId(const uint8_t *data, size_t length, size_t *totalLength)
Parse SubjectUniqueID structure.
error_t x509ParseBasicConstraints(const uint8_t *data, size_t length, X509BasicConstraints *basicConstraints)
Parse BasicConstraints extension.
error_t x509ParseNameConstraints(const uint8_t *data, size_t length, X509NameConstraints *nameConstraints)
Parse NameConstraints extension.
Authority key identifier.
Definition: x509_common.h:683
char_t name[]
error_t x509ParseSignatureValue(const uint8_t *data, size_t length, size_t *totalLength, X509SignatureValue *signatureValue)
Parse SignatureValue field.
Subject alternative name.
Definition: x509_common.h:659
error_t x509ParseTime(const uint8_t *data, size_t length, size_t *totalLength, DateTime *dateTime)
Parse UTCTime or GeneralizedTime field.
X.509 common definitions.
uint8_t signature
Definition: tls.h:1364
Date and time representation.
Definition: date_time.h:44
error_t x509ParseSerialNumber(const uint8_t *data, size_t length, size_t *totalLength, X509SerialNumber *serialNumber)
Parse SerialNumber field.
error_t x509ParseDsaParameters(const uint8_t *data, size_t length, X509DsaParameters *dsaParams)
Parse DSA domain parameters.
Subject public key info.
Definition: x509_common.h:599
error_t
Error codes.
Definition: error.h:40
error_t x509ParseNameAttribute(const uint8_t *data, size_t length, size_t *totalLength, X509NameAttribute *nameAttribute)
Parse name attribute.
DSA domain parameters.
Definition: x509_common.h:551
uint8_t extensions[]
Definition: tls13_misc.h:322
error_t x509ParseIssuerUniqueId(const uint8_t *data, size_t length, size_t *totalLength)
Parse IssuerUniqueID structure.
DSA public key.
Definition: x509_common.h:566
error_t x509ParseExtensions(const uint8_t *data, size_t length, size_t *totalLength, X509Extensions *extensions)
Parse Extensions structure.
uint8_t data[]
Definition: dtls_misc.h:167
error_t x509ParseAuthorityKeyId(const uint8_t *data, size_t length, X509AuthorityKeyId *authorityKeyId)
Parse AuthorityKeyIdentifier extension.
error_t x509ParseVersion(const uint8_t *data, size_t length, size_t *totalLength, X509Version *version)
Parse Version field.
error_t x509ParseRsaPssSaltLength(const uint8_t *data, size_t length, X509RsaPssParameters *rsaPssParams)
Parse RSASSA-PSS salt length.
X.509 certificate.
Definition: x509_common.h:748
error_t x509ParseDsaPublicKey(const uint8_t *data, size_t length, X509DsaPublicKey *dsaPublicKey)
Parse DSAPublicKey structure.
error_t x509ParseRsaPublicKey(const uint8_t *data, size_t length, X509RsaPublicKey *rsaPublicKey)
Parse RSAPublicKey structure.
error_t x509ParsePolicyMappings(const uint8_t *data, size_t length)
Parse PolicyMappings extension.
error_t x509ParseGeneralName(const uint8_t *data, size_t length, size_t *totalLength, X509GeneralName *generalName)
Parse GeneralName field.
error_t x509ParseTbsCertificate(const uint8_t *data, size_t length, size_t *totalLength, X509CertificateInfo *certInfo)
Parse TBSCertificate structure.
error_t x509ParseSubjectPublicKeyInfo(const uint8_t *data, size_t length, size_t *totalLength, X509SubjectPublicKeyInfo *subjectPublicKeyInfo)
Parse SubjectPublicKeyInfo structure.
error_t x509ParseKeyUsage(const uint8_t *data, size_t length, uint16_t *keyUsage)
Parse KeyUsage extension.
error_t x509ParseGeneralSubtrees(const uint8_t *data, size_t length)
Parse GeneralSubtrees field.
Signature algorithm identifier.
Definition: x509_common.h:723
error_t x509ParseInhibitAnyPolicy(const uint8_t *data, size_t length)
Parse InhibitAnyPolicy extension.
uint8_t length
Definition: dtls_misc.h:140
error_t x509ParseSubjectKeyId(const uint8_t *data, size_t length, X509SubjectKeyId *subjectKeyId)
Parse SubjectKeyIdentifier extension.
EC public key.
Definition: x509_common.h:588
Validity.
Definition: x509_common.h:527