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_csr.h |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 3 | * |
| 4 | * \brief X.509 certificate signing request 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_CSR_H |
| 23 | #define MBEDTLS_X509_CSR_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" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 29 | |
| 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | /** |
| 35 | * \addtogroup x509_module |
| 36 | * \{ */ |
| 37 | |
| 38 | /** |
| 39 | * \name Structures and functions for X.509 Certificate Signing Requests (CSR) |
| 40 | * \{ |
| 41 | */ |
| 42 | |
| 43 | /** |
| 44 | * Certificate Signing Request (CSR) structure. |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 45 | * |
| 46 | * Some fields of this structure are publicly readable. Do not modify |
| 47 | * them except via Mbed TLS library functions: the effect of modifying |
Gilles Peskine | 44ffc79 | 2021-08-31 22:59:35 +0200 | [diff] [blame] | 48 | * those fields or the data that those fields point to is unspecified. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 49 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 50 | typedef struct mbedtls_x509_csr { |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 51 | mbedtls_x509_buf raw; /**< The raw CSR data (DER). */ |
| 52 | mbedtls_x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 53 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 54 | int version; /**< CSR version (1=v1). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 55 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 56 | mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). */ |
| 57 | mbedtls_x509_name subject; /**< The parsed subject data (named information object). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 58 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 59 | mbedtls_pk_context pk; /**< Container for the public key context. */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 60 | |
Jens Alfke | 2d9e359 | 2019-10-29 15:03:37 -0700 | [diff] [blame] | 61 | unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */ |
| 62 | unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */ |
Andrzej Kurek | 1747304 | 2023-04-30 14:11:23 -0400 | [diff] [blame] | 63 | mbedtls_x509_sequence subject_alt_names; /**< Optional list of raw entries of Subject Alternative Names extension. These can be later parsed by mbedtls_x509_parse_subject_alt_name. */ |
Jens Alfke | 2d9e359 | 2019-10-29 15:03:37 -0700 | [diff] [blame] | 64 | |
Przemek Stekiel | cbaf316 | 2023-01-12 12:58:02 +0100 | [diff] [blame] | 65 | int MBEDTLS_PRIVATE(ext_types); /**< Bit string containing detected and parsed extensions */ |
| 66 | |
Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 67 | mbedtls_x509_buf sig_oid; |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 68 | mbedtls_x509_buf MBEDTLS_PRIVATE(sig); |
| 69 | mbedtls_md_type_t MBEDTLS_PRIVATE(sig_md); /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */ |
| 70 | mbedtls_pk_type_t MBEDTLS_PRIVATE(sig_pk); /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */ |
| 71 | 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] | 72 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 73 | mbedtls_x509_csr; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Container for writing a CSR |
| 77 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 78 | typedef struct mbedtls_x509write_csr { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 79 | mbedtls_pk_context *MBEDTLS_PRIVATE(key); |
| 80 | mbedtls_asn1_named_data *MBEDTLS_PRIVATE(subject); |
| 81 | mbedtls_md_type_t MBEDTLS_PRIVATE(md_alg); |
| 82 | mbedtls_asn1_named_data *MBEDTLS_PRIVATE(extensions); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 83 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 84 | mbedtls_x509write_csr; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 85 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 86 | #if defined(MBEDTLS_X509_CSR_PARSE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 87 | /** |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 88 | * \brief Load a Certificate Signing Request (CSR) in DER format |
| 89 | * |
Manuel Pégourié-Gonnard | 986bbf2 | 2016-02-24 14:36:05 +0000 | [diff] [blame] | 90 | * \note CSR attributes (if any) are currently silently ignored. |
| 91 | * |
Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 92 | * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto |
| 93 | * subsystem must have been initialized by calling |
| 94 | * psa_crypto_init() before calling this function. |
| 95 | * |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 96 | * \param csr CSR context to fill |
| 97 | * \param buf buffer holding the CRL data |
| 98 | * \param buflen size of the buffer |
| 99 | * |
| 100 | * \return 0 if successful, or a specific X509 error code |
| 101 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 102 | int mbedtls_x509_csr_parse_der(mbedtls_x509_csr *csr, |
| 103 | const unsigned char *buf, size_t buflen); |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * \brief Load a Certificate Signing Request (CSR), DER or PEM format |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 107 | * |
Manuel Pégourié-Gonnard | 986bbf2 | 2016-02-24 14:36:05 +0000 | [diff] [blame] | 108 | * \note See notes for \c mbedtls_x509_csr_parse_der() |
| 109 | * |
Gilles Peskine | 5b7e164 | 2022-08-04 23:44:59 +0200 | [diff] [blame] | 110 | * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto |
| 111 | * subsystem must have been initialized by calling |
| 112 | * psa_crypto_init() before calling this function. |
| 113 | * |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 114 | * \param csr CSR context to fill |
| 115 | * \param buf buffer holding the CRL data |
| 116 | * \param buflen size of the buffer |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 117 | * (including the terminating null byte for PEM data) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 118 | * |
| 119 | * \return 0 if successful, or a specific X509 or PEM error code |
| 120 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 121 | int mbedtls_x509_csr_parse(mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 122 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 123 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 124 | /** |
| 125 | * \brief Load a Certificate Signing Request (CSR) |
| 126 | * |
Manuel Pégourié-Gonnard | 986bbf2 | 2016-02-24 14:36:05 +0000 | [diff] [blame] | 127 | * \note See notes for \c mbedtls_x509_csr_parse() |
| 128 | * |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 129 | * \param csr CSR context to fill |
| 130 | * \param path filename to read the CSR from |
| 131 | * |
| 132 | * \return 0 if successful, or a specific X509 or PEM error code |
| 133 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 134 | int mbedtls_x509_csr_parse_file(mbedtls_x509_csr *csr, const char *path); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 135 | #endif /* MBEDTLS_FS_IO */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 136 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 137 | #if !defined(MBEDTLS_X509_REMOVE_INFO) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 138 | /** |
| 139 | * \brief Returns an informational string about the |
| 140 | * CSR. |
| 141 | * |
| 142 | * \param buf Buffer to write to |
| 143 | * \param size Maximum size of buffer |
| 144 | * \param prefix A line prefix |
| 145 | * \param csr The X509 CSR to represent |
| 146 | * |
Manuel Pégourié-Gonnard | e244f9f | 2015-06-23 12:10:45 +0200 | [diff] [blame] | 147 | * \return The length of the string written (not including the |
| 148 | * terminated nul byte), or a negative error code. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 149 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 150 | int mbedtls_x509_csr_info(char *buf, size_t size, const char *prefix, |
| 151 | const mbedtls_x509_csr *csr); |
Hanno Becker | 88c2bf3 | 2019-06-14 17:21:24 +0100 | [diff] [blame] | 152 | #endif /* !MBEDTLS_X509_REMOVE_INFO */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 153 | |
| 154 | /** |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 155 | * \brief Initialize a CSR |
| 156 | * |
| 157 | * \param csr CSR to initialize |
| 158 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 159 | void mbedtls_x509_csr_init(mbedtls_x509_csr *csr); |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 160 | |
| 161 | /** |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 162 | * \brief Unallocate all CSR data |
| 163 | * |
| 164 | * \param csr CSR to free |
| 165 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 166 | void mbedtls_x509_csr_free(mbedtls_x509_csr *csr); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 167 | #endif /* MBEDTLS_X509_CSR_PARSE_C */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 168 | |
Andrzej Kurek | 38d4fdd | 2021-12-28 16:22:52 +0100 | [diff] [blame] | 169 | /** \} name Structures and functions for X.509 Certificate Signing Requests (CSR) */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 170 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 171 | #if defined(MBEDTLS_X509_CSR_WRITE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 172 | /** |
| 173 | * \brief Initialize a CSR context |
| 174 | * |
| 175 | * \param ctx CSR context to initialize |
| 176 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 177 | void mbedtls_x509write_csr_init(mbedtls_x509write_csr *ctx); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * \brief Set the subject name for a CSR |
| 181 | * Subject names should contain a comma-separated list |
| 182 | * of OID types and values: |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 183 | * e.g. "C=UK,O=ARM,CN=Mbed TLS Server 1" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 184 | * |
| 185 | * \param ctx CSR context to use |
| 186 | * \param subject_name subject name to set |
| 187 | * |
| 188 | * \return 0 if subject name was parsed successfully, or |
| 189 | * a specific error code |
| 190 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 191 | int mbedtls_x509write_csr_set_subject_name(mbedtls_x509write_csr *ctx, |
| 192 | const char *subject_name); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * \brief Set the key for a CSR (public key will be included, |
| 196 | * private key used to sign the CSR when writing it) |
| 197 | * |
| 198 | * \param ctx CSR context to use |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 199 | * \param key Asymmetric key to include |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 200 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 201 | void mbedtls_x509write_csr_set_key(mbedtls_x509write_csr *ctx, mbedtls_pk_context *key); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * \brief Set the MD algorithm to use for the signature |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 205 | * (e.g. MBEDTLS_MD_SHA1) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 206 | * |
| 207 | * \param ctx CSR context to use |
| 208 | * \param md_alg MD algorithm to use |
| 209 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 210 | void mbedtls_x509write_csr_set_md_alg(mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * \brief Set the Key Usage Extension flags |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 214 | * (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] | 215 | * |
| 216 | * \param ctx CSR context to use |
| 217 | * \param key_usage key usage flags to set |
| 218 | * |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 219 | * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED |
Andres Amaya Garcia | d8233f7 | 2018-10-08 19:44:55 +0100 | [diff] [blame] | 220 | * |
| 221 | * \note The <code>decipherOnly</code> flag from the Key Usage |
| 222 | * extension is represented by bit 8 (i.e. |
| 223 | * <code>0x8000</code>), which cannot typically be represented |
| 224 | * in an unsigned char. Therefore, the flag |
| 225 | * <code>decipherOnly</code> (i.e. |
| 226 | * #MBEDTLS_X509_KU_DECIPHER_ONLY) cannot be set using this |
| 227 | * function. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 228 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 229 | int mbedtls_x509write_csr_set_key_usage(mbedtls_x509write_csr *ctx, unsigned char key_usage); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 230 | |
| 231 | /** |
Hannes Tschofenig | 6b10860 | 2022-12-28 18:38:53 +0100 | [diff] [blame] | 232 | * \brief Set Subject Alternative Name |
| 233 | * |
| 234 | * \param ctx CSR context to use |
| 235 | * \param san_list List of SAN values |
| 236 | * |
| 237 | * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED |
| 238 | * |
| 239 | * \note Only "dnsName", "uniformResourceIdentifier" and "otherName", |
| 240 | * as defined in RFC 5280, are supported. |
| 241 | */ |
| 242 | int mbedtls_x509write_csr_set_subject_alternative_name(mbedtls_x509write_csr *ctx, |
| 243 | const mbedtls_x509_san_list *san_list); |
| 244 | |
| 245 | /** |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 246 | * \brief Set the Netscape Cert Type flags |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 247 | * (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] | 248 | * |
| 249 | * \param ctx CSR context to use |
| 250 | * \param ns_cert_type Netscape Cert Type flags to set |
| 251 | * |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 252 | * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 253 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 254 | int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr *ctx, |
| 255 | unsigned char ns_cert_type); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 256 | |
| 257 | /** |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 258 | * \brief Generic function to add to or replace an extension in the |
| 259 | * CSR |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 260 | * |
| 261 | * \param ctx CSR context to use |
| 262 | * \param oid OID of the extension |
| 263 | * \param oid_len length of the OID |
Christoph Reiter | 95273f4 | 2021-01-21 13:31:23 +0100 | [diff] [blame] | 264 | * \param critical Set to 1 to mark the extension as critical, 0 otherwise. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 265 | * \param val value of the extension OCTET STRING |
| 266 | * \param val_len length of the value data |
| 267 | * |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 268 | * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 269 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 270 | int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr *ctx, |
| 271 | const char *oid, size_t oid_len, |
| 272 | int critical, |
| 273 | const unsigned char *val, size_t val_len); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * \brief Free the contents of a CSR context |
| 277 | * |
| 278 | * \param ctx CSR context to free |
| 279 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 280 | void mbedtls_x509write_csr_free(mbedtls_x509write_csr *ctx); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 281 | |
| 282 | /** |
| 283 | * \brief Write a CSR (Certificate Signing Request) to a |
| 284 | * DER structure |
| 285 | * Note: data is written at the end of the buffer! Use the |
| 286 | * return value to determine where you should start |
| 287 | * using the buffer |
| 288 | * |
| 289 | * \param ctx CSR to write away |
| 290 | * \param buf buffer to write to |
| 291 | * \param size size of the buffer |
Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 292 | * \param f_rng RNG function. This must not be \c NULL. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 293 | * \param p_rng RNG parameter |
| 294 | * |
| 295 | * \return length of data written if successful, or a specific |
| 296 | * error code |
| 297 | * |
Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 298 | * \note \p f_rng is used for the signature operation. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 299 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 300 | int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size, |
| 301 | int (*f_rng)(void *, unsigned char *, size_t), |
| 302 | void *p_rng); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 303 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 304 | #if defined(MBEDTLS_PEM_WRITE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 305 | /** |
| 306 | * \brief Write a CSR (Certificate Signing Request) to a |
| 307 | * PEM string |
| 308 | * |
| 309 | * \param ctx CSR to write away |
| 310 | * \param buf buffer to write to |
| 311 | * \param size size of the buffer |
Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 312 | * \param f_rng RNG function. This must not be \c NULL. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 313 | * \param p_rng RNG parameter |
| 314 | * |
Manuel Pégourié-Gonnard | 81abefd | 2015-05-29 12:53:47 +0200 | [diff] [blame] | 315 | * \return 0 if successful, or a specific error code |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 316 | * |
Manuel Pégourié-Gonnard | c305b72 | 2021-06-15 11:29:26 +0200 | [diff] [blame] | 317 | * \note \p f_rng is used for the signature operation. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 318 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 319 | int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size, |
| 320 | int (*f_rng)(void *, unsigned char *, size_t), |
| 321 | void *p_rng); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 322 | #endif /* MBEDTLS_PEM_WRITE_C */ |
| 323 | #endif /* MBEDTLS_X509_CSR_WRITE_C */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 324 | |
Andrzej Kurek | a0defed | 2021-12-30 12:33:31 +0100 | [diff] [blame] | 325 | /** \} addtogroup x509_module */ |
| 326 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 327 | #ifdef __cplusplus |
| 328 | } |
| 329 | #endif |
| 330 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 331 | #endif /* mbedtls_x509_csr.h */ |