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 |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 24 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 25 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 26 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #endif |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 30 | |
Jaeden Amero | 6609aef | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 31 | #include "mbedtls/x509.h" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 32 | |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
| 37 | /** |
| 38 | * \addtogroup x509_module |
| 39 | * \{ */ |
| 40 | |
| 41 | /** |
| 42 | * \name Structures and functions for X.509 Certificate Signing Requests (CSR) |
| 43 | * \{ |
| 44 | */ |
| 45 | |
| 46 | /** |
| 47 | * Certificate Signing Request (CSR) structure. |
| 48 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 49 | typedef struct mbedtls_x509_csr { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 50 | mbedtls_x509_buf raw; /**< The raw CSR data (DER). */ |
| 51 | mbedtls_x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 52 | |
Manuel Pégourié-Gonnard | f4e1b64 | 2014-06-19 11:39:46 +0200 | [diff] [blame] | 53 | int version; /**< CSR version (1=v1). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). */ |
| 56 | mbedtls_x509_name subject; /**< The parsed subject data (named information object). */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 57 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | mbedtls_pk_context pk; /**< Container for the public key context. */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 59 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | mbedtls_x509_buf sig_oid; |
| 61 | mbedtls_x509_buf sig; |
| 62 | mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */ |
| 63 | mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */ |
| 64 | void *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] | 65 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | mbedtls_x509_csr; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Container for writing a CSR |
| 70 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 71 | typedef struct mbedtls_x509write_csr { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 72 | mbedtls_pk_context *key; |
| 73 | mbedtls_asn1_named_data *subject; |
| 74 | mbedtls_md_type_t md_alg; |
| 75 | mbedtls_asn1_named_data *extensions; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 76 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 77 | mbedtls_x509write_csr; |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 78 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 79 | #if defined(MBEDTLS_X509_CSR_PARSE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 80 | /** |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 81 | * \brief Load a Certificate Signing Request (CSR) in DER format |
| 82 | * |
Manuel Pégourié-Gonnard | 986bbf2 | 2016-02-24 14:36:05 +0000 | [diff] [blame] | 83 | * \note CSR attributes (if any) are currently silently ignored. |
| 84 | * |
Gilles Peskine | 07ae208 | 2023-03-07 20:22:51 +0100 | [diff] [blame] | 85 | * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto |
| 86 | * subsystem must have been initialized by calling |
| 87 | * psa_crypto_init() before calling this function. |
| 88 | * |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 89 | * \param csr CSR context to fill |
| 90 | * \param buf buffer holding the CRL data |
| 91 | * \param buflen size of the buffer |
| 92 | * |
| 93 | * \return 0 if successful, or a specific X509 error code |
| 94 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 95 | int mbedtls_x509_csr_parse_der(mbedtls_x509_csr *csr, |
| 96 | const unsigned char *buf, size_t buflen); |
Manuel Pégourié-Gonnard | f3b4724 | 2014-06-16 18:06:48 +0200 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * \brief Load a Certificate Signing Request (CSR), DER or PEM format |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 100 | * |
Manuel Pégourié-Gonnard | 986bbf2 | 2016-02-24 14:36:05 +0000 | [diff] [blame] | 101 | * \note See notes for \c mbedtls_x509_csr_parse_der() |
| 102 | * |
Gilles Peskine | 07ae208 | 2023-03-07 20:22:51 +0100 | [diff] [blame] | 103 | * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto |
| 104 | * subsystem must have been initialized by calling |
| 105 | * psa_crypto_init() before calling this function. |
| 106 | * |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 107 | * \param csr CSR context to fill |
| 108 | * \param buf buffer holding the CRL data |
| 109 | * \param buflen size of the buffer |
Manuel Pégourié-Gonnard | 43b37cb | 2015-05-12 11:20:10 +0200 | [diff] [blame] | 110 | * (including the terminating null byte for PEM data) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 111 | * |
| 112 | * \return 0 if successful, or a specific X509 or PEM error code |
| 113 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 114 | 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] | 115 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 116 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 117 | /** |
| 118 | * \brief Load a Certificate Signing Request (CSR) |
| 119 | * |
Manuel Pégourié-Gonnard | 986bbf2 | 2016-02-24 14:36:05 +0000 | [diff] [blame] | 120 | * \note See notes for \c mbedtls_x509_csr_parse() |
| 121 | * |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 122 | * \param csr CSR context to fill |
| 123 | * \param path filename to read the CSR from |
| 124 | * |
| 125 | * \return 0 if successful, or a specific X509 or PEM error code |
| 126 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 127 | 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] | 128 | #endif /* MBEDTLS_FS_IO */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * \brief Returns an informational string about the |
| 132 | * CSR. |
| 133 | * |
| 134 | * \param buf Buffer to write to |
| 135 | * \param size Maximum size of buffer |
| 136 | * \param prefix A line prefix |
| 137 | * \param csr The X509 CSR to represent |
| 138 | * |
Manuel Pégourié-Gonnard | e244f9f | 2015-06-23 12:10:45 +0200 | [diff] [blame] | 139 | * \return The length of the string written (not including the |
| 140 | * terminated nul byte), or a negative error code. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 141 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 142 | int mbedtls_x509_csr_info(char *buf, size_t size, const char *prefix, |
| 143 | const mbedtls_x509_csr *csr); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 144 | |
| 145 | /** |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 146 | * \brief Initialize a CSR |
| 147 | * |
| 148 | * \param csr CSR to initialize |
| 149 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 150 | void mbedtls_x509_csr_init(mbedtls_x509_csr *csr); |
Paul Bakker | 369d2eb | 2013-09-18 11:58:25 +0200 | [diff] [blame] | 151 | |
| 152 | /** |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 153 | * \brief Unallocate all CSR data |
| 154 | * |
| 155 | * \param csr CSR to free |
| 156 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 157 | void mbedtls_x509_csr_free(mbedtls_x509_csr *csr); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 158 | #endif /* MBEDTLS_X509_CSR_PARSE_C */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 159 | |
Andrzej Kurek | 73afe27 | 2022-01-24 10:31:06 -0500 | [diff] [blame] | 160 | /** \} name Structures and functions for X.509 Certificate Signing Requests (CSR) */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 161 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 162 | #if defined(MBEDTLS_X509_CSR_WRITE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 163 | /** |
| 164 | * \brief Initialize a CSR context |
| 165 | * |
| 166 | * \param ctx CSR context to initialize |
| 167 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 168 | void mbedtls_x509write_csr_init(mbedtls_x509write_csr *ctx); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * \brief Set the subject name for a CSR |
| 172 | * Subject names should contain a comma-separated list |
| 173 | * of OID types and values: |
Manuel Pégourié-Gonnard | b4fe3cb | 2015-01-22 16:11:05 +0000 | [diff] [blame] | 174 | * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1" |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 175 | * |
| 176 | * \param ctx CSR context to use |
| 177 | * \param subject_name subject name to set |
| 178 | * |
| 179 | * \return 0 if subject name was parsed successfully, or |
| 180 | * a specific error code |
| 181 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 182 | int mbedtls_x509write_csr_set_subject_name(mbedtls_x509write_csr *ctx, |
| 183 | const char *subject_name); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * \brief Set the key for a CSR (public key will be included, |
| 187 | * private key used to sign the CSR when writing it) |
| 188 | * |
| 189 | * \param ctx CSR context to use |
Shaun Case | 0e7791f | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 190 | * \param key Asymmetric key to include |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 191 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 192 | 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] | 193 | |
| 194 | /** |
| 195 | * \brief Set the MD algorithm to use for the signature |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | * (e.g. MBEDTLS_MD_SHA1) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 197 | * |
| 198 | * \param ctx CSR context to use |
| 199 | * \param md_alg MD algorithm to use |
| 200 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 201 | 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] | 202 | |
| 203 | /** |
| 204 | * \brief Set the Key Usage Extension flags |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 205 | * (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] | 206 | * |
| 207 | * \param ctx CSR context to use |
| 208 | * \param key_usage key usage flags to set |
| 209 | * |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 210 | * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED |
Andres Amaya Garcia | d8233f7 | 2018-10-08 19:44:55 +0100 | [diff] [blame] | 211 | * |
| 212 | * \note The <code>decipherOnly</code> flag from the Key Usage |
| 213 | * extension is represented by bit 8 (i.e. |
| 214 | * <code>0x8000</code>), which cannot typically be represented |
| 215 | * in an unsigned char. Therefore, the flag |
| 216 | * <code>decipherOnly</code> (i.e. |
| 217 | * #MBEDTLS_X509_KU_DECIPHER_ONLY) cannot be set using this |
| 218 | * function. |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 219 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 220 | 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] | 221 | |
| 222 | /** |
| 223 | * \brief Set the Netscape Cert Type flags |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 224 | * (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] | 225 | * |
| 226 | * \param ctx CSR context to use |
| 227 | * \param ns_cert_type Netscape Cert Type flags to set |
| 228 | * |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 229 | * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 230 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 231 | int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr *ctx, |
| 232 | unsigned char ns_cert_type); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 233 | |
| 234 | /** |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 235 | * \brief Generic function to add to or replace an extension in the |
| 236 | * CSR |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 237 | * |
| 238 | * \param ctx CSR context to use |
| 239 | * \param oid OID of the extension |
| 240 | * \param oid_len length of the OID |
| 241 | * \param val value of the extension OCTET STRING |
| 242 | * \param val_len length of the value data |
| 243 | * |
Manuel Pégourié-Gonnard | 6a8ca33 | 2015-05-28 09:33:39 +0200 | [diff] [blame] | 244 | * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 245 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 246 | int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr *ctx, |
| 247 | const char *oid, size_t oid_len, |
| 248 | const unsigned char *val, size_t val_len); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * \brief Free the contents of a CSR context |
| 252 | * |
| 253 | * \param ctx CSR context to free |
| 254 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 255 | void mbedtls_x509write_csr_free(mbedtls_x509write_csr *ctx); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * \brief Write a CSR (Certificate Signing Request) to a |
| 259 | * DER structure |
| 260 | * Note: data is written at the end of the buffer! Use the |
| 261 | * return value to determine where you should start |
| 262 | * using the buffer |
| 263 | * |
| 264 | * \param ctx CSR to write away |
| 265 | * \param buf buffer to write to |
| 266 | * \param size size of the buffer |
| 267 | * \param f_rng RNG function (for signature, see note) |
| 268 | * \param p_rng RNG parameter |
| 269 | * |
| 270 | * \return length of data written if successful, or a specific |
| 271 | * error code |
| 272 | * |
| 273 | * \note f_rng may be NULL if RSA is used for signature and the |
| 274 | * signature is made offline (otherwise f_rng is desirable |
| 275 | * for countermeasures against timing attacks). |
| 276 | * ECDSA signatures always require a non-NULL f_rng. |
| 277 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 278 | int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size, |
| 279 | int (*f_rng)(void *, unsigned char *, size_t), |
| 280 | void *p_rng); |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 281 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 282 | #if defined(MBEDTLS_PEM_WRITE_C) |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 283 | /** |
| 284 | * \brief Write a CSR (Certificate Signing Request) to a |
| 285 | * PEM string |
| 286 | * |
| 287 | * \param ctx CSR to write away |
| 288 | * \param buf buffer to write to |
| 289 | * \param size size of the buffer |
| 290 | * \param f_rng RNG function (for signature, see note) |
| 291 | * \param p_rng RNG parameter |
| 292 | * |
Manuel Pégourié-Gonnard | 81abefd | 2015-05-29 12:53:47 +0200 | [diff] [blame] | 293 | * \return 0 if successful, or a specific error code |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 294 | * |
| 295 | * \note f_rng may be NULL if RSA is used for signature and the |
| 296 | * signature is made offline (otherwise f_rng is desirable |
Andres AG | cd15327 | 2016-10-04 12:06:50 +0100 | [diff] [blame] | 297 | * for countermeasures against timing attacks). |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 298 | * ECDSA signatures always require a non-NULL f_rng. |
| 299 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 300 | int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size, |
| 301 | int (*f_rng)(void *, unsigned char *, size_t), |
| 302 | void *p_rng); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 303 | #endif /* MBEDTLS_PEM_WRITE_C */ |
| 304 | #endif /* MBEDTLS_X509_CSR_WRITE_C */ |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 305 | |
Andrzej Kurek | ff632d5 | 2022-01-24 10:32:00 -0500 | [diff] [blame] | 306 | /** \} addtogroup x509_module */ |
| 307 | |
Paul Bakker | 7c6b2c3 | 2013-09-16 13:49:26 +0200 | [diff] [blame] | 308 | #ifdef __cplusplus |
| 309 | } |
| 310 | #endif |
| 311 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 312 | #endif /* mbedtls_x509_csr.h */ |