| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 1 | /* | 
|  | 2 | *  Certificate generation and signing | 
|  | 3 | * | 
| Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | *  Copyright The Mbed TLS Contributors | 
| Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 5 | *  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 Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 18 | */ | 
|  | 19 |  | 
| Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 20 | #include "mbedtls/build_info.h" | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 21 |  | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 22 | #include "mbedtls/platform.h" | 
| Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 23 |  | 
| Simon Butcher | 203a693 | 2016-10-07 15:00:17 +0100 | [diff] [blame] | 24 | #if !defined(MBEDTLS_X509_CRT_WRITE_C) || \ | 
|  | 25 | !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_FS_IO) || \ | 
|  | 26 | !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \ | 
|  | 27 | !defined(MBEDTLS_ERROR_C) || !defined(MBEDTLS_SHA256_C) || \ | 
|  | 28 | !defined(MBEDTLS_PEM_WRITE_C) | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 29 | int main(void) | 
| Manuel Pégourié-Gonnard | 8d649c6 | 2015-03-31 15:10:03 +0200 | [diff] [blame] | 30 | { | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 31 | mbedtls_printf("MBEDTLS_X509_CRT_WRITE_C and/or MBEDTLS_X509_CRT_PARSE_C and/or " | 
|  | 32 | "MBEDTLS_FS_IO and/or MBEDTLS_SHA256_C and/or " | 
|  | 33 | "MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or " | 
|  | 34 | "MBEDTLS_ERROR_C not defined.\n"); | 
|  | 35 | mbedtls_exit(0); | 
| Manuel Pégourié-Gonnard | 8d649c6 | 2015-03-31 15:10:03 +0200 | [diff] [blame] | 36 | } | 
|  | 37 | #else | 
|  | 38 |  | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 39 | #include "mbedtls/x509_crt.h" | 
|  | 40 | #include "mbedtls/x509_csr.h" | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 41 | #include "mbedtls/oid.h" | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 42 | #include "mbedtls/entropy.h" | 
|  | 43 | #include "mbedtls/ctr_drbg.h" | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 44 | #include "mbedtls/md.h" | 
| Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 45 | #include "mbedtls/error.h" | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 46 | #include "test/helpers.h" | 
| Manuel Pégourié-Gonnard | 7831b0c | 2013-09-20 12:29:56 +0200 | [diff] [blame] | 47 |  | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 48 | #include <stdio.h> | 
|  | 49 | #include <stdlib.h> | 
|  | 50 | #include <string.h> | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 51 | #include <errno.h> | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 52 |  | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 53 | #define SET_OID(x, oid) \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 54 | do { x.len = MBEDTLS_OID_SIZE(oid); x.p = (unsigned char *) oid; } while (0) | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 55 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | #if defined(MBEDTLS_X509_CSR_PARSE_C) | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 57 | #define USAGE_CSR                                                           \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 58 | "    request_file=%%s         default: (empty)\n"                           \ | 
|  | 59 | "                            If request_file is specified, subject_key,\n"  \ | 
|  | 60 | "                            subject_pwd and subject_name are ignored!\n" | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 61 | #else | 
|  | 62 | #define USAGE_CSR "" | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | #endif /* MBEDTLS_X509_CSR_PARSE_C */ | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 64 |  | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 65 | #define FORMAT_PEM              0 | 
|  | 66 | #define FORMAT_DER              1 | 
|  | 67 |  | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 68 | #define DFL_ISSUER_CRT          "" | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 69 | #define DFL_REQUEST_FILE        "" | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 70 | #define DFL_SUBJECT_KEY         "subject.key" | 
|  | 71 | #define DFL_ISSUER_KEY          "ca.key" | 
|  | 72 | #define DFL_SUBJECT_PWD         "" | 
|  | 73 | #define DFL_ISSUER_PWD          "" | 
|  | 74 | #define DFL_OUTPUT_FILENAME     "cert.crt" | 
| Manuel Pégourié-Gonnard | 9169921 | 2015-01-22 16:26:39 +0000 | [diff] [blame] | 75 | #define DFL_SUBJECT_NAME        "CN=Cert,O=mbed TLS,C=UK" | 
|  | 76 | #define DFL_ISSUER_NAME         "CN=CA,O=mbed TLS,C=UK" | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 77 | #define DFL_NOT_BEFORE          "20010101000000" | 
|  | 78 | #define DFL_NOT_AFTER           "20301231235959" | 
|  | 79 | #define DFL_SERIAL              "1" | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 80 | #define DFL_SERIAL_HEX          "1" | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 81 | #define DFL_SELFSIGN            0 | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 82 | #define DFL_IS_CA               0 | 
|  | 83 | #define DFL_MAX_PATHLEN         -1 | 
| Nicholas Wilson | 99a96b1 | 2015-09-10 18:28:01 +0100 | [diff] [blame] | 84 | #define DFL_SIG_ALG             MBEDTLS_MD_SHA256 | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 85 | #define DFL_KEY_USAGE           0 | 
| Dave Rodgman | 1577c54 | 2022-09-09 10:22:15 +0100 | [diff] [blame] | 86 | #define DFL_EXT_KEY_USAGE       NULL | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 87 | #define DFL_NS_CERT_TYPE        0 | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 88 | #define DFL_VERSION             3 | 
|  | 89 | #define DFL_AUTH_IDENT          1 | 
|  | 90 | #define DFL_SUBJ_IDENT          1 | 
|  | 91 | #define DFL_CONSTRAINTS         1 | 
|  | 92 | #define DFL_DIGEST              MBEDTLS_MD_SHA256 | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 93 | #define DFL_FORMAT              FORMAT_PEM | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 94 |  | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 95 | #define USAGE \ | 
|  | 96 | "\n usage: cert_write param=<>...\n"                \ | 
|  | 97 | "\n acceptable parameters:\n"                       \ | 
|  | 98 | USAGE_CSR                                           \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 99 | "    subject_key=%%s          default: subject.key\n"   \ | 
|  | 100 | "    subject_pwd=%%s          default: (empty)\n"       \ | 
|  | 101 | "    subject_name=%%s         default: CN=Cert,O=mbed TLS,C=UK\n"   \ | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 102 | "\n"                                                \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 103 | "    issuer_crt=%%s           default: (empty)\n"       \ | 
|  | 104 | "                            If issuer_crt is specified, issuer_name is\n"  \ | 
|  | 105 | "                            ignored!\n"                \ | 
|  | 106 | "    issuer_name=%%s          default: CN=CA,O=mbed TLS,C=UK\n"     \ | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 107 | "\n"                                                \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 108 | "    selfsign=%%d             default: 0 (false)\n"     \ | 
|  | 109 | "                            If selfsign is enabled, issuer_name and\n" \ | 
|  | 110 | "                            issuer_key are required (issuer_crt and\n" \ | 
|  | 111 | "                            subject_* are ignored\n"   \ | 
|  | 112 | "    issuer_key=%%s           default: ca.key\n"        \ | 
|  | 113 | "    issuer_pwd=%%s           default: (empty)\n"       \ | 
|  | 114 | "    output_file=%%s          default: cert.crt\n"      \ | 
|  | 115 | "    serial=%%s               default: 1\n"             \ | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 116 | "                            In decimal format; it can be used as\n"     \ | 
|  | 117 | "                            alternative to serial_hex, but it's\n"      \ | 
|  | 118 | "                            limited in max length to\n"                 \ | 
|  | 119 | "                            unsigned long long int\n"                   \ | 
|  | 120 | "    serial_hex=%%s           default: 1\n"             \ | 
|  | 121 | "                            In hex format; it can be used as\n"         \ | 
|  | 122 | "                            alternative to serial\n"                    \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 123 | "    not_before=%%s           default: 20010101000000\n" \ | 
|  | 124 | "    not_after=%%s            default: 20301231235959\n" \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 125 | "    is_ca=%%d                default: 0 (disabled)\n"  \ | 
|  | 126 | "    max_pathlen=%%d          default: -1 (none)\n"     \ | 
|  | 127 | "    md=%%s                   default: SHA256\n"        \ | 
| Gilles Peskine | 18292fe | 2020-08-21 20:42:32 +0200 | [diff] [blame] | 128 | "                            Supported values (if enabled):\n"      \ | 
| TRodziewicz | 10e8cf5 | 2021-05-31 17:58:57 +0200 | [diff] [blame] | 129 | "                            MD5, RIPEMD160, SHA1,\n" \ | 
| Gilles Peskine | 18292fe | 2020-08-21 20:42:32 +0200 | [diff] [blame] | 130 | "                            SHA224, SHA256, SHA384, SHA512\n" \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 131 | "    version=%%d              default: 3\n"            \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 132 | "                            Possible values: 1, 2, 3\n" \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 133 | "    subject_identifier=%%s   default: 1\n"             \ | 
|  | 134 | "                            Possible values: 0, 1\n"   \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 135 | "                            (Considered for v3 only)\n" \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 136 | "    authority_identifier=%%s default: 1\n"             \ | 
|  | 137 | "                            Possible values: 0, 1\n"   \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 138 | "                            (Considered for v3 only)\n" \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 139 | "    basic_constraints=%%d    default: 1\n"             \ | 
|  | 140 | "                            Possible values: 0, 1\n"   \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 141 | "                            (Considered for v3 only)\n" \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 142 | "    key_usage=%%s            default: (empty)\n"       \ | 
|  | 143 | "                            Comma-separated-list of values:\n"     \ | 
|  | 144 | "                            digital_signature\n"     \ | 
|  | 145 | "                            non_repudiation\n"       \ | 
|  | 146 | "                            key_encipherment\n"      \ | 
|  | 147 | "                            data_encipherment\n"     \ | 
|  | 148 | "                            key_agreement\n"         \ | 
|  | 149 | "                            key_cert_sign\n"  \ | 
|  | 150 | "                            crl_sign\n"              \ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 151 | "                            (Considered for v3 only)\n" \ | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 152 | "    ext_key_usage=%%s        default: (empty)\n"      \ | 
|  | 153 | "                            Comma-separated-list of values:\n"     \ | 
|  | 154 | "                            serverAuth\n"             \ | 
|  | 155 | "                            clientAuth\n"             \ | 
|  | 156 | "                            codeSigning\n"            \ | 
|  | 157 | "                            emailProtection\n"        \ | 
|  | 158 | "                            timeStamping\n"           \ | 
|  | 159 | "                            OCSPSigning\n"            \ | 
| Hanno Becker | 81535d0 | 2017-09-13 15:39:59 +0100 | [diff] [blame] | 160 | "    ns_cert_type=%%s         default: (empty)\n"       \ | 
|  | 161 | "                            Comma-separated-list of values:\n"     \ | 
|  | 162 | "                            ssl_client\n"            \ | 
|  | 163 | "                            ssl_server\n"            \ | 
|  | 164 | "                            email\n"                 \ | 
|  | 165 | "                            object_signing\n"        \ | 
|  | 166 | "                            ssl_ca\n"                \ | 
|  | 167 | "                            email_ca\n"              \ | 
|  | 168 | "                            object_signing_ca\n"     \ | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 169 | "   format=pem|der           default: pem\n"         \ | 
| Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 170 | "\n" | 
| Manuel Pégourié-Gonnard | 6c5abfa | 2015-02-13 14:12:07 +0000 | [diff] [blame] | 171 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 172 | typedef enum { | 
|  | 173 | SERIAL_FRMT_UNSPEC, | 
|  | 174 | SERIAL_FRMT_DEC, | 
|  | 175 | SERIAL_FRMT_HEX | 
|  | 176 | } serial_format_t; | 
| Simon Butcher | 63cb97e | 2018-12-06 17:43:31 +0000 | [diff] [blame] | 177 |  | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 178 | /* | 
|  | 179 | * global options | 
|  | 180 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 181 | struct options { | 
| Paul Bakker | 8fc30b1 | 2013-11-25 13:29:43 +0100 | [diff] [blame] | 182 | const char *issuer_crt;     /* filename of the issuer certificate   */ | 
|  | 183 | const char *request_file;   /* filename of the certificate request  */ | 
|  | 184 | const char *subject_key;    /* filename of the subject key file     */ | 
|  | 185 | const char *issuer_key;     /* filename of the issuer key file      */ | 
|  | 186 | const char *subject_pwd;    /* password for the subject key file    */ | 
|  | 187 | const char *issuer_pwd;     /* password for the issuer key file     */ | 
| Hanno Becker | 25d882b | 2018-08-23 15:26:06 +0100 | [diff] [blame] | 188 | const char *output_file;    /* where to store the constructed CRT   */ | 
| Paul Bakker | 8fc30b1 | 2013-11-25 13:29:43 +0100 | [diff] [blame] | 189 | const char *subject_name;   /* subject name for certificate         */ | 
|  | 190 | const char *issuer_name;    /* issuer name for certificate          */ | 
|  | 191 | const char *not_before;     /* validity period not before           */ | 
|  | 192 | const char *not_after;      /* validity period not after            */ | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 193 | const char *serial;         /* serial number string (decimal)       */ | 
|  | 194 | const char *serial_hex;     /* serial number string (hex)           */ | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 195 | int selfsign;               /* selfsign the certificate             */ | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 196 | int is_ca;                  /* is a CA certificate                  */ | 
|  | 197 | int max_pathlen;            /* maximum CA path length               */ | 
| Hanno Becker | e1b1d0a | 2017-09-22 15:35:16 +0100 | [diff] [blame] | 198 | int authority_identifier;   /* add authority identifier to CRT      */ | 
|  | 199 | int subject_identifier;     /* add subject identifier to CRT        */ | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 200 | int basic_constraints;      /* add basic constraints ext to CRT     */ | 
|  | 201 | int version;                /* CRT version                          */ | 
|  | 202 | mbedtls_md_type_t md;       /* Hash used for signing                */ | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 203 | unsigned char key_usage;    /* key usage flags                      */ | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 204 | mbedtls_asn1_sequence *ext_key_usage; /* extended key usages        */ | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 205 | unsigned char ns_cert_type; /* NS cert type                         */ | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 206 | int format;                 /* format                               */ | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 207 | } opt; | 
|  | 208 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 209 | int write_certificate(mbedtls_x509write_cert *crt, const char *output_file, | 
|  | 210 | int (*f_rng)(void *, unsigned char *, size_t), | 
|  | 211 | void *p_rng) | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 212 | { | 
|  | 213 | int ret; | 
|  | 214 | FILE *f; | 
|  | 215 | unsigned char output_buf[4096]; | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 216 | unsigned char *output_start; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 217 | size_t len = 0; | 
|  | 218 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 219 | memset(output_buf, 0, 4096); | 
|  | 220 | if (opt.format == FORMAT_DER) { | 
|  | 221 | ret = mbedtls_x509write_crt_der(crt, output_buf, 4096, | 
|  | 222 | f_rng, p_rng); | 
|  | 223 | if (ret < 0) { | 
|  | 224 | return ret; | 
|  | 225 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 226 |  | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 227 | len = ret; | 
|  | 228 | output_start = output_buf + 4096 - len; | 
|  | 229 | } else { | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 230 | ret = mbedtls_x509write_crt_pem(crt, output_buf, 4096, | 
|  | 231 | f_rng, p_rng); | 
|  | 232 | if (ret < 0) { | 
|  | 233 | return ret; | 
|  | 234 | } | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 235 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 236 | len = strlen((char *) output_buf); | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 237 | output_start = output_buf; | 
|  | 238 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 239 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 240 | if ((f = fopen(output_file, "w")) == NULL) { | 
|  | 241 | return -1; | 
| Paul Bakker | 0c22610 | 2014-04-17 16:02:36 +0200 | [diff] [blame] | 242 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 243 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 244 | if (fwrite(output_start, 1, len, f) != len) { | 
|  | 245 | fclose(f); | 
|  | 246 | return -1; | 
|  | 247 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 248 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 249 | fclose(f); | 
|  | 250 |  | 
|  | 251 | return 0; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 252 | } | 
|  | 253 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 254 | int parse_serial_decimal_format(unsigned char *obuf, size_t obufmax, | 
|  | 255 | const char *ibuf, size_t *len) | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 256 | { | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 257 | unsigned long long int dec; | 
|  | 258 | unsigned int remaining_bytes = sizeof(dec); | 
|  | 259 | unsigned char *p = obuf; | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 260 | unsigned char val; | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 261 | char *end_ptr = NULL; | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 262 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 263 | errno = 0; | 
|  | 264 | dec = strtoull(ibuf, &end_ptr, 10); | 
|  | 265 |  | 
|  | 266 | if ((errno != 0) || (end_ptr == ibuf)) { | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 267 | return -1; | 
|  | 268 | } | 
|  | 269 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 270 | *len = 0; | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 271 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 272 | while (remaining_bytes > 0) { | 
|  | 273 | if (obufmax < (*len + 1)) { | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 274 | return -1; | 
|  | 275 | } | 
|  | 276 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 277 | val = (dec >> ((remaining_bytes - 1) * 8)) & 0xFF; | 
|  | 278 |  | 
|  | 279 | /* Skip leading zeros */ | 
| Valerio Setti | 48fdbb3 | 2023-01-12 15:31:35 +0100 | [diff] [blame] | 280 | if ((val != 0) || (*len != 0)) { | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 281 | *p = val; | 
|  | 282 | (*len)++; | 
|  | 283 | p++; | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | remaining_bytes--; | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 287 | } | 
|  | 288 |  | 
|  | 289 | return 0; | 
|  | 290 | } | 
|  | 291 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 292 | int main(int argc, char *argv[]) | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 293 | { | 
| Andres Amaya Garcia | f9a54d3 | 2018-04-29 21:42:45 +0100 | [diff] [blame] | 294 | int ret = 1; | 
|  | 295 | int exit_code = MBEDTLS_EXIT_FAILURE; | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 296 | mbedtls_x509_crt issuer_crt; | 
|  | 297 | mbedtls_pk_context loaded_issuer_key, loaded_subject_key; | 
|  | 298 | mbedtls_pk_context *issuer_key = &loaded_issuer_key, | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 299 | *subject_key = &loaded_subject_key; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 300 | char buf[1024]; | 
| Jonathan Leroy | bbc75d9 | 2015-10-10 21:58:07 +0200 | [diff] [blame] | 301 | char issuer_name[256]; | 
| Paul Bakker | c97f9f6 | 2013-11-30 15:13:02 +0100 | [diff] [blame] | 302 | int i; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 303 | char *p, *q, *r; | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 304 | #if defined(MBEDTLS_X509_CSR_PARSE_C) | 
| Jonathan Leroy | bbc75d9 | 2015-10-10 21:58:07 +0200 | [diff] [blame] | 305 | char subject_name[256]; | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 306 | mbedtls_x509_csr csr; | 
| Paul Bakker | 7fc7fa6 | 2013-09-17 14:44:00 +0200 | [diff] [blame] | 307 | #endif | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 308 | mbedtls_x509write_cert crt; | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 309 | serial_format_t serial_frmt = SERIAL_FRMT_UNSPEC; | 
| Valerio Setti | acf12fb | 2023-01-09 17:19:26 +0100 | [diff] [blame] | 310 | unsigned char serial[MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN]; | 
|  | 311 | size_t serial_len; | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 312 | mbedtls_asn1_sequence *ext_key_usage; | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 313 | mbedtls_entropy_context entropy; | 
|  | 314 | mbedtls_ctr_drbg_context ctr_drbg; | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 315 | const char *pers = "crt example app"; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 316 |  | 
|  | 317 | /* | 
|  | 318 | * Set to sane values | 
|  | 319 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 320 | mbedtls_x509write_crt_init(&crt); | 
|  | 321 | mbedtls_pk_init(&loaded_issuer_key); | 
|  | 322 | mbedtls_pk_init(&loaded_subject_key); | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 323 | mbedtls_ctr_drbg_init(&ctr_drbg); | 
|  | 324 | mbedtls_entropy_init(&entropy); | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 325 | #if defined(MBEDTLS_X509_CSR_PARSE_C) | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 326 | mbedtls_x509_csr_init(&csr); | 
| Paul Bakker | 7fc7fa6 | 2013-09-17 14:44:00 +0200 | [diff] [blame] | 327 | #endif | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 328 | mbedtls_x509_crt_init(&issuer_crt); | 
|  | 329 | memset(buf, 0, sizeof(buf)); | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 330 | memset(serial, 0, sizeof(serial)); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 331 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 332 | if (argc == 0) { | 
|  | 333 | usage: | 
|  | 334 | mbedtls_printf(USAGE); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 335 | goto exit; | 
|  | 336 | } | 
|  | 337 |  | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 338 | opt.issuer_crt          = DFL_ISSUER_CRT; | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 339 | opt.request_file        = DFL_REQUEST_FILE; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 340 | opt.subject_key         = DFL_SUBJECT_KEY; | 
|  | 341 | opt.issuer_key          = DFL_ISSUER_KEY; | 
|  | 342 | opt.subject_pwd         = DFL_SUBJECT_PWD; | 
|  | 343 | opt.issuer_pwd          = DFL_ISSUER_PWD; | 
|  | 344 | opt.output_file         = DFL_OUTPUT_FILENAME; | 
|  | 345 | opt.subject_name        = DFL_SUBJECT_NAME; | 
|  | 346 | opt.issuer_name         = DFL_ISSUER_NAME; | 
|  | 347 | opt.not_before          = DFL_NOT_BEFORE; | 
|  | 348 | opt.not_after           = DFL_NOT_AFTER; | 
|  | 349 | opt.serial              = DFL_SERIAL; | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 350 | opt.serial_hex          = DFL_SERIAL_HEX; | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 351 | opt.selfsign            = DFL_SELFSIGN; | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 352 | opt.is_ca               = DFL_IS_CA; | 
|  | 353 | opt.max_pathlen         = DFL_MAX_PATHLEN; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 354 | opt.key_usage           = DFL_KEY_USAGE; | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 355 | opt.ext_key_usage       = DFL_EXT_KEY_USAGE; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 356 | opt.ns_cert_type        = DFL_NS_CERT_TYPE; | 
| Hanno Becker | 38eff43 | 2017-09-22 15:38:20 +0100 | [diff] [blame] | 357 | opt.version             = DFL_VERSION - 1; | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 358 | opt.md                  = DFL_DIGEST; | 
|  | 359 | opt.subject_identifier   = DFL_SUBJ_IDENT; | 
|  | 360 | opt.authority_identifier = DFL_AUTH_IDENT; | 
|  | 361 | opt.basic_constraints    = DFL_CONSTRAINTS; | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 362 | opt.format              = DFL_FORMAT; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 363 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 364 | for (i = 1; i < argc; i++) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 365 |  | 
|  | 366 | p = argv[i]; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 367 | if ((q = strchr(p, '=')) == NULL) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 368 | goto usage; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 369 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 370 | *q++ = '\0'; | 
|  | 371 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 372 | if (strcmp(p, "request_file") == 0) { | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 373 | opt.request_file = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 374 | } else if (strcmp(p, "subject_key") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 375 | opt.subject_key = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 376 | } else if (strcmp(p, "issuer_key") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 377 | opt.issuer_key = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 378 | } else if (strcmp(p, "subject_pwd") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 379 | opt.subject_pwd = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 380 | } else if (strcmp(p, "issuer_pwd") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 381 | opt.issuer_pwd = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 382 | } else if (strcmp(p, "issuer_crt") == 0) { | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 383 | opt.issuer_crt = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 384 | } else if (strcmp(p, "output_file") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 385 | opt.output_file = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 386 | } else if (strcmp(p, "subject_name") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 387 | opt.subject_name = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 388 | } else if (strcmp(p, "issuer_name") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 389 | opt.issuer_name = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 390 | } else if (strcmp(p, "not_before") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 391 | opt.not_before = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 392 | } else if (strcmp(p, "not_after") == 0) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 393 | opt.not_after = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 394 | } else if (strcmp(p, "serial") == 0) { | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 395 | if (serial_frmt != SERIAL_FRMT_UNSPEC) { | 
|  | 396 | mbedtls_printf("Invalid attempt to set the serial more than once\n"); | 
|  | 397 | goto usage; | 
|  | 398 | } | 
|  | 399 | serial_frmt = SERIAL_FRMT_DEC; | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 400 | opt.serial = q; | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 401 | } else if (strcmp(p, "serial_hex") == 0) { | 
|  | 402 | if (serial_frmt != SERIAL_FRMT_UNSPEC) { | 
|  | 403 | mbedtls_printf("Invalid attempt to set the serial more than once\n"); | 
|  | 404 | goto usage; | 
|  | 405 | } | 
|  | 406 | serial_frmt = SERIAL_FRMT_HEX; | 
|  | 407 | opt.serial_hex = q; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 408 | } else if (strcmp(p, "authority_identifier") == 0) { | 
|  | 409 | opt.authority_identifier = atoi(q); | 
|  | 410 | if (opt.authority_identifier != 0 && | 
|  | 411 | opt.authority_identifier != 1) { | 
|  | 412 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 413 | goto usage; | 
|  | 414 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 415 | } else if (strcmp(p, "subject_identifier") == 0) { | 
|  | 416 | opt.subject_identifier = atoi(q); | 
|  | 417 | if (opt.subject_identifier != 0 && | 
|  | 418 | opt.subject_identifier != 1) { | 
|  | 419 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 420 | goto usage; | 
|  | 421 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 422 | } else if (strcmp(p, "basic_constraints") == 0) { | 
|  | 423 | opt.basic_constraints = atoi(q); | 
|  | 424 | if (opt.basic_constraints != 0 && | 
|  | 425 | opt.basic_constraints != 1) { | 
|  | 426 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 427 | goto usage; | 
|  | 428 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 429 | } else if (strcmp(p, "md") == 0) { | 
| Gilles Peskine | 18292fe | 2020-08-21 20:42:32 +0200 | [diff] [blame] | 430 | const mbedtls_md_info_t *md_info = | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 431 | mbedtls_md_info_from_string(q); | 
|  | 432 | if (md_info == NULL) { | 
|  | 433 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 434 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 435 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 436 | opt.md = mbedtls_md_get_type(md_info); | 
|  | 437 | } else if (strcmp(p, "version") == 0) { | 
|  | 438 | opt.version = atoi(q); | 
|  | 439 | if (opt.version < 1 || opt.version > 3) { | 
|  | 440 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 441 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 442 | } | 
| Hanno Becker | 38eff43 | 2017-09-22 15:38:20 +0100 | [diff] [blame] | 443 | opt.version--; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 444 | } else if (strcmp(p, "selfsign") == 0) { | 
|  | 445 | opt.selfsign = atoi(q); | 
|  | 446 | if (opt.selfsign < 0 || opt.selfsign > 1) { | 
|  | 447 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 448 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 449 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 450 | } else if (strcmp(p, "is_ca") == 0) { | 
|  | 451 | opt.is_ca = atoi(q); | 
|  | 452 | if (opt.is_ca < 0 || opt.is_ca > 1) { | 
|  | 453 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 454 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 455 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 456 | } else if (strcmp(p, "max_pathlen") == 0) { | 
|  | 457 | opt.max_pathlen = atoi(q); | 
|  | 458 | if (opt.max_pathlen < -1 || opt.max_pathlen > 127) { | 
|  | 459 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 460 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 461 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 462 | } else if (strcmp(p, "key_usage") == 0) { | 
|  | 463 | while (q != NULL) { | 
|  | 464 | if ((r = strchr(q, ',')) != NULL) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 465 | *r++ = '\0'; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 466 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 467 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 468 | if (strcmp(q, "digital_signature") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 469 | opt.key_usage |= MBEDTLS_X509_KU_DIGITAL_SIGNATURE; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 470 | } else if (strcmp(q, "non_repudiation") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 471 | opt.key_usage |= MBEDTLS_X509_KU_NON_REPUDIATION; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 472 | } else if (strcmp(q, "key_encipherment") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 473 | opt.key_usage |= MBEDTLS_X509_KU_KEY_ENCIPHERMENT; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 474 | } else if (strcmp(q, "data_encipherment") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 475 | opt.key_usage |= MBEDTLS_X509_KU_DATA_ENCIPHERMENT; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 476 | } else if (strcmp(q, "key_agreement") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 477 | opt.key_usage |= MBEDTLS_X509_KU_KEY_AGREEMENT; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 478 | } else if (strcmp(q, "key_cert_sign") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 479 | opt.key_usage |= MBEDTLS_X509_KU_KEY_CERT_SIGN; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 480 | } else if (strcmp(q, "crl_sign") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 481 | opt.key_usage |= MBEDTLS_X509_KU_CRL_SIGN; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 482 | } else { | 
|  | 483 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 484 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 485 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 486 |  | 
|  | 487 | q = r; | 
|  | 488 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 489 | } else if (strcmp(p, "ext_key_usage") == 0) { | 
| Dave Rodgman | 6493785 | 2022-08-15 14:12:25 +0100 | [diff] [blame] | 490 | mbedtls_asn1_sequence **tail = &opt.ext_key_usage; | 
|  | 491 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 492 | while (q != NULL) { | 
|  | 493 | if ((r = strchr(q, ',')) != NULL) { | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 494 | *r++ = '\0'; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 495 | } | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 496 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 497 | ext_key_usage = mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence)); | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 498 | ext_key_usage->buf.tag = MBEDTLS_ASN1_OID; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 499 | if (strcmp(q, "serverAuth") == 0) { | 
|  | 500 | SET_OID(ext_key_usage->buf, MBEDTLS_OID_SERVER_AUTH); | 
|  | 501 | } else if (strcmp(q, "clientAuth") == 0) { | 
|  | 502 | SET_OID(ext_key_usage->buf, MBEDTLS_OID_CLIENT_AUTH); | 
|  | 503 | } else if (strcmp(q, "codeSigning") == 0) { | 
|  | 504 | SET_OID(ext_key_usage->buf, MBEDTLS_OID_CODE_SIGNING); | 
|  | 505 | } else if (strcmp(q, "emailProtection") == 0) { | 
|  | 506 | SET_OID(ext_key_usage->buf, MBEDTLS_OID_EMAIL_PROTECTION); | 
|  | 507 | } else if (strcmp(q, "timeStamping") == 0) { | 
|  | 508 | SET_OID(ext_key_usage->buf, MBEDTLS_OID_TIME_STAMPING); | 
|  | 509 | } else if (strcmp(q, "OCSPSigning") == 0) { | 
|  | 510 | SET_OID(ext_key_usage->buf, MBEDTLS_OID_OCSP_SIGNING); | 
|  | 511 | } else { | 
|  | 512 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 513 | goto usage; | 
| Dave Rodgman | c5e0a8a | 2022-08-15 14:24:22 +0100 | [diff] [blame] | 514 | } | 
| Dave Rodgman | 6493785 | 2022-08-15 14:12:25 +0100 | [diff] [blame] | 515 |  | 
|  | 516 | *tail = ext_key_usage; | 
|  | 517 | tail = &ext_key_usage->next; | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 518 |  | 
|  | 519 | q = r; | 
|  | 520 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 521 | } else if (strcmp(p, "ns_cert_type") == 0) { | 
|  | 522 | while (q != NULL) { | 
|  | 523 | if ((r = strchr(q, ',')) != NULL) { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 524 | *r++ = '\0'; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 525 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 526 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 527 | if (strcmp(q, "ssl_client") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 528 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 529 | } else if (strcmp(q, "ssl_server") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 530 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 531 | } else if (strcmp(q, "email") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 532 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_EMAIL; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 533 | } else if (strcmp(q, "object_signing") == 0) { | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 534 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 535 | } else if (strcmp(q, "ssl_ca") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 536 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_SSL_CA; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 537 | } else if (strcmp(q, "email_ca") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 538 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 539 | } else if (strcmp(q, "object_signing_ca") == 0) { | 
| Manuel Pégourié-Gonnard | e6028c9 | 2015-04-20 12:19:02 +0100 | [diff] [blame] | 540 | opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 541 | } else { | 
|  | 542 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 543 | goto usage; | 
| Hanno Becker | 17c3276 | 2017-10-03 14:56:04 +0100 | [diff] [blame] | 544 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 545 |  | 
|  | 546 | q = r; | 
|  | 547 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 548 | } else if (strcmp(p, "format") == 0) { | 
|  | 549 | if (strcmp(q, "der") == 0) { | 
|  | 550 | opt.format = FORMAT_DER; | 
|  | 551 | } else if (strcmp(q, "pem") == 0) { | 
|  | 552 | opt.format = FORMAT_PEM; | 
|  | 553 | } else { | 
|  | 554 | mbedtls_printf("Invalid argument for option %s\n", p); | 
| Dave Rodgman | 66e0550 | 2022-10-27 16:29:38 +0100 | [diff] [blame] | 555 | goto usage; | 
|  | 556 | } | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 557 | } else { | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 558 | goto usage; | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 559 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 560 | } | 
|  | 561 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 562 | mbedtls_printf("\n"); | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 563 |  | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 564 | /* | 
|  | 565 | * 0. Seed the PRNG | 
|  | 566 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 567 | mbedtls_printf("  . Seeding the random number generator..."); | 
|  | 568 | fflush(stdout); | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 569 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 570 | if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, | 
|  | 571 | (const unsigned char *) pers, | 
|  | 572 | strlen(pers))) != 0) { | 
|  | 573 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 574 | mbedtls_printf(" failed\n  !  mbedtls_ctr_drbg_seed returned %d - %s\n", | 
|  | 575 | ret, buf); | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 576 | goto exit; | 
|  | 577 | } | 
|  | 578 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 579 | mbedtls_printf(" ok\n"); | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 580 |  | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 581 | // Parse serial to MPI | 
|  | 582 | // | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 583 | mbedtls_printf("  . Reading serial number..."); | 
|  | 584 | fflush(stdout); | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 585 |  | 
| Valerio Setti | 791bbe6 | 2023-01-11 10:40:18 +0100 | [diff] [blame] | 586 | if (serial_frmt == SERIAL_FRMT_HEX) { | 
|  | 587 | ret = mbedtls_test_unhexify(serial, sizeof(serial), | 
|  | 588 | opt.serial_hex, &serial_len); | 
|  | 589 | } else { // SERIAL_FRMT_DEC || SERIAL_FRMT_UNSPEC | 
|  | 590 | ret = parse_serial_decimal_format(serial, sizeof(serial), | 
|  | 591 | opt.serial, &serial_len); | 
|  | 592 | } | 
|  | 593 |  | 
|  | 594 | if (ret != 0) { | 
|  | 595 | mbedtls_printf(" failed\n  !  Unable to parse serial\n"); | 
|  | 596 | goto exit; | 
|  | 597 | } | 
|  | 598 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 599 | mbedtls_printf(" ok\n"); | 
| Manuel Pégourié-Gonnard | 31e5940 | 2013-09-12 05:59:05 +0200 | [diff] [blame] | 600 |  | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 601 | // Parse issuer certificate if present | 
|  | 602 | // | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 603 | if (!opt.selfsign && strlen(opt.issuer_crt)) { | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 604 | /* | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 605 | * 1.0.a. Load the certificates | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 606 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 607 | mbedtls_printf("  . Loading the issuer certificate ..."); | 
|  | 608 | fflush(stdout); | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 609 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 610 | if ((ret = mbedtls_x509_crt_parse_file(&issuer_crt, opt.issuer_crt)) != 0) { | 
|  | 611 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 612 | mbedtls_printf(" failed\n  !  mbedtls_x509_crt_parse_file " | 
|  | 613 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 614 | goto exit; | 
|  | 615 | } | 
|  | 616 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 617 | ret = mbedtls_x509_dn_gets(issuer_name, sizeof(issuer_name), | 
|  | 618 | &issuer_crt.subject); | 
|  | 619 | if (ret < 0) { | 
|  | 620 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 621 | mbedtls_printf(" failed\n  !  mbedtls_x509_dn_gets " | 
|  | 622 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 623 | goto exit; | 
|  | 624 | } | 
|  | 625 |  | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 626 | opt.issuer_name = issuer_name; | 
|  | 627 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 628 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 629 | } | 
|  | 630 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 631 | #if defined(MBEDTLS_X509_CSR_PARSE_C) | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 632 | // Parse certificate request if present | 
|  | 633 | // | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 634 | if (!opt.selfsign && strlen(opt.request_file)) { | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 635 | /* | 
|  | 636 | * 1.0.b. Load the CSR | 
|  | 637 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 638 | mbedtls_printf("  . Loading the certificate request ..."); | 
|  | 639 | fflush(stdout); | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 640 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 641 | if ((ret = mbedtls_x509_csr_parse_file(&csr, opt.request_file)) != 0) { | 
|  | 642 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 643 | mbedtls_printf(" failed\n  !  mbedtls_x509_csr_parse_file " | 
|  | 644 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 645 | goto exit; | 
|  | 646 | } | 
|  | 647 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 648 | ret = mbedtls_x509_dn_gets(subject_name, sizeof(subject_name), | 
|  | 649 | &csr.subject); | 
|  | 650 | if (ret < 0) { | 
|  | 651 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 652 | mbedtls_printf(" failed\n  !  mbedtls_x509_dn_gets " | 
|  | 653 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 654 | goto exit; | 
|  | 655 | } | 
|  | 656 |  | 
|  | 657 | opt.subject_name = subject_name; | 
| Gilles Peskine | 842edf4 | 2021-08-04 21:56:10 +0200 | [diff] [blame] | 658 | subject_key = &csr.pk; | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 659 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 660 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 661 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 662 | #endif /* MBEDTLS_X509_CSR_PARSE_C */ | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 663 |  | 
|  | 664 | /* | 
|  | 665 | * 1.1. Load the keys | 
|  | 666 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 667 | if (!opt.selfsign && !strlen(opt.request_file)) { | 
|  | 668 | mbedtls_printf("  . Loading the subject key ..."); | 
|  | 669 | fflush(stdout); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 670 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 671 | ret = mbedtls_pk_parse_keyfile(&loaded_subject_key, opt.subject_key, | 
|  | 672 | opt.subject_pwd, mbedtls_ctr_drbg_random, &ctr_drbg); | 
|  | 673 | if (ret != 0) { | 
|  | 674 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 675 | mbedtls_printf(" failed\n  !  mbedtls_pk_parse_keyfile " | 
|  | 676 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | e2673fb | 2013-09-09 15:52:07 +0200 | [diff] [blame] | 677 | goto exit; | 
|  | 678 | } | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 679 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 680 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | 1014e95 | 2013-09-09 13:59:42 +0200 | [diff] [blame] | 681 | } | 
|  | 682 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 683 | mbedtls_printf("  . Loading the issuer key ..."); | 
|  | 684 | fflush(stdout); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 685 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 686 | ret = mbedtls_pk_parse_keyfile(&loaded_issuer_key, opt.issuer_key, | 
|  | 687 | opt.issuer_pwd, mbedtls_ctr_drbg_random, &ctr_drbg); | 
|  | 688 | if (ret != 0) { | 
|  | 689 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 690 | mbedtls_printf(" failed\n  !  mbedtls_pk_parse_keyfile " | 
|  | 691 | "returned -x%02x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 692 | goto exit; | 
|  | 693 | } | 
|  | 694 |  | 
|  | 695 | // Check if key and issuer certificate match | 
|  | 696 | // | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 697 | if (strlen(opt.issuer_crt)) { | 
|  | 698 | if (mbedtls_pk_check_pair(&issuer_crt.pk, issuer_key, | 
|  | 699 | mbedtls_ctr_drbg_random, &ctr_drbg) != 0) { | 
|  | 700 | mbedtls_printf(" failed\n  !  issuer_key does not match " | 
|  | 701 | "issuer certificate\n\n"); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 702 | goto exit; | 
|  | 703 | } | 
|  | 704 | } | 
|  | 705 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 706 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 707 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 708 | if (opt.selfsign) { | 
| Paul Bakker | 93c6aa4 | 2013-10-28 22:28:09 +0100 | [diff] [blame] | 709 | opt.subject_name = opt.issuer_name; | 
| Manuel Pégourié-Gonnard | f38e71a | 2013-09-12 05:21:54 +0200 | [diff] [blame] | 710 | subject_key = issuer_key; | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 711 | } | 
|  | 712 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 713 | mbedtls_x509write_crt_set_subject_key(&crt, subject_key); | 
|  | 714 | mbedtls_x509write_crt_set_issuer_key(&crt, issuer_key); | 
| Paul Bakker | b2d7f23 | 2013-09-09 16:24:18 +0200 | [diff] [blame] | 715 |  | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 716 | /* | 
|  | 717 | * 1.0. Check the names for validity | 
|  | 718 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 719 | if ((ret = mbedtls_x509write_crt_set_subject_name(&crt, opt.subject_name)) != 0) { | 
|  | 720 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 721 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_subject_name " | 
|  | 722 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 723 | goto exit; | 
|  | 724 | } | 
|  | 725 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 726 | if ((ret = mbedtls_x509write_crt_set_issuer_name(&crt, opt.issuer_name)) != 0) { | 
|  | 727 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 728 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_issuer_name " | 
|  | 729 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 730 | goto exit; | 
|  | 731 | } | 
|  | 732 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 733 | mbedtls_printf("  . Setting certificate values ..."); | 
|  | 734 | fflush(stdout); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 735 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 736 | mbedtls_x509write_crt_set_version(&crt, opt.version); | 
|  | 737 | mbedtls_x509write_crt_set_md_alg(&crt, opt.md); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 738 |  | 
| Valerio Setti | af4815c | 2023-01-26 17:43:09 +0100 | [diff] [blame] | 739 | ret = mbedtls_x509write_crt_set_serial_raw(&crt, serial, serial_len); | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 740 | if (ret != 0) { | 
|  | 741 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
| Valerio Setti | af4815c | 2023-01-26 17:43:09 +0100 | [diff] [blame] | 742 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_serial_raw " | 
| Valerio Setti | da0afcc | 2023-01-05 16:46:59 +0100 | [diff] [blame] | 743 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
|  | 744 | goto exit; | 
|  | 745 | } | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 746 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 747 | ret = mbedtls_x509write_crt_set_validity(&crt, opt.not_before, opt.not_after); | 
|  | 748 | if (ret != 0) { | 
|  | 749 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 750 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_validity " | 
|  | 751 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 752 | goto exit; | 
|  | 753 | } | 
|  | 754 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 755 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 756 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 757 | if (opt.version == MBEDTLS_X509_CRT_VERSION_3 && | 
|  | 758 | opt.basic_constraints != 0) { | 
|  | 759 | mbedtls_printf("  . Adding the Basic Constraints extension ..."); | 
|  | 760 | fflush(stdout); | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 761 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 762 | ret = mbedtls_x509write_crt_set_basic_constraints(&crt, opt.is_ca, | 
|  | 763 | opt.max_pathlen); | 
|  | 764 | if (ret != 0) { | 
|  | 765 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 766 | mbedtls_printf(" failed\n  !  x509write_crt_set_basic_constraints " | 
|  | 767 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 768 | goto exit; | 
|  | 769 | } | 
|  | 770 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 771 | mbedtls_printf(" ok\n"); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 772 | } | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 773 |  | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 774 | #if defined(MBEDTLS_SHA1_C) | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 775 | if (opt.version == MBEDTLS_X509_CRT_VERSION_3 && | 
|  | 776 | opt.subject_identifier != 0) { | 
|  | 777 | mbedtls_printf("  . Adding the Subject Key Identifier ..."); | 
|  | 778 | fflush(stdout); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 779 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 780 | ret = mbedtls_x509write_crt_set_subject_key_identifier(&crt); | 
|  | 781 | if (ret != 0) { | 
|  | 782 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 783 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_subject" | 
|  | 784 | "_key_identifier returned -0x%04x - %s\n\n", | 
|  | 785 | (unsigned int) -ret, buf); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 786 | goto exit; | 
|  | 787 | } | 
|  | 788 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 789 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 790 | } | 
|  | 791 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 792 | if (opt.version == MBEDTLS_X509_CRT_VERSION_3 && | 
|  | 793 | opt.authority_identifier != 0) { | 
|  | 794 | mbedtls_printf("  . Adding the Authority Key Identifier ..."); | 
|  | 795 | fflush(stdout); | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 796 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 797 | ret = mbedtls_x509write_crt_set_authority_key_identifier(&crt); | 
|  | 798 | if (ret != 0) { | 
|  | 799 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 800 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_authority_" | 
|  | 801 | "key_identifier returned -0x%04x - %s\n\n", | 
|  | 802 | (unsigned int) -ret, buf); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 803 | goto exit; | 
|  | 804 | } | 
|  | 805 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 806 | mbedtls_printf(" ok\n"); | 
| Hanno Becker | 6c13d37 | 2017-09-13 12:49:22 +0100 | [diff] [blame] | 807 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 808 | #endif /* MBEDTLS_SHA1_C */ | 
| Paul Bakker | 15162a0 | 2013-09-06 19:27:21 +0200 | [diff] [blame] | 809 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 810 | if (opt.version == MBEDTLS_X509_CRT_VERSION_3 && | 
|  | 811 | opt.key_usage != 0) { | 
|  | 812 | mbedtls_printf("  . Adding the Key Usage extension ..."); | 
|  | 813 | fflush(stdout); | 
| Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 814 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 815 | ret = mbedtls_x509write_crt_set_key_usage(&crt, opt.key_usage); | 
|  | 816 | if (ret != 0) { | 
|  | 817 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 818 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_key_usage " | 
|  | 819 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 820 | goto exit; | 
|  | 821 | } | 
|  | 822 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 823 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 824 | } | 
|  | 825 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 826 | if (opt.ext_key_usage) { | 
|  | 827 | mbedtls_printf("  . Adding the Extended Key Usage extension ..."); | 
|  | 828 | fflush(stdout); | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 829 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 830 | ret = mbedtls_x509write_crt_set_ext_key_usage(&crt, opt.ext_key_usage); | 
|  | 831 | if (ret != 0) { | 
|  | 832 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 833 | mbedtls_printf( | 
|  | 834 | " failed\n  !  mbedtls_x509write_crt_set_ext_key_usage returned -0x%02x - %s\n\n", | 
|  | 835 | (unsigned int) -ret, | 
|  | 836 | buf); | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 837 | goto exit; | 
|  | 838 | } | 
|  | 839 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 840 | mbedtls_printf(" ok\n"); | 
| Nicholas Wilson | 8e5bdfb | 2015-09-09 19:03:34 +0100 | [diff] [blame] | 841 | } | 
|  | 842 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 843 | if (opt.version == MBEDTLS_X509_CRT_VERSION_3 && | 
|  | 844 | opt.ns_cert_type != 0) { | 
|  | 845 | mbedtls_printf("  . Adding the NS Cert Type extension ..."); | 
|  | 846 | fflush(stdout); | 
| Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 847 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 848 | ret = mbedtls_x509write_crt_set_ns_cert_type(&crt, opt.ns_cert_type); | 
|  | 849 | if (ret != 0) { | 
|  | 850 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 851 | mbedtls_printf(" failed\n  !  mbedtls_x509write_crt_set_ns_cert_type " | 
|  | 852 | "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf); | 
| Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 853 | goto exit; | 
|  | 854 | } | 
|  | 855 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 856 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | 52be08c | 2013-09-09 12:37:54 +0200 | [diff] [blame] | 857 | } | 
|  | 858 |  | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 859 | /* | 
| Hanno Becker | 25d882b | 2018-08-23 15:26:06 +0100 | [diff] [blame] | 860 | * 1.2. Writing the certificate | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 861 | */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 862 | mbedtls_printf("  . Writing the certificate..."); | 
|  | 863 | fflush(stdout); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 864 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 865 | if ((ret = write_certificate(&crt, opt.output_file, | 
|  | 866 | mbedtls_ctr_drbg_random, &ctr_drbg)) != 0) { | 
|  | 867 | mbedtls_strerror(ret, buf, sizeof(buf)); | 
|  | 868 | mbedtls_printf(" failed\n  !  write_certificate -0x%04x - %s\n\n", | 
|  | 869 | (unsigned int) -ret, buf); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 870 | goto exit; | 
|  | 871 | } | 
|  | 872 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 873 | mbedtls_printf(" ok\n"); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 874 |  | 
| Andres Amaya Garcia | f9a54d3 | 2018-04-29 21:42:45 +0100 | [diff] [blame] | 875 | exit_code = MBEDTLS_EXIT_SUCCESS; | 
|  | 876 |  | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 877 | exit: | 
| Hanno Becker | 30a9510 | 2018-10-05 09:49:33 +0100 | [diff] [blame] | 878 | #if defined(MBEDTLS_X509_CSR_PARSE_C) | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 879 | mbedtls_x509_csr_free(&csr); | 
| Hanno Becker | 30a9510 | 2018-10-05 09:49:33 +0100 | [diff] [blame] | 880 | #endif /* MBEDTLS_X509_CSR_PARSE_C */ | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 881 | mbedtls_x509_crt_free(&issuer_crt); | 
|  | 882 | mbedtls_x509write_crt_free(&crt); | 
|  | 883 | mbedtls_pk_free(&loaded_subject_key); | 
|  | 884 | mbedtls_pk_free(&loaded_issuer_key); | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 885 | mbedtls_ctr_drbg_free(&ctr_drbg); | 
|  | 886 | mbedtls_entropy_free(&entropy); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 887 |  | 
| Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 888 | mbedtls_exit(exit_code); | 
| Paul Bakker | 9397dcb | 2013-09-06 09:55:26 +0200 | [diff] [blame] | 889 | } | 
| Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 890 | #endif /* MBEDTLS_X509_CRT_WRITE_C && MBEDTLS_X509_CRT_PARSE_C && | 
|  | 891 | MBEDTLS_FS_IO && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C && | 
| Simon Butcher | 203a693 | 2016-10-07 15:00:17 +0100 | [diff] [blame] | 892 | MBEDTLS_ERROR_C && MBEDTLS_PEM_WRITE_C */ |