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