blob: f481155e98a26578b1ef8817909bb5417c92eeeb [file] [log] [blame]
Paul Bakker7c6b2c32013-09-16 13:49:26 +02001/*
2 * X.509 certificate writing
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker7c6b2c32013-09-16 13:49:26 +020018 */
19/*
20 * References:
21 * - certificates: RFC 5280, updated by RFC 6818
22 * - CSRs: PKCS#10 v1.7 aka RFC 2986
23 * - attributes: PKCS#9 v2.0 aka RFC 2985
24 */
25
Gilles Peskinedb09ef62020-06-03 01:43:33 +020026#include "common.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if defined(MBEDTLS_X509_CRT_WRITE_C)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020029
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030#include "mbedtls/x509_crt.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000031#include "mbedtls/asn1write.h"
Janos Follath73c616b2019-12-18 15:07:04 +000032#include "mbedtls/error.h"
33#include "mbedtls/oid.h"
Andres Amaya Garcia1f6301b2018-04-17 09:51:09 -050034#include "mbedtls/platform_util.h"
Manuel Pégourié-Gonnard2cd75142023-02-24 12:37:07 +010035#include "mbedtls/md.h"
Paul Bakker7c6b2c32013-09-16 13:49:26 +020036
Rich Evans00ab4702015-02-06 13:43:58 +000037#include <string.h>
38
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_PEM_WRITE_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000040#include "mbedtls/pem.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#endif /* MBEDTLS_PEM_WRITE_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +020042
pespacek7599a772022-02-07 14:40:55 +010043#if defined(MBEDTLS_USE_PSA_CRYPTO)
44#include "psa/crypto.h"
45#include "mbedtls/psa_util.h"
46#endif /* MBEDTLS_USE_PSA_CRYPTO */
47
Przemek Stekiel40afdd22022-09-06 13:08:28 +020048#include "hash_info.h"
Manuel Pégourié-Gonnard07018f92022-09-15 11:29:35 +020049#include "mbedtls/legacy_or_psa.h"
Przemek Stekielfd183662022-08-02 15:29:20 +020050
Gilles Peskine449bd832023-01-11 14:50:10 +010051void mbedtls_x509write_crt_init(mbedtls_x509write_cert *ctx)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052{
Gilles Peskine449bd832023-01-11 14:50:10 +010053 memset(ctx, 0, sizeof(mbedtls_x509write_cert));
Paul Bakker7c6b2c32013-09-16 13:49:26 +020054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055 ctx->version = MBEDTLS_X509_CRT_VERSION_3;
Paul Bakker7c6b2c32013-09-16 13:49:26 +020056}
57
Gilles Peskine449bd832023-01-11 14:50:10 +010058void mbedtls_x509write_crt_free(mbedtls_x509write_cert *ctx)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020059{
Gilles Peskine449bd832023-01-11 14:50:10 +010060 mbedtls_asn1_free_named_data_list(&ctx->subject);
61 mbedtls_asn1_free_named_data_list(&ctx->issuer);
62 mbedtls_asn1_free_named_data_list(&ctx->extensions);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020063
Gilles Peskine449bd832023-01-11 14:50:10 +010064 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_x509write_cert));
Paul Bakker7c6b2c32013-09-16 13:49:26 +020065}
66
Gilles Peskine449bd832023-01-11 14:50:10 +010067void mbedtls_x509write_crt_set_version(mbedtls_x509write_cert *ctx,
68 int version)
Paul Bakker5191e922013-10-11 10:54:28 +020069{
70 ctx->version = version;
71}
72
Gilles Peskine449bd832023-01-11 14:50:10 +010073void mbedtls_x509write_crt_set_md_alg(mbedtls_x509write_cert *ctx,
74 mbedtls_md_type_t md_alg)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020075{
76 ctx->md_alg = md_alg;
77}
78
Gilles Peskine449bd832023-01-11 14:50:10 +010079void mbedtls_x509write_crt_set_subject_key(mbedtls_x509write_cert *ctx,
80 mbedtls_pk_context *key)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020081{
82 ctx->subject_key = key;
83}
84
Gilles Peskine449bd832023-01-11 14:50:10 +010085void mbedtls_x509write_crt_set_issuer_key(mbedtls_x509write_cert *ctx,
86 mbedtls_pk_context *key)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020087{
88 ctx->issuer_key = key;
89}
90
Gilles Peskine449bd832023-01-11 14:50:10 +010091int mbedtls_x509write_crt_set_subject_name(mbedtls_x509write_cert *ctx,
92 const char *subject_name)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020093{
Gilles Peskine449bd832023-01-11 14:50:10 +010094 return mbedtls_x509_string_to_names(&ctx->subject, subject_name);
Paul Bakker7c6b2c32013-09-16 13:49:26 +020095}
96
Gilles Peskine449bd832023-01-11 14:50:10 +010097int mbedtls_x509write_crt_set_issuer_name(mbedtls_x509write_cert *ctx,
98 const char *issuer_name)
Paul Bakker7c6b2c32013-09-16 13:49:26 +020099{
Gilles Peskine449bd832023-01-11 14:50:10 +0100100 return mbedtls_x509_string_to_names(&ctx->issuer, issuer_name);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200101}
102
Valerio Setti5d164c42023-01-09 12:19:40 +0100103#if defined(MBEDTLS_BIGNUM_C) && !defined(MBEDTLS_DEPRECATED_REMOVED)
Gilles Peskine449bd832023-01-11 14:50:10 +0100104int mbedtls_x509write_crt_set_serial(mbedtls_x509write_cert *ctx,
105 const mbedtls_mpi *serial)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200106{
Valerio Settida0afcc2023-01-05 16:46:59 +0100107 int ret;
Valerio Settida0afcc2023-01-05 16:46:59 +0100108 size_t tmp_len;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200109
Valerio Settida0afcc2023-01-05 16:46:59 +0100110 /* Ensure that the MPI value fits into the buffer */
111 tmp_len = mbedtls_mpi_size(serial);
112 if (tmp_len > MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN) {
113 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
114 }
115
116 ctx->serial_len = tmp_len;
117
Valerio Setti4752aac2023-01-10 16:00:15 +0100118 ret = mbedtls_mpi_write_binary(serial, ctx->serial, tmp_len);
Valerio Settida0afcc2023-01-05 16:46:59 +0100119 if (ret < 0) {
Gilles Peskine449bd832023-01-11 14:50:10 +0100120 return ret;
121 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200122
Valerio Settida0afcc2023-01-05 16:46:59 +0100123 return 0;
124}
Valerio Setti5d164c42023-01-09 12:19:40 +0100125#endif // MBEDTLS_BIGNUM_C && !MBEDTLS_DEPRECATED_REMOVED
Valerio Settida0afcc2023-01-05 16:46:59 +0100126
Valerio Settiaf4815c2023-01-26 17:43:09 +0100127int mbedtls_x509write_crt_set_serial_raw(mbedtls_x509write_cert *ctx,
Valerio Setti746def52023-01-10 11:46:34 +0100128 unsigned char *serial, size_t serial_len)
Valerio Settida0afcc2023-01-05 16:46:59 +0100129{
Valerio Setti746def52023-01-10 11:46:34 +0100130 if (serial_len > MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN) {
Valerio Settida0afcc2023-01-05 16:46:59 +0100131 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
132 }
133
Valerio Setti746def52023-01-10 11:46:34 +0100134 ctx->serial_len = serial_len;
135 memcpy(ctx->serial, serial, serial_len);
Valerio Settida0afcc2023-01-05 16:46:59 +0100136
Gilles Peskine449bd832023-01-11 14:50:10 +0100137 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200138}
139
Gilles Peskine449bd832023-01-11 14:50:10 +0100140int mbedtls_x509write_crt_set_validity(mbedtls_x509write_cert *ctx,
141 const char *not_before,
142 const char *not_after)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200143{
Gilles Peskine449bd832023-01-11 14:50:10 +0100144 if (strlen(not_before) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 ||
145 strlen(not_after) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1) {
146 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200147 }
Gilles Peskine449bd832023-01-11 14:50:10 +0100148 strncpy(ctx->not_before, not_before, MBEDTLS_X509_RFC5280_UTC_TIME_LEN);
149 strncpy(ctx->not_after, not_after, MBEDTLS_X509_RFC5280_UTC_TIME_LEN);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 ctx->not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1] = 'Z';
151 ctx->not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1] = 'Z';
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200152
Gilles Peskine449bd832023-01-11 14:50:10 +0100153 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200154}
155
Gilles Peskine449bd832023-01-11 14:50:10 +0100156int mbedtls_x509write_crt_set_extension(mbedtls_x509write_cert *ctx,
157 const char *oid, size_t oid_len,
158 int critical,
159 const unsigned char *val, size_t val_len)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200160{
Gilles Peskine449bd832023-01-11 14:50:10 +0100161 return mbedtls_x509_set_extension(&ctx->extensions, oid, oid_len,
162 critical, val, val_len);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200163}
164
Gilles Peskine449bd832023-01-11 14:50:10 +0100165int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert *ctx,
166 int is_ca, int max_pathlen)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200167{
Janos Follath865b3eb2019-12-16 11:46:15 +0000168 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200169 unsigned char buf[9];
170 unsigned char *c = buf + sizeof(buf);
171 size_t len = 0;
172
Gilles Peskine449bd832023-01-11 14:50:10 +0100173 memset(buf, 0, sizeof(buf));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200174
Gilles Peskine449bd832023-01-11 14:50:10 +0100175 if (is_ca && max_pathlen > 127) {
176 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200177 }
178
Gilles Peskine449bd832023-01-11 14:50:10 +0100179 if (is_ca) {
180 if (max_pathlen >= 0) {
181 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(&c, buf,
182 max_pathlen));
183 }
184 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_bool(&c, buf, 1));
185 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200186
Gilles Peskine449bd832023-01-11 14:50:10 +0100187 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
188 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf,
189 MBEDTLS_ASN1_CONSTRUCTED |
190 MBEDTLS_ASN1_SEQUENCE));
191
192 return
193 mbedtls_x509write_crt_set_extension(ctx, MBEDTLS_OID_BASIC_CONSTRAINTS,
194 MBEDTLS_OID_SIZE(MBEDTLS_OID_BASIC_CONSTRAINTS),
195 is_ca, buf + sizeof(buf) - len, len);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200196}
197
Przemek Stekiel76b753b2022-08-09 10:54:45 +0200198#if defined(MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA)
Gilles Peskine449bd832023-01-11 14:50:10 +0100199static int mbedtls_x509write_crt_set_key_identifier(mbedtls_x509write_cert *ctx,
200 int is_ca,
201 unsigned char tag)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200202{
Janos Follath865b3eb2019-12-16 11:46:15 +0000203 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204 unsigned char buf[MBEDTLS_MPI_MAX_SIZE * 2 + 20]; /* tag, length + 2xMPI */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200205 unsigned char *c = buf + sizeof(buf);
206 size_t len = 0;
pespacek7599a772022-02-07 14:40:55 +0100207#if defined(MBEDTLS_USE_PSA_CRYPTO)
208 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
209 size_t hash_length;
210#endif /* MBEDTLS_USE_PSA_CRYPTO */
211
Gilles Peskine449bd832023-01-11 14:50:10 +0100212 memset(buf, 0, sizeof(buf));
213 MBEDTLS_ASN1_CHK_ADD(len,
214 mbedtls_pk_write_pubkey(&c,
215 buf,
216 is_ca ?
217 ctx->issuer_key :
218 ctx->subject_key));
pespacek30151482022-02-17 15:18:47 +0100219
pespaceka6e955e2022-02-14 15:20:57 +0100220
pespacek7599a772022-02-07 14:40:55 +0100221#if defined(MBEDTLS_USE_PSA_CRYPTO)
Gilles Peskine449bd832023-01-11 14:50:10 +0100222 status = psa_hash_compute(PSA_ALG_SHA_1,
223 buf + sizeof(buf) - len,
224 len,
225 buf + sizeof(buf) - 20,
226 20,
227 &hash_length);
228 if (status != PSA_SUCCESS) {
229 return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
pespacek7599a772022-02-07 14:40:55 +0100230 }
231#else
Manuel Pégourié-Gonnard2cd75142023-02-24 12:37:07 +0100232 ret = mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1),
233 buf + sizeof(buf) - len, len,
234 buf + sizeof(buf) - 20);
Gilles Peskine449bd832023-01-11 14:50:10 +0100235 if (ret != 0) {
236 return ret;
237 }
pespacek7599a772022-02-07 14:40:55 +0100238#endif /* MBEDTLS_USE_PSA_CRYPTO */
239
Gilles Peskine449bd832023-01-11 14:50:10 +0100240 c = buf + sizeof(buf) - 20;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200241 len = 20;
242
Gilles Peskine449bd832023-01-11 14:50:10 +0100243 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
244 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, tag));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200245
Gilles Peskine449bd832023-01-11 14:50:10 +0100246 if (is_ca) { // writes AuthorityKeyIdentifier sequence
247 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
248 MBEDTLS_ASN1_CHK_ADD(len,
249 mbedtls_asn1_write_tag(&c,
250 buf,
251 MBEDTLS_ASN1_CONSTRUCTED |
252 MBEDTLS_ASN1_SEQUENCE));
pespacek30151482022-02-17 15:18:47 +0100253 }
pespacekd924e552022-02-28 11:49:54 +0100254
Gilles Peskine449bd832023-01-11 14:50:10 +0100255 if (is_ca) {
256 return mbedtls_x509write_crt_set_extension(ctx,
257 MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER,
258 MBEDTLS_OID_SIZE(
259 MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER),
260 0, buf + sizeof(buf) - len, len);
261 } else {
262 return mbedtls_x509write_crt_set_extension(ctx,
263 MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER,
264 MBEDTLS_OID_SIZE(
265 MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER),
266 0, buf + sizeof(buf) - len, len);
267 }
pespaceka6e955e2022-02-14 15:20:57 +0100268}
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200269
Gilles Peskine449bd832023-01-11 14:50:10 +0100270int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert *ctx)
pespaceka6e955e2022-02-14 15:20:57 +0100271{
Gilles Peskine449bd832023-01-11 14:50:10 +0100272 return mbedtls_x509write_crt_set_key_identifier(ctx,
273 0,
274 MBEDTLS_ASN1_OCTET_STRING);
pespaceka6e955e2022-02-14 15:20:57 +0100275}
276
Gilles Peskine449bd832023-01-11 14:50:10 +0100277int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert *ctx)
pespaceka6e955e2022-02-14 15:20:57 +0100278{
Gilles Peskine449bd832023-01-11 14:50:10 +0100279 return mbedtls_x509write_crt_set_key_identifier(ctx,
280 1,
281 (MBEDTLS_ASN1_CONTEXT_SPECIFIC | 0));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200282}
Przemek Stekiel41465252022-08-18 12:43:07 +0200283#endif /* MBEDTLS_HAS_ALG_SHA_1_VIA_MD_OR_PSA_BASED_ON_USE_PSA */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200284
Gilles Peskine449bd832023-01-11 14:50:10 +0100285int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert *ctx,
286 unsigned int key_usage)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200287{
Gilles Peskine449bd832023-01-11 14:50:10 +0100288 unsigned char buf[5] = { 0 }, ku[2] = { 0 };
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200289 unsigned char *c;
Janos Follath865b3eb2019-12-16 11:46:15 +0000290 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100291 const unsigned int allowed_bits = MBEDTLS_X509_KU_DIGITAL_SIGNATURE |
Gilles Peskine449bd832023-01-11 14:50:10 +0100292 MBEDTLS_X509_KU_NON_REPUDIATION |
293 MBEDTLS_X509_KU_KEY_ENCIPHERMENT |
294 MBEDTLS_X509_KU_DATA_ENCIPHERMENT |
295 MBEDTLS_X509_KU_KEY_AGREEMENT |
296 MBEDTLS_X509_KU_KEY_CERT_SIGN |
297 MBEDTLS_X509_KU_CRL_SIGN |
298 MBEDTLS_X509_KU_ENCIPHER_ONLY |
299 MBEDTLS_X509_KU_DECIPHER_ONLY;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200300
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100301 /* Check that nothing other than the allowed flags is set */
Gilles Peskine449bd832023-01-11 14:50:10 +0100302 if ((key_usage & ~allowed_bits) != 0) {
303 return MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE;
304 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200305
Andres Amaya Garcia6e959142018-09-26 10:48:24 +0100306 c = buf + 5;
Gilles Peskine449bd832023-01-11 14:50:10 +0100307 MBEDTLS_PUT_UINT16_LE(key_usage, ku, 0);
308 ret = mbedtls_asn1_write_named_bitstring(&c, buf, ku, 9);
Manuel Pégourié-Gonnard1cd10ad2015-06-23 11:07:37 +0200309
Gilles Peskine449bd832023-01-11 14:50:10 +0100310 if (ret < 0) {
311 return ret;
312 } else if (ret < 3 || ret > 5) {
313 return MBEDTLS_ERR_X509_INVALID_FORMAT;
314 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200315
Gilles Peskine449bd832023-01-11 14:50:10 +0100316 ret = mbedtls_x509write_crt_set_extension(ctx, MBEDTLS_OID_KEY_USAGE,
317 MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE),
318 1, c, (size_t) ret);
319 if (ret != 0) {
320 return ret;
321 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200322
Gilles Peskine449bd832023-01-11 14:50:10 +0100323 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200324}
325
Gilles Peskine449bd832023-01-11 14:50:10 +0100326int mbedtls_x509write_crt_set_ext_key_usage(mbedtls_x509write_cert *ctx,
327 const mbedtls_asn1_sequence *exts)
Nicholas Wilson8e5bdfb2015-09-09 19:03:34 +0100328{
329 unsigned char buf[256];
330 unsigned char *c = buf + sizeof(buf);
331 int ret;
332 size_t len = 0;
Dave Rodgman5f3f0d02022-08-11 14:38:26 +0100333 const mbedtls_asn1_sequence *last_ext = NULL;
Dave Rodgmane2b772d2022-08-11 16:04:13 +0100334 const mbedtls_asn1_sequence *ext;
Dave Rodgman5f3f0d02022-08-11 14:38:26 +0100335
Gilles Peskine449bd832023-01-11 14:50:10 +0100336 memset(buf, 0, sizeof(buf));
Nicholas Wilson8e5bdfb2015-09-09 19:03:34 +0100337
Nicholas Wilsonca841d32015-11-13 14:22:36 +0000338 /* We need at least one extension: SEQUENCE SIZE (1..MAX) OF KeyPurposeId */
Gilles Peskine449bd832023-01-11 14:50:10 +0100339 if (exts == NULL) {
340 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
341 }
Nicholas Wilson8e5bdfb2015-09-09 19:03:34 +0100342
Nicholas Wilsonca841d32015-11-13 14:22:36 +0000343 /* Iterate over exts backwards, so we write them out in the requested order */
Gilles Peskine449bd832023-01-11 14:50:10 +0100344 while (last_ext != exts) {
345 for (ext = exts; ext->next != last_ext; ext = ext->next) {
346 }
347 if (ext->buf.tag != MBEDTLS_ASN1_OID) {
348 return MBEDTLS_ERR_X509_BAD_INPUT_DATA;
349 }
350 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(&c, buf, ext->buf.p, ext->buf.len));
351 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, ext->buf.len));
352 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_OID));
Nicholas Wilsonca841d32015-11-13 14:22:36 +0000353 last_ext = ext;
Nicholas Wilson8e5bdfb2015-09-09 19:03:34 +0100354 }
355
Gilles Peskine449bd832023-01-11 14:50:10 +0100356 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
357 MBEDTLS_ASN1_CHK_ADD(len,
358 mbedtls_asn1_write_tag(&c, buf,
359 MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE));
Nicholas Wilson8e5bdfb2015-09-09 19:03:34 +0100360
Gilles Peskine449bd832023-01-11 14:50:10 +0100361 return mbedtls_x509write_crt_set_extension(ctx,
362 MBEDTLS_OID_EXTENDED_KEY_USAGE,
363 MBEDTLS_OID_SIZE(MBEDTLS_OID_EXTENDED_KEY_USAGE),
364 1, c, len);
Nicholas Wilson8e5bdfb2015-09-09 19:03:34 +0100365}
366
Gilles Peskine449bd832023-01-11 14:50:10 +0100367int mbedtls_x509write_crt_set_ns_cert_type(mbedtls_x509write_cert *ctx,
368 unsigned char ns_cert_type)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200369{
Gilles Peskine449bd832023-01-11 14:50:10 +0100370 unsigned char buf[4] = { 0 };
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200371 unsigned char *c;
Janos Follath865b3eb2019-12-16 11:46:15 +0000372 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200373
374 c = buf + 4;
375
Gilles Peskine449bd832023-01-11 14:50:10 +0100376 ret = mbedtls_asn1_write_named_bitstring(&c, buf, &ns_cert_type, 8);
377 if (ret < 3 || ret > 4) {
378 return ret;
379 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200380
Gilles Peskine449bd832023-01-11 14:50:10 +0100381 ret = mbedtls_x509write_crt_set_extension(ctx, MBEDTLS_OID_NS_CERT_TYPE,
382 MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE),
383 0, c, (size_t) ret);
384 if (ret != 0) {
385 return ret;
386 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200387
Gilles Peskine449bd832023-01-11 14:50:10 +0100388 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200389}
390
Gilles Peskine449bd832023-01-11 14:50:10 +0100391static int x509_write_time(unsigned char **p, unsigned char *start,
392 const char *t, size_t size)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200393{
Janos Follath865b3eb2019-12-16 11:46:15 +0000394 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200395 size_t len = 0;
396
397 /*
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200398 * write MBEDTLS_ASN1_UTC_TIME if year < 2050 (2 bytes shorter)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200399 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100400 if (t[0] < '2' || (t[0] == '2' && t[1] == '0' && t[2] < '5')) {
401 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start,
402 (const unsigned char *) t + 2,
403 size - 2));
404 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
405 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start,
406 MBEDTLS_ASN1_UTC_TIME));
407 } else {
408 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start,
409 (const unsigned char *) t,
410 size));
411 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len));
412 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start,
413 MBEDTLS_ASN1_GENERALIZED_TIME));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200414 }
415
Gilles Peskine449bd832023-01-11 14:50:10 +0100416 return (int) len;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200417}
418
Gilles Peskine449bd832023-01-11 14:50:10 +0100419int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx,
420 unsigned char *buf, size_t size,
421 int (*f_rng)(void *, unsigned char *, size_t),
422 void *p_rng)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200423{
Janos Follath865b3eb2019-12-16 11:46:15 +0000424 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200425 const char *sig_oid;
426 size_t sig_oid_len = 0;
427 unsigned char *c, *c2;
Gilles Peskinebf887802019-11-08 19:21:51 +0100428 unsigned char sig[MBEDTLS_PK_SIGNATURE_MAX_SIZE];
pespacek7599a772022-02-07 14:40:55 +0100429 size_t hash_length = 0;
Przemek Stekiel40afdd22022-09-06 13:08:28 +0200430 unsigned char hash[MBEDTLS_HASH_MAX_SIZE];
pespacek7599a772022-02-07 14:40:55 +0100431#if defined(MBEDTLS_USE_PSA_CRYPTO)
432 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
433 psa_algorithm_t psa_algorithm;
pespacek7599a772022-02-07 14:40:55 +0100434#endif /* MBEDTLS_USE_PSA_CRYPTO */
435
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200436 size_t sub_len = 0, pub_len = 0, sig_and_oid_len = 0, sig_len;
437 size_t len = 0;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200438 mbedtls_pk_type_t pk_alg;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200439
440 /*
Hanno Beckerdef43052019-05-04 07:54:36 +0100441 * Prepare data to be signed at the end of the target buffer
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200442 */
Hanno Beckerdef43052019-05-04 07:54:36 +0100443 c = buf + size;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200444
445 /* Signature algorithm needed in TBS, and later for actual signature */
Hanno Beckerfc771442017-09-13 08:45:48 +0100446
447 /* There's no direct way of extracting a signature algorithm
448 * (represented as an element of mbedtls_pk_type_t) from a PK instance. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100449 if (mbedtls_pk_can_do(ctx->issuer_key, MBEDTLS_PK_RSA)) {
Hanno Beckerfc771442017-09-13 08:45:48 +0100450 pk_alg = MBEDTLS_PK_RSA;
Gilles Peskine449bd832023-01-11 14:50:10 +0100451 } else if (mbedtls_pk_can_do(ctx->issuer_key, MBEDTLS_PK_ECDSA)) {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200452 pk_alg = MBEDTLS_PK_ECDSA;
Gilles Peskine449bd832023-01-11 14:50:10 +0100453 } else {
454 return MBEDTLS_ERR_X509_INVALID_ALG;
455 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200456
Gilles Peskine449bd832023-01-11 14:50:10 +0100457 if ((ret = mbedtls_oid_get_oid_by_sig_alg(pk_alg, ctx->md_alg,
458 &sig_oid, &sig_oid_len)) != 0) {
459 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200460 }
461
462 /*
463 * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
464 */
Hanno Beckerd7f35202017-09-13 12:00:15 +0100465
466 /* Only for v3 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100467 if (ctx->version == MBEDTLS_X509_CRT_VERSION_3) {
468 MBEDTLS_ASN1_CHK_ADD(len,
469 mbedtls_x509_write_extensions(&c,
470 buf, ctx->extensions));
471 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
472 MBEDTLS_ASN1_CHK_ADD(len,
473 mbedtls_asn1_write_tag(&c, buf,
474 MBEDTLS_ASN1_CONSTRUCTED |
475 MBEDTLS_ASN1_SEQUENCE));
476 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
477 MBEDTLS_ASN1_CHK_ADD(len,
478 mbedtls_asn1_write_tag(&c, buf,
479 MBEDTLS_ASN1_CONTEXT_SPECIFIC |
480 MBEDTLS_ASN1_CONSTRUCTED | 3));
Hanno Beckerd7f35202017-09-13 12:00:15 +0100481 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200482
483 /*
484 * SubjectPublicKeyInfo
485 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100486 MBEDTLS_ASN1_CHK_ADD(pub_len,
487 mbedtls_pk_write_pubkey_der(ctx->subject_key,
488 buf, c - buf));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200489 c -= pub_len;
490 len += pub_len;
491
492 /*
493 * Subject ::= Name
494 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100495 MBEDTLS_ASN1_CHK_ADD(len,
496 mbedtls_x509_write_names(&c, buf,
497 ctx->subject));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200498
499 /*
500 * Validity ::= SEQUENCE {
501 * notBefore Time,
502 * notAfter Time }
503 */
504 sub_len = 0;
505
Gilles Peskine449bd832023-01-11 14:50:10 +0100506 MBEDTLS_ASN1_CHK_ADD(sub_len,
507 x509_write_time(&c, buf, ctx->not_after,
508 MBEDTLS_X509_RFC5280_UTC_TIME_LEN));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200509
Gilles Peskine449bd832023-01-11 14:50:10 +0100510 MBEDTLS_ASN1_CHK_ADD(sub_len,
511 x509_write_time(&c, buf, ctx->not_before,
512 MBEDTLS_X509_RFC5280_UTC_TIME_LEN));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200513
514 len += sub_len;
Gilles Peskine449bd832023-01-11 14:50:10 +0100515 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, sub_len));
516 MBEDTLS_ASN1_CHK_ADD(len,
517 mbedtls_asn1_write_tag(&c, buf,
518 MBEDTLS_ASN1_CONSTRUCTED |
519 MBEDTLS_ASN1_SEQUENCE));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200520
521 /*
522 * Issuer ::= Name
523 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100524 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_x509_write_names(&c, buf,
525 ctx->issuer));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200526
527 /*
528 * Signature ::= AlgorithmIdentifier
529 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100530 MBEDTLS_ASN1_CHK_ADD(len,
531 mbedtls_asn1_write_algorithm_identifier(&c, buf,
532 sig_oid, strlen(sig_oid), 0));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200533
534 /*
535 * Serial ::= INTEGER
Valerio Settida0afcc2023-01-05 16:46:59 +0100536 *
537 * Written data is:
Valerio Setti4752aac2023-01-10 16:00:15 +0100538 * - "ctx->serial_len" bytes for the raw serial buffer
539 * - if MSb of "serial" is 1, then prepend an extra 0x00 byte
Valerio Settida0afcc2023-01-05 16:46:59 +0100540 * - 1 byte for the length
541 * - 1 byte for the TAG
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200542 */
Valerio Settida0afcc2023-01-05 16:46:59 +0100543 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(&c, buf,
544 ctx->serial, ctx->serial_len));
Valerio Setti4752aac2023-01-10 16:00:15 +0100545 if (*c & 0x80) {
546 if (c - buf < 1) {
547 return MBEDTLS_ERR_X509_BUFFER_TOO_SMALL;
548 }
Valerio Setti856cec42023-01-12 14:56:54 +0100549 *(--c) = 0x0;
Valerio Setti4752aac2023-01-10 16:00:15 +0100550 len++;
551 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf,
552 ctx->serial_len + 1));
553 } else {
554 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf,
555 ctx->serial_len));
556 }
Valerio Settida0afcc2023-01-05 16:46:59 +0100557 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf,
558 MBEDTLS_ASN1_INTEGER));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200559
560 /*
561 * Version ::= INTEGER { v1(0), v2(1), v3(2) }
562 */
Hanno Becker47698652017-09-13 11:59:26 +0100563
564 /* Can be omitted for v1 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100565 if (ctx->version != MBEDTLS_X509_CRT_VERSION_1) {
Hanno Becker47698652017-09-13 11:59:26 +0100566 sub_len = 0;
Gilles Peskine449bd832023-01-11 14:50:10 +0100567 MBEDTLS_ASN1_CHK_ADD(sub_len,
568 mbedtls_asn1_write_int(&c, buf, ctx->version));
Hanno Becker47698652017-09-13 11:59:26 +0100569 len += sub_len;
Gilles Peskine449bd832023-01-11 14:50:10 +0100570 MBEDTLS_ASN1_CHK_ADD(len,
571 mbedtls_asn1_write_len(&c, buf, sub_len));
572 MBEDTLS_ASN1_CHK_ADD(len,
573 mbedtls_asn1_write_tag(&c, buf,
574 MBEDTLS_ASN1_CONTEXT_SPECIFIC |
575 MBEDTLS_ASN1_CONSTRUCTED | 0));
Hanno Becker47698652017-09-13 11:59:26 +0100576 }
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200577
Gilles Peskine449bd832023-01-11 14:50:10 +0100578 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
579 MBEDTLS_ASN1_CHK_ADD(len,
580 mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED |
581 MBEDTLS_ASN1_SEQUENCE));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200582
583 /*
584 * Make signature
585 */
Hanno Beckerdef43052019-05-04 07:54:36 +0100586
587 /* Compute hash of CRT. */
pespacek7599a772022-02-07 14:40:55 +0100588#if defined(MBEDTLS_USE_PSA_CRYPTO)
Gilles Peskine449bd832023-01-11 14:50:10 +0100589 psa_algorithm = mbedtls_hash_info_psa_from_md(ctx->md_alg);
pespacek7599a772022-02-07 14:40:55 +0100590
Gilles Peskine449bd832023-01-11 14:50:10 +0100591 status = psa_hash_compute(psa_algorithm,
592 c,
593 len,
594 hash,
595 sizeof(hash),
596 &hash_length);
597 if (status != PSA_SUCCESS) {
598 return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
pespacek7599a772022-02-07 14:40:55 +0100599 }
600#else
Gilles Peskine449bd832023-01-11 14:50:10 +0100601 if ((ret = mbedtls_md(mbedtls_md_info_from_type(ctx->md_alg), c,
602 len, hash)) != 0) {
603 return ret;
Andres Amaya Garcia8d8204f2017-06-28 11:07:30 +0100604 }
pespacek7599a772022-02-07 14:40:55 +0100605#endif /* MBEDTLS_USE_PSA_CRYPTO */
606
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200607
Gilles Peskine449bd832023-01-11 14:50:10 +0100608 if ((ret = mbedtls_pk_sign(ctx->issuer_key, ctx->md_alg,
609 hash, hash_length, sig, sizeof(sig), &sig_len,
610 f_rng, p_rng)) != 0) {
611 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200612 }
613
Hanno Beckerdef43052019-05-04 07:54:36 +0100614 /* Move CRT to the front of the buffer to have space
615 * for the signature. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100616 memmove(buf, c, len);
Hanno Beckerdef43052019-05-04 07:54:36 +0100617 c = buf + len;
618
619 /* Add signature at the end of the buffer,
620 * making sure that it doesn't underflow
621 * into the CRT buffer. */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200622 c2 = buf + size;
Gilles Peskine449bd832023-01-11 14:50:10 +0100623 MBEDTLS_ASN1_CHK_ADD(sig_and_oid_len, mbedtls_x509_write_sig(&c2, c,
624 sig_oid, sig_oid_len, sig,
625 sig_len));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200626
Hanno Beckerdef43052019-05-04 07:54:36 +0100627 /*
628 * Memory layout after this step:
629 *
630 * buf c=buf+len c2 buf+size
631 * [CRT0,...,CRTn, UNUSED, ..., UNUSED, SIG0, ..., SIGm]
632 */
Andres AG60dbc932016-09-02 15:23:48 +0100633
Hanno Beckerdef43052019-05-04 07:54:36 +0100634 /* Move raw CRT to just before the signature. */
635 c = c2 - len;
Gilles Peskine449bd832023-01-11 14:50:10 +0100636 memmove(c, buf, len);
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200637
638 len += sig_and_oid_len;
Gilles Peskine449bd832023-01-11 14:50:10 +0100639 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len));
640 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf,
641 MBEDTLS_ASN1_CONSTRUCTED |
642 MBEDTLS_ASN1_SEQUENCE));
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200643
Gilles Peskine449bd832023-01-11 14:50:10 +0100644 return (int) len;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200645}
646
647#define PEM_BEGIN_CRT "-----BEGIN CERTIFICATE-----\n"
648#define PEM_END_CRT "-----END CERTIFICATE-----\n"
649
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200650#if defined(MBEDTLS_PEM_WRITE_C)
Gilles Peskine449bd832023-01-11 14:50:10 +0100651int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *crt,
652 unsigned char *buf, size_t size,
653 int (*f_rng)(void *, unsigned char *, size_t),
654 void *p_rng)
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200655{
Janos Follath865b3eb2019-12-16 11:46:15 +0000656 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Hanno Becker67d42592019-05-04 08:13:23 +0100657 size_t olen;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200658
Gilles Peskine449bd832023-01-11 14:50:10 +0100659 if ((ret = mbedtls_x509write_crt_der(crt, buf, size,
660 f_rng, p_rng)) < 0) {
661 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200662 }
663
Gilles Peskine449bd832023-01-11 14:50:10 +0100664 if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_CRT, PEM_END_CRT,
665 buf + size - ret, ret,
666 buf, size, &olen)) != 0) {
667 return ret;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200668 }
669
Gilles Peskine449bd832023-01-11 14:50:10 +0100670 return 0;
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200671}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672#endif /* MBEDTLS_PEM_WRITE_C */
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200673
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674#endif /* MBEDTLS_X509_CRT_WRITE_C */