2013-09-06 07:55:26 +00:00
|
|
|
/*
|
|
|
|
* Certificate generation and signing
|
|
|
|
*
|
2020-08-07 11:07:28 +00:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2015-09-04 12:21:07 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-09-06 07:55:26 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2013-09-06 07:55:26 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-09-06 07:55:26 +00:00
|
|
|
*
|
2015-09-04 12:21:07 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2013-09-06 07:55:26 +00:00
|
|
|
*/
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/config.h"
|
2014-04-29 10:39:06 +00:00
|
|
|
#else
|
2015-04-08 10:49:31 +00:00
|
|
|
#include MBEDTLS_CONFIG_FILE
|
2014-04-29 10:39:06 +00:00
|
|
|
#endif
|
2013-09-06 07:55:26 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_PLATFORM_C)
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/platform.h"
|
2015-01-19 14:26:37 +00:00
|
|
|
#else
|
2015-02-11 14:06:19 +00:00
|
|
|
#include <stdio.h>
|
2018-04-29 20:42:45 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#define mbedtls_printf printf
|
2018-12-10 13:31:45 +00:00
|
|
|
#define mbedtls_exit exit
|
2018-04-30 21:42:33 +00:00
|
|
|
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
|
2018-04-29 20:42:45 +00:00
|
|
|
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
|
|
|
|
#endif /* MBEDTLS_PLATFORM_C */
|
2015-01-19 14:26:37 +00:00
|
|
|
|
2016-10-07 14:00:17 +00:00
|
|
|
#if !defined(MBEDTLS_X509_CRT_WRITE_C) || \
|
|
|
|
!defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_FS_IO) || \
|
|
|
|
!defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
|
|
|
|
!defined(MBEDTLS_ERROR_C) || !defined(MBEDTLS_SHA256_C) || \
|
|
|
|
!defined(MBEDTLS_PEM_WRITE_C)
|
2015-03-31 13:10:03 +00:00
|
|
|
int main( void )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( "MBEDTLS_X509_CRT_WRITE_C and/or MBEDTLS_X509_CRT_PARSE_C and/or "
|
2015-08-06 16:22:26 +00:00
|
|
|
"MBEDTLS_FS_IO and/or MBEDTLS_SHA256_C and/or "
|
2015-04-08 10:49:31 +00:00
|
|
|
"MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
|
|
|
|
"MBEDTLS_ERROR_C not defined.\n");
|
2019-04-24 12:24:46 +00:00
|
|
|
mbedtls_exit( 0 );
|
2015-03-31 13:10:03 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/x509_crt.h"
|
|
|
|
#include "mbedtls/x509_csr.h"
|
|
|
|
#include "mbedtls/entropy.h"
|
|
|
|
#include "mbedtls/ctr_drbg.h"
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
#include "mbedtls/md.h"
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/error.h"
|
2013-09-20 10:29:56 +00:00
|
|
|
|
2015-02-11 14:06:19 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_X509_CSR_PARSE_C)
|
2015-02-11 14:06:19 +00:00
|
|
|
#define USAGE_CSR \
|
2017-09-13 14:39:59 +00:00
|
|
|
" request_file=%%s default: (empty)\n" \
|
|
|
|
" If request_file is specified, subject_key,\n" \
|
|
|
|
" subject_pwd and subject_name are ignored!\n"
|
2015-02-11 14:06:19 +00:00
|
|
|
#else
|
|
|
|
#define USAGE_CSR ""
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* MBEDTLS_X509_CSR_PARSE_C */
|
2015-02-11 14:06:19 +00:00
|
|
|
|
2013-09-09 11:59:42 +00:00
|
|
|
#define DFL_ISSUER_CRT ""
|
2013-09-09 13:52:07 +00:00
|
|
|
#define DFL_REQUEST_FILE ""
|
2013-09-06 07:55:26 +00:00
|
|
|
#define DFL_SUBJECT_KEY "subject.key"
|
|
|
|
#define DFL_ISSUER_KEY "ca.key"
|
|
|
|
#define DFL_SUBJECT_PWD ""
|
|
|
|
#define DFL_ISSUER_PWD ""
|
|
|
|
#define DFL_OUTPUT_FILENAME "cert.crt"
|
2015-01-22 16:26:39 +00:00
|
|
|
#define DFL_SUBJECT_NAME "CN=Cert,O=mbed TLS,C=UK"
|
|
|
|
#define DFL_ISSUER_NAME "CN=CA,O=mbed TLS,C=UK"
|
2013-09-06 07:55:26 +00:00
|
|
|
#define DFL_NOT_BEFORE "20010101000000"
|
|
|
|
#define DFL_NOT_AFTER "20301231235959"
|
|
|
|
#define DFL_SERIAL "1"
|
2013-09-09 14:24:18 +00:00
|
|
|
#define DFL_SELFSIGN 0
|
2013-09-06 17:27:21 +00:00
|
|
|
#define DFL_IS_CA 0
|
|
|
|
#define DFL_MAX_PATHLEN -1
|
2013-09-06 07:55:26 +00:00
|
|
|
#define DFL_KEY_USAGE 0
|
|
|
|
#define DFL_NS_CERT_TYPE 0
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
#define DFL_VERSION 3
|
|
|
|
#define DFL_AUTH_IDENT 1
|
|
|
|
#define DFL_SUBJ_IDENT 1
|
|
|
|
#define DFL_CONSTRAINTS 1
|
|
|
|
#define DFL_DIGEST MBEDTLS_MD_SHA256
|
2013-09-06 07:55:26 +00:00
|
|
|
|
2015-02-11 14:06:19 +00:00
|
|
|
#define USAGE \
|
|
|
|
"\n usage: cert_write param=<>...\n" \
|
|
|
|
"\n acceptable parameters:\n" \
|
|
|
|
USAGE_CSR \
|
2017-09-13 14:39:59 +00:00
|
|
|
" subject_key=%%s default: subject.key\n" \
|
|
|
|
" subject_pwd=%%s default: (empty)\n" \
|
|
|
|
" subject_name=%%s default: CN=Cert,O=mbed TLS,C=UK\n" \
|
2015-02-11 14:06:19 +00:00
|
|
|
"\n" \
|
2017-09-13 14:39:59 +00:00
|
|
|
" issuer_crt=%%s default: (empty)\n" \
|
|
|
|
" If issuer_crt is specified, issuer_name is\n" \
|
|
|
|
" ignored!\n" \
|
|
|
|
" issuer_name=%%s default: CN=CA,O=mbed TLS,C=UK\n" \
|
2015-02-11 14:06:19 +00:00
|
|
|
"\n" \
|
2017-09-13 14:39:59 +00:00
|
|
|
" selfsign=%%d default: 0 (false)\n" \
|
|
|
|
" If selfsign is enabled, issuer_name and\n" \
|
|
|
|
" issuer_key are required (issuer_crt and\n" \
|
|
|
|
" subject_* are ignored\n" \
|
|
|
|
" issuer_key=%%s default: ca.key\n" \
|
|
|
|
" issuer_pwd=%%s default: (empty)\n" \
|
|
|
|
" output_file=%%s default: cert.crt\n" \
|
|
|
|
" serial=%%s default: 1\n" \
|
|
|
|
" not_before=%%s default: 20010101000000\n"\
|
|
|
|
" not_after=%%s default: 20301231235959\n"\
|
|
|
|
" is_ca=%%d default: 0 (disabled)\n" \
|
|
|
|
" max_pathlen=%%d default: -1 (none)\n" \
|
|
|
|
" md=%%s default: SHA256\n" \
|
2020-08-21 18:42:32 +00:00
|
|
|
" Supported values (if enabled):\n" \
|
|
|
|
" MD2, MD4, MD5, RIPEMD160, SHA1,\n" \
|
|
|
|
" SHA224, SHA256, SHA384, SHA512\n" \
|
2017-09-13 14:39:59 +00:00
|
|
|
" version=%%d default: 3\n" \
|
|
|
|
" Possible values: 1, 2, 3\n"\
|
|
|
|
" subject_identifier=%%s default: 1\n" \
|
|
|
|
" Possible values: 0, 1\n" \
|
|
|
|
" (Considered for v3 only)\n"\
|
|
|
|
" authority_identifier=%%s default: 1\n" \
|
|
|
|
" Possible values: 0, 1\n" \
|
|
|
|
" (Considered for v3 only)\n"\
|
|
|
|
" basic_constraints=%%d default: 1\n" \
|
|
|
|
" Possible values: 0, 1\n" \
|
|
|
|
" (Considered for v3 only)\n"\
|
|
|
|
" key_usage=%%s default: (empty)\n" \
|
|
|
|
" Comma-separated-list of values:\n" \
|
|
|
|
" digital_signature\n" \
|
|
|
|
" non_repudiation\n" \
|
|
|
|
" key_encipherment\n" \
|
|
|
|
" data_encipherment\n" \
|
|
|
|
" key_agreement\n" \
|
|
|
|
" key_cert_sign\n" \
|
|
|
|
" crl_sign\n" \
|
|
|
|
" (Considered for v3 only)\n"\
|
|
|
|
" ns_cert_type=%%s default: (empty)\n" \
|
|
|
|
" Comma-separated-list of values:\n" \
|
|
|
|
" ssl_client\n" \
|
|
|
|
" ssl_server\n" \
|
|
|
|
" email\n" \
|
|
|
|
" object_signing\n" \
|
|
|
|
" ssl_ca\n" \
|
|
|
|
" email_ca\n" \
|
|
|
|
" object_signing_ca\n" \
|
2015-02-11 14:06:19 +00:00
|
|
|
"\n"
|
2015-02-13 14:12:07 +00:00
|
|
|
|
2018-12-06 17:43:31 +00:00
|
|
|
|
2013-09-06 07:55:26 +00:00
|
|
|
/*
|
|
|
|
* global options
|
|
|
|
*/
|
|
|
|
struct options
|
|
|
|
{
|
2013-11-25 12:29:43 +00:00
|
|
|
const char *issuer_crt; /* filename of the issuer certificate */
|
|
|
|
const char *request_file; /* filename of the certificate request */
|
|
|
|
const char *subject_key; /* filename of the subject key file */
|
|
|
|
const char *issuer_key; /* filename of the issuer key file */
|
|
|
|
const char *subject_pwd; /* password for the subject key file */
|
|
|
|
const char *issuer_pwd; /* password for the issuer key file */
|
2018-08-23 14:26:06 +00:00
|
|
|
const char *output_file; /* where to store the constructed CRT */
|
2013-11-25 12:29:43 +00:00
|
|
|
const char *subject_name; /* subject name for certificate */
|
|
|
|
const char *issuer_name; /* issuer name for certificate */
|
|
|
|
const char *not_before; /* validity period not before */
|
|
|
|
const char *not_after; /* validity period not after */
|
|
|
|
const char *serial; /* serial number string */
|
2013-09-09 14:24:18 +00:00
|
|
|
int selfsign; /* selfsign the certificate */
|
2013-09-06 17:27:21 +00:00
|
|
|
int is_ca; /* is a CA certificate */
|
|
|
|
int max_pathlen; /* maximum CA path length */
|
2017-09-22 14:35:16 +00:00
|
|
|
int authority_identifier; /* add authority identifier to CRT */
|
|
|
|
int subject_identifier; /* add subject identifier to CRT */
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
int basic_constraints; /* add basic constraints ext to CRT */
|
|
|
|
int version; /* CRT version */
|
|
|
|
mbedtls_md_type_t md; /* Hash used for signing */
|
2013-09-06 07:55:26 +00:00
|
|
|
unsigned char key_usage; /* key usage flags */
|
|
|
|
unsigned char ns_cert_type; /* NS cert type */
|
|
|
|
} opt;
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
int write_certificate( mbedtls_x509write_cert *crt, const char *output_file,
|
2013-09-12 03:59:05 +00:00
|
|
|
int (*f_rng)(void *, unsigned char *, size_t),
|
|
|
|
void *p_rng )
|
2013-09-06 07:55:26 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
FILE *f;
|
|
|
|
unsigned char output_buf[4096];
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
memset( output_buf, 0, 4096 );
|
2017-09-13 14:39:59 +00:00
|
|
|
if( ( ret = mbedtls_x509write_crt_pem( crt, output_buf, 4096,
|
|
|
|
f_rng, p_rng ) ) < 0 )
|
2013-09-06 07:55:26 +00:00
|
|
|
return( ret );
|
|
|
|
|
|
|
|
len = strlen( (char *) output_buf );
|
|
|
|
|
|
|
|
if( ( f = fopen( output_file, "w" ) ) == NULL )
|
|
|
|
return( -1 );
|
|
|
|
|
|
|
|
if( fwrite( output_buf, 1, len, f ) != len )
|
2014-04-17 14:02:36 +00:00
|
|
|
{
|
|
|
|
fclose( f );
|
2013-09-06 07:55:26 +00:00
|
|
|
return( -1 );
|
2014-04-17 14:02:36 +00:00
|
|
|
}
|
2013-09-06 07:55:26 +00:00
|
|
|
|
2014-04-17 14:02:36 +00:00
|
|
|
fclose( f );
|
2013-09-06 07:55:26 +00:00
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
2018-04-29 20:42:45 +00:00
|
|
|
int ret = 1;
|
|
|
|
int exit_code = MBEDTLS_EXIT_FAILURE;
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509_crt issuer_crt;
|
|
|
|
mbedtls_pk_context loaded_issuer_key, loaded_subject_key;
|
|
|
|
mbedtls_pk_context *issuer_key = &loaded_issuer_key,
|
2013-09-12 03:21:54 +00:00
|
|
|
*subject_key = &loaded_subject_key;
|
2013-09-06 07:55:26 +00:00
|
|
|
char buf[1024];
|
2015-10-10 19:58:07 +00:00
|
|
|
char issuer_name[256];
|
2013-11-30 14:13:02 +00:00
|
|
|
int i;
|
2013-09-06 07:55:26 +00:00
|
|
|
char *p, *q, *r;
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_X509_CSR_PARSE_C)
|
2015-10-10 19:58:07 +00:00
|
|
|
char subject_name[256];
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509_csr csr;
|
2013-09-17 12:44:00 +00:00
|
|
|
#endif
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509write_cert crt;
|
|
|
|
mbedtls_mpi serial;
|
|
|
|
mbedtls_entropy_context entropy;
|
|
|
|
mbedtls_ctr_drbg_context ctr_drbg;
|
2013-09-12 03:59:05 +00:00
|
|
|
const char *pers = "crt example app";
|
2013-09-06 07:55:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set to sane values
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509write_crt_init( &crt );
|
|
|
|
mbedtls_pk_init( &loaded_issuer_key );
|
|
|
|
mbedtls_pk_init( &loaded_subject_key );
|
|
|
|
mbedtls_mpi_init( &serial );
|
2015-04-28 20:52:30 +00:00
|
|
|
mbedtls_ctr_drbg_init( &ctr_drbg );
|
2018-10-05 08:49:33 +00:00
|
|
|
mbedtls_entropy_init( &entropy );
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_X509_CSR_PARSE_C)
|
|
|
|
mbedtls_x509_csr_init( &csr );
|
2013-09-17 12:44:00 +00:00
|
|
|
#endif
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509_crt_init( &issuer_crt );
|
2013-09-06 07:55:26 +00:00
|
|
|
memset( buf, 0, 1024 );
|
|
|
|
|
|
|
|
if( argc == 0 )
|
|
|
|
{
|
|
|
|
usage:
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( USAGE );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-09-09 11:59:42 +00:00
|
|
|
opt.issuer_crt = DFL_ISSUER_CRT;
|
2013-09-09 13:52:07 +00:00
|
|
|
opt.request_file = DFL_REQUEST_FILE;
|
2013-09-06 07:55:26 +00:00
|
|
|
opt.subject_key = DFL_SUBJECT_KEY;
|
|
|
|
opt.issuer_key = DFL_ISSUER_KEY;
|
|
|
|
opt.subject_pwd = DFL_SUBJECT_PWD;
|
|
|
|
opt.issuer_pwd = DFL_ISSUER_PWD;
|
|
|
|
opt.output_file = DFL_OUTPUT_FILENAME;
|
|
|
|
opt.subject_name = DFL_SUBJECT_NAME;
|
|
|
|
opt.issuer_name = DFL_ISSUER_NAME;
|
|
|
|
opt.not_before = DFL_NOT_BEFORE;
|
|
|
|
opt.not_after = DFL_NOT_AFTER;
|
|
|
|
opt.serial = DFL_SERIAL;
|
2013-09-09 14:24:18 +00:00
|
|
|
opt.selfsign = DFL_SELFSIGN;
|
2013-09-06 17:27:21 +00:00
|
|
|
opt.is_ca = DFL_IS_CA;
|
|
|
|
opt.max_pathlen = DFL_MAX_PATHLEN;
|
2013-09-06 07:55:26 +00:00
|
|
|
opt.key_usage = DFL_KEY_USAGE;
|
|
|
|
opt.ns_cert_type = DFL_NS_CERT_TYPE;
|
2017-09-22 14:38:20 +00:00
|
|
|
opt.version = DFL_VERSION - 1;
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
opt.md = DFL_DIGEST;
|
|
|
|
opt.subject_identifier = DFL_SUBJ_IDENT;
|
|
|
|
opt.authority_identifier = DFL_AUTH_IDENT;
|
|
|
|
opt.basic_constraints = DFL_CONSTRAINTS;
|
2013-09-06 07:55:26 +00:00
|
|
|
|
|
|
|
for( i = 1; i < argc; i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
p = argv[i];
|
|
|
|
if( ( q = strchr( p, '=' ) ) == NULL )
|
|
|
|
goto usage;
|
|
|
|
*q++ = '\0';
|
|
|
|
|
2013-09-09 13:52:07 +00:00
|
|
|
if( strcmp( p, "request_file" ) == 0 )
|
|
|
|
opt.request_file = q;
|
|
|
|
else if( strcmp( p, "subject_key" ) == 0 )
|
2013-09-06 07:55:26 +00:00
|
|
|
opt.subject_key = q;
|
|
|
|
else if( strcmp( p, "issuer_key" ) == 0 )
|
|
|
|
opt.issuer_key = q;
|
|
|
|
else if( strcmp( p, "subject_pwd" ) == 0 )
|
|
|
|
opt.subject_pwd = q;
|
|
|
|
else if( strcmp( p, "issuer_pwd" ) == 0 )
|
|
|
|
opt.issuer_pwd = q;
|
2013-09-09 11:59:42 +00:00
|
|
|
else if( strcmp( p, "issuer_crt" ) == 0 )
|
|
|
|
opt.issuer_crt = q;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( p, "output_file" ) == 0 )
|
|
|
|
opt.output_file = q;
|
|
|
|
else if( strcmp( p, "subject_name" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.subject_name = q;
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "issuer_name" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.issuer_name = q;
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "not_before" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.not_before = q;
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "not_after" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.not_after = q;
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "serial" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.serial = q;
|
|
|
|
}
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
else if( strcmp( p, "authority_identifier" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.authority_identifier = atoi( q );
|
|
|
|
if( opt.authority_identifier != 0 &&
|
|
|
|
opt.authority_identifier != 1 )
|
|
|
|
{
|
2017-10-03 13:56:04 +00:00
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "subject_identifier" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.subject_identifier = atoi( q );
|
|
|
|
if( opt.subject_identifier != 0 &&
|
|
|
|
opt.subject_identifier != 1 )
|
|
|
|
{
|
2017-10-03 13:56:04 +00:00
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "basic_constraints" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.basic_constraints = atoi( q );
|
|
|
|
if( opt.basic_constraints != 0 &&
|
|
|
|
opt.basic_constraints != 1 )
|
|
|
|
{
|
2017-10-03 13:56:04 +00:00
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "md" ) == 0 )
|
|
|
|
{
|
2020-08-21 18:42:32 +00:00
|
|
|
const mbedtls_md_info_t *md_info =
|
|
|
|
mbedtls_md_info_from_string( q );
|
|
|
|
if( md_info == NULL )
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2020-08-21 18:42:32 +00:00
|
|
|
opt.md = mbedtls_md_get_type( md_info );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
}
|
|
|
|
else if( strcmp( p, "version" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.version = atoi( q );
|
|
|
|
if( opt.version < 1 || opt.version > 3 )
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2017-09-22 14:38:20 +00:00
|
|
|
opt.version--;
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
}
|
2013-09-09 14:24:18 +00:00
|
|
|
else if( strcmp( p, "selfsign" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.selfsign = atoi( q );
|
|
|
|
if( opt.selfsign < 0 || opt.selfsign > 1 )
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
2013-09-09 14:24:18 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2013-09-09 14:24:18 +00:00
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
else if( strcmp( p, "is_ca" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.is_ca = atoi( q );
|
|
|
|
if( opt.is_ca < 0 || opt.is_ca > 1 )
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
2013-09-06 17:27:21 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
}
|
|
|
|
else if( strcmp( p, "max_pathlen" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.max_pathlen = atoi( q );
|
|
|
|
if( opt.max_pathlen < -1 || opt.max_pathlen > 127 )
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
2013-09-06 17:27:21 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
}
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( p, "key_usage" ) == 0 )
|
|
|
|
{
|
|
|
|
while( q != NULL )
|
|
|
|
{
|
|
|
|
if( ( r = strchr( q, ',' ) ) != NULL )
|
|
|
|
*r++ = '\0';
|
|
|
|
|
|
|
|
if( strcmp( q, "digital_signature" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_DIGITAL_SIGNATURE;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "non_repudiation" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_NON_REPUDIATION;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "key_encipherment" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_KEY_ENCIPHERMENT;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "data_encipherment" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_DATA_ENCIPHERMENT;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "key_agreement" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_KEY_AGREEMENT;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "key_cert_sign" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_KEY_CERT_SIGN;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "crl_sign" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.key_usage |= MBEDTLS_X509_KU_CRL_SIGN;
|
2013-09-06 07:55:26 +00:00
|
|
|
else
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2013-09-06 07:55:26 +00:00
|
|
|
|
|
|
|
q = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( strcmp( p, "ns_cert_type" ) == 0 )
|
|
|
|
{
|
|
|
|
while( q != NULL )
|
|
|
|
{
|
|
|
|
if( ( r = strchr( q, ',' ) ) != NULL )
|
|
|
|
*r++ = '\0';
|
|
|
|
|
|
|
|
if( strcmp( q, "ssl_client" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "ssl_server" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "email" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_EMAIL;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "object_signing" ) == 0 )
|
2015-04-08 10:49:31 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "ssl_ca" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_SSL_CA;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "email_ca" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA;
|
2013-09-06 07:55:26 +00:00
|
|
|
else if( strcmp( q, "object_signing_ca" ) == 0 )
|
2015-04-20 11:19:02 +00:00
|
|
|
opt.ns_cert_type |= MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA;
|
2013-09-06 07:55:26 +00:00
|
|
|
else
|
2017-10-03 13:56:04 +00:00
|
|
|
{
|
|
|
|
mbedtls_printf( "Invalid argument for option %s\n", p );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto usage;
|
2017-10-03 13:56:04 +00:00
|
|
|
}
|
2013-09-06 07:55:26 +00:00
|
|
|
|
|
|
|
q = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf("\n");
|
2013-09-09 11:59:42 +00:00
|
|
|
|
2013-09-12 03:59:05 +00:00
|
|
|
/*
|
|
|
|
* 0. Seed the PRNG
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Seeding the random number generator..." );
|
2013-09-12 03:59:05 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-28 20:52:30 +00:00
|
|
|
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
|
2013-09-12 03:59:05 +00:00
|
|
|
(const unsigned char *) pers,
|
|
|
|
strlen( pers ) ) ) != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d - %s\n",
|
|
|
|
ret, buf );
|
2013-09-12 03:59:05 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-12 03:59:05 +00:00
|
|
|
|
2013-09-06 07:55:26 +00:00
|
|
|
// Parse serial to MPI
|
|
|
|
//
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Reading serial number..." );
|
2013-09-12 03:59:05 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
if( ( ret = mbedtls_mpi_read_string( &serial, 10, opt.serial ) ) != 0 )
|
2013-09-06 07:55:26 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_mpi_read_string "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-12 03:59:05 +00:00
|
|
|
|
2013-09-09 11:59:42 +00:00
|
|
|
// Parse issuer certificate if present
|
|
|
|
//
|
2013-09-09 14:24:18 +00:00
|
|
|
if( !opt.selfsign && strlen( opt.issuer_crt ) )
|
2013-09-09 11:59:42 +00:00
|
|
|
{
|
|
|
|
/*
|
2013-09-09 13:52:07 +00:00
|
|
|
* 1.0.a. Load the certificates
|
2013-09-09 11:59:42 +00:00
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Loading the issuer certificate ..." );
|
2013-09-09 11:59:42 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
if( ( ret = mbedtls_x509_crt_parse_file( &issuer_crt, opt.issuer_crt ) ) != 0 )
|
2013-09-09 11:59:42 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 11:59:42 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_x509_dn_gets( issuer_name, sizeof(issuer_name),
|
2014-04-25 09:48:35 +00:00
|
|
|
&issuer_crt.subject );
|
2013-09-09 11:59:42 +00:00
|
|
|
if( ret < 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509_dn_gets "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 11:59:42 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-09-09 13:52:07 +00:00
|
|
|
opt.issuer_name = issuer_name;
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-09 13:52:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
#if defined(MBEDTLS_X509_CSR_PARSE_C)
|
2013-09-09 13:52:07 +00:00
|
|
|
// Parse certificate request if present
|
|
|
|
//
|
2013-09-09 14:24:18 +00:00
|
|
|
if( !opt.selfsign && strlen( opt.request_file ) )
|
2013-09-09 13:52:07 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 1.0.b. Load the CSR
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Loading the certificate request ..." );
|
2013-09-09 13:52:07 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
if( ( ret = mbedtls_x509_csr_parse_file( &csr, opt.request_file ) ) != 0 )
|
2013-09-09 13:52:07 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509_csr_parse_file "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 13:52:07 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_x509_dn_gets( subject_name, sizeof(subject_name),
|
2013-09-09 13:52:07 +00:00
|
|
|
&csr.subject );
|
|
|
|
if( ret < 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509_dn_gets "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 13:52:07 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt.subject_name = subject_name;
|
2013-09-12 03:21:54 +00:00
|
|
|
subject_key = &csr.pk;
|
2013-09-09 11:59:42 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-09 11:59:42 +00:00
|
|
|
}
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* MBEDTLS_X509_CSR_PARSE_C */
|
2013-09-09 11:59:42 +00:00
|
|
|
|
2013-09-06 07:55:26 +00:00
|
|
|
/*
|
|
|
|
* 1.1. Load the keys
|
|
|
|
*/
|
2013-09-09 14:24:18 +00:00
|
|
|
if( !opt.selfsign && !strlen( opt.request_file ) )
|
2013-09-06 07:55:26 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Loading the subject key ..." );
|
2013-09-09 13:52:07 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_pk_parse_keyfile( &loaded_subject_key, opt.subject_key,
|
2013-09-12 03:21:54 +00:00
|
|
|
opt.subject_pwd );
|
2013-09-09 13:52:07 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 13:52:07 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-06 07:55:26 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Loading the issuer key ..." );
|
2013-09-06 07:55:26 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_pk_parse_keyfile( &loaded_issuer_key, opt.issuer_key,
|
2013-09-15 11:01:22 +00:00
|
|
|
opt.issuer_pwd );
|
2013-09-06 07:55:26 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -x%02x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-09-09 11:59:42 +00:00
|
|
|
// Check if key and issuer certificate match
|
|
|
|
//
|
|
|
|
if( strlen( opt.issuer_crt ) )
|
|
|
|
{
|
2017-02-07 17:14:58 +00:00
|
|
|
if( mbedtls_pk_check_pair( &issuer_crt.pk, issuer_key ) != 0 )
|
2013-09-09 11:59:42 +00:00
|
|
|
{
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! issuer_key does not match "
|
|
|
|
"issuer certificate\n\n" );
|
2013-09-09 11:59:42 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-06 07:55:26 +00:00
|
|
|
|
2013-09-09 14:24:18 +00:00
|
|
|
if( opt.selfsign )
|
|
|
|
{
|
2013-10-28 21:28:09 +00:00
|
|
|
opt.subject_name = opt.issuer_name;
|
2013-09-12 03:21:54 +00:00
|
|
|
subject_key = issuer_key;
|
2013-09-09 14:24:18 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509write_crt_set_subject_key( &crt, subject_key );
|
|
|
|
mbedtls_x509write_crt_set_issuer_key( &crt, issuer_key );
|
2013-09-09 14:24:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 1.0. Check the names for validity
|
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
if( ( ret = mbedtls_x509write_crt_set_subject_name( &crt, opt.subject_name ) ) != 0 )
|
2013-09-09 14:24:18 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_subject_name "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 14:24:18 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
if( ( ret = mbedtls_x509write_crt_set_issuer_name( &crt, opt.issuer_name ) ) != 0 )
|
2013-09-09 14:24:18 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_issuer_name "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 14:24:18 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Setting certificate values ..." );
|
2013-09-06 07:55:26 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2017-09-22 14:38:20 +00:00
|
|
|
mbedtls_x509write_crt_set_version( &crt, opt.version );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
mbedtls_x509write_crt_set_md_alg( &crt, opt.md );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_serial( &crt, &serial );
|
2013-09-06 07:55:26 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_serial "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_validity( &crt, opt.not_before, opt.not_after );
|
2013-09-06 07:55:26 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_validity "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-06 07:55:26 +00:00
|
|
|
|
2017-09-22 14:38:20 +00:00
|
|
|
if( opt.version == MBEDTLS_X509_CRT_VERSION_3 &&
|
|
|
|
opt.basic_constraints != 0 )
|
2013-09-06 17:27:21 +00:00
|
|
|
{
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
mbedtls_printf( " . Adding the Basic Constraints extension ..." );
|
|
|
|
fflush( stdout );
|
2013-09-06 17:27:21 +00:00
|
|
|
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_basic_constraints( &crt, opt.is_ca,
|
|
|
|
opt.max_pathlen );
|
|
|
|
if( ret != 0 )
|
|
|
|
{
|
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
|
|
|
mbedtls_printf( " failed\n ! x509write_crt_set_basic_contraints "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
#if defined(MBEDTLS_SHA1_C)
|
2017-09-22 14:38:20 +00:00
|
|
|
if( opt.version == MBEDTLS_X509_CRT_VERSION_3 &&
|
|
|
|
opt.subject_identifier != 0 )
|
2013-09-06 17:27:21 +00:00
|
|
|
{
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
mbedtls_printf( " . Adding the Subject Key Identifier ..." );
|
|
|
|
fflush( stdout );
|
2013-09-06 17:27:21 +00:00
|
|
|
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_subject_key_identifier( &crt );
|
|
|
|
if( ret != 0 )
|
|
|
|
{
|
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_subject"
|
2017-09-22 14:39:02 +00:00
|
|
|
"_key_identifier returned -0x%04x - %s\n\n",
|
2020-04-01 15:22:45 +00:00
|
|
|
(unsigned int) -ret, buf );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
|
|
|
}
|
2013-09-06 17:27:21 +00:00
|
|
|
|
2017-09-22 14:38:20 +00:00
|
|
|
if( opt.version == MBEDTLS_X509_CRT_VERSION_3 &&
|
|
|
|
opt.authority_identifier != 0 )
|
2013-09-06 17:27:21 +00:00
|
|
|
{
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
mbedtls_printf( " . Adding the Authority Key Identifier ..." );
|
|
|
|
fflush( stdout );
|
2013-09-06 17:27:21 +00:00
|
|
|
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_authority_key_identifier( &crt );
|
|
|
|
if( ret != 0 )
|
|
|
|
{
|
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_authority_"
|
2017-09-22 14:39:02 +00:00
|
|
|
"key_identifier returned -0x%04x - %s\n\n",
|
2020-04-01 15:22:45 +00:00
|
|
|
(unsigned int) -ret, buf );
|
Extend cert_write example program by multiple cmd line options
This commit adds the following command line options to programs/x509/cert_write:
- version (val 1, 2, 3): Set the certificate's version (v1, v2, v3)
- authority_identifier (val 0, 1): Enable or disable the addition of the
authority identifier extension.
- subject_identifier (val 0, 1): Enable or disable the addition of the
subject identifier extension.
- basic_constraints (val 0, 1): Enable or disable the addition of the
basic constraints extension.
- md (val MD5, SHA1, SHA256, SHA512): Set the hash function used
when creating the CRT.
2017-09-13 11:49:22 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
mbedtls_printf( " ok\n" );
|
|
|
|
}
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* MBEDTLS_SHA1_C */
|
2013-09-06 17:27:21 +00:00
|
|
|
|
2017-09-22 14:38:20 +00:00
|
|
|
if( opt.version == MBEDTLS_X509_CRT_VERSION_3 &&
|
|
|
|
opt.key_usage != 0 )
|
2013-09-09 10:37:54 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Adding the Key Usage extension ..." );
|
2013-09-09 10:37:54 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_key_usage( &crt, opt.key_usage );
|
2013-09-09 10:37:54 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_key_usage "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 10:37:54 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-09 10:37:54 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 14:38:20 +00:00
|
|
|
if( opt.version == MBEDTLS_X509_CRT_VERSION_3 &&
|
|
|
|
opt.ns_cert_type != 0 )
|
2013-09-09 10:37:54 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Adding the NS Cert Type extension ..." );
|
2013-09-09 10:37:54 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
ret = mbedtls_x509write_crt_set_ns_cert_type( &crt, opt.ns_cert_type );
|
2013-09-09 10:37:54 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-13 14:39:59 +00:00
|
|
|
mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_ns_cert_type "
|
2020-04-01 15:22:45 +00:00
|
|
|
"returned -0x%04x - %s\n\n", (unsigned int) -ret, buf );
|
2013-09-09 10:37:54 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-09 10:37:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-06 07:55:26 +00:00
|
|
|
/*
|
2018-08-23 14:26:06 +00:00
|
|
|
* 1.2. Writing the certificate
|
2013-09-06 07:55:26 +00:00
|
|
|
*/
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " . Writing the certificate..." );
|
2013-09-06 07:55:26 +00:00
|
|
|
fflush( stdout );
|
|
|
|
|
2013-09-12 03:59:05 +00:00
|
|
|
if( ( ret = write_certificate( &crt, opt.output_file,
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
2013-09-06 07:55:26 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_strerror( ret, buf, 1024 );
|
2017-09-22 14:39:02 +00:00
|
|
|
mbedtls_printf( " failed\n ! write_certificate -0x%04x - %s\n\n",
|
2020-04-01 15:22:45 +00:00
|
|
|
(unsigned int) -ret, buf );
|
2013-09-06 07:55:26 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " ok\n" );
|
2013-09-06 07:55:26 +00:00
|
|
|
|
2018-04-29 20:42:45 +00:00
|
|
|
exit_code = MBEDTLS_EXIT_SUCCESS;
|
|
|
|
|
2013-09-06 07:55:26 +00:00
|
|
|
exit:
|
2018-10-05 08:49:33 +00:00
|
|
|
#if defined(MBEDTLS_X509_CSR_PARSE_C)
|
|
|
|
mbedtls_x509_csr_free( &csr );
|
|
|
|
#endif /* MBEDTLS_X509_CSR_PARSE_C */
|
|
|
|
mbedtls_x509_crt_free( &issuer_crt );
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509write_crt_free( &crt );
|
|
|
|
mbedtls_pk_free( &loaded_subject_key );
|
|
|
|
mbedtls_pk_free( &loaded_issuer_key );
|
|
|
|
mbedtls_mpi_free( &serial );
|
|
|
|
mbedtls_ctr_drbg_free( &ctr_drbg );
|
|
|
|
mbedtls_entropy_free( &entropy );
|
2013-09-06 07:55:26 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_printf( " + Press Enter to exit this program.\n" );
|
2013-09-06 07:55:26 +00:00
|
|
|
fflush( stdout ); getchar();
|
|
|
|
#endif
|
|
|
|
|
2019-04-24 12:24:46 +00:00
|
|
|
mbedtls_exit( exit_code );
|
2013-09-06 07:55:26 +00:00
|
|
|
}
|
2015-04-08 10:49:31 +00:00
|
|
|
#endif /* MBEDTLS_X509_CRT_WRITE_C && MBEDTLS_X509_CRT_PARSE_C &&
|
|
|
|
MBEDTLS_FS_IO && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C &&
|
2016-10-07 14:00:17 +00:00
|
|
|
MBEDTLS_ERROR_C && MBEDTLS_PEM_WRITE_C */
|