Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file x509write.h |
| 3 | * |
| 4 | * \brief X509 buffer writing functionality |
| 5 | * |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 26 | */ |
| 27 | #ifndef POLARSSL_X509_WRITE_H |
| 28 | #define POLARSSL_X509_WRITE_H |
| 29 | |
Paul Bakker | bc956d9 | 2013-04-19 14:51:29 +0200 | [diff] [blame] | 30 | #include "config.h" |
| 31 | |
Paul Bakker | fde4270 | 2013-08-25 14:47:27 +0200 | [diff] [blame] | 32 | #include "x509.h" |
Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 33 | |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 34 | /** |
| 35 | * \addtogroup x509_module |
| 36 | * \{ |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * \name X509 Write Error codes |
| 41 | * \{ |
| 42 | */ |
Paul Bakker | 0e06c0f | 2013-08-25 11:21:30 +0200 | [diff] [blame] | 43 | #define POLARSSL_ERR_X509WRITE_UNKNOWN_OID -0x5F80 /**< Requested OID is unknown. */ |
| 44 | #define POLARSSL_ERR_X509WRITE_BAD_INPUT_DATA -0x5F00 /**< Failed to allocate memory. */ |
| 45 | #define POLARSSL_ERR_X509WRITE_MALLOC_FAILED -0x5E80 /**< Failed to allocate memory. */ |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 46 | /* \} name */ |
| 47 | /* \} addtogroup x509_module */ |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 48 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 53 | /** |
| 54 | * \addtogroup x509_module |
| 55 | * \{ |
| 56 | */ |
| 57 | |
| 58 | /** |
| 59 | * \name Structures for writing X.509 CSRs (Certificate Signing Request) |
| 60 | * \{ |
| 61 | */ |
| 62 | |
| 63 | /** |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 64 | * Container for a CSR |
| 65 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 66 | typedef struct _x509write_csr |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 67 | { |
Manuel Pégourié-Gonnard | 5353a03 | 2013-09-11 12:14:26 +0200 | [diff] [blame] | 68 | pk_context *key; |
Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 69 | asn1_named_data *subject; |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 70 | md_type_t md_alg; |
Paul Bakker | e5eae76 | 2013-08-26 12:05:14 +0200 | [diff] [blame] | 71 | asn1_named_data *extensions; |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 72 | } |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 73 | x509write_csr; |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 74 | |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 75 | #define X509_CRT_VERSION_1 0 |
| 76 | #define X509_CRT_VERSION_2 1 |
| 77 | #define X509_CRT_VERSION_3 2 |
| 78 | |
| 79 | #define X509_RFC5280_MAX_SERIAL_LEN 32 |
| 80 | #define X509_RFC5280_UTC_TIME_LEN 15 |
| 81 | |
| 82 | /** |
| 83 | * Container for writing a certificate (CRT) |
| 84 | */ |
| 85 | typedef struct _x509write_cert |
| 86 | { |
| 87 | int version; |
| 88 | mpi serial; |
Manuel Pégourié-Gonnard | 53c6425 | 2013-09-12 05:39:46 +0200 | [diff] [blame] | 89 | pk_context *subject_key; |
| 90 | pk_context *issuer_key; |
Paul Bakker | 5f45e62 | 2013-09-09 12:02:36 +0200 | [diff] [blame] | 91 | asn1_named_data *subject; |
| 92 | asn1_named_data *issuer; |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 93 | md_type_t md_alg; |
| 94 | char not_before[X509_RFC5280_UTC_TIME_LEN + 1]; |
| 95 | char not_after[X509_RFC5280_UTC_TIME_LEN + 1]; |
| 96 | asn1_named_data *extensions; |
| 97 | } |
| 98 | x509write_cert; |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 99 | |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 100 | /* \} name */ |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 101 | /* \} addtogroup x509_module */ |
| 102 | |
| 103 | /** |
| 104 | * \brief Initialize a CSR context |
| 105 | * |
| 106 | * \param ctx CSR context to initialize |
| 107 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 108 | void x509write_csr_init( x509write_csr *ctx ); |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * \brief Set the subject name for a CSR |
| 112 | * Subject names should contain a comma-separated list |
| 113 | * of OID types and values: |
| 114 | * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1" |
| 115 | * |
| 116 | * \param ctx CSR context to use |
| 117 | * \param subject_name subject name to set |
| 118 | * |
| 119 | * \return 0 if subject name was parsed successfully, or |
| 120 | * a specific error code |
| 121 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 122 | int x509write_csr_set_subject_name( x509write_csr *ctx, char *subject_name ); |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 123 | |
| 124 | /** |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 125 | * \brief Set the key for a CSR (public key will be included, |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 126 | * private key used to sign the CSR when writing it) |
| 127 | * |
| 128 | * \param ctx CSR context to use |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 129 | * \param key Asymetric key to include |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 130 | */ |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 131 | void x509write_csr_set_key( x509write_csr *ctx, pk_context *key ); |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * \brief Set the MD algorithm to use for the signature |
| 135 | * (e.g. POLARSSL_MD_SHA1) |
| 136 | * |
| 137 | * \param ctx CSR context to use |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 138 | * \param md_alg MD algorithm to use |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 139 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 140 | void x509write_csr_set_md_alg( x509write_csr *ctx, md_type_t md_alg ); |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 141 | |
| 142 | /** |
Paul Bakker | fde4270 | 2013-08-25 14:47:27 +0200 | [diff] [blame] | 143 | * \brief Set the Key Usage Extension flags |
| 144 | * (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN) |
| 145 | * |
| 146 | * \param ctx CSR context to use |
Paul Bakker | 1c0e550 | 2013-08-26 13:41:01 +0200 | [diff] [blame] | 147 | * \param key_usage key usage flags to set |
Paul Bakker | e5eae76 | 2013-08-26 12:05:14 +0200 | [diff] [blame] | 148 | * |
| 149 | * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
Paul Bakker | fde4270 | 2013-08-25 14:47:27 +0200 | [diff] [blame] | 150 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 151 | int x509write_csr_set_key_usage( x509write_csr *ctx, unsigned char key_usage ); |
Paul Bakker | fde4270 | 2013-08-25 14:47:27 +0200 | [diff] [blame] | 152 | |
| 153 | /** |
Paul Bakker | 1c0e550 | 2013-08-26 13:41:01 +0200 | [diff] [blame] | 154 | * \brief Set the Netscape Cert Type flags |
| 155 | * (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL) |
| 156 | * |
| 157 | * \param ctx CSR context to use |
| 158 | * \param ns_cert_type Netscape Cert Type flags to set |
| 159 | * |
| 160 | * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 161 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 162 | int x509write_csr_set_ns_cert_type( x509write_csr *ctx, |
| 163 | unsigned char ns_cert_type ); |
Paul Bakker | 1c0e550 | 2013-08-26 13:41:01 +0200 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * \brief Generic function to add to or replace an extension in the CSR |
| 167 | * |
| 168 | * \param ctx CSR context to use |
| 169 | * \param oid OID of the extension |
| 170 | * \param oid_len length of the OID |
| 171 | * \param val value of the extension OCTET STRING |
| 172 | * \param val_len length of the value data |
| 173 | * |
| 174 | * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 175 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 176 | int x509write_csr_set_extension( x509write_csr *ctx, |
Paul Bakker | 1c0e550 | 2013-08-26 13:41:01 +0200 | [diff] [blame] | 177 | const char *oid, size_t oid_len, |
| 178 | const unsigned char *val, size_t val_len ); |
| 179 | |
| 180 | /** |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 181 | * \brief Free the contents of a CSR context |
| 182 | * |
| 183 | * \param ctx CSR context to free |
| 184 | */ |
Paul Bakker | cd35803 | 2013-09-09 12:08:11 +0200 | [diff] [blame] | 185 | void x509write_csr_free( x509write_csr *ctx ); |
Paul Bakker | 8eabfc1 | 2013-08-25 10:18:25 +0200 | [diff] [blame] | 186 | |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 187 | /** |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 188 | * \brief Initialize a CRT writing context |
| 189 | * |
| 190 | * \param ctx CRT context to initialize |
| 191 | */ |
| 192 | void x509write_crt_init( x509write_cert *ctx ); |
| 193 | |
| 194 | /** |
| 195 | * \brief Set the verion for a Certificate |
| 196 | * Default: X509_CRT_VERSION_3 |
| 197 | * |
| 198 | * \param ctx CRT context to use |
| 199 | * \param version version to set (X509_CRT_VERSION_1, X509_CRT_VERSION_2 or |
| 200 | * X509_CRT_VERSION_3) |
| 201 | */ |
| 202 | void x509write_crt_set_version( x509write_cert *ctx, int version ); |
| 203 | |
| 204 | /** |
| 205 | * \brief Set the serial number for a Certificate. |
| 206 | * |
| 207 | * \param ctx CRT context to use |
| 208 | * \param serial serial number to set |
| 209 | * |
| 210 | * \return 0 if successful |
| 211 | */ |
| 212 | int x509write_crt_set_serial( x509write_cert *ctx, const mpi *serial ); |
| 213 | |
| 214 | /** |
| 215 | * \brief Set the validity period for a Certificate |
| 216 | * Timestamps should be in string format for UTC timezone |
| 217 | * i.e. "YYYYMMDDhhmmss" |
| 218 | * e.g. "20131231235959" for December 31st 2013 |
| 219 | * at 23:59:59 |
| 220 | * |
| 221 | * \param ctx CRT context to use |
| 222 | * \param not_before not_before timestamp |
| 223 | * \param not_after not_after timestamp |
| 224 | * |
| 225 | * \return 0 if timestamp was parsed successfully, or |
| 226 | * a specific error code |
| 227 | */ |
| 228 | int x509write_crt_set_validity( x509write_cert *ctx, char *not_before, |
| 229 | char *not_after ); |
| 230 | |
| 231 | /** |
| 232 | * \brief Set the issuer name for a Certificate |
| 233 | * Issuer names should contain a comma-separated list |
| 234 | * of OID types and values: |
| 235 | * e.g. "C=NL,O=Offspark,CN=PolarSSL CA" |
| 236 | * |
| 237 | * \param ctx CRT context to use |
| 238 | * \param issuer_name issuer name to set |
| 239 | * |
| 240 | * \return 0 if issuer name was parsed successfully, or |
| 241 | * a specific error code |
| 242 | */ |
| 243 | int x509write_crt_set_issuer_name( x509write_cert *ctx, char *issuer_name ); |
| 244 | |
| 245 | /** |
| 246 | * \brief Set the subject name for a Certificate |
| 247 | * Subject names should contain a comma-separated list |
| 248 | * of OID types and values: |
| 249 | * e.g. "C=NL,O=Offspark,CN=PolarSSL Server 1" |
| 250 | * |
| 251 | * \param ctx CRT context to use |
| 252 | * \param subject_name subject name to set |
| 253 | * |
| 254 | * \return 0 if subject name was parsed successfully, or |
| 255 | * a specific error code |
| 256 | */ |
| 257 | int x509write_crt_set_subject_name( x509write_cert *ctx, char *subject_name ); |
| 258 | |
| 259 | /** |
| 260 | * \brief Set the subject public key for the certificate |
| 261 | * |
| 262 | * \param ctx CRT context to use |
Manuel Pégourié-Gonnard | f38e71a | 2013-09-12 05:21:54 +0200 | [diff] [blame] | 263 | * \param key public key to include |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 264 | */ |
Manuel Pégourié-Gonnard | f38e71a | 2013-09-12 05:21:54 +0200 | [diff] [blame] | 265 | void x509write_crt_set_subject_key( x509write_cert *ctx, pk_context *key ); |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 266 | |
| 267 | /** |
| 268 | * \brief Set the issuer key used for signing the certificate |
| 269 | * |
| 270 | * \param ctx CRT context to use |
Manuel Pégourié-Gonnard | f38e71a | 2013-09-12 05:21:54 +0200 | [diff] [blame] | 271 | * \param key private key to sign with |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 272 | */ |
Manuel Pégourié-Gonnard | f38e71a | 2013-09-12 05:21:54 +0200 | [diff] [blame] | 273 | void x509write_crt_set_issuer_key( x509write_cert *ctx, pk_context *key ); |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * \brief Set the MD algorithm to use for the signature |
| 277 | * (e.g. POLARSSL_MD_SHA1) |
| 278 | * |
| 279 | * \param ctx CRT context to use |
| 280 | * \param md_ald MD algorithm to use |
| 281 | */ |
| 282 | void x509write_crt_set_md_alg( x509write_cert *ctx, md_type_t md_alg ); |
| 283 | |
| 284 | /** |
Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 285 | * \brief Generic function to add to or replace an extension in the |
| 286 | * CRT |
| 287 | * |
| 288 | * \param ctx CRT context to use |
| 289 | * \param oid OID of the extension |
| 290 | * \param oid_len length of the OID |
| 291 | * \param critical if the extension is critical (per the RFC's definition) |
| 292 | * \param val value of the extension OCTET STRING |
| 293 | * \param val_len length of the value data |
| 294 | * |
| 295 | * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 296 | */ |
| 297 | int x509write_crt_set_extension( x509write_cert *ctx, |
| 298 | const char *oid, size_t oid_len, |
| 299 | int critical, |
| 300 | const unsigned char *val, size_t val_len ); |
| 301 | |
| 302 | /** |
| 303 | * \brief Set the basicConstraints extension for a CRT |
| 304 | * |
| 305 | * \param ctx CRT context to use |
| 306 | * \param is_ca is this a CA certificate |
| 307 | * \param max_pathlen maximum length of certificate chains below this |
| 308 | * certificate (only for CA certificates, -1 is |
| 309 | * inlimited) |
| 310 | * |
| 311 | * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 312 | */ |
| 313 | int x509write_crt_set_basic_constraints( x509write_cert *ctx, |
| 314 | int is_ca, int max_pathlen ); |
| 315 | |
| 316 | /** |
| 317 | * \brief Set the subjectKeyIdentifier extension for a CRT |
| 318 | * Requires that x509write_crt_set_subject_key() has been |
| 319 | * called before |
| 320 | * |
| 321 | * \param ctx CRT context to use |
| 322 | * |
| 323 | * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 324 | */ |
| 325 | int x509write_crt_set_subject_key_identifier( x509write_cert *ctx ); |
| 326 | |
| 327 | /** |
| 328 | * \brief Set the authorityKeyIdentifier extension for a CRT |
| 329 | * Requires that x509write_crt_set_issuer_key() has been |
| 330 | * called before |
| 331 | * |
| 332 | * \param ctx CRT context to use |
| 333 | * |
| 334 | * \return 0 if successful, or a POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 335 | */ |
| 336 | int x509write_crt_set_authority_key_identifier( x509write_cert *ctx ); |
| 337 | |
| 338 | /** |
Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 339 | * \brief Set the Key Usage Extension flags |
| 340 | * (e.g. KU_DIGITAL_SIGNATURE | KU_KEY_CERT_SIGN) |
| 341 | * |
| 342 | * \param ctx CRT context to use |
| 343 | * \param key_usage key usage flags to set |
| 344 | * |
| 345 | * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 346 | */ |
| 347 | int x509write_crt_set_key_usage( x509write_cert *ctx, unsigned char key_usage ); |
| 348 | |
| 349 | /** |
| 350 | * \brief Set the Netscape Cert Type flags |
| 351 | * (e.g. NS_CERT_TYPE_SSL_CLIENT | NS_CERT_TYPE_EMAIL) |
| 352 | * |
| 353 | * \param ctx CRT context to use |
| 354 | * \param ns_cert_type Netscape Cert Type flags to set |
| 355 | * |
| 356 | * \return 0 if successful, or POLARSSL_ERR_X509WRITE_MALLOC_FAILED |
| 357 | */ |
| 358 | int x509write_crt_set_ns_cert_type( x509write_cert *ctx, |
| 359 | unsigned char ns_cert_type ); |
| 360 | |
| 361 | /** |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 362 | * \brief Free the contents of a CRT write context |
| 363 | * |
| 364 | * \param ctx CRT context to free |
| 365 | */ |
| 366 | void x509write_crt_free( x509write_cert *ctx ); |
| 367 | |
| 368 | /** |
| 369 | * \brief Write a built up certificate to a X509 DER structure |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 370 | * Note: data is written at the end of the buffer! Use the |
| 371 | * return value to determine where you should start |
| 372 | * using the buffer |
| 373 | * |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 374 | * \param crt certificate to write away |
| 375 | * \param buf buffer to write to |
| 376 | * \param size size of the buffer |
Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 377 | * \param f_rng RNG function (for signature, see note) |
| 378 | * \param p_rng RNG parameter |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 379 | * |
| 380 | * \return length of data written if successful, or a specific |
| 381 | * error code |
Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 382 | * |
| 383 | * \note f_rng may be NULL if RSA is used for signature and the |
| 384 | * signature is made offline (otherwise f_rng is desirable |
| 385 | * for countermeasures against timing attacks). |
| 386 | * ECDSA signatures always require a non-NULL f_rng. |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 387 | */ |
Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 388 | int x509write_crt_der( x509write_cert *ctx, unsigned char *buf, size_t size, |
| 389 | int (*f_rng)(void *, unsigned char *, size_t), |
| 390 | void *p_rng ); |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 391 | |
| 392 | /** |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 393 | * \brief Write a CSR (Certificate Signing Request) to a |
| 394 | * DER structure |
| 395 | * Note: data is written at the end of the buffer! Use the |
| 396 | * return value to determine where you should start |
| 397 | * using the buffer |
| 398 | * |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 399 | * \param ctx CSR to write away |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 400 | * \param buf buffer to write to |
| 401 | * \param size size of the buffer |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 402 | * \param f_rng RNG function (for signature, see note) |
| 403 | * \param p_rng RNG parameter |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 404 | * |
| 405 | * \return length of data written if successful, or a specific |
| 406 | * error code |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 407 | * |
| 408 | * \note f_rng may be NULL if RSA is used for signature and the |
| 409 | * signature is made offline (otherwise f_rng is desirable |
| 410 | * for countermeasures against timing attacks). |
| 411 | * ECDSA signatures always require a non-NULL f_rng. |
Paul Bakker | f677466 | 2013-08-25 11:47:51 +0200 | [diff] [blame] | 412 | */ |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 413 | int x509write_csr_der( x509write_csr *ctx, unsigned char *buf, size_t size, |
| 414 | int (*f_rng)(void *, unsigned char *, size_t), |
| 415 | void *p_rng ); |
Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 416 | |
Paul Bakker | 77e23fb | 2013-09-15 20:03:26 +0200 | [diff] [blame^] | 417 | #if defined(POLARSSL_PEM_C) |
Paul Bakker | 135f1e9 | 2013-08-26 16:54:13 +0200 | [diff] [blame] | 418 | /** |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 419 | * \brief Write a built up certificate to a X509 PEM string |
Paul Bakker | f3df61a | 2013-08-26 17:22:23 +0200 | [diff] [blame] | 420 | * |
Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 421 | * \param crt certificate to write away |
Paul Bakker | f3df61a | 2013-08-26 17:22:23 +0200 | [diff] [blame] | 422 | * \param buf buffer to write to |
| 423 | * \param size size of the buffer |
Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 424 | * \param f_rng RNG function (for signature, see note) |
| 425 | * \param p_rng RNG parameter |
Paul Bakker | f3df61a | 2013-08-26 17:22:23 +0200 | [diff] [blame] | 426 | * |
| 427 | * \return 0 successful, or a specific error code |
Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 428 | * |
| 429 | * \note f_rng may be NULL if RSA is used for signature and the |
| 430 | * signature is made offline (otherwise f_rng is desirable |
| 431 | * for countermeasures against timing attacks). |
| 432 | * ECDSA signatures always require a non-NULL f_rng. |
Paul Bakker | f3df61a | 2013-08-26 17:22:23 +0200 | [diff] [blame] | 433 | */ |
Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 434 | int x509write_crt_pem( x509write_cert *ctx, unsigned char *buf, size_t size, |
| 435 | int (*f_rng)(void *, unsigned char *, size_t), |
| 436 | void *p_rng ); |
Paul Bakker | f3df61a | 2013-08-26 17:22:23 +0200 | [diff] [blame] | 437 | |
| 438 | /** |
Paul Bakker | 135f1e9 | 2013-08-26 16:54:13 +0200 | [diff] [blame] | 439 | * \brief Write a CSR (Certificate Signing Request) to a |
| 440 | * PEM string |
| 441 | * |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 442 | * \param ctx CSR to write away |
Paul Bakker | 135f1e9 | 2013-08-26 16:54:13 +0200 | [diff] [blame] | 443 | * \param buf buffer to write to |
| 444 | * \param size size of the buffer |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 445 | * \param f_rng RNG function (for signature, see note) |
| 446 | * \param p_rng RNG parameter |
Paul Bakker | 135f1e9 | 2013-08-26 16:54:13 +0200 | [diff] [blame] | 447 | * |
| 448 | * \return 0 successful, or a specific error code |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 449 | * |
| 450 | * \note f_rng may be NULL if RSA is used for signature and the |
| 451 | * signature is made offline (otherwise f_rng is desirable |
| 452 | * for couermeasures against timing attacks). |
| 453 | * ECDSA signatures always require a non-NULL f_rng. |
Paul Bakker | 135f1e9 | 2013-08-26 16:54:13 +0200 | [diff] [blame] | 454 | */ |
Manuel Pégourié-Gonnard | ee73179 | 2013-09-11 22:48:40 +0200 | [diff] [blame] | 455 | int x509write_csr_pem( x509write_csr *ctx, unsigned char *buf, size_t size, |
| 456 | int (*f_rng)(void *, unsigned char *, size_t), |
| 457 | void *p_rng ); |
Paul Bakker | 77e23fb | 2013-09-15 20:03:26 +0200 | [diff] [blame^] | 458 | #endif /* POLARSSL_PEM_C */ |
Paul Bakker | 135f1e9 | 2013-08-26 16:54:13 +0200 | [diff] [blame] | 459 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 460 | #ifdef __cplusplus |
| 461 | } |
| 462 | #endif |
| 463 | |
Paul Bakker | bdb912d | 2012-02-13 23:11:30 +0000 | [diff] [blame] | 464 | #endif /* POLARSSL_X509_WRITE_H */ |