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