blob: 363771dc7fd76da759afe88dabe72e4ea41fb0f2 [file] [log] [blame]
Paul Bakkera9507c02011-02-12 15:27:28 +00001/*
2 * CRL reading application
3 *
Manuel Pégourié-Gonnard0edee5e2015-01-26 15:29:40 +00004 * Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
Paul Bakkera9507c02011-02-12 15:27:28 +00005 *
Manuel Pégourié-Gonnard0edee5e2015-01-26 15:29:40 +00006 * This file is part of mbed TLS (https://www.polarssl.org)
Paul Bakkera9507c02011-02-12 15:27:28 +00007 *
8 * 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
23#ifndef _CRT_SECURE_NO_DEPRECATE
24#define _CRT_SECURE_NO_DEPRECATE 1
25#endif
26
27#include <string.h>
28#include <stdlib.h>
29#include <stdio.h>
30
Paul Bakker5690efc2011-05-26 13:16:06 +000031#include "polarssl/config.h"
32
Paul Bakkera9507c02011-02-12 15:27:28 +000033#include "polarssl/x509.h"
34
35#define DFL_FILENAME "crl.pem"
36#define DFL_DEBUG_LEVEL 0
37
38/*
39 * global options
40 */
41struct options
42{
Paul Bakkere0225e42013-06-06 12:52:24 +020043 const char *filename; /* filename of the certificate file */
Paul Bakkera9507c02011-02-12 15:27:28 +000044 int debug_level; /* level of debugging */
45} opt;
46
47void my_debug( void *ctx, int level, const char *str )
48{
49 if( level < opt.debug_level )
50 {
51 fprintf( (FILE *) ctx, "%s", str );
52 fflush( (FILE *) ctx );
53 }
54}
55
56#define USAGE \
57 "\n usage: crl_app param=<>...\n" \
58 "\n acceptable parameters:\n" \
Paul Bakkerd3b486a2011-10-12 10:15:05 +000059 " filename=%%s default: crl.pem\n" \
Paul Bakkera9507c02011-02-12 15:27:28 +000060 " debug_level=%%d default: 0 (disabled)\n" \
61 "\n"
62
Paul Bakker5690efc2011-05-26 13:16:06 +000063#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
64 !defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
Paul Bakkercce9d772011-11-18 14:26:47 +000065int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +000066{
Paul Bakkercce9d772011-11-18 14:26:47 +000067 ((void) argc);
68 ((void) argv);
69
Paul Bakker5690efc2011-05-26 13:16:06 +000070 printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
71 "POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
72 return( 0 );
73}
74#else
Paul Bakkera9507c02011-02-12 15:27:28 +000075int main( int argc, char *argv[] )
76{
77 int ret = 0;
Paul Bakkerb8ba90b2011-12-05 14:34:12 +000078 unsigned char buf[100000];
Paul Bakkera9507c02011-02-12 15:27:28 +000079 x509_crl crl;
Paul Bakker256a4af2013-11-30 15:13:02 +010080 int i;
Paul Bakkera9507c02011-02-12 15:27:28 +000081 char *p, *q;
82
83 /*
84 * Set to sane values
85 */
86 memset( &crl, 0, sizeof( x509_crl ) );
87
88 if( argc == 0 )
89 {
90 usage:
91 printf( USAGE );
92 goto exit;
93 }
94
95 opt.filename = DFL_FILENAME;
96 opt.debug_level = DFL_DEBUG_LEVEL;
97
98 for( i = 1; i < argc; i++ )
99 {
Paul Bakkera9507c02011-02-12 15:27:28 +0000100 p = argv[i];
101 if( ( q = strchr( p, '=' ) ) == NULL )
102 goto usage;
103 *q++ = '\0';
104
105 if( strcmp( p, "filename" ) == 0 )
106 opt.filename = q;
107 else if( strcmp( p, "debug_level" ) == 0 )
108 {
109 opt.debug_level = atoi( q );
110 if( opt.debug_level < 0 || opt.debug_level > 65535 )
111 goto usage;
112 }
113 else
114 goto usage;
115 }
116
117 /*
118 * 1.1. Load the CRL
119 */
120 printf( "\n . Loading the CRL ..." );
121 fflush( stdout );
122
123 ret = x509parse_crlfile( &crl, opt.filename );
124
125 if( ret != 0 )
126 {
127 printf( " failed\n ! x509parse_crl returned %d\n\n", ret );
128 x509_crl_free( &crl );
129 goto exit;
130 }
131
132 printf( " ok\n" );
133
134 /*
135 * 1.2 Print the CRL
136 */
137 printf( " . CRL information ...\n" );
138 ret = x509parse_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
139 if( ret == -1 )
140 {
141 printf( " failed\n ! x509parse_crl_info returned %d\n\n", ret );
142 x509_crl_free( &crl );
143 goto exit;
144 }
145
146 printf( "%s\n", buf );
147
148exit:
149 x509_crl_free( &crl );
150
Paul Bakkercce9d772011-11-18 14:26:47 +0000151#if defined(_WIN32)
Paul Bakkera9507c02011-02-12 15:27:28 +0000152 printf( " + Press Enter to exit this program.\n" );
153 fflush( stdout ); getchar();
154#endif
155
156 return( ret );
157}
Paul Bakker5690efc2011-05-26 13:16:06 +0000158#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_PARSE_C &&
159 POLARSSL_FS_IO */