| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1 | /** | 
| Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 2 | * \file x509_crt.h | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 3 | * | 
|  | 4 | * \brief X.509 certificate parsing and writing | 
| Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ | 
|  | 6 | /* | 
| Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | *  Copyright The Mbed TLS Contributors | 
| Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 8 | *  SPDX-License-Identifier: Apache-2.0 | 
|  | 9 | * | 
|  | 10 | *  Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 11 | *  not use this file except in compliance with the License. | 
|  | 12 | *  You may obtain a copy of the License at | 
|  | 13 | * | 
|  | 14 | *  http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 15 | * | 
|  | 16 | *  Unless required by applicable law or agreed to in writing, software | 
|  | 17 | *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 18 | *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 19 | *  See the License for the specific language governing permissions and | 
|  | 20 | *  limitations under the License. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 21 | */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 22 | #ifndef MBEDTLS_X509_CRT_H | 
|  | 23 | #define MBEDTLS_X509_CRT_H | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 24 | #include "mbedtls/private_access.h" | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 25 |  | 
| Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 26 | #include "mbedtls/build_info.h" | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 27 |  | 
| Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 28 | #include "mbedtls/x509.h" | 
|  | 29 | #include "mbedtls/x509_crl.h" | 
|  | 30 | #include "mbedtls/bignum.h" | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 31 |  | 
|  | 32 | /** | 
|  | 33 | * \addtogroup x509_module | 
|  | 34 | * \{ | 
|  | 35 | */ | 
|  | 36 |  | 
|  | 37 | #ifdef __cplusplus | 
|  | 38 | extern "C" { | 
|  | 39 | #endif | 
|  | 40 |  | 
|  | 41 | /** | 
|  | 42 | * \name Structures and functions for parsing and writing X.509 certificates | 
|  | 43 | * \{ | 
|  | 44 | */ | 
|  | 45 |  | 
|  | 46 | /** | 
|  | 47 | * Container for an X.509 certificate. The certificate may be chained. | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 48 | * | 
|  | 49 | * Some fields of this structure are publicly readable. Do not modify | 
|  | 50 | * them except via Mbed TLS library functions: the effect of modifying | 
|  | 51 | * those fields or the data that those fields points to is unspecified. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 52 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 53 | typedef struct mbedtls_x509_crt { | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 54 | int MBEDTLS_PRIVATE(own_buffer);                     /**< Indicates if \c raw is owned | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 55 | *   by the structure or not.        */ | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 56 | mbedtls_x509_buf raw;               /**< The raw certificate data (DER). */ | 
|  | 57 | mbedtls_x509_buf tbs;               /**< The raw certificate body (DER). The part that is To Be Signed. */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 58 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 59 | int version;                /**< The X.509 version. (1=v1, 2=v2, 3=v3) */ | 
|  | 60 | mbedtls_x509_buf serial;            /**< Unique id for certificate issued by a specific CA. */ | 
|  | 61 | mbedtls_x509_buf sig_oid;           /**< Signature algorithm, e.g. sha1RSA */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 62 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 63 | mbedtls_x509_buf issuer_raw;        /**< The raw issuer data (DER). Used for quick comparison. */ | 
|  | 64 | mbedtls_x509_buf subject_raw;       /**< The raw subject data (DER). Used for quick comparison. */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 65 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 66 | mbedtls_x509_name issuer;           /**< The parsed issuer data (named information object). */ | 
|  | 67 | mbedtls_x509_name subject;          /**< The parsed subject data (named information object). */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 68 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 69 | mbedtls_x509_time valid_from;       /**< Start time of certificate validity. */ | 
|  | 70 | mbedtls_x509_time valid_to;         /**< End time of certificate validity. */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 71 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 72 | mbedtls_x509_buf pk_raw; | 
|  | 73 | mbedtls_pk_context pk;              /**< Container for the public key context. */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 74 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 75 | mbedtls_x509_buf issuer_id;         /**< Optional X.509 v2/v3 issuer unique identifier. */ | 
|  | 76 | mbedtls_x509_buf subject_id;        /**< Optional X.509 v2/v3 subject unique identifier. */ | 
|  | 77 | mbedtls_x509_buf v3_ext;            /**< Optional X.509 v3 extensions.  */ | 
| Andrzej Kurek | 8bc128e | 2023-02-27 16:09:52 -0500 | [diff] [blame] | 78 | mbedtls_x509_sequence subject_alt_names;    /**< Optional list of raw entries of Subject Alternative Names extension (currently only dNSName, uniformResourceIdentifier, DirectoryName and OtherName are listed). */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 79 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 80 | mbedtls_x509_sequence certificate_policies; /**< Optional list of certificate policies (Only anyPolicy is printed and enforced, however the rest of the policies are still listed). */ | 
| Ron Eldor | 74d9acc | 2019-03-21 14:00:03 +0200 | [diff] [blame] | 81 |  | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 82 | int MBEDTLS_PRIVATE(ext_types);              /**< Bit string containing detected and parsed extensions */ | 
|  | 83 | int MBEDTLS_PRIVATE(ca_istrue);              /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */ | 
|  | 84 | int MBEDTLS_PRIVATE(max_pathlen);            /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. Path length is 1 higher than RFC 5280 'meaning', so 1+ */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 85 |  | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 86 | unsigned int MBEDTLS_PRIVATE(key_usage);     /**< Optional key usage extension value: See the values in x509.h */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 87 |  | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 88 | mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 89 |  | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 90 | unsigned char MBEDTLS_PRIVATE(ns_cert_type); /**< Optional Netscape certificate type extension value: See the values in x509.h */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 91 |  | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 92 | mbedtls_x509_buf MBEDTLS_PRIVATE(sig);               /**< Signature: hash of the tbs part signed with the private key. */ | 
|  | 93 | mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md);           /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */ | 
|  | 94 | mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk);           /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */ | 
|  | 95 | void *MBEDTLS_PRIVATE(sig_opts);             /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 96 |  | 
| Gilles Peskine | ca93995 | 2021-08-31 23:18:07 +0200 | [diff] [blame] | 97 | /** Next certificate in the linked list that constitutes the CA chain. | 
|  | 98 | * \p NULL indicates the end of the list. | 
|  | 99 | * Do not modify this field directly. */ | 
|  | 100 | struct mbedtls_x509_crt *next; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 101 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 102 | mbedtls_x509_crt; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 103 |  | 
| Janos Follath | 5091bec | 2019-05-08 15:23:08 +0100 | [diff] [blame] | 104 | /** | 
| Manuel Pégourié-Gonnard | f8ea856 | 2015-06-15 15:33:19 +0200 | [diff] [blame] | 105 | * Build flag from an algorithm/curve identifier (pk, md, ecp) | 
|  | 106 | * Since 0 is always XXX_NONE, ignore it. | 
|  | 107 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 108 | #define MBEDTLS_X509_ID_FLAG(id)   (1 << ((id) - 1)) | 
| Manuel Pégourié-Gonnard | f8ea856 | 2015-06-15 15:33:19 +0200 | [diff] [blame] | 109 |  | 
|  | 110 | /** | 
| Manuel Pégourié-Gonnard | 88db5da | 2015-06-15 14:34:59 +0200 | [diff] [blame] | 111 | * Security profile for certificate verification. | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 112 | * | 
| Manuel Pégourié-Gonnard | f8ea856 | 2015-06-15 15:33:19 +0200 | [diff] [blame] | 113 | * All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG(). | 
| Manuel Pégourié-Gonnard | 55a7fb8 | 2021-06-17 10:39:39 +0200 | [diff] [blame] | 114 | * | 
|  | 115 | * The fields of this structure are part of the public API and can be | 
|  | 116 | * manipulated directly by applications. Future versions of the library may | 
|  | 117 | * add extra fields or reorder existing fields. | 
| Manuel Pégourié-Gonnard | 9d4c2c4 | 2021-06-18 09:48:27 +0200 | [diff] [blame] | 118 | * | 
|  | 119 | * You can create custom profiles by starting from a copy of | 
|  | 120 | * an existing profile, such as mbedtls_x509_crt_profile_default or | 
|  | 121 | * mbedtls_x509_ctr_profile_none and then tune it to your needs. | 
|  | 122 | * | 
|  | 123 | * For example to allow SHA-224 in addition to the default: | 
|  | 124 | * | 
|  | 125 | *  mbedtls_x509_crt_profile my_profile = mbedtls_x509_crt_profile_default; | 
|  | 126 | *  my_profile.allowed_mds |= MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ); | 
|  | 127 | * | 
|  | 128 | * Or to allow only RSA-3072+ with SHA-256: | 
|  | 129 | * | 
|  | 130 | *  mbedtls_x509_crt_profile my_profile = mbedtls_x509_crt_profile_none; | 
|  | 131 | *  my_profile.allowed_mds = MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA256 ); | 
|  | 132 | *  my_profile.allowed_pks = MBEDTLS_X509_ID_FLAG( MBEDTLS_PK_RSA ); | 
|  | 133 | *  my_profile.rsa_min_bitlen = 3072; | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 134 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 135 | typedef struct mbedtls_x509_crt_profile { | 
| Manuel Pégourié-Gonnard | 5314e08 | 2021-06-17 10:32:01 +0200 | [diff] [blame] | 136 | uint32_t allowed_mds;       /**< MDs for signatures         */ | 
| Hanno Becker | 2b9fb88 | 2018-10-11 11:36:29 +0100 | [diff] [blame] | 137 | uint32_t allowed_pks;       /**< PK algs for public keys; | 
| Manuel Pégourié-Gonnard | 8ba99e7 | 2022-04-25 10:12:01 +0200 | [diff] [blame] | 138 | *   this applies to all certificates | 
| Hanno Becker | 2b9fb88 | 2018-10-11 11:36:29 +0100 | [diff] [blame] | 139 | *   in the provided chain.     */ | 
| Manuel Pégourié-Gonnard | 5314e08 | 2021-06-17 10:32:01 +0200 | [diff] [blame] | 140 | uint32_t allowed_curves;    /**< Elliptic curves for ECDSA  */ | 
|  | 141 | uint32_t rsa_min_bitlen;    /**< Minimum size for RSA keys  */ | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 142 | } | 
|  | 143 | mbedtls_x509_crt_profile; | 
|  | 144 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 145 | #define MBEDTLS_X509_CRT_VERSION_1              0 | 
|  | 146 | #define MBEDTLS_X509_CRT_VERSION_2              1 | 
|  | 147 | #define MBEDTLS_X509_CRT_VERSION_3              2 | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 148 |  | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 149 | #define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 20 | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 150 | #define MBEDTLS_X509_RFC5280_UTC_TIME_LEN   15 | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 151 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 152 | #if !defined(MBEDTLS_X509_MAX_FILE_PATH_LEN) | 
| Andres AG | f911319 | 2016-09-02 14:06:04 +0100 | [diff] [blame] | 153 | #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 | 
|  | 154 | #endif | 
|  | 155 |  | 
| Hanno Becker | 7ac83f9 | 2020-10-09 10:48:22 +0100 | [diff] [blame] | 156 | /* This macro unfolds to the concatenation of macro invocations | 
|  | 157 | * X509_CRT_ERROR_INFO( error code, | 
|  | 158 | *                             error code as string, | 
|  | 159 | *                             human readable description ) | 
|  | 160 | * where X509_CRT_ERROR_INFO is defined by the user. | 
|  | 161 | * See x509_crt.c for an example of how to use this. */ | 
|  | 162 | #define MBEDTLS_X509_CRT_ERROR_INFO_LIST                                  \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 163 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXPIRED,            \ | 
|  | 164 | "MBEDTLS_X509_BADCERT_EXPIRED",          \ | 
|  | 165 | "The certificate validity has expired") \ | 
|  | 166 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_REVOKED,            \ | 
|  | 167 | "MBEDTLS_X509_BADCERT_REVOKED",          \ | 
|  | 168 | "The certificate has been revoked (is on a CRL)") \ | 
|  | 169 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_CN_MISMATCH,                  \ | 
|  | 170 | "MBEDTLS_X509_BADCERT_CN_MISMATCH",                \ | 
|  | 171 | "The certificate Common Name (CN) does not match with the expected CN") \ | 
|  | 172 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NOT_TRUSTED,                             \ | 
|  | 173 | "MBEDTLS_X509_BADCERT_NOT_TRUSTED",                           \ | 
|  | 174 | "The certificate is not correctly signed by the trusted CA") \ | 
|  | 175 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_NOT_TRUSTED,                      \ | 
|  | 176 | "MBEDTLS_X509_BADCRL_NOT_TRUSTED",                    \ | 
|  | 177 | "The CRL is not correctly signed by the trusted CA") \ | 
|  | 178 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_EXPIRED,    \ | 
|  | 179 | "MBEDTLS_X509_BADCRL_EXPIRED",  \ | 
|  | 180 | "The CRL is expired")          \ | 
|  | 181 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_MISSING,   \ | 
|  | 182 | "MBEDTLS_X509_BADCERT_MISSING", \ | 
|  | 183 | "Certificate was missing")     \ | 
|  | 184 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_SKIP_VERIFY,         \ | 
|  | 185 | "MBEDTLS_X509_BADCERT_SKIP_VERIFY",       \ | 
|  | 186 | "Certificate verification was skipped")  \ | 
|  | 187 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_OTHER,                          \ | 
|  | 188 | "MBEDTLS_X509_BADCERT_OTHER",                        \ | 
|  | 189 | "Other reason (can be used by verify callback)")    \ | 
|  | 190 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_FUTURE,                         \ | 
|  | 191 | "MBEDTLS_X509_BADCERT_FUTURE",                       \ | 
|  | 192 | "The certificate validity starts in the future")    \ | 
|  | 193 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_FUTURE,     \ | 
|  | 194 | "MBEDTLS_X509_BADCRL_FUTURE",   \ | 
|  | 195 | "The CRL is from the future")  \ | 
|  | 196 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_KEY_USAGE,                      \ | 
|  | 197 | "MBEDTLS_X509_BADCERT_KEY_USAGE",                    \ | 
|  | 198 | "Usage does not match the keyUsage extension")      \ | 
|  | 199 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_EXT_KEY_USAGE,                       \ | 
|  | 200 | "MBEDTLS_X509_BADCERT_EXT_KEY_USAGE",                     \ | 
|  | 201 | "Usage does not match the extendedKeyUsage extension")   \ | 
|  | 202 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_NS_CERT_TYPE,                        \ | 
|  | 203 | "MBEDTLS_X509_BADCERT_NS_CERT_TYPE",                      \ | 
|  | 204 | "Usage does not match the nsCertType extension")         \ | 
|  | 205 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_MD,                              \ | 
|  | 206 | "MBEDTLS_X509_BADCERT_BAD_MD",                            \ | 
|  | 207 | "The certificate is signed with an unacceptable hash.")  \ | 
|  | 208 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_PK,                                                  \ | 
|  | 209 | "MBEDTLS_X509_BADCERT_BAD_PK",                                                \ | 
|  | 210 | "The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA).")  \ | 
|  | 211 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCERT_BAD_KEY,                                                            \ | 
|  | 212 | "MBEDTLS_X509_BADCERT_BAD_KEY",                                                          \ | 
|  | 213 | "The certificate is signed with an unacceptable key (eg bad curve, RSA too short).")    \ | 
|  | 214 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_MD,                          \ | 
|  | 215 | "MBEDTLS_X509_BADCRL_BAD_MD",                        \ | 
|  | 216 | "The CRL is signed with an unacceptable hash.")     \ | 
|  | 217 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_PK,                                            \ | 
|  | 218 | "MBEDTLS_X509_BADCRL_BAD_PK",                                          \ | 
|  | 219 | "The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA).")   \ | 
|  | 220 | X509_CRT_ERROR_INFO(MBEDTLS_X509_BADCRL_BAD_KEY,                                                    \ | 
|  | 221 | "MBEDTLS_X509_BADCRL_BAD_KEY",                                                  \ | 
|  | 222 | "The CRL is signed with an unacceptable key (eg bad curve, RSA too short).") | 
| Hanno Becker | 7ac83f9 | 2020-10-09 10:48:22 +0100 | [diff] [blame] | 223 |  | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 224 | /** | 
|  | 225 | * Container for writing a certificate (CRT) | 
|  | 226 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 227 | typedef struct mbedtls_x509write_cert { | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 228 | int MBEDTLS_PRIVATE(version); | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 229 | unsigned char MBEDTLS_PRIVATE(serial)[MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN]; | 
|  | 230 | size_t MBEDTLS_PRIVATE(serial_len); | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 231 | mbedtls_pk_context *MBEDTLS_PRIVATE(subject_key); | 
|  | 232 | mbedtls_pk_context *MBEDTLS_PRIVATE(issuer_key); | 
|  | 233 | mbedtls_asn1_named_data *MBEDTLS_PRIVATE(subject); | 
|  | 234 | mbedtls_asn1_named_data *MBEDTLS_PRIVATE(issuer); | 
|  | 235 | mbedtls_md_type_t MBEDTLS_PRIVATE(md_alg); | 
|  | 236 | char MBEDTLS_PRIVATE(not_before)[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1]; | 
|  | 237 | char MBEDTLS_PRIVATE(not_after)[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1]; | 
|  | 238 | mbedtls_asn1_named_data *MBEDTLS_PRIVATE(extensions); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 239 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 240 | mbedtls_x509write_cert; | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 241 |  | 
| Manuel Pégourié-Gonnard | c11e4ba | 2017-08-14 17:17:14 +0200 | [diff] [blame] | 242 | /** | 
|  | 243 | * Item in a verification chain: cert and flags for it | 
|  | 244 | */ | 
|  | 245 | typedef struct { | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 246 | mbedtls_x509_crt *MBEDTLS_PRIVATE(crt); | 
|  | 247 | uint32_t MBEDTLS_PRIVATE(flags); | 
| Manuel Pégourié-Gonnard | c11e4ba | 2017-08-14 17:17:14 +0200 | [diff] [blame] | 248 | } mbedtls_x509_crt_verify_chain_item; | 
|  | 249 |  | 
|  | 250 | /** | 
|  | 251 | * Max size of verification chain: end-entity + intermediates + trusted root | 
|  | 252 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 253 | #define MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE  (MBEDTLS_X509_MAX_INTERMEDIATE_CA + 2) | 
| Manuel Pégourié-Gonnard | c11e4ba | 2017-08-14 17:17:14 +0200 | [diff] [blame] | 254 |  | 
|  | 255 | /** | 
|  | 256 | * Verification chain as built by \c mbedtls_crt_verify_chain() | 
|  | 257 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 258 | typedef struct { | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 259 | mbedtls_x509_crt_verify_chain_item MBEDTLS_PRIVATE(items)[MBEDTLS_X509_MAX_VERIFY_CHAIN_SIZE]; | 
|  | 260 | unsigned MBEDTLS_PRIVATE(len); | 
| Hanno Becker | f53893b | 2019-03-28 13:45:55 +0000 | [diff] [blame] | 261 |  | 
|  | 262 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) | 
|  | 263 | /* This stores the list of potential trusted signers obtained from | 
|  | 264 | * the CA callback used for the CRT verification, if configured. | 
|  | 265 | * We must track it somewhere because the callback passes its | 
|  | 266 | * ownership to the caller. */ | 
| Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 267 | mbedtls_x509_crt *MBEDTLS_PRIVATE(trust_ca_cb_result); | 
| Hanno Becker | f53893b | 2019-03-28 13:45:55 +0000 | [diff] [blame] | 268 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ | 
| Manuel Pégourié-Gonnard | c11e4ba | 2017-08-14 17:17:14 +0200 | [diff] [blame] | 269 | } mbedtls_x509_crt_verify_chain; | 
|  | 270 |  | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 271 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) | 
|  | 272 |  | 
|  | 273 | /** | 
|  | 274 | * \brief       Context for resuming X.509 verify operations | 
|  | 275 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 276 | typedef struct { | 
| Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 277 | /* for check_signature() */ | 
| Mateusz Starzyk | 363eb29 | 2021-05-19 17:32:44 +0200 | [diff] [blame] | 278 | mbedtls_pk_restart_ctx MBEDTLS_PRIVATE(pk); | 
| Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 279 |  | 
|  | 280 | /* for find_parent_in() */ | 
| Mateusz Starzyk | 363eb29 | 2021-05-19 17:32:44 +0200 | [diff] [blame] | 281 | mbedtls_x509_crt *MBEDTLS_PRIVATE(parent); /* non-null iff parent_in in progress */ | 
|  | 282 | mbedtls_x509_crt *MBEDTLS_PRIVATE(fallback_parent); | 
|  | 283 | int MBEDTLS_PRIVATE(fallback_signature_is_good); | 
| Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 284 |  | 
|  | 285 | /* for find_parent() */ | 
| Mateusz Starzyk | 363eb29 | 2021-05-19 17:32:44 +0200 | [diff] [blame] | 286 | int MBEDTLS_PRIVATE(parent_is_trusted); /* -1 if find_parent is not in progress */ | 
| Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 287 |  | 
|  | 288 | /* for verify_chain() */ | 
| Manuel Pégourié-Gonnard | daf0491 | 2017-08-23 12:32:19 +0200 | [diff] [blame] | 289 | enum { | 
|  | 290 | x509_crt_rs_none, | 
|  | 291 | x509_crt_rs_find_parent, | 
| Mateusz Starzyk | 363eb29 | 2021-05-19 17:32:44 +0200 | [diff] [blame] | 292 | } MBEDTLS_PRIVATE(in_progress);  /* none if no operation is in progress */ | 
|  | 293 | int MBEDTLS_PRIVATE(self_cnt); | 
|  | 294 | mbedtls_x509_crt_verify_chain MBEDTLS_PRIVATE(ver_chain); | 
| Manuel Pégourié-Gonnard | 8b59049 | 2017-08-14 18:04:19 +0200 | [diff] [blame] | 295 |  | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 296 | } mbedtls_x509_crt_restart_ctx; | 
|  | 297 |  | 
|  | 298 | #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ | 
|  | 299 |  | 
|  | 300 | /* Now we can declare functions that take a pointer to that */ | 
|  | 301 | typedef void mbedtls_x509_crt_restart_ctx; | 
|  | 302 |  | 
|  | 303 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ | 
|  | 304 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 305 | #if defined(MBEDTLS_X509_CRT_PARSE_C) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 306 | /** | 
| Manuel Pégourié-Gonnard | 88db5da | 2015-06-15 14:34:59 +0200 | [diff] [blame] | 307 | * Default security profile. Should provide a good balance between security | 
|  | 308 | * and compatibility with current deployments. | 
| Gilles Peskine | ffb92da | 2021-06-02 00:03:26 +0200 | [diff] [blame] | 309 | * | 
|  | 310 | * This profile permits: | 
|  | 311 | * - SHA2 hashes with at least 256 bits: SHA-256, SHA-384, SHA-512. | 
| Gilles Peskine | 3995750 | 2021-06-17 23:17:52 +0200 | [diff] [blame] | 312 | * - Elliptic curves with 255 bits and above except secp256k1. | 
| Gilles Peskine | ffb92da | 2021-06-02 00:03:26 +0200 | [diff] [blame] | 313 | * - RSA with 2048 bits and above. | 
|  | 314 | * | 
|  | 315 | * New minor versions of Mbed TLS may extend this profile, for example if | 
| Gilles Peskine | 3995750 | 2021-06-17 23:17:52 +0200 | [diff] [blame] | 316 | * new algorithms are added to the library. New minor versions of Mbed TLS will | 
| Gilles Peskine | ffb92da | 2021-06-02 00:03:26 +0200 | [diff] [blame] | 317 | * not reduce this profile unless serious security concerns require it. | 
| Manuel Pégourié-Gonnard | 88db5da | 2015-06-15 14:34:59 +0200 | [diff] [blame] | 318 | */ | 
|  | 319 | extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default; | 
|  | 320 |  | 
|  | 321 | /** | 
|  | 322 | * Expected next default profile. Recommended for new deployments. | 
| Gilles Peskine | ffb92da | 2021-06-02 00:03:26 +0200 | [diff] [blame] | 323 | * Currently targets a 128-bit security level, except for allowing RSA-2048. | 
|  | 324 | * This profile may change at any time. | 
| Manuel Pégourié-Gonnard | 88db5da | 2015-06-15 14:34:59 +0200 | [diff] [blame] | 325 | */ | 
|  | 326 | extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next; | 
|  | 327 |  | 
|  | 328 | /** | 
|  | 329 | * NSA Suite B profile. | 
|  | 330 | */ | 
|  | 331 | extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb; | 
|  | 332 |  | 
|  | 333 | /** | 
| Manuel Pégourié-Gonnard | 9d4c2c4 | 2021-06-18 09:48:27 +0200 | [diff] [blame] | 334 | * Empty profile that allows nothing. Useful as a basis for constructing | 
|  | 335 | * custom profiles. | 
|  | 336 | */ | 
|  | 337 | extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_none; | 
|  | 338 |  | 
|  | 339 | /** | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 340 | * \brief          Parse a single DER formatted certificate and add it | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 341 | *                 to the end of the provided chained list. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 342 | * | 
| Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 343 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 344 | *                 subsystem must have been initialized by calling | 
|  | 345 | *                 psa_crypto_init() before calling this function. | 
|  | 346 | * | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 347 | * \param chain    The pointer to the start of the CRT chain to attach to. | 
|  | 348 | *                 When parsing the first CRT in a chain, this should point | 
|  | 349 | *                 to an instance of ::mbedtls_x509_crt initialized through | 
|  | 350 | *                 mbedtls_x509_crt_init(). | 
|  | 351 | * \param buf      The buffer holding the DER encoded certificate. | 
|  | 352 | * \param buflen   The size in Bytes of \p buf. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 353 | * | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 354 | * \note           This function makes an internal copy of the CRT buffer | 
|  | 355 | *                 \p buf. In particular, \p buf may be destroyed or reused | 
|  | 356 | *                 after this call returns. To avoid duplicating the CRT | 
|  | 357 | *                 buffer (at the cost of stricter lifetime constraints), | 
|  | 358 | *                 use mbedtls_x509_crt_parse_der_nocopy() instead. | 
|  | 359 | * | 
|  | 360 | * \return         \c 0 if successful. | 
|  | 361 | * \return         A negative error code on failure. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 362 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 363 | int mbedtls_x509_crt_parse_der(mbedtls_x509_crt *chain, | 
|  | 364 | const unsigned char *buf, | 
|  | 365 | size_t buflen); | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 366 |  | 
|  | 367 | /** | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 368 | * \brief          The type of certificate extension callbacks. | 
|  | 369 | * | 
|  | 370 | *                 Callbacks of this type are passed to and used by the | 
| Nicola Di Lieto | fde98f7 | 2020-05-28 08:34:33 +0200 | [diff] [blame] | 371 | *                 mbedtls_x509_crt_parse_der_with_ext_cb() routine when | 
| Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 372 | *                 it encounters either an unsupported extension or a | 
|  | 373 | *                 "certificate policies" extension containing any | 
|  | 374 | *                 unsupported certificate policies. | 
| Nicola Di Lieto | 511bc8c | 2020-06-23 00:15:28 +0200 | [diff] [blame] | 375 | *                 Future versions of the library may invoke the callback | 
|  | 376 | *                 in other cases, if and when the need arises. | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 377 | * | 
| Nicola Di Lieto | 5659e7e | 2020-05-28 23:41:38 +0200 | [diff] [blame] | 378 | * \param p_ctx    An opaque context passed to the callback. | 
| ndilieto | 6e24980 | 2020-05-28 06:17:38 +0000 | [diff] [blame] | 379 | * \param crt      The certificate being parsed. | 
|  | 380 | * \param oid      The OID of the extension. | 
|  | 381 | * \param critical Whether the extension is critical. | 
| Nicola Di Lieto | fae25a1 | 2020-05-28 08:55:08 +0200 | [diff] [blame] | 382 | * \param p        Pointer to the start of the extension value | 
| ndilieto | 6e24980 | 2020-05-28 06:17:38 +0000 | [diff] [blame] | 383 | *                 (the content of the OCTET STRING). | 
| ndilieto | 6e24980 | 2020-05-28 06:17:38 +0000 | [diff] [blame] | 384 | * \param end      End of extension value. | 
| Nicola Di Lieto | 565b52b | 2020-05-29 22:46:56 +0200 | [diff] [blame] | 385 | * | 
|  | 386 | * \note           The callback must fail and return a negative error code | 
|  | 387 | *                 if it can not parse or does not support the extension. | 
|  | 388 | *                 When the callback fails to parse a critical extension | 
|  | 389 | *                 mbedtls_x509_crt_parse_der_with_ext_cb() also fails. | 
|  | 390 | *                 When the callback fails to parse a non critical extension | 
|  | 391 | *                 mbedtls_x509_crt_parse_der_with_ext_cb() simply skips | 
|  | 392 | *                 the extension and continues parsing. | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 393 | * | 
|  | 394 | * \return         \c 0 on success. | 
|  | 395 | * \return         A negative error code on failure. | 
|  | 396 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 397 | typedef int (*mbedtls_x509_crt_ext_cb_t)(void *p_ctx, | 
|  | 398 | mbedtls_x509_crt const *crt, | 
|  | 399 | mbedtls_x509_buf const *oid, | 
|  | 400 | int critical, | 
|  | 401 | const unsigned char *p, | 
|  | 402 | const unsigned char *end); | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 403 |  | 
|  | 404 | /** | 
| Nicola Di Lieto | 4dbe567 | 2020-05-28 09:18:42 +0200 | [diff] [blame] | 405 | * \brief            Parse a single DER formatted certificate and add it | 
|  | 406 | *                   to the end of the provided chained list. | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 407 | * | 
| Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 408 | * \note             If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 409 | *                   subsystem must have been initialized by calling | 
|  | 410 | *                   psa_crypto_init() before calling this function. | 
|  | 411 | * | 
| Nicola Di Lieto | 4dbe567 | 2020-05-28 09:18:42 +0200 | [diff] [blame] | 412 | * \param chain      The pointer to the start of the CRT chain to attach to. | 
|  | 413 | *                   When parsing the first CRT in a chain, this should point | 
|  | 414 | *                   to an instance of ::mbedtls_x509_crt initialized through | 
|  | 415 | *                   mbedtls_x509_crt_init(). | 
|  | 416 | * \param buf        The buffer holding the DER encoded certificate. | 
|  | 417 | * \param buflen     The size in Bytes of \p buf. | 
|  | 418 | * \param make_copy  When not zero this function makes an internal copy of the | 
|  | 419 | *                   CRT buffer \p buf. In particular, \p buf may be destroyed | 
|  | 420 | *                   or reused after this call returns. | 
|  | 421 | *                   When zero this function avoids duplicating the CRT buffer | 
|  | 422 | *                   by taking temporary ownership thereof until the CRT | 
|  | 423 | *                   is destroyed (like mbedtls_x509_crt_parse_der_nocopy()) | 
|  | 424 | * \param cb         A callback invoked for every unsupported certificate | 
|  | 425 | *                   extension. | 
| Nicola Di Lieto | 5659e7e | 2020-05-28 23:41:38 +0200 | [diff] [blame] | 426 | * \param p_ctx      An opaque context passed to the callback. | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 427 | * | 
| Nicola Di Lieto | 4dbe567 | 2020-05-28 09:18:42 +0200 | [diff] [blame] | 428 | * \note             This call is functionally equivalent to | 
|  | 429 | *                   mbedtls_x509_crt_parse_der(), and/or | 
|  | 430 | *                   mbedtls_x509_crt_parse_der_nocopy() | 
|  | 431 | *                   but it calls the callback with every unsupported | 
| Nicola Di Lieto | c84b1e6 | 2020-06-13 11:08:16 +0200 | [diff] [blame] | 432 | *                   certificate extension and additionally the | 
|  | 433 | *                   "certificate policies" extension if it contains any | 
|  | 434 | *                   unsupported certificate policies. | 
| Nicola Di Lieto | 4dbe567 | 2020-05-28 09:18:42 +0200 | [diff] [blame] | 435 | *                   The callback must return a negative error code if it | 
|  | 436 | *                   does not know how to handle such an extension. | 
| Nicola Di Lieto | 565b52b | 2020-05-29 22:46:56 +0200 | [diff] [blame] | 437 | *                   When the callback fails to parse a critical extension | 
|  | 438 | *                   mbedtls_x509_crt_parse_der_with_ext_cb() also fails. | 
|  | 439 | *                   When the callback fails to parse a non critical extension | 
|  | 440 | *                   mbedtls_x509_crt_parse_der_with_ext_cb() simply skips | 
|  | 441 | *                   the extension and continues parsing. | 
| Nicola Di Lieto | 511bc8c | 2020-06-23 00:15:28 +0200 | [diff] [blame] | 442 | *                   Future versions of the library may invoke the callback | 
|  | 443 | *                   in other cases, if and when the need arises. | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 444 | * | 
| Nicola Di Lieto | 4dbe567 | 2020-05-28 09:18:42 +0200 | [diff] [blame] | 445 | * \return           \c 0 if successful. | 
|  | 446 | * \return           A negative error code on failure. | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 447 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 448 | int mbedtls_x509_crt_parse_der_with_ext_cb(mbedtls_x509_crt *chain, | 
|  | 449 | const unsigned char *buf, | 
|  | 450 | size_t buflen, | 
|  | 451 | int make_copy, | 
|  | 452 | mbedtls_x509_crt_ext_cb_t cb, | 
|  | 453 | void *p_ctx); | 
| Nicola Di Lieto | 502d4b4 | 2020-04-25 14:41:25 +0200 | [diff] [blame] | 454 |  | 
|  | 455 | /** | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 456 | * \brief          Parse a single DER formatted certificate and add it | 
|  | 457 | *                 to the end of the provided chained list. This is a | 
|  | 458 | *                 variant of mbedtls_x509_crt_parse_der() which takes | 
|  | 459 | *                 temporary ownership of the CRT buffer until the CRT | 
|  | 460 | *                 is destroyed. | 
|  | 461 | * | 
| Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 462 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 463 | *                 subsystem must have been initialized by calling | 
|  | 464 | *                 psa_crypto_init() before calling this function. | 
|  | 465 | * | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 466 | * \param chain    The pointer to the start of the CRT chain to attach to. | 
|  | 467 | *                 When parsing the first CRT in a chain, this should point | 
|  | 468 | *                 to an instance of ::mbedtls_x509_crt initialized through | 
|  | 469 | *                 mbedtls_x509_crt_init(). | 
|  | 470 | * \param buf      The address of the readable buffer holding the DER encoded | 
|  | 471 | *                 certificate to use. On success, this buffer must be | 
| Jan Bruckner | b33f6e5 | 2022-10-06 11:23:49 +0200 | [diff] [blame] | 472 | *                 retained and not be changed for the lifetime of the | 
| Hanno Becker | 1a65dcd | 2019-01-31 08:57:44 +0000 | [diff] [blame] | 473 | *                 CRT chain \p chain, that is, until \p chain is destroyed | 
|  | 474 | *                 through a call to mbedtls_x509_crt_free(). | 
|  | 475 | * \param buflen   The size in Bytes of \p buf. | 
|  | 476 | * | 
|  | 477 | * \note           This call is functionally equivalent to | 
|  | 478 | *                 mbedtls_x509_crt_parse_der(), but it avoids creating a | 
|  | 479 | *                 copy of the input buffer at the cost of stronger lifetime | 
|  | 480 | *                 constraints. This is useful in constrained environments | 
|  | 481 | *                 where duplication of the CRT cannot be tolerated. | 
|  | 482 | * | 
|  | 483 | * \return         \c 0 if successful. | 
|  | 484 | * \return         A negative error code on failure. | 
|  | 485 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 486 | int mbedtls_x509_crt_parse_der_nocopy(mbedtls_x509_crt *chain, | 
|  | 487 | const unsigned char *buf, | 
|  | 488 | size_t buflen); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 489 |  | 
|  | 490 | /** | 
| Hanno Becker | 89a9112 | 2018-08-23 16:14:00 +0100 | [diff] [blame] | 491 | * \brief          Parse one DER-encoded or one or more concatenated PEM-encoded | 
| Hanno Becker | 65e619a | 2018-08-23 15:46:33 +0100 | [diff] [blame] | 492 | *                 certificates and add them to the chained list. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 493 | * | 
| Hanno Becker | e8658e2 | 2018-08-24 10:01:17 +0100 | [diff] [blame] | 494 | *                 For CRTs in PEM encoding, the function parses permissively: | 
|  | 495 | *                 if at least one certificate can be parsed, the function | 
| Hanno Becker | 65e619a | 2018-08-23 15:46:33 +0100 | [diff] [blame] | 496 | *                 returns the number of certificates for which parsing failed | 
|  | 497 | *                 (hence \c 0 if all certificates were parsed successfully). | 
|  | 498 | *                 If no certificate could be parsed, the function returns | 
|  | 499 | *                 the first (negative) error encountered during parsing. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 500 | * | 
| Hanno Becker | 65e619a | 2018-08-23 15:46:33 +0100 | [diff] [blame] | 501 | *                 PEM encoded certificates may be interleaved by other data | 
|  | 502 | *                 such as human readable descriptions of their content, as | 
|  | 503 | *                 long as the certificates are enclosed in the PEM specific | 
|  | 504 | *                 '-----{BEGIN/END} CERTIFICATE-----' delimiters. | 
|  | 505 | * | 
| Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 506 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 507 | *                 subsystem must have been initialized by calling | 
|  | 508 | *                 psa_crypto_init() before calling this function. | 
|  | 509 | * | 
| Hanno Becker | 65e619a | 2018-08-23 15:46:33 +0100 | [diff] [blame] | 510 | * \param chain    The chain to which to add the parsed certificates. | 
|  | 511 | * \param buf      The buffer holding the certificate data in PEM or DER format. | 
|  | 512 | *                 For certificates in PEM encoding, this may be a concatenation | 
|  | 513 | *                 of multiple certificates; for DER encoding, the buffer must | 
|  | 514 | *                 comprise exactly one certificate. | 
|  | 515 | * \param buflen   The size of \p buf, including the terminating \c NULL byte | 
|  | 516 | *                 in case of PEM encoded data. | 
|  | 517 | * | 
|  | 518 | * \return         \c 0 if all certificates were parsed successfully. | 
|  | 519 | * \return         The (positive) number of certificates that couldn't | 
|  | 520 | *                 be parsed if parsing was partly successful (see above). | 
| Hanno Becker | 89a9112 | 2018-08-23 16:14:00 +0100 | [diff] [blame] | 521 | * \return         A negative X509 or PEM error code otherwise. | 
| Hanno Becker | 65e619a | 2018-08-23 15:46:33 +0100 | [diff] [blame] | 522 | * | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 523 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 524 | int mbedtls_x509_crt_parse(mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 525 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 526 | #if defined(MBEDTLS_FS_IO) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 527 | /** | 
|  | 528 | * \brief          Load one or more certificates and add them | 
|  | 529 | *                 to the chained list. Parses permissively. If some | 
|  | 530 | *                 certificates can be parsed, the result is the number | 
|  | 531 | *                 of failed certificates it encountered. If none complete | 
|  | 532 | *                 correctly, the first error is returned. | 
|  | 533 | * | 
| Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 534 | * \note           If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto | 
|  | 535 | *                 subsystem must have been initialized by calling | 
|  | 536 | *                 psa_crypto_init() before calling this function. | 
|  | 537 | * | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 538 | * \param chain    points to the start of the chain | 
|  | 539 | * \param path     filename to read the certificates from | 
|  | 540 | * | 
|  | 541 | * \return         0 if all certificates parsed successfully, a positive number | 
|  | 542 | *                 if partly successful or a specific X509 or PEM error code | 
|  | 543 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 544 | int mbedtls_x509_crt_parse_file(mbedtls_x509_crt *chain, const char *path); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 545 |  | 
|  | 546 | /** | 
|  | 547 | * \brief          Load one or more certificate files from a path and add them | 
|  | 548 | *                 to the chained list. Parses permissively. If some | 
|  | 549 | *                 certificates can be parsed, the result is the number | 
|  | 550 | *                 of failed certificates it encountered. If none complete | 
|  | 551 | *                 correctly, the first error is returned. | 
|  | 552 | * | 
|  | 553 | * \param chain    points to the start of the chain | 
|  | 554 | * \param path     directory / folder to read the certificate files from | 
|  | 555 | * | 
|  | 556 | * \return         0 if all certificates parsed successfully, a positive number | 
|  | 557 | *                 if partly successful or a specific X509 or PEM error code | 
|  | 558 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 559 | int mbedtls_x509_crt_parse_path(mbedtls_x509_crt *chain, const char *path); | 
| Janos Follath | 11b41eb | 2019-05-08 15:26:49 +0100 | [diff] [blame] | 560 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 561 | #endif /* MBEDTLS_FS_IO */ | 
| Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 562 | #if !defined(MBEDTLS_X509_REMOVE_INFO) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 563 | /** | 
|  | 564 | * \brief          Returns an informational string about the | 
|  | 565 | *                 certificate. | 
|  | 566 | * | 
|  | 567 | * \param buf      Buffer to write to | 
|  | 568 | * \param size     Maximum size of buffer | 
|  | 569 | * \param prefix   A line prefix | 
|  | 570 | * \param crt      The X509 certificate to represent | 
|  | 571 | * | 
| Manuel Pégourié-Gonnard | e244f9f | 2015-06-23 12:10:45 +0200 | [diff] [blame] | 572 | * \return         The length of the string written (not including the | 
|  | 573 | *                 terminated nul byte), or a negative error code. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 574 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 575 | int mbedtls_x509_crt_info(char *buf, size_t size, const char *prefix, | 
|  | 576 | const mbedtls_x509_crt *crt); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 577 |  | 
|  | 578 | /** | 
| Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 579 | * \brief          Returns an informational string about the | 
|  | 580 | *                 verification status of a certificate. | 
|  | 581 | * | 
|  | 582 | * \param buf      Buffer to write to | 
|  | 583 | * \param size     Maximum size of buffer | 
|  | 584 | * \param prefix   A line prefix | 
|  | 585 | * \param flags    Verification flags created by mbedtls_x509_crt_verify() | 
|  | 586 | * | 
| Manuel Pégourié-Gonnard | e244f9f | 2015-06-23 12:10:45 +0200 | [diff] [blame] | 587 | * \return         The length of the string written (not including the | 
|  | 588 | *                 terminated nul byte), or a negative error code. | 
| Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 589 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 590 | int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix, | 
|  | 591 | uint32_t flags); | 
| Hanno Becker | 88c2bf3 | 2019-06-14 17:21:24 +0100 | [diff] [blame] | 592 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ | 
| Manuel Pégourié-Gonnard | 39a183a | 2015-04-17 16:14:32 +0200 | [diff] [blame] | 593 |  | 
|  | 594 | /** | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 595 | * \brief          Verify a chain of certificates. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 596 | * | 
|  | 597 | *                 The verify callback is a user-supplied callback that | 
|  | 598 | *                 can clear / modify / add flags for a certificate. If set, | 
|  | 599 | *                 the verification callback is called for each | 
|  | 600 | *                 certificate in the chain (from the trust-ca down to the | 
|  | 601 | *                 presented crt). The parameters for the callback are: | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 602 | *                 (void *parameter, mbedtls_x509_crt *crt, int certificate_depth, | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 603 | *                 int *flags). With the flags representing current flags for | 
|  | 604 | *                 that specific certificate and the certificate depth from | 
|  | 605 | *                 the bottom (Peer cert depth = 0). | 
|  | 606 | * | 
|  | 607 | *                 All flags left after returning from the callback | 
|  | 608 | *                 are also returned to the application. The function should | 
| Manuel Pégourié-Gonnard | 31458a1 | 2017-06-26 10:11:49 +0200 | [diff] [blame] | 609 | *                 return 0 for anything (including invalid certificates) | 
|  | 610 | *                 other than fatal error, as a non-zero return code | 
|  | 611 | *                 immediately aborts the verification process. For fatal | 
|  | 612 | *                 errors, a specific error code should be used (different | 
|  | 613 | *                 from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not | 
|  | 614 | *                 be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR | 
|  | 615 | *                 can be used if no better code is available. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 616 | * | 
| Manuel Pégourié-Gonnard | b5f48ad | 2015-04-20 10:38:13 +0100 | [diff] [blame] | 617 | * \note           In case verification failed, the results can be displayed | 
|  | 618 | *                 using \c mbedtls_x509_crt_verify_info() | 
|  | 619 | * | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 620 | * \note           Same as \c mbedtls_x509_crt_verify_with_profile() with the | 
|  | 621 | *                 default security profile. | 
|  | 622 | * | 
| Manuel Pégourié-Gonnard | eeef947 | 2016-02-22 11:36:55 +0100 | [diff] [blame] | 623 | * \note           It is your responsibility to provide up-to-date CRLs for | 
|  | 624 | *                 all trusted CAs. If no CRL is provided for the CA that was | 
|  | 625 | *                 used to sign the certificate, CRL verification is skipped | 
|  | 626 | *                 silently, that is *without* setting any flag. | 
|  | 627 | * | 
| Manuel Pégourié-Gonnard | 08eacec | 2017-10-18 14:20:24 +0200 | [diff] [blame] | 628 | * \note           The \c trust_ca list can contain two types of certificates: | 
| Manuel Pégourié-Gonnard | a4a206e | 2017-06-21 09:35:44 +0200 | [diff] [blame] | 629 | *                 (1) those of trusted root CAs, so that certificates | 
|  | 630 | *                 chaining up to those CAs will be trusted, and (2) | 
|  | 631 | *                 self-signed end-entity certificates to be trusted (for | 
|  | 632 | *                 specific peers you know) - in that case, the self-signed | 
| Manuel Pégourié-Gonnard | 562df40 | 2017-08-08 18:09:14 +0200 | [diff] [blame] | 633 | *                 certificate doesn't need to have the CA bit set. | 
| Manuel Pégourié-Gonnard | a4a206e | 2017-06-21 09:35:44 +0200 | [diff] [blame] | 634 | * | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 635 | * \param crt      The certificate chain to be verified. | 
|  | 636 | * \param trust_ca The list of trusted CAs. | 
|  | 637 | * \param ca_crl   The list of CRLs for trusted CAs. | 
| Manuel Pégourié-Gonnard | f58e5cc | 2020-07-24 10:31:37 +0200 | [diff] [blame] | 638 | * \param cn       The expected Common Name. This will be checked to be | 
|  | 639 | *                 present in the certificate's subjectAltNames extension or, | 
|  | 640 | *                 if this extension is absent, as a CN component in its | 
| Glenn Strauss | c26bd76 | 2022-10-23 19:48:18 -0400 | [diff] [blame] | 641 | *                 Subject name. DNS names and IP addresses are supported. This | 
| Manuel Pégourié-Gonnard | f58e5cc | 2020-07-24 10:31:37 +0200 | [diff] [blame] | 642 | *                 may be \c NULL if the CN need not be verified. | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 643 | * \param flags    The address at which to store the result of the verification. | 
| Janos Follath | 846ae7a | 2019-04-05 16:45:01 +0100 | [diff] [blame] | 644 | *                 If the verification couldn't be completed, the flag value is | 
|  | 645 | *                 set to (uint32_t) -1. | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 646 | * \param f_vrfy   The verification callback to use. See the documentation | 
|  | 647 | *                 of mbedtls_x509_crt_verify() for more information. | 
|  | 648 | * \param p_vrfy   The context to be passed to \p f_vrfy. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 649 | * | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 650 | * \return         \c 0 if the chain is valid with respect to the | 
|  | 651 | *                 passed CN, CAs, CRLs and security profile. | 
|  | 652 | * \return         #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the | 
|  | 653 | *                 certificate chain verification failed. In this case, | 
|  | 654 | *                 \c *flags will have one or more | 
|  | 655 | *                 \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX | 
|  | 656 | *                 flags set. | 
|  | 657 | * \return         Another negative error code in case of a fatal error | 
|  | 658 | *                 encountered during the verification process. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 659 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 660 | int mbedtls_x509_crt_verify(mbedtls_x509_crt *crt, | 
|  | 661 | mbedtls_x509_crt *trust_ca, | 
|  | 662 | mbedtls_x509_crl *ca_crl, | 
|  | 663 | const char *cn, uint32_t *flags, | 
|  | 664 | int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), | 
|  | 665 | void *p_vrfy); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 666 |  | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 667 | /** | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 668 | * \brief          Verify a chain of certificates with respect to | 
|  | 669 | *                 a configurable security profile. | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 670 | * | 
|  | 671 | * \note           Same as \c mbedtls_x509_crt_verify(), but with explicit | 
|  | 672 | *                 security profile. | 
|  | 673 | * | 
| Manuel Pégourié-Gonnard | 27716cc | 2015-06-17 11:49:39 +0200 | [diff] [blame] | 674 | * \note           The restrictions on keys (RSA minimum size, allowed curves | 
| Manuel Pégourié-Gonnard | 65eefc8 | 2015-10-23 14:08:48 +0200 | [diff] [blame] | 675 | *                 for ECDSA) apply to all certificates: trusted root, | 
|  | 676 | *                 intermediate CAs if any, and end entity certificate. | 
| Manuel Pégourié-Gonnard | 27716cc | 2015-06-17 11:49:39 +0200 | [diff] [blame] | 677 | * | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 678 | * \param crt      The certificate chain to be verified. | 
|  | 679 | * \param trust_ca The list of trusted CAs. | 
|  | 680 | * \param ca_crl   The list of CRLs for trusted CAs. | 
|  | 681 | * \param profile  The security profile to use for the verification. | 
|  | 682 | * \param cn       The expected Common Name. This may be \c NULL if the | 
|  | 683 | *                 CN need not be verified. | 
|  | 684 | * \param flags    The address at which to store the result of the verification. | 
| Janos Follath | 846ae7a | 2019-04-05 16:45:01 +0100 | [diff] [blame] | 685 | *                 If the verification couldn't be completed, the flag value is | 
|  | 686 | *                 set to (uint32_t) -1. | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 687 | * \param f_vrfy   The verification callback to use. See the documentation | 
|  | 688 | *                 of mbedtls_x509_crt_verify() for more information. | 
|  | 689 | * \param p_vrfy   The context to be passed to \p f_vrfy. | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 690 | * | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 691 | * \return         \c 0 if the chain is valid with respect to the | 
|  | 692 | *                 passed CN, CAs, CRLs and security profile. | 
|  | 693 | * \return         #MBEDTLS_ERR_X509_CERT_VERIFY_FAILED in case the | 
|  | 694 | *                 certificate chain verification failed. In this case, | 
|  | 695 | *                 \c *flags will have one or more | 
|  | 696 | *                 \c MBEDTLS_X509_BADCERT_XXX or \c MBEDTLS_X509_BADCRL_XXX | 
|  | 697 | *                 flags set. | 
|  | 698 | * \return         Another negative error code in case of a fatal error | 
|  | 699 | *                 encountered during the verification process. | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 700 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 701 | int mbedtls_x509_crt_verify_with_profile(mbedtls_x509_crt *crt, | 
|  | 702 | mbedtls_x509_crt *trust_ca, | 
|  | 703 | mbedtls_x509_crl *ca_crl, | 
|  | 704 | const mbedtls_x509_crt_profile *profile, | 
|  | 705 | const char *cn, uint32_t *flags, | 
|  | 706 | int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), | 
|  | 707 | void *p_vrfy); | 
| Manuel Pégourié-Gonnard | 9505164 | 2015-06-15 10:39:46 +0200 | [diff] [blame] | 708 |  | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 709 | /** | 
|  | 710 | * \brief          Restartable version of \c mbedtls_crt_verify_with_profile() | 
|  | 711 | * | 
|  | 712 | * \note           Performs the same job as \c mbedtls_crt_verify_with_profile() | 
|  | 713 | *                 but can return early and restart according to the limit | 
|  | 714 | *                 set with \c mbedtls_ecp_set_max_ops() to reduce blocking. | 
|  | 715 | * | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 716 | * \param crt      The certificate chain to be verified. | 
|  | 717 | * \param trust_ca The list of trusted CAs. | 
|  | 718 | * \param ca_crl   The list of CRLs for trusted CAs. | 
|  | 719 | * \param profile  The security profile to use for the verification. | 
|  | 720 | * \param cn       The expected Common Name. This may be \c NULL if the | 
|  | 721 | *                 CN need not be verified. | 
|  | 722 | * \param flags    The address at which to store the result of the verification. | 
| Janos Follath | 846ae7a | 2019-04-05 16:45:01 +0100 | [diff] [blame] | 723 | *                 If the verification couldn't be completed, the flag value is | 
|  | 724 | *                 set to (uint32_t) -1. | 
| Hanno Becker | 902451d | 2019-03-27 11:48:40 +0000 | [diff] [blame] | 725 | * \param f_vrfy   The verification callback to use. See the documentation | 
|  | 726 | *                 of mbedtls_x509_crt_verify() for more information. | 
|  | 727 | * \param p_vrfy   The context to be passed to \p f_vrfy. | 
|  | 728 | * \param rs_ctx   The restart context to use. This may be set to \c NULL | 
|  | 729 | *                 to disable restartable ECC. | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 730 | * | 
|  | 731 | * \return         See \c mbedtls_crt_verify_with_profile(), or | 
| Manuel Pégourié-Gonnard | 12e4a8b | 2018-09-12 10:55:15 +0200 | [diff] [blame] | 732 | * \return         #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 733 | *                 operations was reached: see \c mbedtls_ecp_set_max_ops(). | 
|  | 734 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 735 | int mbedtls_x509_crt_verify_restartable(mbedtls_x509_crt *crt, | 
|  | 736 | mbedtls_x509_crt *trust_ca, | 
|  | 737 | mbedtls_x509_crl *ca_crl, | 
|  | 738 | const mbedtls_x509_crt_profile *profile, | 
|  | 739 | const char *cn, uint32_t *flags, | 
|  | 740 | int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), | 
|  | 741 | void *p_vrfy, | 
|  | 742 | mbedtls_x509_crt_restart_ctx *rs_ctx); | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 743 |  | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 744 | /** | 
|  | 745 | * \brief               The type of trusted certificate callbacks. | 
|  | 746 | * | 
|  | 747 | *                      Callbacks of this type are passed to and used by the CRT | 
| Jarno Lamsa | 31d9db6 | 2019-04-01 14:33:49 +0300 | [diff] [blame] | 748 | *                      verification routine mbedtls_x509_crt_verify_with_ca_cb() | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 749 | *                      when looking for trusted signers of a given certificate. | 
|  | 750 | * | 
|  | 751 | *                      On success, the callback returns a list of trusted | 
|  | 752 | *                      certificates to be considered as potential signers | 
|  | 753 | *                      for the input certificate. | 
|  | 754 | * | 
|  | 755 | * \param p_ctx         An opaque context passed to the callback. | 
|  | 756 | * \param child         The certificate for which to search a potential signer. | 
| Jarno Lamsa | f49fedc | 2019-04-01 14:58:30 +0300 | [diff] [blame] | 757 | *                      This will point to a readable certificate. | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 758 | * \param candidate_cas The address at which to store the address of the first | 
|  | 759 | *                      entry in the generated linked list of candidate signers. | 
| Jarno Lamsa | f49fedc | 2019-04-01 14:58:30 +0300 | [diff] [blame] | 760 | *                      This will not be \c NULL. | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 761 | * | 
|  | 762 | * \note                The callback must only return a non-zero value on a | 
|  | 763 | *                      fatal error. If, in contrast, the search for a potential | 
|  | 764 | *                      signer completes without a single candidate, the | 
| Jarno Lamsa | f49fedc | 2019-04-01 14:58:30 +0300 | [diff] [blame] | 765 | *                      callback must return \c 0 and set \c *candidate_cas | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 766 | *                      to \c NULL. | 
|  | 767 | * | 
|  | 768 | * \return              \c 0 on success. In this case, \c *candidate_cas points | 
|  | 769 | *                      to a heap-allocated linked list of instances of | 
|  | 770 | *                      ::mbedtls_x509_crt, and ownership of this list is passed | 
|  | 771 | *                      to the caller. | 
|  | 772 | * \return              A negative error code on failure. | 
|  | 773 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 774 | typedef int (*mbedtls_x509_crt_ca_cb_t)(void *p_ctx, | 
|  | 775 | mbedtls_x509_crt const *child, | 
|  | 776 | mbedtls_x509_crt **candidate_cas); | 
| Hanno Becker | e15dae7 | 2019-03-28 13:55:38 +0000 | [diff] [blame] | 777 |  | 
|  | 778 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 779 | /** | 
|  | 780 | * \brief          Version of \c mbedtls_x509_crt_verify_with_profile() which | 
|  | 781 | *                 uses a callback to acquire the list of trusted CA | 
|  | 782 | *                 certificates. | 
|  | 783 | * | 
|  | 784 | * \param crt      The certificate chain to be verified. | 
|  | 785 | * \param f_ca_cb  The callback to be used to query for potential signers | 
|  | 786 | *                 of a given child certificate. See the documentation of | 
|  | 787 | *                 ::mbedtls_x509_crt_ca_cb_t for more information. | 
|  | 788 | * \param p_ca_cb  The opaque context to be passed to \p f_ca_cb. | 
|  | 789 | * \param profile  The security profile for the verification. | 
|  | 790 | * \param cn       The expected Common Name. This may be \c NULL if the | 
|  | 791 | *                 CN need not be verified. | 
|  | 792 | * \param flags    The address at which to store the result of the verification. | 
| Janos Follath | 846ae7a | 2019-04-05 16:45:01 +0100 | [diff] [blame] | 793 | *                 If the verification couldn't be completed, the flag value is | 
|  | 794 | *                 set to (uint32_t) -1. | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 795 | * \param f_vrfy   The verification callback to use. See the documentation | 
|  | 796 | *                 of mbedtls_x509_crt_verify() for more information. | 
|  | 797 | * \param p_vrfy   The context to be passed to \p f_vrfy. | 
|  | 798 | * | 
|  | 799 | * \return         See \c mbedtls_crt_verify_with_profile(). | 
|  | 800 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 801 | int mbedtls_x509_crt_verify_with_ca_cb(mbedtls_x509_crt *crt, | 
|  | 802 | mbedtls_x509_crt_ca_cb_t f_ca_cb, | 
|  | 803 | void *p_ca_cb, | 
|  | 804 | const mbedtls_x509_crt_profile *profile, | 
|  | 805 | const char *cn, uint32_t *flags, | 
|  | 806 | int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), | 
|  | 807 | void *p_vrfy); | 
| Hanno Becker | 5c8df78 | 2019-03-27 11:01:17 +0000 | [diff] [blame] | 808 |  | 
|  | 809 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ | 
|  | 810 |  | 
| Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 811 | /** | 
|  | 812 | * \brief          Check usage of certificate against keyUsage extension. | 
|  | 813 | * | 
|  | 814 | * \param crt      Leaf certificate used. | 
| Manuel Pégourié-Gonnard | 655a964 | 2015-06-23 10:48:44 +0200 | [diff] [blame] | 815 | * \param usage    Intended usage(s) (eg MBEDTLS_X509_KU_KEY_ENCIPHERMENT | 
|  | 816 | *                 before using the certificate to perform an RSA key | 
|  | 817 | *                 exchange). | 
|  | 818 | * | 
|  | 819 | * \note           Except for decipherOnly and encipherOnly, a bit set in the | 
|  | 820 | *                 usage argument means this bit MUST be set in the | 
|  | 821 | *                 certificate. For decipherOnly and encipherOnly, it means | 
|  | 822 | *                 that bit MAY be set. | 
| Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 823 | * | 
|  | 824 | * \return         0 is these uses of the certificate are allowed, | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 825 | *                 MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension | 
| Manuel Pégourié-Gonnard | 655a964 | 2015-06-23 10:48:44 +0200 | [diff] [blame] | 826 | *                 is present but does not match the usage argument. | 
| Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 827 | * | 
|  | 828 | * \note           You should only call this function on leaf certificates, on | 
|  | 829 | *                 (intermediate) CAs the keyUsage extension is automatically | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 830 | *                 checked by \c mbedtls_x509_crt_verify(). | 
| Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 831 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 832 | int mbedtls_x509_crt_check_key_usage(const mbedtls_x509_crt *crt, | 
|  | 833 | unsigned int usage); | 
| Manuel Pégourié-Gonnard | 603116c | 2014-04-09 09:50:03 +0200 | [diff] [blame] | 834 |  | 
| Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 835 | /** | 
| Andres Amaya Garcia | 5a6da63 | 2017-11-14 21:40:51 +0000 | [diff] [blame] | 836 | * \brief           Check usage of certificate against extendedKeyUsage. | 
| Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 837 | * | 
| Andres Amaya Garcia | 5a6da63 | 2017-11-14 21:40:51 +0000 | [diff] [blame] | 838 | * \param crt       Leaf certificate used. | 
|  | 839 | * \param usage_oid Intended usage (eg MBEDTLS_OID_SERVER_AUTH or | 
|  | 840 | *                  MBEDTLS_OID_CLIENT_AUTH). | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 841 | * \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()). | 
| Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 842 | * | 
| Andres Amaya Garcia | 5a6da63 | 2017-11-14 21:40:51 +0000 | [diff] [blame] | 843 | * \return          0 if this use of the certificate is allowed, | 
|  | 844 | *                  MBEDTLS_ERR_X509_BAD_INPUT_DATA if not. | 
| Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 845 | * | 
| Andres Amaya Garcia | 5a6da63 | 2017-11-14 21:40:51 +0000 | [diff] [blame] | 846 | * \note            Usually only makes sense on leaf certificates. | 
| Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 847 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 848 | int mbedtls_x509_crt_check_extended_key_usage(const mbedtls_x509_crt *crt, | 
|  | 849 | const char *usage_oid, | 
|  | 850 | size_t usage_len); | 
| Manuel Pégourié-Gonnard | 7afb8a0 | 2014-04-10 17:53:56 +0200 | [diff] [blame] | 851 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 852 | #if defined(MBEDTLS_X509_CRL_PARSE_C) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 853 | /** | 
| Manuel Pégourié-Gonnard | cbf3ef3 | 2013-09-23 12:20:02 +0200 | [diff] [blame] | 854 | * \brief          Verify the certificate revocation status | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 855 | * | 
|  | 856 | * \param crt      a certificate to be verified | 
|  | 857 | * \param crl      the CRL to verify against | 
|  | 858 | * | 
|  | 859 | * \return         1 if the certificate is revoked, 0 otherwise | 
|  | 860 | * | 
|  | 861 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 862 | int mbedtls_x509_crt_is_revoked(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl); | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 863 | #endif /* MBEDTLS_X509_CRL_PARSE_C */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 864 |  | 
|  | 865 | /** | 
| Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 866 | * \brief          Initialize a certificate (chain) | 
|  | 867 | * | 
|  | 868 | * \param crt      Certificate chain to initialize | 
|  | 869 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 870 | void mbedtls_x509_crt_init(mbedtls_x509_crt *crt); | 
| Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 871 |  | 
|  | 872 | /** | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 873 | * \brief          Unallocate all certificate data | 
|  | 874 | * | 
|  | 875 | * \param crt      Certificate chain to free | 
|  | 876 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 877 | void mbedtls_x509_crt_free(mbedtls_x509_crt *crt); | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 878 |  | 
|  | 879 | #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) | 
|  | 880 | /** | 
|  | 881 | * \brief           Initialize a restart context | 
|  | 882 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 883 | void mbedtls_x509_crt_restart_init(mbedtls_x509_crt_restart_ctx *ctx); | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 884 |  | 
|  | 885 | /** | 
|  | 886 | * \brief           Free the components of a restart context | 
|  | 887 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 888 | void mbedtls_x509_crt_restart_free(mbedtls_x509_crt_restart_ctx *ctx); | 
| Manuel Pégourié-Gonnard | bc3f44a | 2017-07-11 11:02:20 +0200 | [diff] [blame] | 889 | #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 890 | #endif /* MBEDTLS_X509_CRT_PARSE_C */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 891 |  | 
| Thomas Daubney | a5f39e0 | 2022-06-06 15:42:32 +0100 | [diff] [blame] | 892 | /** | 
|  | 893 | * \brief               Query certificate for given extension type | 
|  | 894 | * | 
|  | 895 | * \param[in] ctx       Certificate context to be queried, must not be \c NULL | 
|  | 896 | * \param ext_type      Extension type being queried for, must be a valid | 
|  | 897 | *                      extension type. Must be one of the MBEDTLS_X509_EXT_XXX | 
|  | 898 | *                      values | 
|  | 899 | * | 
|  | 900 | * \return              0 if the given extension type is not present, | 
|  | 901 | *                      non-zero otherwise | 
|  | 902 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 903 | static inline int mbedtls_x509_crt_has_ext_type(const mbedtls_x509_crt *ctx, | 
|  | 904 | int ext_type) | 
| Thomas Daubney | a5f39e0 | 2022-06-06 15:42:32 +0100 | [diff] [blame] | 905 | { | 
|  | 906 | return ctx->MBEDTLS_PRIVATE(ext_types) & ext_type; | 
|  | 907 | } | 
|  | 908 |  | 
| Andrzej Kurek | 38d4fdd | 2021-12-28 16:22:52 +0100 | [diff] [blame] | 909 | /** \} name Structures and functions for parsing and writing X.509 certificates */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 910 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 911 | #if defined(MBEDTLS_X509_CRT_WRITE_C) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 912 | /** | 
|  | 913 | * \brief           Initialize a CRT writing context | 
|  | 914 | * | 
|  | 915 | * \param ctx       CRT context to initialize | 
|  | 916 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 917 | void mbedtls_x509write_crt_init(mbedtls_x509write_cert *ctx); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 918 |  | 
|  | 919 | /** | 
| Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 920 | * \brief           Set the version for a Certificate | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 921 | *                  Default: MBEDTLS_X509_CRT_VERSION_3 | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 922 | * | 
|  | 923 | * \param ctx       CRT context to use | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 924 | * \param version   version to set (MBEDTLS_X509_CRT_VERSION_1, MBEDTLS_X509_CRT_VERSION_2 or | 
|  | 925 | *                                  MBEDTLS_X509_CRT_VERSION_3) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 926 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 927 | void mbedtls_x509write_crt_set_version(mbedtls_x509write_cert *ctx, int version); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 928 |  | 
| Valerio Setti | 5d164c4 | 2023-01-09 12:19:40 +0100 | [diff] [blame] | 929 | #if defined(MBEDTLS_BIGNUM_C) && !defined(MBEDTLS_DEPRECATED_REMOVED) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 930 | /** | 
|  | 931 | * \brief           Set the serial number for a Certificate. | 
|  | 932 | * | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 933 | * \deprecated      This function is deprecated and will be removed in a | 
|  | 934 | *                  future version of the library. Please use | 
| Valerio Setti | af4815c | 2023-01-26 17:43:09 +0100 | [diff] [blame] | 935 | *                  mbedtls_x509write_crt_set_serial_raw() instead. | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 936 | * | 
|  | 937 | * \note            Even though the MBEDTLS_BIGNUM_C guard looks redundant since | 
|  | 938 | *                  X509 depends on PK and PK depends on BIGNUM, this emphasizes | 
|  | 939 | *                  a direct dependency between X509 and BIGNUM which is going | 
|  | 940 | *                  to be deprecated in the future. | 
|  | 941 | * | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 942 | * \param ctx       CRT context to use | 
|  | 943 | * \param serial    serial number to set | 
|  | 944 | * | 
|  | 945 | * \return          0 if successful | 
|  | 946 | */ | 
| Valerio Setti | 5d164c4 | 2023-01-09 12:19:40 +0100 | [diff] [blame] | 947 | int MBEDTLS_DEPRECATED mbedtls_x509write_crt_set_serial( | 
|  | 948 | mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial); | 
|  | 949 | #endif // MBEDTLS_BIGNUM_C && !MBEDTLS_DEPRECATED_REMOVED | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 950 |  | 
|  | 951 | /** | 
|  | 952 | * \brief           Set the serial number for a Certificate. | 
|  | 953 | * | 
| Valerio Setti | 746def5 | 2023-01-10 11:46:34 +0100 | [diff] [blame] | 954 | * \param ctx          CRT context to use | 
|  | 955 | * \param serial       A raw array of bytes containing the serial number in big | 
|  | 956 | *                     endian format | 
| Valerio Setti | 9b5e1da | 2023-01-26 17:49:10 +0100 | [diff] [blame] | 957 | * \param serial_len   Length of valid bytes (expressed in bytes) in \p serial | 
|  | 958 | *                     input buffer | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 959 | * | 
|  | 960 | * \return          0 if successful, or | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 961 | *                  MBEDTLS_ERR_X509_BAD_INPUT_DATA if the provided input buffer | 
|  | 962 | *                  is too big (longer than MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN) | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 963 | */ | 
| Valerio Setti | af4815c | 2023-01-26 17:43:09 +0100 | [diff] [blame] | 964 | int mbedtls_x509write_crt_set_serial_raw(mbedtls_x509write_cert *ctx, | 
| Valerio Setti | 746def5 | 2023-01-10 11:46:34 +0100 | [diff] [blame] | 965 | unsigned char *serial, size_t serial_len); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 966 |  | 
|  | 967 | /** | 
|  | 968 | * \brief           Set the validity period for a Certificate | 
|  | 969 | *                  Timestamps should be in string format for UTC timezone | 
|  | 970 | *                  i.e. "YYYYMMDDhhmmss" | 
|  | 971 | *                  e.g. "20131231235959" for December 31st 2013 | 
|  | 972 | *                       at 23:59:59 | 
|  | 973 | * | 
|  | 974 | * \param ctx       CRT context to use | 
|  | 975 | * \param not_before    not_before timestamp | 
|  | 976 | * \param not_after     not_after timestamp | 
|  | 977 | * | 
|  | 978 | * \return          0 if timestamp was parsed successfully, or | 
|  | 979 | *                  a specific error code | 
|  | 980 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 981 | int mbedtls_x509write_crt_set_validity(mbedtls_x509write_cert *ctx, const char *not_before, | 
|  | 982 | const char *not_after); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 983 |  | 
|  | 984 | /** | 
|  | 985 | * \brief           Set the issuer name for a Certificate | 
|  | 986 | *                  Issuer names should contain a comma-separated list | 
|  | 987 | *                  of OID types and values: | 
| Manuel Pégourié-Gonnard | b4fe3cb | 2015-01-22 16:11:05 +0000 | [diff] [blame] | 988 | *                  e.g. "C=UK,O=ARM,CN=mbed TLS CA" | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 989 | * | 
|  | 990 | * \param ctx           CRT context to use | 
|  | 991 | * \param issuer_name   issuer name to set | 
|  | 992 | * | 
|  | 993 | * \return          0 if issuer name was parsed successfully, or | 
|  | 994 | *                  a specific error code | 
|  | 995 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 996 | int mbedtls_x509write_crt_set_issuer_name(mbedtls_x509write_cert *ctx, | 
|  | 997 | const char *issuer_name); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 998 |  | 
|  | 999 | /** | 
|  | 1000 | * \brief           Set the subject name for a Certificate | 
|  | 1001 | *                  Subject names should contain a comma-separated list | 
|  | 1002 | *                  of OID types and values: | 
| Manuel Pégourié-Gonnard | b4fe3cb | 2015-01-22 16:11:05 +0000 | [diff] [blame] | 1003 | *                  e.g. "C=UK,O=ARM,CN=mbed TLS Server 1" | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1004 | * | 
|  | 1005 | * \param ctx           CRT context to use | 
|  | 1006 | * \param subject_name  subject name to set | 
|  | 1007 | * | 
|  | 1008 | * \return          0 if subject name was parsed successfully, or | 
|  | 1009 | *                  a specific error code | 
|  | 1010 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1011 | int mbedtls_x509write_crt_set_subject_name(mbedtls_x509write_cert *ctx, | 
|  | 1012 | const char *subject_name); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1013 |  | 
|  | 1014 | /** | 
|  | 1015 | * \brief           Set the subject public key for the certificate | 
|  | 1016 | * | 
|  | 1017 | * \param ctx       CRT context to use | 
|  | 1018 | * \param key       public key to include | 
|  | 1019 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1020 | void mbedtls_x509write_crt_set_subject_key(mbedtls_x509write_cert *ctx, mbedtls_pk_context *key); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1021 |  | 
|  | 1022 | /** | 
|  | 1023 | * \brief           Set the issuer key used for signing the certificate | 
|  | 1024 | * | 
|  | 1025 | * \param ctx       CRT context to use | 
|  | 1026 | * \param key       private key to sign with | 
|  | 1027 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1028 | void mbedtls_x509write_crt_set_issuer_key(mbedtls_x509write_cert *ctx, mbedtls_pk_context *key); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1029 |  | 
|  | 1030 | /** | 
|  | 1031 | * \brief           Set the MD algorithm to use for the signature | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1032 | *                  (e.g. MBEDTLS_MD_SHA1) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1033 | * | 
|  | 1034 | * \param ctx       CRT context to use | 
| Paul Bakker | a36d23e | 2013-12-30 17:57:27 +0100 | [diff] [blame] | 1035 | * \param md_alg    MD algorithm to use | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1036 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1037 | void mbedtls_x509write_crt_set_md_alg(mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1038 |  | 
|  | 1039 | /** | 
|  | 1040 | * \brief           Generic function to add to or replace an extension in the | 
|  | 1041 | *                  CRT | 
|  | 1042 | * | 
|  | 1043 | * \param ctx       CRT context to use | 
|  | 1044 | * \param oid       OID of the extension | 
|  | 1045 | * \param oid_len   length of the OID | 
|  | 1046 | * \param critical  if the extension is critical (per the RFC's definition) | 
|  | 1047 | * \param val       value of the extension OCTET STRING | 
|  | 1048 | * \param val_len   length of the value data | 
|  | 1049 | * | 
| Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 1050 | * \return          0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1051 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1052 | int mbedtls_x509write_crt_set_extension(mbedtls_x509write_cert *ctx, | 
|  | 1053 | const char *oid, size_t oid_len, | 
|  | 1054 | int critical, | 
|  | 1055 | const unsigned char *val, size_t val_len); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1056 |  | 
|  | 1057 | /** | 
|  | 1058 | * \brief           Set the basicConstraints extension for a CRT | 
|  | 1059 | * | 
|  | 1060 | * \param ctx       CRT context to use | 
|  | 1061 | * \param is_ca     is this a CA certificate | 
|  | 1062 | * \param max_pathlen   maximum length of certificate chains below this | 
|  | 1063 | *                      certificate (only for CA certificates, -1 is | 
| Tom Cosgrove | 1e21144 | 2022-05-26 11:51:00 +0100 | [diff] [blame] | 1064 | *                      unlimited) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1065 | * | 
| Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 1066 | * \return          0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1067 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1068 | int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert *ctx, | 
|  | 1069 | int is_ca, int max_pathlen); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1070 |  | 
| Manuel Pégourié-Gonnard | a946489 | 2023-03-17 12:08:50 +0100 | [diff] [blame] | 1071 | #if defined(MBEDTLS_MD_CAN_SHA1) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1072 | /** | 
|  | 1073 | * \brief           Set the subjectKeyIdentifier extension for a CRT | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1074 | *                  Requires that mbedtls_x509write_crt_set_subject_key() has been | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1075 | *                  called before | 
|  | 1076 | * | 
|  | 1077 | * \param ctx       CRT context to use | 
|  | 1078 | * | 
| Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 1079 | * \return          0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1080 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1081 | int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert *ctx); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1082 |  | 
|  | 1083 | /** | 
|  | 1084 | * \brief           Set the authorityKeyIdentifier extension for a CRT | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1085 | *                  Requires that mbedtls_x509write_crt_set_issuer_key() has been | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1086 | *                  called before | 
|  | 1087 | * | 
|  | 1088 | * \param ctx       CRT context to use | 
|  | 1089 | * | 
| Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 1090 | * \return          0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1091 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1092 | int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *ctx); | 
| Manuel Pégourié-Gonnard | a946489 | 2023-03-17 12:08:50 +0100 | [diff] [blame] | 1093 | #endif /* MBEDTLS_MD_CAN_SHA1 */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1094 |  | 
|  | 1095 | /** | 
|  | 1096 | * \brief           Set the Key Usage Extension flags | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1097 | *                  (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1098 | * | 
|  | 1099 | * \param ctx       CRT context to use | 
|  | 1100 | * \param key_usage key usage flags to set | 
|  | 1101 | * | 
| Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 1102 | * \return          0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1103 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1104 | int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert *ctx, | 
|  | 1105 | unsigned int key_usage); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1106 |  | 
|  | 1107 | /** | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 1108 | * \brief           Set the Extended Key Usage Extension | 
|  | 1109 | *                  (e.g. MBEDTLS_OID_SERVER_AUTH) | 
|  | 1110 | * | 
|  | 1111 | * \param ctx       CRT context to use | 
|  | 1112 | * \param exts      extended key usage extensions to set, a sequence of | 
|  | 1113 | *                  MBEDTLS_ASN1_OID objects | 
|  | 1114 | * | 
|  | 1115 | * \return          0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED | 
|  | 1116 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1117 | int mbedtls_x509write_crt_set_ext_key_usage(mbedtls_x509write_cert *ctx, | 
|  | 1118 | const mbedtls_asn1_sequence *exts); | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 1119 |  | 
|  | 1120 | /** | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1121 | * \brief           Set the Netscape Cert Type flags | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1122 | *                  (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1123 | * | 
|  | 1124 | * \param ctx           CRT context to use | 
|  | 1125 | * \param ns_cert_type  Netscape Cert Type flags to set | 
|  | 1126 | * | 
| Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 1127 | * \return          0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1128 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1129 | int mbedtls_x509write_crt_set_ns_cert_type(mbedtls_x509write_cert *ctx, | 
|  | 1130 | unsigned char ns_cert_type); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1131 |  | 
|  | 1132 | /** | 
|  | 1133 | * \brief           Free the contents of a CRT write context | 
|  | 1134 | * | 
|  | 1135 | * \param ctx       CRT context to free | 
|  | 1136 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1137 | void mbedtls_x509write_crt_free(mbedtls_x509write_cert *ctx); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1138 |  | 
|  | 1139 | /** | 
|  | 1140 | * \brief           Write a built up certificate to a X509 DER structure | 
|  | 1141 | *                  Note: data is written at the end of the buffer! Use the | 
|  | 1142 | *                        return value to determine where you should start | 
|  | 1143 | *                        using the buffer | 
|  | 1144 | * | 
| Paul Bakker | a36d23e | 2013-12-30 17:57:27 +0100 | [diff] [blame] | 1145 | * \param ctx       certificate to write away | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1146 | * \param buf       buffer to write to | 
|  | 1147 | * \param size      size of the buffer | 
| Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 1148 | * \param f_rng     RNG function. This must not be \c NULL. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1149 | * \param p_rng     RNG parameter | 
|  | 1150 | * | 
|  | 1151 | * \return          length of data written if successful, or a specific | 
|  | 1152 | *                  error code | 
|  | 1153 | * | 
| Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 1154 | * \note            \p f_rng is used for the signature operation. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1155 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1156 | int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, | 
|  | 1157 | int (*f_rng)(void *, unsigned char *, size_t), | 
|  | 1158 | void *p_rng); | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1159 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1160 | #if defined(MBEDTLS_PEM_WRITE_C) | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1161 | /** | 
|  | 1162 | * \brief           Write a built up certificate to a X509 PEM string | 
|  | 1163 | * | 
| Paul Bakker | a36d23e | 2013-12-30 17:57:27 +0100 | [diff] [blame] | 1164 | * \param ctx       certificate to write away | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1165 | * \param buf       buffer to write to | 
|  | 1166 | * \param size      size of the buffer | 
| Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 1167 | * \param f_rng     RNG function. This must not be \c NULL. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1168 | * \param p_rng     RNG parameter | 
|  | 1169 | * | 
| Manuel Pégourié-Gonnard | 81abefd | 2015-05-29 12:53:47 +0200 | [diff] [blame] | 1170 | * \return          0 if successful, or a specific error code | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1171 | * | 
| Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 1172 | * \note            \p f_rng is used for the signature operation. | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1173 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 1174 | int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, | 
|  | 1175 | int (*f_rng)(void *, unsigned char *, size_t), | 
|  | 1176 | void *p_rng); | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1177 | #endif /* MBEDTLS_PEM_WRITE_C */ | 
|  | 1178 | #endif /* MBEDTLS_X509_CRT_WRITE_C */ | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1179 |  | 
| Andrzej Kurek | a0defed | 2021-12-30 12:33:31 +0100 | [diff] [blame] | 1180 | /** \} addtogroup x509_module */ | 
|  | 1181 |  | 
| Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 1182 | #ifdef __cplusplus | 
|  | 1183 | } | 
|  | 1184 | #endif | 
|  | 1185 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1186 | #endif /* mbedtls_x509_crt.h */ |