blob: 4097554f35f1eb99b112acc203f386035022a260 [file] [log] [blame]
Paul Bakkera9507c02011-02-12 15:27:28 +00001/*
2 * CRL reading application
3 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkera9507c02011-02-12 15:27:28 +00005 *
Manuel Pégourié-Gonnard085ab042015-01-23 11:06:27 +00006 * This file is part of mbed TLS (https://www.polarssl.org)
Paul Bakkera9507c02011-02-12 15:27:28 +00007 *
Paul Bakkera9507c02011-02-12 15:27:28 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_CONFIG_FILE)
Manuel Pégourié-Gonnardabd6e022013-09-20 13:30:43 +020024#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakkera9507c02011-02-12 15:27:28 +000028
Rich Evansf90016a2015-01-19 14:26:37 +000029#if defined(POLARSSL_PLATFORM_C)
30#include "polarssl/platform.h"
31#else
32#define polarssl_printf printf
33#define polarssl_fprintf fprintf
34#define polarssl_malloc malloc
35#define polarssl_free free
36#endif
37
Paul Bakkera9507c02011-02-12 15:27:28 +000038#include <string.h>
39#include <stdlib.h>
40#include <stdio.h>
41
Paul Bakker7c6b2c32013-09-16 13:49:26 +020042#include "polarssl/x509_crl.h"
Paul Bakkera9507c02011-02-12 15:27:28 +000043
Paul Bakker80d44fe2013-09-09 15:59:20 +020044#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
Paul Bakker7c6b2c32013-09-16 13:49:26 +020045 !defined(POLARSSL_X509_CRL_PARSE_C) || !defined(POLARSSL_FS_IO)
Paul Bakker80d44fe2013-09-09 15:59:20 +020046int main( int argc, char *argv[] )
47{
48 ((void) argc);
49 ((void) argv);
50
Rich Evansf90016a2015-01-19 14:26:37 +000051 polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
Paul Bakker7c6b2c32013-09-16 13:49:26 +020052 "POLARSSL_X509_CRL_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
Paul Bakker80d44fe2013-09-09 15:59:20 +020053 return( 0 );
54}
55#else
56
Paul Bakkera9507c02011-02-12 15:27:28 +000057#define DFL_FILENAME "crl.pem"
58#define DFL_DEBUG_LEVEL 0
59
60/*
61 * global options
62 */
63struct options
64{
Paul Bakkeref3f8c72013-06-24 13:01:08 +020065 const char *filename; /* filename of the certificate file */
Paul Bakkera9507c02011-02-12 15:27:28 +000066} opt;
67
Paul Bakkera9507c02011-02-12 15:27:28 +000068#define USAGE \
69 "\n usage: crl_app param=<>...\n" \
70 "\n acceptable parameters:\n" \
Paul Bakkerd3b486a2011-10-12 10:15:05 +000071 " filename=%%s default: crl.pem\n" \
Paul Bakkera9507c02011-02-12 15:27:28 +000072 "\n"
73
74int main( int argc, char *argv[] )
75{
76 int ret = 0;
Paul Bakkerb8ba90b2011-12-05 14:34:12 +000077 unsigned char buf[100000];
Paul Bakkera9507c02011-02-12 15:27:28 +000078 x509_crl crl;
Paul Bakkerc97f9f62013-11-30 15:13:02 +010079 int i;
Paul Bakkera9507c02011-02-12 15:27:28 +000080 char *p, *q;
81
82 /*
83 * Set to sane values
84 */
Paul Bakker369d2eb2013-09-18 11:58:25 +020085 x509_crl_init( &crl );
Paul Bakkera9507c02011-02-12 15:27:28 +000086
87 if( argc == 0 )
88 {
89 usage:
Rich Evansf90016a2015-01-19 14:26:37 +000090 polarssl_printf( USAGE );
Paul Bakkera9507c02011-02-12 15:27:28 +000091 goto exit;
92 }
93
94 opt.filename = DFL_FILENAME;
Paul Bakkera9507c02011-02-12 15:27:28 +000095
96 for( i = 1; i < argc; i++ )
97 {
Paul Bakkera9507c02011-02-12 15:27:28 +000098 p = argv[i];
99 if( ( q = strchr( p, '=' ) ) == NULL )
100 goto usage;
101 *q++ = '\0';
102
103 if( strcmp( p, "filename" ) == 0 )
104 opt.filename = q;
Paul Bakkera9507c02011-02-12 15:27:28 +0000105 else
106 goto usage;
107 }
108
109 /*
110 * 1.1. Load the CRL
111 */
Rich Evansf90016a2015-01-19 14:26:37 +0000112 polarssl_printf( "\n . Loading the CRL ..." );
Paul Bakkera9507c02011-02-12 15:27:28 +0000113 fflush( stdout );
114
Paul Bakkerddf26b42013-09-18 13:46:23 +0200115 ret = x509_crl_parse_file( &crl, opt.filename );
Paul Bakkera9507c02011-02-12 15:27:28 +0000116
117 if( ret != 0 )
118 {
Rich Evansf90016a2015-01-19 14:26:37 +0000119 polarssl_printf( " failed\n ! x509_crl_parse_file returned %d\n\n", ret );
Paul Bakkera9507c02011-02-12 15:27:28 +0000120 x509_crl_free( &crl );
121 goto exit;
122 }
123
Rich Evansf90016a2015-01-19 14:26:37 +0000124 polarssl_printf( " ok\n" );
Paul Bakkera9507c02011-02-12 15:27:28 +0000125
126 /*
127 * 1.2 Print the CRL
128 */
Rich Evansf90016a2015-01-19 14:26:37 +0000129 polarssl_printf( " . CRL information ...\n" );
Paul Bakkerddf26b42013-09-18 13:46:23 +0200130 ret = x509_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
Paul Bakkera9507c02011-02-12 15:27:28 +0000131 if( ret == -1 )
132 {
Rich Evansf90016a2015-01-19 14:26:37 +0000133 polarssl_printf( " failed\n ! x509_crl_info returned %d\n\n", ret );
Paul Bakkera9507c02011-02-12 15:27:28 +0000134 x509_crl_free( &crl );
135 goto exit;
136 }
137
Rich Evansf90016a2015-01-19 14:26:37 +0000138 polarssl_printf( "%s\n", buf );
Paul Bakkera9507c02011-02-12 15:27:28 +0000139
140exit:
141 x509_crl_free( &crl );
142
Paul Bakkercce9d772011-11-18 14:26:47 +0000143#if defined(_WIN32)
Rich Evansf90016a2015-01-19 14:26:37 +0000144 polarssl_printf( " + Press Enter to exit this program.\n" );
Paul Bakkera9507c02011-02-12 15:27:28 +0000145 fflush( stdout ); getchar();
146#endif
147
148 return( ret );
149}
Paul Bakker36713e82013-09-17 13:25:29 +0200150#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_CRL_PARSE_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000151 POLARSSL_FS_IO */