XenevaOS
Loading...
Searching...
No Matches
x509_crt.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_CRT_H
11#define MBEDTLS_X509_CRT_H
13
14#include "mbedtls/build_info.h"
15
16#include "mbedtls/x509.h"
17#include "mbedtls/x509_crl.h"
18#include "mbedtls/bignum.h"
19
25#ifdef __cplusplus
26extern "C" {
27#endif
28
93
98#define MBEDTLS_X509_ID_FLAG(id) (1 << ((id) - 1))
99
134
135#define MBEDTLS_X509_CRT_VERSION_1 0
136#define MBEDTLS_X509_CRT_VERSION_2 1
137#define MBEDTLS_X509_CRT_VERSION_3 2
138
139#define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 20
140#define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
141
142#if !defined(MBEDTLS_X509_MAX_FILE_PATH_LEN)
143#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
144#endif
145
146/* This macro unfolds to the concatenation of macro invocations
147 * X509_CRT_ERROR_INFO( error code,
148 * error code as string,
149 * human readable description )
150 * where X509_CRT_ERROR_INFO is defined by the user.
151 * See x509_crt.c for an example of how to use this. */
152#define MBEDTLS_X509_CRT_ERROR_INFO_LIST \
153 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXPIRED, \
154 "MBEDTLS_X509_BADCERT_EXPIRED", \
155 "The certificate validity has expired") \
156 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_REVOKED, \
157 "MBEDTLS_X509_BADCERT_REVOKED", \
158 "The certificate has been revoked (is on a CRL)") \
159 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_CN_MISMATCH, \
160 "MBEDTLS_X509_BADCERT_CN_MISMATCH", \
161 "The certificate Common Name (CN) does not match with the expected CN") \
162 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NOT_TRUSTED, \
163 "MBEDTLS_X509_BADCERT_NOT_TRUSTED", \
164 "The certificate is not correctly signed by the trusted CA") \
165 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_NOT_TRUSTED, \
166 "MBEDTLS_X509_BADCRL_NOT_TRUSTED", \
167 "The CRL is not correctly signed by the trusted CA") \
168 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_EXPIRED, \
169 "MBEDTLS_X509_BADCRL_EXPIRED", \
170 "The CRL is expired") \
171 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_MISSING, \
172 "MBEDTLS_X509_BADCERT_MISSING", \
173 "Certificate was missing") \
174 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_SKIP_VERIFY, \
175 "MBEDTLS_X509_BADCERT_SKIP_VERIFY", \
176 "Certificate verification was skipped") \
177 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_OTHER, \
178 "MBEDTLS_X509_BADCERT_OTHER", \
179 "Other reason (can be used by verify callback)") \
180 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_FUTURE, \
181 "MBEDTLS_X509_BADCERT_FUTURE", \
182 "The certificate validity starts in the future") \
183 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_FUTURE, \
184 "MBEDTLS_X509_BADCRL_FUTURE", \
185 "The CRL is from the future") \
186 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_KEY_USAGE, \
187 "MBEDTLS_X509_BADCERT_KEY_USAGE", \
188 "Usage does not match the keyUsage extension") \
189 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXT_KEY_USAGE, \
190 "MBEDTLS_X509_BADCERT_EXT_KEY_USAGE", \
191 "Usage does not match the extendedKeyUsage extension") \
192 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NS_CERT_TYPE, \
193 "MBEDTLS_X509_BADCERT_NS_CERT_TYPE", \
194 "Usage does not match the nsCertType extension") \
195 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_MD, \
196 "MBEDTLS_X509_BADCERT_BAD_MD", \
197 "The certificate is signed with an unacceptable hash.") \
198 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_PK, \
199 "MBEDTLS_X509_BADCERT_BAD_PK", \
200 "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).") \
201 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_KEY, \
202 "MBEDTLS_X509_BADCERT_BAD_KEY", \
203 "The certificate is signed with an unacceptable key (eg bad curve, RSA too short).") \
204 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_MD, \
205 "MBEDTLS_X509_BADCRL_BAD_MD", \
206 "The CRL is signed with an unacceptable hash.") \
207 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_PK, \
208 "MBEDTLS_X509_BADCRL_BAD_PK", \
209 "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).") \
210 X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_KEY, \
211 "MBEDTLS_X509_BADCRL_BAD_KEY", \
212 "The CRL is signed with an unacceptable key (eg bad curve, RSA too short).")
213
231
245 const mbedtls_x509_san_list *san_list);
246
254
258#define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE (MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)
259
263typedef struct {
266
267#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
268 /* This stores the list of potential trusted signers obtained from
269 * the CA callback used for the CRT verification, if configured.
270 * We must track it somewhere because the callback passes its
271 * ownership to the caller. */
272 mbedtls_x509_crt *MBEDTLS_PRIVATE(trust_ca_cb_result);
273#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
275
276#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
277
281typedef struct {
282 /* for check_signature() */
284
285 /* for find_parent_in() */
286 mbedtls_x509_crt *MBEDTLS_PRIVATE(parent); /* non-null iff parent_in in progress */
287 mbedtls_x509_crt *MBEDTLS_PRIVATE(fallback_parent);
288 int MBEDTLS_PRIVATE(fallback_signature_is_good);
289
290 /* for find_parent() */
291 int MBEDTLS_PRIVATE(parent_is_trusted); /* -1 if find_parent is not in progress */
292
293 /* for verify_chain() */
294 enum {
295 x509_crt_rs_none,
296 x509_crt_rs_find_parent,
297 } MBEDTLS_PRIVATE(in_progress); /* none if no operation is in progress */
298 int MBEDTLS_PRIVATE(self_cnt);
300
302
303#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
304
305/* Now we can declare functions that take a pointer to that */
307
308#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
309
310#if defined(MBEDTLS_X509_CRT_PARSE_C)
324extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
325
331extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
332
336extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
337
342extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_none;
343
368int mbedtls_x509_crt_parse_der(mbedtls_x509_crt *chain,
369 const unsigned char *buf,
370 size_t buflen);
371
402typedef int (*mbedtls_x509_crt_ext_cb_t)(void *p_ctx,
403 mbedtls_x509_crt const *crt,
404 mbedtls_x509_buf const *oid,
405 int critical,
406 const unsigned char *p,
407 const unsigned char *end);
408
453int mbedtls_x509_crt_parse_der_with_ext_cb(mbedtls_x509_crt *chain,
454 const unsigned char *buf,
455 size_t buflen,
456 int make_copy,
457 mbedtls_x509_crt_ext_cb_t cb,
458 void *p_ctx);
459
491int mbedtls_x509_crt_parse_der_nocopy(mbedtls_x509_crt *chain,
492 const unsigned char *buf,
493 size_t buflen);
494
529int mbedtls_x509_crt_parse(mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen);
530
531#if defined(MBEDTLS_FS_IO)
549int mbedtls_x509_crt_parse_file(mbedtls_x509_crt *chain, const char *path);
550
564int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path);
565
566#endif /* MBEDTLS_FS_IO */
567
568#if !defined(MBEDTLS_X509_REMOVE_INFO)
581int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix,
582 const mbedtls_x509_crt *crt);
583
596int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
598#endif /* !MBEDTLS_X509_REMOVE_INFO */
599
670int mbedtls_x509_crt_verify(mbedtls_x509_crt *crt,
671 mbedtls_x509_crt *trust_ca,
672 mbedtls_x509_crl *ca_crl,
673 const char *cn, uint32_t *flags,
674 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
675 void *p_vrfy);
676
711int mbedtls_x509_crt_verify_with_profile(mbedtls_x509_crt *crt,
712 mbedtls_x509_crt *trust_ca,
713 mbedtls_x509_crl *ca_crl,
714 const mbedtls_x509_crt_profile *profile,
715 const char *cn, uint32_t *flags,
716 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
717 void *p_vrfy);
718
745int mbedtls_x509_crt_verify_restartable(mbedtls_x509_crt *crt,
746 mbedtls_x509_crt *trust_ca,
747 mbedtls_x509_crl *ca_crl,
748 const mbedtls_x509_crt_profile *profile,
749 const char *cn, uint32_t *flags,
750 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
751 void *p_vrfy,
753
784typedef int (*mbedtls_x509_crt_ca_cb_t)(void *p_ctx,
785 mbedtls_x509_crt const *child,
786 mbedtls_x509_crt **candidate_cas);
787
788#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
811int mbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt *crt,
812 mbedtls_x509_crt_ca_cb_t f_ca_cb,
813 void *p_ca_cb,
814 const mbedtls_x509_crt_profile *profile,
815 const char *cn, uint32_t *flags,
816 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
817 void *p_vrfy);
818
819#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
820
842int mbedtls_x509_crt_check_key_usage(const mbedtls_x509_crt *crt,
843 unsigned int usage);
844
858int mbedtls_x509_crt_check_extended_key_usage(const mbedtls_x509_crt *crt,
859 const char *usage_oid,
860 size_t usage_len);
861
862#if defined(MBEDTLS_X509_CRL_PARSE_C)
872int mbedtls_x509_crt_is_revoked(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl);
873#endif /* MBEDTLS_X509_CRL_PARSE_C */
874
880void mbedtls_x509_crt_init(mbedtls_x509_crt *crt);
881
887void mbedtls_x509_crt_free(mbedtls_x509_crt *crt);
888
889#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
893void mbedtls_x509_crt_restart_init(mbedtls_x509_crt_restart_ctx *ctx);
894
898void mbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx *ctx);
899#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
900#endif /* MBEDTLS_X509_CRT_PARSE_C */
901
913static inline int mbedtls_x509_crt_has_ext_type(const mbedtls_x509_crt *ctx,
914 int ext_type)
915{
916 return ctx->MBEDTLS_PRIVATE(ext_types) & ext_type;
917}
918
930
933#if defined(MBEDTLS_X509_CRT_WRITE_C)
939void mbedtls_x509write_crt_init(mbedtls_x509write_cert *ctx);
940
949void mbedtls_x509write_crt_set_version(mbedtls_x509write_cert *ctx, int version);
950
951#if defined(MBEDTLS_BIGNUM_C) && !defined(MBEDTLS_DEPRECATED_REMOVED)
969int MBEDTLS_DEPRECATED mbedtls_x509write_crt_set_serial(
970 mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial);
971#endif // MBEDTLS_BIGNUM_C && !MBEDTLS_DEPRECATED_REMOVED
972
986int mbedtls_x509write_crt_set_serial_raw(mbedtls_x509write_cert *ctx,
987 unsigned char *serial, size_t serial_len);
988
1003int mbedtls_x509write_crt_set_validity(mbedtls_x509write_cert *ctx, const char *not_before,
1004 const char *not_after);
1005
1018int mbedtls_x509write_crt_set_issuer_name(mbedtls_x509write_cert *ctx,
1019 const char *issuer_name);
1020
1033int mbedtls_x509write_crt_set_subject_name(mbedtls_x509write_cert *ctx,
1034 const char *subject_name);
1035
1042void mbedtls_x509write_crt_set_subject_key(mbedtls_x509write_cert *ctx, mbedtls_pk_context *key);
1043
1050void mbedtls_x509write_crt_set_issuer_key(mbedtls_x509write_cert *ctx, mbedtls_pk_context *key);
1051
1059void mbedtls_x509write_crt_set_md_alg(mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg);
1060
1074int mbedtls_x509write_crt_set_extension(mbedtls_x509write_cert *ctx,
1075 const char *oid, size_t oid_len,
1076 int critical,
1077 const unsigned char *val, size_t val_len);
1078
1090int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert *ctx,
1091 int is_ca, int max_pathlen);
1092
1093#if defined(MBEDTLS_MD_CAN_SHA1)
1103int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert *ctx);
1104
1114int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *ctx);
1115#endif /* MBEDTLS_MD_CAN_SHA1 */
1116
1126int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert *ctx,
1127 unsigned int key_usage);
1128
1139int mbedtls_x509write_crt_set_ext_key_usage(mbedtls_x509write_cert *ctx,
1140 const mbedtls_asn1_sequence *exts);
1141
1151int mbedtls_x509write_crt_set_ns_cert_type(mbedtls_x509write_cert *ctx,
1152 unsigned char ns_cert_type);
1153
1159void mbedtls_x509write_crt_free(mbedtls_x509write_cert *ctx);
1160
1178int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
1179 mbedtls_f_rng_t *f_rng,
1180 void *p_rng);
1181
1182#if defined(MBEDTLS_PEM_WRITE_C)
1196int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
1197 mbedtls_f_rng_t *f_rng,
1198 void *p_rng);
1199#endif /* MBEDTLS_PEM_WRITE_C */
1200#endif /* MBEDTLS_X509_CRT_WRITE_C */
1201
1204#ifdef __cplusplus
1205}
1206#endif
1207
1208#endif /* mbedtls_x509_crt.h */
ReportItem items[32]
Definition main.cpp:145
uint8_t flags
Definition virtio.h:0
unsigned int uint32_t
Definition acefiex.h:163
Multi-precision integer library.
GameVersion_t version
Definition d_main.c:943
size_t size
Definition drm_bridge.h:1299
#define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN
Definition x509_crt.h:139
void mbedtls_x509_crt_restart_ctx
Definition x509_crt.h:306
#define MBEDTLS_X509_RFC5280_UTC_TIME_LEN
Definition x509_crt.h:140
#define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE
Definition x509_crt.h:258
int mbedtls_x509write_crt_set_subject_alternative_name(mbedtls_x509write_cert *ctx, const mbedtls_x509_san_list *san_list)
Set Subject Alternative Name.
int mbedtls_x509_crt_get_ca_istrue(const mbedtls_x509_crt *crt)
Access the ca_istrue field.
__u64 extensions
Definition i915_drm.h:0
size_t len
Definition initial.c:23
struct kobject * parent
Definition kobject.h:91
char end[]
Build-time configuration info.
mbedtls_md_type_t
Supported message digests.
Definition md.h:47
mbedtls_pk_type_t
Public key types.
Definition pk.h:73
void mbedtls_pk_restart_ctx
Definition pk.h:277
int mbedtls_f_rng_t(void *p_rng, unsigned char *output, size_t output_size)
The type of custom random generator (RNG) callbacks.
Definition platform_util.h:209
#define MBEDTLS_DEPRECATED
Definition platform_util.h:37
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
Definition private_access.h:15
Definition asn1.h:141
Definition asn1.h:178
Definition asn1.h:161
MPI structure.
Definition bignum.h:208
Public key container.
Definition pk.h:220
Definition x509.h:237
Definition x509_crl.h:64
Definition x509_crt.h:125
uint32_t rsa_min_bitlen
Definition x509_crt.h:131
uint32_t allowed_mds
Definition x509_crt.h:126
uint32_t allowed_pks
Definition x509_crt.h:127
uint32_t allowed_curves
Definition x509_crt.h:130
Definition x509_crt.h:250
mbedtls_x509_crt * MBEDTLS_PRIVATE(crt)
Definition x509_crt.h:263
mbedtls_x509_crt_verify_chain_item MBEDTLS_PRIVATE(items)[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE]
Definition x509_crt.h:41
mbedtls_x509_time valid_to
Definition x509_crt.h:58
mbedtls_x509_buf sig_oid
Definition x509_crt.h:49
int MBEDTLS_PRIVATE(own_buffer)
mbedtls_x509_sequence subject_alt_names
Definition x509_crt.h:66
int MBEDTLS_PRIVATE(max_pathlen)
int MBEDTLS_PRIVATE(ext_types)
mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md)
mbedtls_x509_buf tbs
Definition x509_crt.h:45
mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk)
mbedtls_x509_authority authority_key_id
Definition x509_crt.h:68
mbedtls_x509_buf subject_key_id
Definition x509_crt.h:67
mbedtls_x509_buf raw
Definition x509_crt.h:44
mbedtls_x509_buf serial
Definition x509_crt.h:48
mbedtls_pk_context pk
Definition x509_crt.h:61
mbedtls_x509_buf v3_ext
Definition x509_crt.h:65
mbedtls_x509_buf issuer_id
Definition x509_crt.h:63
void * MBEDTLS_PRIVATE(sig_opts)
mbedtls_x509_name subject
Definition x509_crt.h:55
int MBEDTLS_PRIVATE(ca_istrue)
mbedtls_x509_sequence certificate_policies
Definition x509_crt.h:70
int version
Definition x509_crt.h:47
unsigned int MBEDTLS_PRIVATE(key_usage)
mbedtls_x509_buf pk_raw
Definition x509_crt.h:60
unsigned char MBEDTLS_PRIVATE(ns_cert_type)
mbedtls_x509_time valid_from
Definition x509_crt.h:57
mbedtls_x509_buf subject_raw
Definition x509_crt.h:52
mbedtls_x509_sequence ext_key_usage
Definition x509_crt.h:78
struct mbedtls_x509_crt * next
Definition x509_crt.h:90
mbedtls_x509_buf MBEDTLS_PRIVATE(sig)
mbedtls_x509_buf subject_id
Definition x509_crt.h:64
mbedtls_x509_name issuer
Definition x509_crt.h:54
mbedtls_x509_buf issuer_raw
Definition x509_crt.h:51
Definition x509.h:303
Definition x509.h:246
Definition x509_crt.h:217
size_t MBEDTLS_PRIVATE(serial_len)
mbedtls_asn1_named_data * MBEDTLS_PRIVATE(issuer)
mbedtls_asn1_named_data * MBEDTLS_PRIVATE(subject)
unsigned char MBEDTLS_PRIVATE(serial)[MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN]
mbedtls_pk_context * MBEDTLS_PRIVATE(subject_key)
mbedtls_pk_context * MBEDTLS_PRIVATE(issuer_key)
int MBEDTLS_PRIVATE(version)
char MBEDTLS_PRIVATE(not_before)[MBEDTLS_X509_RFC5280_UTC_TIME_LEN+1]
mbedtls_asn1_named_data * MBEDTLS_PRIVATE(extensions)
mbedtls_md_type_t MBEDTLS_PRIVATE(md_alg)
char MBEDTLS_PRIVATE(not_after)[MBEDTLS_X509_RFC5280_UTC_TIME_LEN+1]
Definition path.h:8
X.509 generic defines and structures.
X.509 certificate revocation list parsing.