mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file mbedtls_x509_crt.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief X.509 certificate parsing and writing
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_X509_CRT_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_X509_CRT_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 27 #include "config.h"
mbedAustin 11:cada08fc8a70 28 #else
mbedAustin 11:cada08fc8a70 29 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 30 #endif
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #include "x509.h"
mbedAustin 11:cada08fc8a70 33 #include "x509_crl.h"
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 /**
mbedAustin 11:cada08fc8a70 36 * \addtogroup x509_module
mbedAustin 11:cada08fc8a70 37 * \{
mbedAustin 11:cada08fc8a70 38 */
mbedAustin 11:cada08fc8a70 39
mbedAustin 11:cada08fc8a70 40 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 41 extern "C" {
mbedAustin 11:cada08fc8a70 42 #endif
mbedAustin 11:cada08fc8a70 43
mbedAustin 11:cada08fc8a70 44 /**
mbedAustin 11:cada08fc8a70 45 * \name Structures and functions for parsing and writing X.509 certificates
mbedAustin 11:cada08fc8a70 46 * \{
mbedAustin 11:cada08fc8a70 47 */
mbedAustin 11:cada08fc8a70 48
mbedAustin 11:cada08fc8a70 49 /**
mbedAustin 11:cada08fc8a70 50 * Container for an X.509 certificate. The certificate may be chained.
mbedAustin 11:cada08fc8a70 51 */
mbedAustin 11:cada08fc8a70 52 typedef struct mbedtls_x509_crt
mbedAustin 11:cada08fc8a70 53 {
mbedAustin 11:cada08fc8a70 54 mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
mbedAustin 11:cada08fc8a70 55 mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
mbedAustin 11:cada08fc8a70 56
mbedAustin 11:cada08fc8a70 57 int version; /**< The X.509 version. (1=v1, 2=v2, 3=v3) */
mbedAustin 11:cada08fc8a70 58 mbedtls_x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
mbedAustin 11:cada08fc8a70 59 mbedtls_x509_buf sig_oid; /**< Signature algorithm, e.g. sha1RSA */
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
mbedAustin 11:cada08fc8a70 62 mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
mbedAustin 11:cada08fc8a70 63
mbedAustin 11:cada08fc8a70 64 mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
mbedAustin 11:cada08fc8a70 65 mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
mbedAustin 11:cada08fc8a70 66
mbedAustin 11:cada08fc8a70 67 mbedtls_x509_time valid_from; /**< Start time of certificate validity. */
mbedAustin 11:cada08fc8a70 68 mbedtls_x509_time valid_to; /**< End time of certificate validity. */
mbedAustin 11:cada08fc8a70 69
mbedAustin 11:cada08fc8a70 70 mbedtls_pk_context pk; /**< Container for the public key context. */
mbedAustin 11:cada08fc8a70 71
mbedAustin 11:cada08fc8a70 72 mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
mbedAustin 11:cada08fc8a70 73 mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
mbedAustin 11:cada08fc8a70 74 mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
mbedAustin 11:cada08fc8a70 75 mbedtls_x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
mbedAustin 11:cada08fc8a70 76
mbedAustin 11:cada08fc8a70 77 int ext_types; /**< Bit string containing detected and parsed extensions */
mbedAustin 11:cada08fc8a70 78 int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
mbedAustin 11:cada08fc8a70 79 int 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+ */
mbedAustin 11:cada08fc8a70 80
mbedAustin 11:cada08fc8a70 81 unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */
mbedAustin 11:cada08fc8a70 82
mbedAustin 11:cada08fc8a70 83 mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
mbedAustin 11:cada08fc8a70 84
mbedAustin 11:cada08fc8a70 85 unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
mbedAustin 11:cada08fc8a70 86
mbedAustin 11:cada08fc8a70 87 mbedtls_x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
mbedAustin 11:cada08fc8a70 88 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
mbedAustin 11:cada08fc8a70 89 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
mbedAustin 11:cada08fc8a70 90 void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
mbedAustin 11:cada08fc8a70 91
mbedAustin 11:cada08fc8a70 92 struct mbedtls_x509_crt *next; /**< Next certificate in the CA-chain. */
mbedAustin 11:cada08fc8a70 93 }
mbedAustin 11:cada08fc8a70 94 mbedtls_x509_crt;
mbedAustin 11:cada08fc8a70 95
mbedAustin 11:cada08fc8a70 96 /**
mbedAustin 11:cada08fc8a70 97 * Build flag from an algorithm/curve identifier (pk, md, ecp)
mbedAustin 11:cada08fc8a70 98 * Since 0 is always XXX_NONE, ignore it.
mbedAustin 11:cada08fc8a70 99 */
mbedAustin 11:cada08fc8a70 100 #define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( id - 1 ) )
mbedAustin 11:cada08fc8a70 101
mbedAustin 11:cada08fc8a70 102 /**
mbedAustin 11:cada08fc8a70 103 * Security profile for certificate verification.
mbedAustin 11:cada08fc8a70 104 *
mbedAustin 11:cada08fc8a70 105 * All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG().
mbedAustin 11:cada08fc8a70 106 */
mbedAustin 11:cada08fc8a70 107 typedef struct
mbedAustin 11:cada08fc8a70 108 {
mbedAustin 11:cada08fc8a70 109 uint32_t allowed_mds; /**< MDs for signatures */
mbedAustin 11:cada08fc8a70 110 uint32_t allowed_pks; /**< PK algs for signatures */
mbedAustin 11:cada08fc8a70 111 uint32_t allowed_curves; /**< Elliptic curves for ECDSA */
mbedAustin 11:cada08fc8a70 112 uint32_t rsa_min_bitlen; /**< Minimum size for RSA keys */
mbedAustin 11:cada08fc8a70 113 }
mbedAustin 11:cada08fc8a70 114 mbedtls_x509_crt_profile;
mbedAustin 11:cada08fc8a70 115
mbedAustin 11:cada08fc8a70 116 #define MBEDTLS_X509_CRT_VERSION_1 0
mbedAustin 11:cada08fc8a70 117 #define MBEDTLS_X509_CRT_VERSION_2 1
mbedAustin 11:cada08fc8a70 118 #define MBEDTLS_X509_CRT_VERSION_3 2
mbedAustin 11:cada08fc8a70 119
mbedAustin 11:cada08fc8a70 120 #define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 32
mbedAustin 11:cada08fc8a70 121 #define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
mbedAustin 11:cada08fc8a70 122
mbedAustin 11:cada08fc8a70 123 /**
mbedAustin 11:cada08fc8a70 124 * Container for writing a certificate (CRT)
mbedAustin 11:cada08fc8a70 125 */
mbedAustin 11:cada08fc8a70 126 typedef struct mbedtls_x509write_cert
mbedAustin 11:cada08fc8a70 127 {
mbedAustin 11:cada08fc8a70 128 int version;
mbedAustin 11:cada08fc8a70 129 mbedtls_mpi serial;
mbedAustin 11:cada08fc8a70 130 mbedtls_pk_context *subject_key;
mbedAustin 11:cada08fc8a70 131 mbedtls_pk_context *issuer_key;
mbedAustin 11:cada08fc8a70 132 mbedtls_asn1_named_data *subject;
mbedAustin 11:cada08fc8a70 133 mbedtls_asn1_named_data *issuer;
mbedAustin 11:cada08fc8a70 134 mbedtls_md_type_t md_alg;
mbedAustin 11:cada08fc8a70 135 char not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
mbedAustin 11:cada08fc8a70 136 char not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
mbedAustin 11:cada08fc8a70 137 mbedtls_asn1_named_data *extensions;
mbedAustin 11:cada08fc8a70 138 }
mbedAustin 11:cada08fc8a70 139 mbedtls_x509write_cert;
mbedAustin 11:cada08fc8a70 140
mbedAustin 11:cada08fc8a70 141 #if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedAustin 11:cada08fc8a70 142 /**
mbedAustin 11:cada08fc8a70 143 * Default security profile. Should provide a good balance between security
mbedAustin 11:cada08fc8a70 144 * and compatibility with current deployments.
mbedAustin 11:cada08fc8a70 145 */
mbedAustin 11:cada08fc8a70 146 extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
mbedAustin 11:cada08fc8a70 147
mbedAustin 11:cada08fc8a70 148 /**
mbedAustin 11:cada08fc8a70 149 * Expected next default profile. Recommended for new deployments.
mbedAustin 11:cada08fc8a70 150 * Currently targets a 128-bit security level, except for RSA-2048.
mbedAustin 11:cada08fc8a70 151 */
mbedAustin 11:cada08fc8a70 152 extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
mbedAustin 11:cada08fc8a70 153
mbedAustin 11:cada08fc8a70 154 /**
mbedAustin 11:cada08fc8a70 155 * NSA Suite B profile.
mbedAustin 11:cada08fc8a70 156 */
mbedAustin 11:cada08fc8a70 157 extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
mbedAustin 11:cada08fc8a70 158
mbedAustin 11:cada08fc8a70 159 /**
mbedAustin 11:cada08fc8a70 160 * \brief Parse a single DER formatted certificate and add it
mbedAustin 11:cada08fc8a70 161 * to the chained list.
mbedAustin 11:cada08fc8a70 162 *
mbedAustin 11:cada08fc8a70 163 * \param chain points to the start of the chain
mbedAustin 11:cada08fc8a70 164 * \param buf buffer holding the certificate DER data
mbedAustin 11:cada08fc8a70 165 * \param buflen size of the buffer
mbedAustin 11:cada08fc8a70 166 *
mbedAustin 11:cada08fc8a70 167 * \return 0 if successful, or a specific X509 or PEM error code
mbedAustin 11:cada08fc8a70 168 */
mbedAustin 11:cada08fc8a70 169 int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *buf,
mbedAustin 11:cada08fc8a70 170 size_t buflen );
mbedAustin 11:cada08fc8a70 171
mbedAustin 11:cada08fc8a70 172 /**
mbedAustin 11:cada08fc8a70 173 * \brief Parse one or more certificates and add them
mbedAustin 11:cada08fc8a70 174 * to the chained list. Parses permissively. If some
mbedAustin 11:cada08fc8a70 175 * certificates can be parsed, the result is the number
mbedAustin 11:cada08fc8a70 176 * of failed certificates it encountered. If none complete
mbedAustin 11:cada08fc8a70 177 * correctly, the first error is returned.
mbedAustin 11:cada08fc8a70 178 *
mbedAustin 11:cada08fc8a70 179 * \param chain points to the start of the chain
mbedAustin 11:cada08fc8a70 180 * \param buf buffer holding the certificate data in PEM or DER format
mbedAustin 11:cada08fc8a70 181 * \param buflen size of the buffer
mbedAustin 11:cada08fc8a70 182 * (including the terminating null byte for PEM data)
mbedAustin 11:cada08fc8a70 183 *
mbedAustin 11:cada08fc8a70 184 * \return 0 if all certificates parsed successfully, a positive number
mbedAustin 11:cada08fc8a70 185 * if partly successful or a specific X509 or PEM error code
mbedAustin 11:cada08fc8a70 186 */
mbedAustin 11:cada08fc8a70 187 int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen );
mbedAustin 11:cada08fc8a70 188
mbedAustin 11:cada08fc8a70 189 #if defined(MBEDTLS_FS_IO)
mbedAustin 11:cada08fc8a70 190 /**
mbedAustin 11:cada08fc8a70 191 * \brief Load one or more certificates and add them
mbedAustin 11:cada08fc8a70 192 * to the chained list. Parses permissively. If some
mbedAustin 11:cada08fc8a70 193 * certificates can be parsed, the result is the number
mbedAustin 11:cada08fc8a70 194 * of failed certificates it encountered. If none complete
mbedAustin 11:cada08fc8a70 195 * correctly, the first error is returned.
mbedAustin 11:cada08fc8a70 196 *
mbedAustin 11:cada08fc8a70 197 * \param chain points to the start of the chain
mbedAustin 11:cada08fc8a70 198 * \param path filename to read the certificates from
mbedAustin 11:cada08fc8a70 199 *
mbedAustin 11:cada08fc8a70 200 * \return 0 if all certificates parsed successfully, a positive number
mbedAustin 11:cada08fc8a70 201 * if partly successful or a specific X509 or PEM error code
mbedAustin 11:cada08fc8a70 202 */
mbedAustin 11:cada08fc8a70 203 int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path );
mbedAustin 11:cada08fc8a70 204
mbedAustin 11:cada08fc8a70 205 /**
mbedAustin 11:cada08fc8a70 206 * \brief Load one or more certificate files from a path and add them
mbedAustin 11:cada08fc8a70 207 * to the chained list. Parses permissively. If some
mbedAustin 11:cada08fc8a70 208 * certificates can be parsed, the result is the number
mbedAustin 11:cada08fc8a70 209 * of failed certificates it encountered. If none complete
mbedAustin 11:cada08fc8a70 210 * correctly, the first error is returned.
mbedAustin 11:cada08fc8a70 211 *
mbedAustin 11:cada08fc8a70 212 * \param chain points to the start of the chain
mbedAustin 11:cada08fc8a70 213 * \param path directory / folder to read the certificate files from
mbedAustin 11:cada08fc8a70 214 *
mbedAustin 11:cada08fc8a70 215 * \return 0 if all certificates parsed successfully, a positive number
mbedAustin 11:cada08fc8a70 216 * if partly successful or a specific X509 or PEM error code
mbedAustin 11:cada08fc8a70 217 */
mbedAustin 11:cada08fc8a70 218 int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
mbedAustin 11:cada08fc8a70 219 #endif /* MBEDTLS_FS_IO */
mbedAustin 11:cada08fc8a70 220
mbedAustin 11:cada08fc8a70 221 /**
mbedAustin 11:cada08fc8a70 222 * \brief Returns an informational string about the
mbedAustin 11:cada08fc8a70 223 * certificate.
mbedAustin 11:cada08fc8a70 224 *
mbedAustin 11:cada08fc8a70 225 * \param buf Buffer to write to
mbedAustin 11:cada08fc8a70 226 * \param size Maximum size of buffer
mbedAustin 11:cada08fc8a70 227 * \param prefix A line prefix
mbedAustin 11:cada08fc8a70 228 * \param crt The X509 certificate to represent
mbedAustin 11:cada08fc8a70 229 *
mbedAustin 11:cada08fc8a70 230 * \return The length of the string written (not including the
mbedAustin 11:cada08fc8a70 231 * terminated nul byte), or a negative error code.
mbedAustin 11:cada08fc8a70 232 */
mbedAustin 11:cada08fc8a70 233 int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
mbedAustin 11:cada08fc8a70 234 const mbedtls_x509_crt *crt );
mbedAustin 11:cada08fc8a70 235
mbedAustin 11:cada08fc8a70 236 /**
mbedAustin 11:cada08fc8a70 237 * \brief Returns an informational string about the
mbedAustin 11:cada08fc8a70 238 * verification status of a certificate.
mbedAustin 11:cada08fc8a70 239 *
mbedAustin 11:cada08fc8a70 240 * \param buf Buffer to write to
mbedAustin 11:cada08fc8a70 241 * \param size Maximum size of buffer
mbedAustin 11:cada08fc8a70 242 * \param prefix A line prefix
mbedAustin 11:cada08fc8a70 243 * \param flags Verification flags created by mbedtls_x509_crt_verify()
mbedAustin 11:cada08fc8a70 244 *
mbedAustin 11:cada08fc8a70 245 * \return The length of the string written (not including the
mbedAustin 11:cada08fc8a70 246 * terminated nul byte), or a negative error code.
mbedAustin 11:cada08fc8a70 247 */
mbedAustin 11:cada08fc8a70 248 int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
mbedAustin 11:cada08fc8a70 249 uint32_t flags );
mbedAustin 11:cada08fc8a70 250
mbedAustin 11:cada08fc8a70 251 /**
mbedAustin 11:cada08fc8a70 252 * \brief Verify the certificate signature
mbedAustin 11:cada08fc8a70 253 *
mbedAustin 11:cada08fc8a70 254 * The verify callback is a user-supplied callback that
mbedAustin 11:cada08fc8a70 255 * can clear / modify / add flags for a certificate. If set,
mbedAustin 11:cada08fc8a70 256 * the verification callback is called for each
mbedAustin 11:cada08fc8a70 257 * certificate in the chain (from the trust-ca down to the
mbedAustin 11:cada08fc8a70 258 * presented crt). The parameters for the callback are:
mbedAustin 11:cada08fc8a70 259 * (void *parameter, mbedtls_x509_crt *crt, int certificate_depth,
mbedAustin 11:cada08fc8a70 260 * int *flags). With the flags representing current flags for
mbedAustin 11:cada08fc8a70 261 * that specific certificate and the certificate depth from
mbedAustin 11:cada08fc8a70 262 * the bottom (Peer cert depth = 0).
mbedAustin 11:cada08fc8a70 263 *
mbedAustin 11:cada08fc8a70 264 * All flags left after returning from the callback
mbedAustin 11:cada08fc8a70 265 * are also returned to the application. The function should
mbedAustin 11:cada08fc8a70 266 * return 0 for anything but a fatal error.
mbedAustin 11:cada08fc8a70 267 *
mbedAustin 11:cada08fc8a70 268 * \note In case verification failed, the results can be displayed
mbedAustin 11:cada08fc8a70 269 * using \c mbedtls_x509_crt_verify_info()
mbedAustin 11:cada08fc8a70 270 *
mbedAustin 11:cada08fc8a70 271 * \note Same as \c mbedtls_x509_crt_verify_with_profile() with the
mbedAustin 11:cada08fc8a70 272 * default security profile.
mbedAustin 11:cada08fc8a70 273 *
mbedAustin 11:cada08fc8a70 274 * \param crt a certificate to be verified
mbedAustin 11:cada08fc8a70 275 * \param trust_ca the trusted CA chain
mbedAustin 11:cada08fc8a70 276 * \param ca_crl the CRL chain for trusted CA's
mbedAustin 11:cada08fc8a70 277 * \param cn expected Common Name (can be set to
mbedAustin 11:cada08fc8a70 278 * NULL if the CN must not be verified)
mbedAustin 11:cada08fc8a70 279 * \param flags result of the verification
mbedAustin 11:cada08fc8a70 280 * \param f_vrfy verification function
mbedAustin 11:cada08fc8a70 281 * \param p_vrfy verification parameter
mbedAustin 11:cada08fc8a70 282 *
mbedAustin 11:cada08fc8a70 283 * \return 0 if successful or MBEDTLS_ERR_X509_CERT_VERIFY_FAILED
mbedAustin 11:cada08fc8a70 284 * in which case *flags will have one or more
mbedAustin 11:cada08fc8a70 285 * MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX flags
mbedAustin 11:cada08fc8a70 286 * set,
mbedAustin 11:cada08fc8a70 287 * or another error in case of a fatal error encountered
mbedAustin 11:cada08fc8a70 288 * during the verification process.
mbedAustin 11:cada08fc8a70 289 */
mbedAustin 11:cada08fc8a70 290 int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt,
mbedAustin 11:cada08fc8a70 291 mbedtls_x509_crt *trust_ca,
mbedAustin 11:cada08fc8a70 292 mbedtls_x509_crl *ca_crl,
mbedAustin 11:cada08fc8a70 293 const char *cn, uint32_t *flags,
mbedAustin 11:cada08fc8a70 294 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
mbedAustin 11:cada08fc8a70 295 void *p_vrfy );
mbedAustin 11:cada08fc8a70 296
mbedAustin 11:cada08fc8a70 297 /**
mbedAustin 11:cada08fc8a70 298 * \brief Verify the certificate signature according to profile
mbedAustin 11:cada08fc8a70 299 *
mbedAustin 11:cada08fc8a70 300 * \note Same as \c mbedtls_x509_crt_verify(), but with explicit
mbedAustin 11:cada08fc8a70 301 * security profile.
mbedAustin 11:cada08fc8a70 302 *
mbedAustin 11:cada08fc8a70 303 * \note The restrictions on keys (RSA minimum size, allowed curves
mbedAustin 11:cada08fc8a70 304 * for ECDSA) apply to all certificates: trusted root,
mbedAustin 11:cada08fc8a70 305 * intermediate CAs if any, and end entity certificate.
mbedAustin 11:cada08fc8a70 306 *
mbedAustin 11:cada08fc8a70 307 * \param crt a certificate to be verified
mbedAustin 11:cada08fc8a70 308 * \param trust_ca the trusted CA chain
mbedAustin 11:cada08fc8a70 309 * \param ca_crl the CRL chain for trusted CA's
mbedAustin 11:cada08fc8a70 310 * \param profile security profile for verification
mbedAustin 11:cada08fc8a70 311 * \param cn expected Common Name (can be set to
mbedAustin 11:cada08fc8a70 312 * NULL if the CN must not be verified)
mbedAustin 11:cada08fc8a70 313 * \param flags result of the verification
mbedAustin 11:cada08fc8a70 314 * \param f_vrfy verification function
mbedAustin 11:cada08fc8a70 315 * \param p_vrfy verification parameter
mbedAustin 11:cada08fc8a70 316 *
mbedAustin 11:cada08fc8a70 317 * \return 0 if successful or MBEDTLS_ERR_X509_CERT_VERIFY_FAILED
mbedAustin 11:cada08fc8a70 318 * in which case *flags will have one or more
mbedAustin 11:cada08fc8a70 319 * MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX flags
mbedAustin 11:cada08fc8a70 320 * set,
mbedAustin 11:cada08fc8a70 321 * or another error in case of a fatal error encountered
mbedAustin 11:cada08fc8a70 322 * during the verification process.
mbedAustin 11:cada08fc8a70 323 */
mbedAustin 11:cada08fc8a70 324 int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt,
mbedAustin 11:cada08fc8a70 325 mbedtls_x509_crt *trust_ca,
mbedAustin 11:cada08fc8a70 326 mbedtls_x509_crl *ca_crl,
mbedAustin 11:cada08fc8a70 327 const mbedtls_x509_crt_profile *profile,
mbedAustin 11:cada08fc8a70 328 const char *cn, uint32_t *flags,
mbedAustin 11:cada08fc8a70 329 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
mbedAustin 11:cada08fc8a70 330 void *p_vrfy );
mbedAustin 11:cada08fc8a70 331
mbedAustin 11:cada08fc8a70 332 #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
mbedAustin 11:cada08fc8a70 333 /**
mbedAustin 11:cada08fc8a70 334 * \brief Check usage of certificate against keyUsage extension.
mbedAustin 11:cada08fc8a70 335 *
mbedAustin 11:cada08fc8a70 336 * \param crt Leaf certificate used.
mbedAustin 11:cada08fc8a70 337 * \param usage Intended usage(s) (eg MBEDTLS_X509_KU_KEY_ENCIPHERMENT
mbedAustin 11:cada08fc8a70 338 * before using the certificate to perform an RSA key
mbedAustin 11:cada08fc8a70 339 * exchange).
mbedAustin 11:cada08fc8a70 340 *
mbedAustin 11:cada08fc8a70 341 * \note Except for decipherOnly and encipherOnly, a bit set in the
mbedAustin 11:cada08fc8a70 342 * usage argument means this bit MUST be set in the
mbedAustin 11:cada08fc8a70 343 * certificate. For decipherOnly and encipherOnly, it means
mbedAustin 11:cada08fc8a70 344 * that bit MAY be set.
mbedAustin 11:cada08fc8a70 345 *
mbedAustin 11:cada08fc8a70 346 * \return 0 is these uses of the certificate are allowed,
mbedAustin 11:cada08fc8a70 347 * MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
mbedAustin 11:cada08fc8a70 348 * is present but does not match the usage argument.
mbedAustin 11:cada08fc8a70 349 *
mbedAustin 11:cada08fc8a70 350 * \note You should only call this function on leaf certificates, on
mbedAustin 11:cada08fc8a70 351 * (intermediate) CAs the keyUsage extension is automatically
mbedAustin 11:cada08fc8a70 352 * checked by \c mbedtls_x509_crt_verify().
mbedAustin 11:cada08fc8a70 353 */
mbedAustin 11:cada08fc8a70 354 int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
mbedAustin 11:cada08fc8a70 355 unsigned int usage );
mbedAustin 11:cada08fc8a70 356 #endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
mbedAustin 11:cada08fc8a70 357
mbedAustin 11:cada08fc8a70 358 #if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
mbedAustin 11:cada08fc8a70 359 /**
mbedAustin 11:cada08fc8a70 360 * \brief Check usage of certificate against extentedJeyUsage.
mbedAustin 11:cada08fc8a70 361 *
mbedAustin 11:cada08fc8a70 362 * \param crt Leaf certificate used.
mbedAustin 11:cada08fc8a70 363 * \param usage_oid Intended usage (eg MBEDTLS_OID_SERVER_AUTH or MBEDTLS_OID_CLIENT_AUTH).
mbedAustin 11:cada08fc8a70 364 * \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()).
mbedAustin 11:cada08fc8a70 365 *
mbedAustin 11:cada08fc8a70 366 * \return 0 if this use of the certificate is allowed,
mbedAustin 11:cada08fc8a70 367 * MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
mbedAustin 11:cada08fc8a70 368 *
mbedAustin 11:cada08fc8a70 369 * \note Usually only makes sense on leaf certificates.
mbedAustin 11:cada08fc8a70 370 */
mbedAustin 11:cada08fc8a70 371 int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
mbedAustin 11:cada08fc8a70 372 const char *usage_oid,
mbedAustin 11:cada08fc8a70 373 size_t usage_len );
mbedAustin 11:cada08fc8a70 374 #endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE) */
mbedAustin 11:cada08fc8a70 375
mbedAustin 11:cada08fc8a70 376 #if defined(MBEDTLS_X509_CRL_PARSE_C)
mbedAustin 11:cada08fc8a70 377 /**
mbedAustin 11:cada08fc8a70 378 * \brief Verify the certificate revocation status
mbedAustin 11:cada08fc8a70 379 *
mbedAustin 11:cada08fc8a70 380 * \param crt a certificate to be verified
mbedAustin 11:cada08fc8a70 381 * \param crl the CRL to verify against
mbedAustin 11:cada08fc8a70 382 *
mbedAustin 11:cada08fc8a70 383 * \return 1 if the certificate is revoked, 0 otherwise
mbedAustin 11:cada08fc8a70 384 *
mbedAustin 11:cada08fc8a70 385 */
mbedAustin 11:cada08fc8a70 386 int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl );
mbedAustin 11:cada08fc8a70 387 #endif /* MBEDTLS_X509_CRL_PARSE_C */
mbedAustin 11:cada08fc8a70 388
mbedAustin 11:cada08fc8a70 389 /**
mbedAustin 11:cada08fc8a70 390 * \brief Initialize a certificate (chain)
mbedAustin 11:cada08fc8a70 391 *
mbedAustin 11:cada08fc8a70 392 * \param crt Certificate chain to initialize
mbedAustin 11:cada08fc8a70 393 */
mbedAustin 11:cada08fc8a70 394 void mbedtls_x509_crt_init( mbedtls_x509_crt *crt );
mbedAustin 11:cada08fc8a70 395
mbedAustin 11:cada08fc8a70 396 /**
mbedAustin 11:cada08fc8a70 397 * \brief Unallocate all certificate data
mbedAustin 11:cada08fc8a70 398 *
mbedAustin 11:cada08fc8a70 399 * \param crt Certificate chain to free
mbedAustin 11:cada08fc8a70 400 */
mbedAustin 11:cada08fc8a70 401 void mbedtls_x509_crt_free( mbedtls_x509_crt *crt );
mbedAustin 11:cada08fc8a70 402 #endif /* MBEDTLS_X509_CRT_PARSE_C */
mbedAustin 11:cada08fc8a70 403
mbedAustin 11:cada08fc8a70 404 /* \} name */
mbedAustin 11:cada08fc8a70 405 /* \} addtogroup x509_module */
mbedAustin 11:cada08fc8a70 406
mbedAustin 11:cada08fc8a70 407 #if defined(MBEDTLS_X509_CRT_WRITE_C)
mbedAustin 11:cada08fc8a70 408 /**
mbedAustin 11:cada08fc8a70 409 * \brief Initialize a CRT writing context
mbedAustin 11:cada08fc8a70 410 *
mbedAustin 11:cada08fc8a70 411 * \param ctx CRT context to initialize
mbedAustin 11:cada08fc8a70 412 */
mbedAustin 11:cada08fc8a70 413 void mbedtls_x509write_crt_init( mbedtls_x509write_cert *ctx );
mbedAustin 11:cada08fc8a70 414
mbedAustin 11:cada08fc8a70 415 /**
mbedAustin 11:cada08fc8a70 416 * \brief Set the verion for a Certificate
mbedAustin 11:cada08fc8a70 417 * Default: MBEDTLS_X509_CRT_VERSION_3
mbedAustin 11:cada08fc8a70 418 *
mbedAustin 11:cada08fc8a70 419 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 420 * \param version version to set (MBEDTLS_X509_CRT_VERSION_1, MBEDTLS_X509_CRT_VERSION_2 or
mbedAustin 11:cada08fc8a70 421 * MBEDTLS_X509_CRT_VERSION_3)
mbedAustin 11:cada08fc8a70 422 */
mbedAustin 11:cada08fc8a70 423 void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version );
mbedAustin 11:cada08fc8a70 424
mbedAustin 11:cada08fc8a70 425 /**
mbedAustin 11:cada08fc8a70 426 * \brief Set the serial number for a Certificate.
mbedAustin 11:cada08fc8a70 427 *
mbedAustin 11:cada08fc8a70 428 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 429 * \param serial serial number to set
mbedAustin 11:cada08fc8a70 430 *
mbedAustin 11:cada08fc8a70 431 * \return 0 if successful
mbedAustin 11:cada08fc8a70 432 */
mbedAustin 11:cada08fc8a70 433 int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial );
mbedAustin 11:cada08fc8a70 434
mbedAustin 11:cada08fc8a70 435 /**
mbedAustin 11:cada08fc8a70 436 * \brief Set the validity period for a Certificate
mbedAustin 11:cada08fc8a70 437 * Timestamps should be in string format for UTC timezone
mbedAustin 11:cada08fc8a70 438 * i.e. "YYYYMMDDhhmmss"
mbedAustin 11:cada08fc8a70 439 * e.g. "20131231235959" for December 31st 2013
mbedAustin 11:cada08fc8a70 440 * at 23:59:59
mbedAustin 11:cada08fc8a70 441 *
mbedAustin 11:cada08fc8a70 442 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 443 * \param not_before not_before timestamp
mbedAustin 11:cada08fc8a70 444 * \param not_after not_after timestamp
mbedAustin 11:cada08fc8a70 445 *
mbedAustin 11:cada08fc8a70 446 * \return 0 if timestamp was parsed successfully, or
mbedAustin 11:cada08fc8a70 447 * a specific error code
mbedAustin 11:cada08fc8a70 448 */
mbedAustin 11:cada08fc8a70 449 int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
mbedAustin 11:cada08fc8a70 450 const char *not_after );
mbedAustin 11:cada08fc8a70 451
mbedAustin 11:cada08fc8a70 452 /**
mbedAustin 11:cada08fc8a70 453 * \brief Set the issuer name for a Certificate
mbedAustin 11:cada08fc8a70 454 * Issuer names should contain a comma-separated list
mbedAustin 11:cada08fc8a70 455 * of OID types and values:
mbedAustin 11:cada08fc8a70 456 * e.g. "C=UK,O=ARM,CN=mbed TLS CA"
mbedAustin 11:cada08fc8a70 457 *
mbedAustin 11:cada08fc8a70 458 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 459 * \param issuer_name issuer name to set
mbedAustin 11:cada08fc8a70 460 *
mbedAustin 11:cada08fc8a70 461 * \return 0 if issuer name was parsed successfully, or
mbedAustin 11:cada08fc8a70 462 * a specific error code
mbedAustin 11:cada08fc8a70 463 */
mbedAustin 11:cada08fc8a70 464 int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
mbedAustin 11:cada08fc8a70 465 const char *issuer_name );
mbedAustin 11:cada08fc8a70 466
mbedAustin 11:cada08fc8a70 467 /**
mbedAustin 11:cada08fc8a70 468 * \brief Set the subject name for a Certificate
mbedAustin 11:cada08fc8a70 469 * Subject names should contain a comma-separated list
mbedAustin 11:cada08fc8a70 470 * of OID types and values:
mbedAustin 11:cada08fc8a70 471 * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
mbedAustin 11:cada08fc8a70 472 *
mbedAustin 11:cada08fc8a70 473 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 474 * \param subject_name subject name to set
mbedAustin 11:cada08fc8a70 475 *
mbedAustin 11:cada08fc8a70 476 * \return 0 if subject name was parsed successfully, or
mbedAustin 11:cada08fc8a70 477 * a specific error code
mbedAustin 11:cada08fc8a70 478 */
mbedAustin 11:cada08fc8a70 479 int mbedtls_x509write_crt_set_subject_name( mbedtls_x509write_cert *ctx,
mbedAustin 11:cada08fc8a70 480 const char *subject_name );
mbedAustin 11:cada08fc8a70 481
mbedAustin 11:cada08fc8a70 482 /**
mbedAustin 11:cada08fc8a70 483 * \brief Set the subject public key for the certificate
mbedAustin 11:cada08fc8a70 484 *
mbedAustin 11:cada08fc8a70 485 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 486 * \param key public key to include
mbedAustin 11:cada08fc8a70 487 */
mbedAustin 11:cada08fc8a70 488 void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
mbedAustin 11:cada08fc8a70 489
mbedAustin 11:cada08fc8a70 490 /**
mbedAustin 11:cada08fc8a70 491 * \brief Set the issuer key used for signing the certificate
mbedAustin 11:cada08fc8a70 492 *
mbedAustin 11:cada08fc8a70 493 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 494 * \param key private key to sign with
mbedAustin 11:cada08fc8a70 495 */
mbedAustin 11:cada08fc8a70 496 void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
mbedAustin 11:cada08fc8a70 497
mbedAustin 11:cada08fc8a70 498 /**
mbedAustin 11:cada08fc8a70 499 * \brief Set the MD algorithm to use for the signature
mbedAustin 11:cada08fc8a70 500 * (e.g. MBEDTLS_MD_SHA1)
mbedAustin 11:cada08fc8a70 501 *
mbedAustin 11:cada08fc8a70 502 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 503 * \param md_alg MD algorithm to use
mbedAustin 11:cada08fc8a70 504 */
mbedAustin 11:cada08fc8a70 505 void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg );
mbedAustin 11:cada08fc8a70 506
mbedAustin 11:cada08fc8a70 507 /**
mbedAustin 11:cada08fc8a70 508 * \brief Generic function to add to or replace an extension in the
mbedAustin 11:cada08fc8a70 509 * CRT
mbedAustin 11:cada08fc8a70 510 *
mbedAustin 11:cada08fc8a70 511 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 512 * \param oid OID of the extension
mbedAustin 11:cada08fc8a70 513 * \param oid_len length of the OID
mbedAustin 11:cada08fc8a70 514 * \param critical if the extension is critical (per the RFC's definition)
mbedAustin 11:cada08fc8a70 515 * \param val value of the extension OCTET STRING
mbedAustin 11:cada08fc8a70 516 * \param val_len length of the value data
mbedAustin 11:cada08fc8a70 517 *
mbedAustin 11:cada08fc8a70 518 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 519 */
mbedAustin 11:cada08fc8a70 520 int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
mbedAustin 11:cada08fc8a70 521 const char *oid, size_t oid_len,
mbedAustin 11:cada08fc8a70 522 int critical,
mbedAustin 11:cada08fc8a70 523 const unsigned char *val, size_t val_len );
mbedAustin 11:cada08fc8a70 524
mbedAustin 11:cada08fc8a70 525 /**
mbedAustin 11:cada08fc8a70 526 * \brief Set the basicConstraints extension for a CRT
mbedAustin 11:cada08fc8a70 527 *
mbedAustin 11:cada08fc8a70 528 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 529 * \param is_ca is this a CA certificate
mbedAustin 11:cada08fc8a70 530 * \param max_pathlen maximum length of certificate chains below this
mbedAustin 11:cada08fc8a70 531 * certificate (only for CA certificates, -1 is
mbedAustin 11:cada08fc8a70 532 * inlimited)
mbedAustin 11:cada08fc8a70 533 *
mbedAustin 11:cada08fc8a70 534 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 535 */
mbedAustin 11:cada08fc8a70 536 int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
mbedAustin 11:cada08fc8a70 537 int is_ca, int max_pathlen );
mbedAustin 11:cada08fc8a70 538
mbedAustin 11:cada08fc8a70 539 #if defined(MBEDTLS_SHA1_C)
mbedAustin 11:cada08fc8a70 540 /**
mbedAustin 11:cada08fc8a70 541 * \brief Set the subjectKeyIdentifier extension for a CRT
mbedAustin 11:cada08fc8a70 542 * Requires that mbedtls_x509write_crt_set_subject_key() has been
mbedAustin 11:cada08fc8a70 543 * called before
mbedAustin 11:cada08fc8a70 544 *
mbedAustin 11:cada08fc8a70 545 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 546 *
mbedAustin 11:cada08fc8a70 547 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 548 */
mbedAustin 11:cada08fc8a70 549 int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx );
mbedAustin 11:cada08fc8a70 550
mbedAustin 11:cada08fc8a70 551 /**
mbedAustin 11:cada08fc8a70 552 * \brief Set the authorityKeyIdentifier extension for a CRT
mbedAustin 11:cada08fc8a70 553 * Requires that mbedtls_x509write_crt_set_issuer_key() has been
mbedAustin 11:cada08fc8a70 554 * called before
mbedAustin 11:cada08fc8a70 555 *
mbedAustin 11:cada08fc8a70 556 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 557 *
mbedAustin 11:cada08fc8a70 558 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 559 */
mbedAustin 11:cada08fc8a70 560 int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *ctx );
mbedAustin 11:cada08fc8a70 561 #endif /* MBEDTLS_SHA1_C */
mbedAustin 11:cada08fc8a70 562
mbedAustin 11:cada08fc8a70 563 /**
mbedAustin 11:cada08fc8a70 564 * \brief Set the Key Usage Extension flags
mbedAustin 11:cada08fc8a70 565 * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
mbedAustin 11:cada08fc8a70 566 *
mbedAustin 11:cada08fc8a70 567 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 568 * \param key_usage key usage flags to set
mbedAustin 11:cada08fc8a70 569 *
mbedAustin 11:cada08fc8a70 570 * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 571 */
mbedAustin 11:cada08fc8a70 572 int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
mbedAustin 11:cada08fc8a70 573 unsigned int key_usage );
mbedAustin 11:cada08fc8a70 574
mbedAustin 11:cada08fc8a70 575 /**
mbedAustin 11:cada08fc8a70 576 * \brief Set the Netscape Cert Type flags
mbedAustin 11:cada08fc8a70 577 * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
mbedAustin 11:cada08fc8a70 578 *
mbedAustin 11:cada08fc8a70 579 * \param ctx CRT context to use
mbedAustin 11:cada08fc8a70 580 * \param ns_cert_type Netscape Cert Type flags to set
mbedAustin 11:cada08fc8a70 581 *
mbedAustin 11:cada08fc8a70 582 * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
mbedAustin 11:cada08fc8a70 583 */
mbedAustin 11:cada08fc8a70 584 int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
mbedAustin 11:cada08fc8a70 585 unsigned char ns_cert_type );
mbedAustin 11:cada08fc8a70 586
mbedAustin 11:cada08fc8a70 587 /**
mbedAustin 11:cada08fc8a70 588 * \brief Free the contents of a CRT write context
mbedAustin 11:cada08fc8a70 589 *
mbedAustin 11:cada08fc8a70 590 * \param ctx CRT context to free
mbedAustin 11:cada08fc8a70 591 */
mbedAustin 11:cada08fc8a70 592 void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx );
mbedAustin 11:cada08fc8a70 593
mbedAustin 11:cada08fc8a70 594 /**
mbedAustin 11:cada08fc8a70 595 * \brief Write a built up certificate to a X509 DER structure
mbedAustin 11:cada08fc8a70 596 * Note: data is written at the end of the buffer! Use the
mbedAustin 11:cada08fc8a70 597 * return value to determine where you should start
mbedAustin 11:cada08fc8a70 598 * using the buffer
mbedAustin 11:cada08fc8a70 599 *
mbedAustin 11:cada08fc8a70 600 * \param ctx certificate to write away
mbedAustin 11:cada08fc8a70 601 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 602 * \param size size of the buffer
mbedAustin 11:cada08fc8a70 603 * \param f_rng RNG function (for signature, see note)
mbedAustin 11:cada08fc8a70 604 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 605 *
mbedAustin 11:cada08fc8a70 606 * \return length of data written if successful, or a specific
mbedAustin 11:cada08fc8a70 607 * error code
mbedAustin 11:cada08fc8a70 608 *
mbedAustin 11:cada08fc8a70 609 * \note f_rng may be NULL if RSA is used for signature and the
mbedAustin 11:cada08fc8a70 610 * signature is made offline (otherwise f_rng is desirable
mbedAustin 11:cada08fc8a70 611 * for countermeasures against timing attacks).
mbedAustin 11:cada08fc8a70 612 * ECDSA signatures always require a non-NULL f_rng.
mbedAustin 11:cada08fc8a70 613 */
mbedAustin 11:cada08fc8a70 614 int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
mbedAustin 11:cada08fc8a70 615 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 616 void *p_rng );
mbedAustin 11:cada08fc8a70 617
mbedAustin 11:cada08fc8a70 618 #if defined(MBEDTLS_PEM_WRITE_C)
mbedAustin 11:cada08fc8a70 619 /**
mbedAustin 11:cada08fc8a70 620 * \brief Write a built up certificate to a X509 PEM string
mbedAustin 11:cada08fc8a70 621 *
mbedAustin 11:cada08fc8a70 622 * \param ctx certificate to write away
mbedAustin 11:cada08fc8a70 623 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 624 * \param size size of the buffer
mbedAustin 11:cada08fc8a70 625 * \param f_rng RNG function (for signature, see note)
mbedAustin 11:cada08fc8a70 626 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 627 *
mbedAustin 11:cada08fc8a70 628 * \return 0 if successful, or a specific error code
mbedAustin 11:cada08fc8a70 629 *
mbedAustin 11:cada08fc8a70 630 * \note f_rng may be NULL if RSA is used for signature and the
mbedAustin 11:cada08fc8a70 631 * signature is made offline (otherwise f_rng is desirable
mbedAustin 11:cada08fc8a70 632 * for countermeasures against timing attacks).
mbedAustin 11:cada08fc8a70 633 * ECDSA signatures always require a non-NULL f_rng.
mbedAustin 11:cada08fc8a70 634 */
mbedAustin 11:cada08fc8a70 635 int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
mbedAustin 11:cada08fc8a70 636 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 637 void *p_rng );
mbedAustin 11:cada08fc8a70 638 #endif /* MBEDTLS_PEM_WRITE_C */
mbedAustin 11:cada08fc8a70 639 #endif /* MBEDTLS_X509_CRT_WRITE_C */
mbedAustin 11:cada08fc8a70 640
mbedAustin 11:cada08fc8a70 641 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 642 }
mbedAustin 11:cada08fc8a70 643 #endif
mbedAustin 11:cada08fc8a70 644
mbedAustin 11:cada08fc8a70 645 #endif /* mbedtls_x509_crt.h */