Mbed TLS v4.1.1
Loading...
Searching...
No Matches
x509.h
Go to the documentation of this file.
1
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 */
10#ifndef MBEDTLS_X509_H
11#define MBEDTLS_X509_H
12#include "mbedtls/private_access.h"
13
14#include "mbedtls/build_info.h"
15
16#include "mbedtls/asn1.h"
17#include "mbedtls/pk.h"
18
23
24#if !defined(MBEDTLS_X509_MAX_INTERMEDIATE_CA)
33#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8
34#endif
35
41#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080
43#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100
45#define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180
47#define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200
49#define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280
51#define MBEDTLS_ERR_X509_INVALID_ALG -0x2300
53#define MBEDTLS_ERR_X509_INVALID_NAME -0x2380
55#define MBEDTLS_ERR_X509_INVALID_DATE -0x2400
57#define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480
59#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500
61#define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580
63#define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600
65#define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680
67#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700
69#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780
71#define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800
73#define MBEDTLS_ERR_X509_ALLOC_FAILED PSA_ERROR_INSUFFICIENT_MEMORY
75#define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900
77#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL PSA_ERROR_BUFFER_TOO_SMALL
79#define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000
81
86/* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
87#define MBEDTLS_X509_BADCERT_EXPIRED 0x01
88#define MBEDTLS_X509_BADCERT_REVOKED 0x02
89#define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04
90#define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08
91#define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10
92#define MBEDTLS_X509_BADCRL_EXPIRED 0x20
93#define MBEDTLS_X509_BADCERT_MISSING 0x40
94#define MBEDTLS_X509_BADCERT_SKIP_VERIFY 0x80
95#define MBEDTLS_X509_BADCERT_OTHER 0x0100
96#define MBEDTLS_X509_BADCERT_FUTURE 0x0200
97#define MBEDTLS_X509_BADCRL_FUTURE 0x0400
98#define MBEDTLS_X509_BADCERT_KEY_USAGE 0x0800
99#define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE 0x1000
100#define MBEDTLS_X509_BADCERT_NS_CERT_TYPE 0x2000
101#define MBEDTLS_X509_BADCERT_BAD_MD 0x4000
102#define MBEDTLS_X509_BADCERT_BAD_PK 0x8000
103#define MBEDTLS_X509_BADCERT_BAD_KEY 0x010000
104#define MBEDTLS_X509_BADCRL_BAD_MD 0x020000
105#define MBEDTLS_X509_BADCRL_BAD_PK 0x040000
106#define MBEDTLS_X509_BADCRL_BAD_KEY 0x080000
107
110
111/*
112 * X.509 v3 Subject Alternative Name types.
113 * otherName [0] OtherName,
114 * rfc822Name [1] IA5String,
115 * dNSName [2] IA5String,
116 * x400Address [3] ORAddress,
117 * directoryName [4] Name,
118 * ediPartyName [5] EDIPartyName,
119 * uniformResourceIdentifier [6] IA5String,
120 * iPAddress [7] OCTET STRING,
121 * registeredID [8] OBJECT IDENTIFIER
122 */
123#define MBEDTLS_X509_SAN_OTHER_NAME 0
124#define MBEDTLS_X509_SAN_RFC822_NAME 1
125#define MBEDTLS_X509_SAN_DNS_NAME 2
126#define MBEDTLS_X509_SAN_X400_ADDRESS_NAME 3
127#define MBEDTLS_X509_SAN_DIRECTORY_NAME 4
128#define MBEDTLS_X509_SAN_EDI_PARTY_NAME 5
129#define MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER 6
130#define MBEDTLS_X509_SAN_IP_ADDRESS 7
131#define MBEDTLS_X509_SAN_REGISTERED_ID 8
132
133/*
134 * X.509 v3 Key Usage Extension flags
135 * Reminder: update mbedtls_x509_info_key_usage() when adding new flags.
136 */
137#define MBEDTLS_X509_KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
138#define MBEDTLS_X509_KU_NON_REPUDIATION (0x40) /* bit 1 */
139#define MBEDTLS_X509_KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
140#define MBEDTLS_X509_KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
141#define MBEDTLS_X509_KU_KEY_AGREEMENT (0x08) /* bit 4 */
142#define MBEDTLS_X509_KU_KEY_CERT_SIGN (0x04) /* bit 5 */
143#define MBEDTLS_X509_KU_CRL_SIGN (0x02) /* bit 6 */
144#define MBEDTLS_X509_KU_ENCIPHER_ONLY (0x01) /* bit 7 */
145#define MBEDTLS_X509_KU_DECIPHER_ONLY (0x8000) /* bit 8 */
146
147/*
148 * Netscape certificate types
149 * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
150 */
151
152#define MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
153#define MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
154#define MBEDTLS_X509_NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
155#define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
156#define MBEDTLS_X509_NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
157#define MBEDTLS_X509_NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
158#define MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
159#define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
160
161/*
162 * X.509 extension types
163 *
164 * Comments refer to the status for using certificates. Status can be
165 * different for writing certificates or reading CRLs or CSRs.
166 */
167#define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
168#define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
169#define MBEDTLS_X509_EXT_KEY_USAGE (1 << 2)
170#define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES (1 << 3)
171#define MBEDTLS_X509_EXT_POLICY_MAPPINGS (1 << 4)
172#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME (1 << 5) /* Supported (DNS) */
173#define MBEDTLS_X509_EXT_ISSUER_ALT_NAME (1 << 6)
174#define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
175#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS (1 << 8) /* Supported */
176#define MBEDTLS_X509_EXT_NAME_CONSTRAINTS (1 << 9)
177#define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS (1 << 10)
178#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE (1 << 11)
179#define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
180#define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
181#define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14)
182#define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16)
183
184/*
185 * Storage format identifiers
186 * Recognized formats: PEM and DER
187 */
188#define MBEDTLS_X509_FORMAT_DER 1
189#define MBEDTLS_X509_FORMAT_PEM 2
190
191#define MBEDTLS_X509_MAX_DN_NAME_SIZE 256
192
193#ifdef __cplusplus
194extern "C" {
195#endif
196
200
205
210
215
221
226
227/*
228 * Container for the fields of the Authority Key Identifier object
229 */
237
239typedef struct mbedtls_x509_time {
240 int year, mon, day;
241 int hour, min, sec;
242}
244
277
295
301
304
316int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn);
317
318
327
345
359{
360 while (dn->MBEDTLS_PRIVATE(next_merged) && dn->next != NULL) {
361 dn = dn->next;
362 }
363 return dn->next;
364}
365
377int mbedtls_x509_serial_gets(char *buf, size_t size, const mbedtls_x509_buf *serial);
378
390
391#if defined(MBEDTLS_HAVE_TIME_DATE)
402#endif /* MBEDTLS_HAVE_TIME_DATE */
403
417
431
472
488size_t mbedtls_x509_crt_parse_cn_inet_pton(const char *cn, void *dst);
489
490#define MBEDTLS_X509_SAFE_SNPRINTF \
491 do { \
492 if (ret < 0 || (size_t) ret >= n) \
493 return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL; \
494 \
495 n -= (size_t) ret; \
496 p += (size_t) ret; \
497 } while (0)
498
499#ifdef __cplusplus
500}
501#endif
502
503#endif /* MBEDTLS_X509_H */
Generic ASN.1 parsing.
mbedtls_asn1_named_data mbedtls_x509_name
Definition x509.h:220
mbedtls_asn1_buf mbedtls_x509_buf
Definition x509.h:209
mbedtls_asn1_sequence mbedtls_x509_sequence
Definition x509.h:225
mbedtls_asn1_bitstring mbedtls_x509_bitstring
Definition x509.h:214
Build-time configuration info.
Public Key abstraction layer.
time_t mbedtls_time_t
struct mbedtls_asn1_named_data * next
Definition asn1.h:185
Public key container.
Definition pk.h:106
mbedtls_x509_buf raw
Definition x509.h:234
mbedtls_x509_buf authorityCertSerialNumber
Definition x509.h:233
mbedtls_x509_sequence authorityCertIssuer
Definition x509.h:232
mbedtls_x509_buf keyIdentifier
Definition x509.h:231
mbedtls_x509_subject_alternative_name node
Definition x509.h:297
struct mbedtls_x509_san_list * next
Definition x509.h:298
struct mbedtls_x509_san_other_name::@204277133263220210323164012206267232075066344130::@301145364366337221204155370376302375110347157015 hardware_module_name
mbedtls_x509_buf oid
Definition x509.h:269
mbedtls_x509_buf val
Definition x509.h:270
mbedtls_x509_buf type_id
Definition x509.h:260
union mbedtls_x509_san_other_name::@204277133263220210323164012206267232075066344130 value
union mbedtls_x509_subject_alternative_name::@365027234250273254154315107271161122106150335224 san
mbedtls_x509_san_other_name other_name
Definition x509.h:288
mbedtls_x509_buf unstructured_name
Definition x509.h:290
mbedtls_x509_name directory_name
Definition x509.h:289
int mbedtls_x509_time_is_past(const mbedtls_x509_time *to)
Check a given mbedtls_x509_time against the system time and tell if it's in the past.
int mbedtls_x509_time_is_future(const mbedtls_x509_time *from)
Check a given mbedtls_x509_time against the system time and tell if it's in the future.
int mbedtls_x509_parse_subject_alt_name(const mbedtls_x509_buf *san_buf, mbedtls_x509_subject_alternative_name *san)
This function parses an item in the SubjectAlternativeNames extension. Please note that this function...
void mbedtls_x509_free_subject_alt_name(mbedtls_x509_subject_alternative_name *san)
Unallocate all data related to subject alternative name.
static mbedtls_x509_name * mbedtls_x509_dn_get_next(mbedtls_x509_name *dn)
Return the next relative DN in an X509 name.
Definition x509.h:357
int mbedtls_x509_dn_gets(char *buf, size_t size, const mbedtls_x509_name *dn)
Store the certificate DN in printable form into buf; no more than size characters will be written.
int mbedtls_x509_time_cmp(const mbedtls_x509_time *t1, const mbedtls_x509_time *t2)
Compare pair of mbedtls_x509_time.
int mbedtls_x509_time_gmtime(mbedtls_time_t tt, mbedtls_x509_time *now)
Fill mbedtls_x509_time with provided mbedtls_time_t.
const char * mbedtls_x509_pk_type_as_string(const mbedtls_pk_context *pk)
Return the key's type as a string.
size_t mbedtls_x509_crt_parse_cn_inet_pton(const char *cn, void *dst)
This function parses a CN string as an IP address.
int mbedtls_x509_string_to_names(mbedtls_asn1_named_data **head, const char *name)
Convert the certificate DN string name into a linked list of mbedtls_x509_name (equivalent to mbedtls...
int mbedtls_x509_serial_gets(char *buf, size_t size, const mbedtls_x509_buf *serial)
Store the certificate serial in printable form into buf; no more than size characters will be written...