2 * CRL reading application
4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
5 * SPDX-License-Identifier: Apache-2.0
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * This file is part of mbed TLS (https://tls.mbed.org)
22 #if !defined(MBEDTLS_CONFIG_FILE)
23 #include "mbedtls/config.h"
25 #include MBEDTLS_CONFIG_FILE
28 #if defined(MBEDTLS_PLATFORM_C)
29 #include "mbedtls/platform.h"
33 #define mbedtls_printf printf
34 #define mbedtls_exit exit
35 #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
36 #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
37 #endif /* MBEDTLS_PLATFORM_C */
39 #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \
40 !defined(MBEDTLS_X509_CRL_PARSE_C) || !defined(MBEDTLS_FS_IO)
43 mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_RSA_C and/or "
44 "MBEDTLS_X509_CRL_PARSE_C and/or MBEDTLS_FS_IO not defined.\n");
49 #include "mbedtls/x509_crl.h"
55 #define DFL_FILENAME "crl.pem"
56 #define DFL_DEBUG_LEVEL 0
59 "\n usage: crl_app param=<>...\n" \
60 "\n acceptable parameters:\n" \
61 " filename=%%s default: crl.pem\n" \
64 #if defined(MBEDTLS_CHECK_PARAMS)
65 #define mbedtls_exit exit
66 void mbedtls_param_failed( const char *failure_condition,
70 mbedtls_printf( "%s:%i: Input param failed - %s\n",
71 file, line, failure_condition );
72 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
81 const char *filename; /* filename of the certificate file */
84 int main( int argc, char *argv[] )
87 int exit_code = MBEDTLS_EXIT_FAILURE;
88 unsigned char buf[100000];
96 mbedtls_x509_crl_init( &crl );
101 mbedtls_printf( USAGE );
105 opt.filename = DFL_FILENAME;
107 for( i = 1; i < argc; i++ )
110 if( ( q = strchr( p, '=' ) ) == NULL )
114 if( strcmp( p, "filename" ) == 0 )
123 mbedtls_printf( "\n . Loading the CRL ..." );
126 ret = mbedtls_x509_crl_parse_file( &crl, opt.filename );
130 mbedtls_printf( " failed\n ! mbedtls_x509_crl_parse_file returned %d\n\n", ret );
131 mbedtls_x509_crl_free( &crl );
135 mbedtls_printf( " ok\n" );
140 mbedtls_printf( " . CRL information ...\n" );
141 ret = mbedtls_x509_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
144 mbedtls_printf( " failed\n ! mbedtls_x509_crl_info returned %d\n\n", ret );
145 mbedtls_x509_crl_free( &crl );
149 mbedtls_printf( "%s\n", buf );
151 exit_code = MBEDTLS_EXIT_SUCCESS;
154 mbedtls_x509_crl_free( &crl );
157 mbedtls_printf( " + Press Enter to exit this program.\n" );
158 fflush( stdout ); getchar();
163 #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_X509_CRL_PARSE_C &&