34 #if defined(MBEDTLS_X509_CRT_PARSE_C)
43 #if defined(MBEDTLS_PEM_PARSE_C)
47 #if defined(MBEDTLS_USE_PSA_CRYPTO)
54 #if defined(MBEDTLS_THREADING_C)
58 #if defined(MBEDTLS_HAVE_TIME)
59 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
66 #if defined(MBEDTLS_FS_IO)
68 #if !defined(_WIN32) || defined(EFIX64) || defined(EFI32)
69 #include <sys/types.h>
87 #define X509_MAX_VERIFY_CHAIN_SIZE (MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2)
113 #if defined(MBEDTLS_ECP_C)
139 #if defined(MBEDTLS_ECP_C)
194 #if defined(MBEDTLS_RSA_C)
204 #if defined(MBEDTLS_ECP_C)
232 const unsigned char *n1 = s1, *n2 = s2;
234 for (
i = 0;
i <
len;
i++) {
235 diff = n1[
i] ^ n2[
i];
242 ((n1[
i] >=
'a' && n1[
i] <=
'z') ||
243 (n1[
i] >=
'A' && n1[
i] <=
'Z'))) {
259 size_t cn_idx = 0, cn_len = strlen(cn);
262 if (name->
len < 3 || name->
p[0] !=
'*' || name->
p[1] !=
'.') {
266 for (
i = 0;
i < cn_len; ++
i) {
277 if (cn_len - cn_idx == name->
len - 1 &&
293 if (
a->tag ==
b->tag &&
295 memcmp(
a->p,
b->p,
b->len) == 0) {
328 if (
a->oid.tag !=
b->oid.tag ||
329 a->oid.len !=
b->oid.len ||
330 memcmp(
a->oid.p,
b->oid.p,
b->oid.len) != 0) {
340 if (
a->next_merged !=
b->next_merged) {
367 #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
368 ver_chain->trust_ca_cb_result =
NULL;
376 const unsigned char *end,
413 const unsigned char *end,
447 const unsigned char *end,
475 const unsigned char *end,
508 if (*ca_istrue != 0) {
528 if (*max_pathlen == INT_MAX) {
539 const unsigned char *end,
540 unsigned char *ns_cert_type)
555 *ns_cert_type = *bs.
p;
560 const unsigned char *end,
561 unsigned int *key_usage)
578 for (
i = 0;
i < bs.
len &&
i <
sizeof(
unsigned int);
i++) {
579 *key_usage |= (
unsigned int) bs.
p[
i] << (8*
i);
591 const unsigned char *end,
637 const unsigned char *end,
650 if (*p +
len != end) {
658 memset(&dummy_san_buf, 0,
sizeof(dummy_san_buf));
660 tmp_san_buf.
tag = **p;
668 tmp_san_buf.
len = tag_len;
687 while (seq_cur !=
NULL) {
689 seq_cur = seq_cur->
next;
714 cur->
buf = tmp_san_buf;
715 *p += tmp_san_buf.
len;
779 const unsigned char *end,
782 int ret, parse_ret = 0;
794 if (*p +
len != end) {
809 const unsigned char *policy_end;
819 policy_end = *p +
len;
859 buf->tag = policy_oid.
tag;
860 buf->p = policy_oid.
p;
861 buf->len = policy_oid.
len;
869 if (*p < policy_end) {
881 if (*p != policy_end) {
903 const unsigned char *end,
905 mbedtls_x509_crt_ext_cb_t cb,
910 unsigned char *end_ext_data, *start_ext_octet, *end_ext_octet;
937 end_ext_data = *p +
len;
961 start_ext_octet = *p;
962 end_ext_octet = *p +
len;
964 if (end_ext_octet != end_ext_data) {
977 ret = cb(p_ctx, crt, &extn_oid, is_critical, *p, end_ext_octet);
978 if (ret != 0 && is_critical) {
988 #if !defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
1053 cb(p_ctx, crt, &extn_oid, is_critical,
1054 start_ext_octet, end_ext_octet) == 0) {
1058 #if !defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
1081 #if !defined(MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
1102 const unsigned char *
buf,
1105 mbedtls_x509_crt_ext_cb_t cb,
1110 unsigned char *p, *end, *crt_end;
1125 p = (
unsigned char *)
buf;
1141 end = crt_end = p +
len;
1143 if (make_copy != 0) {
1154 end = crt_end = p +
len;
1156 crt->
raw.
p = (
unsigned char *)
buf;
1184 &sig_params1)) != 0) {
1285 int extensions_allowed = 1;
1286 #if !defined(MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3)
1288 extensions_allowed = 0;
1291 if (extensions_allowed) {
1321 sig_params1.
tag != sig_params2.
tag ||
1322 sig_params1.
len != sig_params2.
len ||
1323 (sig_params1.
len != 0 &&
1324 memcmp(sig_params1.
p, sig_params2.
p, sig_params1.
len) != 0)) {
1348 const unsigned char *
buf,
1351 mbedtls_x509_crt_ext_cb_t cb,
1401 const unsigned char *
buf,
1408 const unsigned char *
buf,
1411 mbedtls_x509_crt_ext_cb_t cb,
1418 const unsigned char *
buf,
1429 const unsigned char *
buf,
1432 #if defined(MBEDTLS_PEM_PARSE_C)
1433 int success = 0, first_error = 0, total_failed = 0;
1448 #if defined(MBEDTLS_PEM_PARSE_C)
1449 if (buflen != 0 &&
buf[buflen - 1] ==
'\0' &&
1450 strstr((
const char *)
buf,
"-----BEGIN CERTIFICATE-----") !=
NULL) {
1461 #if defined(MBEDTLS_PEM_PARSE_C)
1464 mbedtls_pem_context pem;
1467 while (buflen > 1) {
1473 "-----BEGIN CERTIFICATE-----",
1474 "-----END CERTIFICATE-----",
1494 if (first_error == 0) {
1516 if (first_error == 0) {
1529 return total_failed;
1530 }
else if (first_error) {
1538 #if defined(MBEDTLS_FS_IO)
1563 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
1565 WCHAR szDir[MAX_PATH];
1566 char filename[MAX_PATH];
1568 size_t len = strlen(path);
1570 WIN32_FIND_DATAW file_data;
1573 if (
len > MAX_PATH - 3) {
1577 memset(szDir, 0,
sizeof(szDir));
1578 memset(filename, 0, MAX_PATH);
1579 memcpy(filename, path,
len);
1580 filename[
len++] =
'\\';
1582 filename[
len++] =
'*';
1584 w_ret = MultiByteToWideChar(CP_ACP, 0, filename, (
int)
len, szDir,
1590 hFind = FindFirstFileW(szDir, &file_data);
1599 if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1603 w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName,
1618 }
while (FindNextFileW(hFind, &file_data) != 0);
1620 if (GetLastError() != ERROR_NO_MORE_FILES) {
1630 struct dirent *entry;
1632 DIR *dir = opendir(path);
1638 #if defined(MBEDTLS_THREADING_C)
1645 memset(&sb, 0,
sizeof(sb));
1647 while ((entry = readdir(dir)) !=
NULL) {
1649 "%s/%s", path, entry->d_name);
1651 if (snp_ret < 0 || (
size_t) snp_ret >=
sizeof(entry_name)) {
1654 }
else if (stat(entry_name, &sb) == -1) {
1655 if (errno == ENOENT) {
1670 if (!S_ISREG(sb.st_mode)) {
1687 #if defined(MBEDTLS_THREADING_C)
1716 unsigned char *p = subject_alt_name->
p;
1717 const unsigned char *end = p + subject_alt_name->
len;
1720 if ((subject_alt_name->
tag &
1752 if (end != p +
len) {
1762 if (end != p +
len) {
1805 while (cur !=
NULL) {
1806 memset(&san, 0,
sizeof(san));
1808 if (parse_ret != 0) {
1901 switch (san_buf->
tag &
1919 &other_name,
sizeof(other_name));
1933 san_buf,
sizeof(*san_buf));
1947 #define PRINT_ITEM(i) \
1949 ret = mbedtls_snprintf(p, n, "%s" i, sep); \
1950 MBEDTLS_X509_SAFE_SNPRINTF; \
1954 #define CERT_TYPE(type, name) \
1955 if (ns_cert_type & (type)) \
1959 unsigned char ns_cert_type)
1964 const char *sep =
"";
1981 #define KEY_USAGE(code, name) \
1982 if (key_usage & (code)) \
1986 unsigned int key_usage)
1991 const char *sep =
"";
2017 const char *sep =
"";
2019 while (cur !=
NULL) {
2046 const char *sep =
"";
2048 while (cur !=
NULL) {
2070 #define BEFORE_COLON 18
2087 return (
int) (
size -
n);
2111 "%04d-%02d-%02d %02d:%02d:%02d",
prefix,
2118 "%04d-%02d-%02d %02d:%02d:%02d",
prefix,
2208 return (
int) (
size -
n);
2220 "The certificate Common Name (CN) does not match with the expected CN" },
2222 "The certificate is not correctly signed by the trusted CA" },
2235 "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA)." },
2237 "The certificate is signed with an unacceptable key (eg bad curve, RSA too short)." },
2240 "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA)." },
2242 "The CRL is signed with an unacceptable key (eg bad curve, RSA too short)." },
2266 "(this should not happen)\n",
prefix);
2270 return (
int) (
size -
n);
2273 #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
2277 unsigned int usage_must, usage_may;
2285 usage_must =
usage & ~may_mask;
2287 if (((crt->
key_usage & ~may_mask) & usage_must) != usage_must) {
2291 usage_may =
usage & may_mask;
2293 if (((crt->
key_usage & may_mask) | usage_may) != usage_may) {
2301 #if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
2303 const char *usage_oid,
2319 if (cur_oid->
len == usage_len &&
2320 memcmp(cur_oid->
p, usage_oid, usage_len) == 0) {
2333 #if defined(MBEDTLS_X509_CRL_PARSE_C)
2369 while (crl_list !=
NULL) {
2372 crl_list = crl_list->
next;
2379 #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
2435 crl_list = crl_list->
next;
2451 #if !defined(MBEDTLS_USE_PSA_CRYPTO)
2483 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2519 if (top && parent->
version < 3) {
2523 if (need_ca_bit && !parent->
ca_istrue) {
2527 #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
2584 int *r_signature_is_good,
2592 int signature_is_good = 0, fallback_signature_is_good;
2594 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2596 if (rs_ctx !=
NULL && rs_ctx->parent !=
NULL) {
2598 parent = rs_ctx->parent;
2599 fallback_parent = rs_ctx->fallback_parent;
2600 fallback_signature_is_good = rs_ctx->fallback_signature_is_good;
2603 rs_ctx->parent =
NULL;
2604 rs_ctx->fallback_parent =
NULL;
2605 rs_ctx->fallback_signature_is_good = 0;
2608 goto check_signature;
2612 fallback_parent =
NULL;
2613 fallback_signature_is_good = 0;
2615 for (parent = candidates; parent !=
NULL; parent = parent->
next) {
2623 (
size_t) parent->
max_pathlen < 1 + path_cnt - self_cnt) {
2628 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2633 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2636 rs_ctx->parent = parent;
2637 rs_ctx->fallback_parent = fallback_parent;
2638 rs_ctx->fallback_signature_is_good = fallback_signature_is_good;
2646 signature_is_good = ret == 0;
2647 if (top && !signature_is_good) {
2654 if (fallback_parent ==
NULL) {
2655 fallback_parent = parent;
2656 fallback_signature_is_good = signature_is_good;
2663 *r_signature_is_good = signature_is_good;
2668 if (parent ==
NULL) {
2669 *r_parent = fallback_parent;
2670 *r_signature_is_good = fallback_signature_is_good;
2702 int *parent_is_trusted,
2703 int *signature_is_good,
2711 *parent_is_trusted = 1;
2713 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2715 if (rs_ctx !=
NULL && rs_ctx->parent_is_trusted != -1) {
2716 *parent_is_trusted = rs_ctx->parent_is_trusted;
2717 rs_ctx->parent_is_trusted = -1;
2722 search_list = *parent_is_trusted ? trust_ca : child->
next;
2725 parent, signature_is_good,
2727 path_cnt, self_cnt, rs_ctx);
2729 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2732 rs_ctx->parent_is_trusted = *parent_is_trusted;
2740 if (*parent !=
NULL || *parent_is_trusted == 0) {
2745 *parent_is_trusted = 0;
2749 if (*parent ==
NULL) {
2750 *parent_is_trusted = 0;
2751 *signature_is_good = 0;
2775 for (cur = trust_ca; cur !=
NULL; cur = cur->
next) {
2830 mbedtls_x509_crt_ca_cb_t f_ca_cb,
2843 int parent_is_trusted;
2844 int child_is_trusted;
2845 int signature_is_good;
2849 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2851 if (rs_ctx !=
NULL && rs_ctx->in_progress == x509_crt_rs_find_parent) {
2853 *ver_chain = rs_ctx->ver_chain;
2854 self_cnt = rs_ctx->self_cnt;
2857 cur = &ver_chain->
items[ver_chain->
len - 1];
2867 parent_is_trusted = 0;
2868 child_is_trusted = 0;
2872 cur = &ver_chain->
items[ver_chain->
len];
2888 if (child_is_trusted) {
2902 if (ver_chain->
len == 1 &&
2907 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2913 #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
2914 if (f_ca_cb !=
NULL) {
2917 ver_chain->trust_ca_cb_result =
NULL;
2919 ret = f_ca_cb(p_ca_cb, child, &ver_chain->trust_ca_cb_result);
2924 cur_trust_ca = ver_chain->trust_ca_cb_result;
2930 cur_trust_ca = trust_ca;
2935 &parent_is_trusted, &signature_is_good,
2936 ver_chain->
len - 1, self_cnt, rs_ctx);
2938 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
2941 rs_ctx->in_progress = x509_crt_rs_find_parent;
2942 rs_ctx->self_cnt = self_cnt;
2943 rs_ctx->ver_chain = *ver_chain;
2952 if (parent ==
NULL) {
2960 if (ver_chain->
len != 1 &&
2967 if (!parent_is_trusted &&
2974 if (!signature_is_good) {
2983 #if defined(MBEDTLS_X509_CRL_PARSE_C)
2993 child_is_trusted = parent_is_trusted;
2994 signature_is_good = 0;
3002 const char *cn,
size_t cn_len)
3005 if (name->
len == cn_len &&
3022 const char *cn,
size_t cn_len)
3024 const unsigned char san_type = (
unsigned char) name->
tag &
3047 size_t cn_len = strlen(cn);
3087 for (
i = ver_chain->
len;
i != 0; --
i) {
3088 cur = &ver_chain->
items[
i-1];
3089 cur_flags = cur->
flags;
3091 if (
NULL != f_vrfy) {
3092 if ((ret = f_vrfy(p_vrfy, cur->
crt, (
int)
i-1, &cur_flags)) != 0) {
3097 *
flags |= cur_flags;
3123 mbedtls_x509_crt_ca_cb_t f_ca_cb,
3127 int (*f_vrfy)(
void *,
3143 if (profile ==
NULL) {
3166 f_ca_cb, p_ca_cb, profile,
3167 &ver_chain, rs_ctx);
3181 #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
3184 ver_chain.trust_ca_cb_result =
NULL;
3187 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
3189 mbedtls_x509_crt_restart_free(rs_ctx);
3227 f_vrfy, p_vrfy,
NULL);
3244 f_vrfy, p_vrfy,
NULL);
3247 #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
3253 mbedtls_x509_crt_ca_cb_t f_ca_cb,
3263 f_vrfy, p_vrfy,
NULL);
3279 f_vrfy, p_vrfy, rs_ctx);
3310 #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
3315 while (name_cur !=
NULL) {
3316 name_prv = name_cur;
3317 name_cur = name_cur->
next;
3323 while (name_cur !=
NULL) {
3324 name_prv = name_cur;
3325 name_cur = name_cur->
next;
3331 while (seq_cur !=
NULL) {
3333 seq_cur = seq_cur->
next;
3340 while (seq_cur !=
NULL) {
3342 seq_cur = seq_cur->
next;
3349 while (seq_cur !=
NULL) {
3351 seq_cur = seq_cur->
next;
3362 cert_cur = cert_cur->
next;
3363 }
while (cert_cur !=
NULL);
3367 cert_prv = cert_cur;
3368 cert_cur = cert_cur->
next;
3371 if (cert_prv != crt) {
3374 }
while (cert_cur !=
NULL);
3377 #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
3383 mbedtls_pk_restart_init(&
ctx->pk);
3387 ctx->fallback_signature_is_good = 0;
3389 ctx->parent_is_trusted = -1;
3391 ctx->in_progress = x509_crt_rs_none;
3405 mbedtls_pk_restart_free(&
ctx->pk);
3406 mbedtls_x509_crt_restart_init(
ctx);
Platform Security Architecture cryptography module.
static void cleanup(void)
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
#define MBEDTLS_ERR_ECP_IN_PROGRESS
Operation in progress, call again with the same parameters to continue.
mbedtls_ecp_group_id
Domain-parameter identifiers: curve, subgroup, and generator.
@ MBEDTLS_ECP_DP_SECP384R1
@ MBEDTLS_ECP_DP_SECP256K1
@ MBEDTLS_ECP_DP_SECP521R1
@ MBEDTLS_ECP_DP_SECP256R1
#define MBEDTLS_ASN1_TAG_CLASS_MASK
#define MBEDTLS_ASN1_OCTET_STRING
#define MBEDTLS_OID_CMP(oid_str, oid_buf)
Compares an mbedtls_asn1_buf structure to a reference OID.
#define MBEDTLS_ERR_ASN1_INVALID_LENGTH
Error when trying to determine the length or invalid length.
#define MBEDTLS_ASN1_PRINTABLE_STRING
#define MBEDTLS_ASN1_SEQUENCE
int mbedtls_asn1_get_int(unsigned char **p, const unsigned char *end, int *val)
Retrieve an integer ASN.1 tag and its value.
int mbedtls_asn1_get_sequence_of(unsigned char **p, const unsigned char *end, mbedtls_asn1_sequence *cur, int tag)
Parses and splits an ASN.1 "SEQUENCE OF <tag>".
#define MBEDTLS_ASN1_CONTEXT_SPECIFIC
#define MBEDTLS_ASN1_CONSTRUCTED
#define MBEDTLS_ASN1_TAG_VALUE_MASK
#define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
ASN1 tag was of an unexpected value.
#define MBEDTLS_ERR_ASN1_ALLOC_FAILED
Memory allocation failed.
#define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH
Actual length differs from expected length.
int mbedtls_asn1_get_len(unsigned char **p, const unsigned char *end, size_t *len)
Get the length of an ASN.1 element.
int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end, mbedtls_asn1_bitstring *bs)
Retrieve a bitstring ASN.1 tag and its value.
int mbedtls_asn1_get_tag(unsigned char **p, const unsigned char *end, size_t *len, int tag)
Get the tag and length of the element.
int mbedtls_asn1_get_bool(unsigned char **p, const unsigned char *end, int *val)
Retrieve a boolean ASN.1 tag and its value.
#define MBEDTLS_ASN1_UTF8_STRING
#define INVALID_HANDLE_VALUE
A value for an invalid file handle.
#define HANDLE
An abstraction for a file handle.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
#define PSA_SUCCESS
The action was completed successfully.
psa_status_t psa_hash_finish(psa_hash_operation_t *operation, uint8_t *hash, size_t hash_size, size_t *hash_length)
Finish the calculation of the hash of a message.
psa_status_t psa_hash_update(psa_hash_operation_t *operation, const uint8_t *input, size_t input_length)
Add a message fragment to a multipart hash operation.
#define PSA_HASH_OPERATION_INIT
This macro returns a suitable initializer for a hash operation object of type psa_hash_operation_t.
psa_status_t psa_hash_setup(psa_hash_operation_t *operation, psa_algorithm_t alg)
Set up a multipart hash operation.
unsigned int
A callback function used to compare two keys in a database.
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.
#define MBEDTLS_X509_BADCERT_NOT_TRUSTED
The certificate is not correctly signed by the trusted CA.
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.
#define MBEDTLS_X509_BADCRL_BAD_PK
The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).
#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE
Unavailable feature, e.g.
#define MBEDTLS_X509_BADCERT_SKIP_VERIFY
Certificate verification was skipped.
#define MBEDTLS_X509_BADCERT_KEY_USAGE
Usage does not match the keyUsage extension.
void mbedtls_x509_crt_restart_ctx
#define MBEDTLS_X509_BADCERT_BAD_MD
The certificate is signed with an unacceptable hash.
#define MBEDTLS_ERR_X509_INVALID_FORMAT
The CRT/CRL/CSR format is invalid, e.g.
#define MBEDTLS_X509_MAX_FILE_PATH_LEN
#define MBEDTLS_ERR_X509_FATAL_ERROR
A fatal error occurred, eg the chain is too long or the vrfy callback failed.
#define MBEDTLS_ERR_X509_INVALID_VERSION
The CRT/CRL/CSR version element is invalid.
#define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE
Max size of verification chain: end-entity + intermediates + trusted root.
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.
#define MBEDTLS_X509_BADCERT_EXPIRED
The certificate validity has expired.
#define MBEDTLS_X509_BADCERT_CN_MISMATCH
The certificate Common Name (CN) does not match with the expected CN.
#define MBEDTLS_X509_BADCERT_OTHER
Other reason (can be used by verify callback)
#define MBEDTLS_X509_BADCERT_MISSING
Certificate was missing.
#define MBEDTLS_X509_BADCERT_BAD_PK
The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).
#define MBEDTLS_ERR_X509_INVALID_EXTENSIONS
The extension tag or value is invalid.
#define MBEDTLS_X509_BADCERT_NS_CERT_TYPE
Usage does not match the nsCertType extension.
#define MBEDTLS_ERR_X509_UNKNOWN_VERSION
CRT/CRL/CSR has an unsupported version number.
#define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL
Destination buffer is too small.
#define MBEDTLS_X509_MAX_INTERMEDIATE_CA
Maximum number of intermediate CAs in a verification chain.
#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED
Certificate verification failed, e.g.
#define MBEDTLS_X509_BADCRL_BAD_KEY
The CRL is signed with an unacceptable key (eg bad curve, RSA too short).
#define MBEDTLS_ERR_X509_INVALID_DATE
The date tag or value is invalid.
#define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE
Usage does not match the extendedKeyUsage extension.
#define MBEDTLS_ERR_X509_SIG_MISMATCH
Signature algorithms do not match.
#define MBEDTLS_X509_BADCERT_FUTURE
The certificate validity starts in the future.
#define MBEDTLS_ERR_X509_ALLOC_FAILED
Allocation of memory failed.
#define MBEDTLS_X509_BADCRL_NOT_TRUSTED
The CRL is not correctly signed by the trusted CA.
#define MBEDTLS_X509_BADCRL_BAD_MD
The CRL is signed with an unacceptable hash.
#define MBEDTLS_ERR_X509_FILE_IO_ERROR
Read/write of file failed.
#define MBEDTLS_X509_BADCRL_FUTURE
The CRL is from the future.
#define MBEDTLS_X509_BADCERT_REVOKED
The certificate has been revoked (is on a CRL).
#define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT
Format not recognized as DER or PEM.
#define MBEDTLS_X509_BADCRL_EXPIRED
The CRL is expired.
#define MBEDTLS_X509_ID_FLAG(id)
Build flag from an algorithm/curve identifier (pk, md, ecp) Since 0 is always XXX_NONE,...
#define MBEDTLS_ERR_X509_BAD_INPUT_DATA
Input invalid.
#define MBEDTLS_X509_BADCERT_BAD_KEY
The certificate is signed with an unacceptable key (eg bad curve, RSA too short).
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...
if(yy_accept[yy_current_state])
mbedtls_md_type_t
Supported message digests.
@ MBEDTLS_MD_SHA512
The SHA-512 message digest.
@ MBEDTLS_MD_SHA384
The SHA-384 message digest.
@ MBEDTLS_MD_SHA256
The SHA-256 message digest.
@ MBEDTLS_MD_SHA224
The SHA-224 message digest.
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the message-digest of a buffer, with respect to a configurable message-diges...
const mbedtls_md_info_t * mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
This function returns the message-digest information associated with the given digest type.
#define MBEDTLS_MD_MAX_SIZE
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
This function extracts the message-digest size from the message-digest information structure.
const struct ncbi::grid::netcache::search::fields::SIZE size
#define mbedtls_pem_read_buffer
#define mbedtls_x509_crt_parse_der
#define mbedtls_x509_crt_parse_der_nocopy
#define mbedtls_x509_crt_profile_default
#define mbedtls_x509_crt_parse_der_with_ext_cb
#define mbedtls_x509_parse_subject_alt_name
#define mbedtls_x509_crt_parse_file
#define mbedtls_x509_crt_is_revoked
#define mbedtls_x509_crt_profile_next
#define mbedtls_pk_load_file
#define mbedtls_x509_crt_init
#define mbedtls_x509_crt_check_extended_key_usage
#define mbedtls_x509_crt_verify_restartable
#define mbedtls_x509_crt_free
#define mbedtls_pk_parse_subpubkey
#define mbedtls_x509_crt_profile_suiteb
#define mbedtls_x509_crt_check_key_usage
#define mbedtls_x509_crt_verify_info
#define mbedtls_x509_crt_parse
#define mbedtls_mutex_lock
#define mbedtls_x509_crt_info
#define mbedtls_x509_crt_verify
#define mbedtls_threading_readdir_mutex
#define mbedtls_mutex_unlock
#define mbedtls_x509_crt_parse_path
#define mbedtls_x509_crt_verify_with_profile
Object Identifier (OID) database.
#define MBEDTLS_OID_ON_HW_MODULE_NAME
id-on-hardwareModuleName OBJECT IDENTIFIER ::= { id-on 4 }
#define MBEDTLS_OID_ANY_POLICY
anyPolicy OBJECT IDENTIFIER ::= { id-ce-certificatePolicies 0 }
int mbedtls_oid_get_extended_key_usage(const mbedtls_asn1_buf *oid, const char **desc)
Translate Extended Key Usage OID into description.
#define MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE
anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 }
int mbedtls_oid_get_x509_ext_type(const mbedtls_asn1_buf *oid, int *ext_type)
Translate an X.509 extension OID into local values.
int mbedtls_oid_get_certificate_policies(const mbedtls_asn1_buf *oid, const char **desc)
Translate certificate policies OID into description.
#define MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES
#define MBEDTLS_OID_AT_CN
id-at-commonName AttributeType:= {id-at 3}
int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid)
Translate an ASN.1 OID into its numeric representation (e.g.
static const char * prefix[]
Privacy Enhanced Mail (PEM) decoding.
#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA
Bad input parameters to function.
#define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT
No PEM header or footer found.
const char * mbedtls_pk_get_name(const mbedtls_pk_context *ctx)
Access the type name.
int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type)
Tell if a context can do the operation given by type.
mbedtls_pk_type_t
Public key types.
size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx)
Get the size in bits of the underlying key.
int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options, mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len)
Verify signature, with options.
int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len, mbedtls_pk_restart_ctx *rs_ctx)
Restartable version of mbedtls_pk_verify()
mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx)
Get the key type.
void mbedtls_pk_free(mbedtls_pk_context *ctx)
Free the components of a mbedtls_pk_context.
Utility functions for the use of the PSA Crypto library.
Error to string translation.
#define MBEDTLS_ERROR_ADD(high, low)
Combines a high-level and low-level error code together.
#define MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED
This is a bug in the library.
Container for ASN1 bit strings.
size_t len
ASN1 length, in octets.
unsigned char * p
Raw ASN1 data for the bit string.
Type-length-value structure that allows for ASN1 using DER.
size_t len
ASN1 length, in octets.
unsigned char * p
ASN1 data, e.g.
Container for a sequence or list of 'named' ASN.1 data items.
mbedtls_asn1_buf oid
The object identifier.
struct mbedtls_asn1_named_data * next
The next entry in the sequence.
mbedtls_asn1_buf val
The named value.
Container for a sequence of ASN.1 items.
mbedtls_asn1_buf buf
Buffer containing the given ASN.1 item.
struct mbedtls_asn1_sequence * next
The next entry in the sequence.
Message digest information.
Certificate revocation list entry.
struct mbedtls_x509_crl_entry * next
Certificate revocation list structure.
mbedtls_x509_time this_update
struct mbedtls_x509_crl * next
mbedtls_md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
mbedtls_x509_time next_update
mbedtls_x509_crl_entry entry
The CRL entries containing the certificate revocation times for this CA.
mbedtls_pk_type_t sig_pk
Internal representation of the Public Key algorithm of the signature algorithm, e....
mbedtls_x509_name issuer
The parsed issuer data (named information object).
int version
CRL version (1=v1, 2=v2)
mbedtls_x509_buf tbs
The raw certificate body (DER).
void * sig_opts
Signature options to be passed to mbedtls_pk_verify_ext(), e.g.
Security profile for certificate verification.
uint32_t rsa_min_bitlen
Minimum size for RSA keys.
uint32_t allowed_mds
MDs for signatures.
uint32_t allowed_pks
PK algs for public keys; this applies to all certificates in the provided chain.
uint32_t allowed_curves
Elliptic curves for ECDSA.
Item in a verification chain: cert and flags for it.
Verification chain as built by mbedtls_crt_verify_chain()
mbedtls_x509_crt_verify_chain_item items[(MBEDTLS_X509_MAX_INTERMEDIATE_CA+2)]
Container for an X.509 certificate.
mbedtls_x509_time valid_to
End time of certificate validity.
mbedtls_x509_buf sig_oid
Signature algorithm, e.g.
int ca_istrue
Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise.
mbedtls_x509_sequence subject_alt_names
Optional list of raw entries of Subject Alternative Names extension (currently only dNSName and Other...
unsigned int key_usage
Optional key usage extension value: See the values in x509.h.
mbedtls_x509_buf tbs
The raw certificate body (DER).
int own_buffer
Indicates if raw is owned by the structure or not.
mbedtls_x509_buf raw
The raw certificate data (DER).
mbedtls_x509_buf serial
Unique id for certificate issued by a specific CA.
mbedtls_md_type_t sig_md
Internal representation of the MD algorithm of the signature algorithm, e.g.
int ext_types
Bit string containing detected and parsed extensions.
mbedtls_pk_context pk
Container for the public key context.
mbedtls_pk_type_t sig_pk
Internal representation of the Public Key algorithm of the signature algorithm, e....
void * sig_opts
Signature options to be passed to mbedtls_pk_verify_ext(), e.g.
mbedtls_x509_buf v3_ext
Optional X.509 v3 extensions.
mbedtls_x509_buf issuer_id
Optional X.509 v2/v3 issuer unique identifier.
mbedtls_x509_name subject
The parsed subject data (named information object).
mbedtls_x509_sequence certificate_policies
Optional list of certificate policies (Only anyPolicy is printed and enforced, however the rest of th...
int version
The X.509 version.
mbedtls_x509_time valid_from
Start time of certificate validity.
int max_pathlen
Optional Basic Constraint extension value: The maximum path length to the root certificate.
mbedtls_x509_buf subject_raw
The raw subject data (DER).
mbedtls_x509_sequence ext_key_usage
Optional list of extended key usage OIDs.
struct mbedtls_x509_crt * next
Next certificate in the CA-chain.
mbedtls_x509_buf subject_id
Optional X.509 v2/v3 subject unique identifier.
unsigned char ns_cert_type
Optional Netscape certificate type extension value: See the values in x509.h.
mbedtls_x509_name issuer
The parsed issuer data (named information object).
mbedtls_x509_buf sig
Signature: hash of the tbs part signed with the private key.
mbedtls_x509_buf issuer_raw
The raw issuer data (DER).
From RFC 5280 section 4.2.1.6: OtherName ::= SEQUENCE { type-id OBJECT IDENTIFIER,...
struct mbedtls_x509_san_other_name::@947::@948 hardware_module_name
From RFC 4108 section 5: HardwareModuleName ::= SEQUENCE { hwType OBJECT IDENTIFIER,...
union mbedtls_x509_san_other_name::@947 value
A structure for holding the parsed Subject Alternative Name, according to type.
mbedtls_x509_san_other_name other_name
The otherName supported type.
mbedtls_x509_buf unstructured_name
The buffer for the un constructed types.
union mbedtls_x509_subject_alternative_name::@949 san
A union of the supported SAN types.
int type
The SAN type, value of MBEDTLS_X509_SAN_XXX.
Container for date and time (precision in seconds).
Threading abstraction layer.
#define MBEDTLS_ERR_THREADING_MUTEX_ERROR
Locking / unlocking / free failed with error code.
#define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING
#define MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA
#define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA
#define MBEDTLS_X509_FORMAT_PEM
int mbedtls_x509_get_name(unsigned char **p, const unsigned char *end, mbedtls_x509_name *cur)
#define MBEDTLS_X509_KU_DIGITAL_SIGNATURE
#define MBEDTLS_X509_KU_DECIPHER_ONLY
#define MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT
#define MBEDTLS_X509_NS_CERT_TYPE_EMAIL
#define MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER
#define MBEDTLS_X509_KU_KEY_CERT_SIGN
#define MBEDTLS_X509_NS_CERT_TYPE_SSL_CA
#define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE
#define MBEDTLS_X509_SAFE_SNPRINTF
int mbedtls_x509_get_sig_alg(const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params, mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg, void **sig_opts)
#define MBEDTLS_X509_SAN_OTHER_NAME
#define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS
int mbedtls_x509_get_alg(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *alg, mbedtls_x509_buf *params)
#define MBEDTLS_X509_KU_CRL_SIGN
#define MBEDTLS_X509_SAN_DNS_NAME
int mbedtls_x509_get_ext(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *ext, int tag)
#define MBEDTLS_X509_KU_NON_REPUDIATION
#define MBEDTLS_X509_EXT_KEY_USAGE
#define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME
int mbedtls_x509_key_size_helper(char *buf, size_t buf_size, const char *name)
#define MBEDTLS_X509_KU_KEY_AGREEMENT
#define MBEDTLS_X509_KU_ENCIPHER_ONLY
int mbedtls_x509_sig_alg_gets(char *buf, size_t size, const mbedtls_x509_buf *sig_oid, mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, const void *sig_opts)
int mbedtls_x509_get_serial(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *serial)
int mbedtls_x509_get_sig(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig)
#define MBEDTLS_X509_FORMAT_DER
#define MBEDTLS_X509_KU_DATA_ENCIPHERMENT
int mbedtls_x509_get_time(unsigned char **p, const unsigned char *end, mbedtls_x509_time *t)
#define MBEDTLS_X509_KU_KEY_ENCIPHERMENT
#define MBEDTLS_X509_EXT_NS_CERT_TYPE
#define MBEDTLS_X509_NS_CERT_TYPE_RESERVED
static int x509_get_key_usage(unsigned char **p, const unsigned char *end, unsigned int *key_usage)
static int x509_memcasecmp(const void *s1, const void *s2, size_t len)
static int x509_crt_check_parent(const mbedtls_x509_crt *child, const mbedtls_x509_crt *parent, int top)
static int x509_get_dates(unsigned char **p, const unsigned char *end, mbedtls_x509_time *from, mbedtls_x509_time *to)
#define KEY_USAGE(code, name)
static int x509_get_ext_key_usage(unsigned char **p, const unsigned char *end, mbedtls_x509_sequence *ext_key_usage)
static int x509_crt_check_cn(const mbedtls_x509_buf *name, const char *cn, size_t cn_len)
static int x509_crt_verify_chain(mbedtls_x509_crt *crt, mbedtls_x509_crt *trust_ca, mbedtls_x509_crl *ca_crl, mbedtls_x509_crt_ca_cb_t f_ca_cb, void *p_ca_cb, const mbedtls_x509_crt_profile *profile, mbedtls_x509_crt_verify_chain *ver_chain, mbedtls_x509_crt_restart_ctx *rs_ctx)
static int x509_get_ns_cert_type(unsigned char **p, const unsigned char *end, unsigned char *ns_cert_type)
static int x509_get_uid(unsigned char **p, const unsigned char *end, mbedtls_x509_buf *uid, int n)
static int x509_string_cmp(const mbedtls_x509_buf *a, const mbedtls_x509_buf *b)
static int x509_get_version(unsigned char **p, const unsigned char *end, int *ver)
static int x509_crt_check_san(const mbedtls_x509_buf *name, const char *cn, size_t cn_len)
static int x509_profile_check_pk_alg(const mbedtls_x509_crt_profile *profile, mbedtls_pk_type_t pk_alg)
static int x509_info_subject_alt_name(char **buf, size_t *size, const mbedtls_x509_sequence *subject_alt_name, const char *prefix)
static void x509_crt_verify_chain_reset(mbedtls_x509_crt_verify_chain *ver_chain)
static int x509_get_basic_constraints(unsigned char **p, const unsigned char *end, int *ca_istrue, int *max_pathlen)
static int mbedtls_x509_crt_parse_der_internal(mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen, int make_copy, mbedtls_x509_crt_ext_cb_t cb, void *p_ctx)
static int x509_info_key_usage(char **buf, size_t *size, unsigned int key_usage)
static void x509_crt_verify_name(const mbedtls_x509_crt *crt, const char *cn, uint32_t *flags)
static int x509_crt_find_parent(mbedtls_x509_crt *child, mbedtls_x509_crt *trust_ca, mbedtls_x509_crt **parent, int *parent_is_trusted, int *signature_is_good, unsigned path_cnt, unsigned self_cnt, mbedtls_x509_crt_restart_ctx *rs_ctx)
static int x509_crt_verify_restartable_ca_cb(mbedtls_x509_crt *crt, mbedtls_x509_crt *trust_ca, mbedtls_x509_crl *ca_crl, mbedtls_x509_crt_ca_cb_t f_ca_cb, void *p_ca_cb, const mbedtls_x509_crt_profile *profile, const char *cn, uint32_t *flags, int(*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy, mbedtls_x509_crt_restart_ctx *rs_ctx)
static int x509_profile_check_md_alg(const mbedtls_x509_crt_profile *profile, mbedtls_md_type_t md_alg)
static int x509_get_subject_alt_name(unsigned char **p, const unsigned char *end, mbedtls_x509_sequence *subject_alt_name)
static int x509_check_wildcard(const char *cn, const mbedtls_x509_buf *name)
static int x509_info_ext_key_usage(char **buf, size_t *size, const mbedtls_x509_sequence *extended_key_usage)
static int x509_crt_find_parent_in(mbedtls_x509_crt *child, mbedtls_x509_crt *candidates, mbedtls_x509_crt **r_parent, int *r_signature_is_good, int top, unsigned path_cnt, unsigned self_cnt, mbedtls_x509_crt_restart_ctx *rs_ctx)
static int x509_name_cmp(const mbedtls_x509_name *a, const mbedtls_x509_name *b)
static int x509_crt_check_signature(const mbedtls_x509_crt *child, mbedtls_x509_crt *parent, mbedtls_x509_crt_restart_ctx *rs_ctx)
static int x509_get_other_name(const mbedtls_x509_buf *subject_alt_name, mbedtls_x509_san_other_name *other_name)
static int x509_profile_check_key(const mbedtls_x509_crt_profile *profile, const mbedtls_pk_context *pk)
static int x509_crt_parse_der_core(mbedtls_x509_crt *crt, const unsigned char *buf, size_t buflen, int make_copy, mbedtls_x509_crt_ext_cb_t cb, void *p_ctx)
static int x509_get_certificate_policies(unsigned char **p, const unsigned char *end, mbedtls_x509_sequence *certificate_policies)
static int x509_crt_merge_flags_with_cb(uint32_t *flags, const mbedtls_x509_crt_verify_chain *ver_chain, int(*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy)
static int x509_crt_verifycrl(mbedtls_x509_crt *crt, mbedtls_x509_crt *ca, mbedtls_x509_crl *crl_list, const mbedtls_x509_crt_profile *profile)
static int x509_info_cert_type(char **buf, size_t *size, unsigned char ns_cert_type)
static int x509_info_cert_policies(char **buf, size_t *size, const mbedtls_x509_sequence *certificate_policies)
static const struct x509_crt_verify_string x509_crt_verify_strings[]
#define CERT_TYPE(type, name)
static int x509_get_crt_ext(unsigned char **p, const unsigned char *end, mbedtls_x509_crt *crt, mbedtls_x509_crt_ext_cb_t cb, void *p_ctx)
static int x509_crt_check_ee_locally_trusted(mbedtls_x509_crt *crt, mbedtls_x509_crt *trust_ca)
X.509 certificate parsing and writing.