blob: 2213f81960b0aad4112bf7aeacb190742fdffdfe [file] [log] [blame]
Paul Bakkera9507c02011-02-12 15:27:28 +00001/*
2 * CRL reading application
3 *
Paul Bakker3c5ef712013-06-25 16:37:45 +02004 * Copyright (C) 2006-2013, Brainspark B.V.
Paul Bakkera9507c02011-02-12 15:27:28 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26#ifndef _CRT_SECURE_NO_DEPRECATE
27#define _CRT_SECURE_NO_DEPRECATE 1
28#endif
29
30#include <string.h>
31#include <stdlib.h>
32#include <stdio.h>
33
Paul Bakker5690efc2011-05-26 13:16:06 +000034#include "polarssl/config.h"
35
Paul Bakker7c6b2c32013-09-16 13:49:26 +020036#include "polarssl/x509_crl.h"
Paul Bakkera9507c02011-02-12 15:27:28 +000037
Paul Bakker80d44fe2013-09-09 15:59:20 +020038#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
Paul Bakker7c6b2c32013-09-16 13:49:26 +020039 !defined(POLARSSL_X509_CRL_PARSE_C) || !defined(POLARSSL_FS_IO)
Paul Bakker80d44fe2013-09-09 15:59:20 +020040int main( int argc, char *argv[] )
41{
42 ((void) argc);
43 ((void) argv);
44
45 printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
Paul Bakker7c6b2c32013-09-16 13:49:26 +020046 "POLARSSL_X509_CRL_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
Paul Bakker80d44fe2013-09-09 15:59:20 +020047 return( 0 );
48}
49#else
50
Paul Bakkera9507c02011-02-12 15:27:28 +000051#define DFL_FILENAME "crl.pem"
52#define DFL_DEBUG_LEVEL 0
53
54/*
55 * global options
56 */
57struct options
58{
Paul Bakkeref3f8c72013-06-24 13:01:08 +020059 const char *filename; /* filename of the certificate file */
Paul Bakkera9507c02011-02-12 15:27:28 +000060} opt;
61
Paul Bakkera9507c02011-02-12 15:27:28 +000062#define USAGE \
63 "\n usage: crl_app param=<>...\n" \
64 "\n acceptable parameters:\n" \
Paul Bakkerd3b486a2011-10-12 10:15:05 +000065 " filename=%%s default: crl.pem\n" \
Paul Bakkera9507c02011-02-12 15:27:28 +000066 "\n"
67
68int main( int argc, char *argv[] )
69{
70 int ret = 0;
Paul Bakkerb8ba90b2011-12-05 14:34:12 +000071 unsigned char buf[100000];
Paul Bakkera9507c02011-02-12 15:27:28 +000072 x509_crl crl;
73 int i, j, n;
74 char *p, *q;
75
76 /*
77 * Set to sane values
78 */
Paul Bakker369d2eb2013-09-18 11:58:25 +020079 x509_crl_init( &crl );
Paul Bakkera9507c02011-02-12 15:27:28 +000080
81 if( argc == 0 )
82 {
83 usage:
84 printf( USAGE );
85 goto exit;
86 }
87
88 opt.filename = DFL_FILENAME;
Paul Bakkera9507c02011-02-12 15:27:28 +000089
90 for( i = 1; i < argc; i++ )
91 {
92 n = strlen( argv[i] );
93
94 for( j = 0; j < n; j++ )
95 {
96 if( argv[i][j] >= 'A' && argv[i][j] <= 'Z' )
97 argv[i][j] |= 0x20;
98 }
99
100 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;
Paul Bakkera9507c02011-02-12 15:27:28 +0000107 else
108 goto usage;
109 }
110
111 /*
112 * 1.1. Load the CRL
113 */
114 printf( "\n . Loading the CRL ..." );
115 fflush( stdout );
116
117 ret = x509parse_crlfile( &crl, opt.filename );
118
119 if( ret != 0 )
120 {
121 printf( " failed\n ! x509parse_crl returned %d\n\n", ret );
122 x509_crl_free( &crl );
123 goto exit;
124 }
125
126 printf( " ok\n" );
127
128 /*
129 * 1.2 Print the CRL
130 */
131 printf( " . CRL information ...\n" );
132 ret = x509parse_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
133 if( ret == -1 )
134 {
135 printf( " failed\n ! x509parse_crl_info returned %d\n\n", ret );
136 x509_crl_free( &crl );
137 goto exit;
138 }
139
140 printf( "%s\n", buf );
141
142exit:
143 x509_crl_free( &crl );
144
Paul Bakkercce9d772011-11-18 14:26:47 +0000145#if defined(_WIN32)
Paul Bakkera9507c02011-02-12 15:27:28 +0000146 printf( " + Press Enter to exit this program.\n" );
147 fflush( stdout ); getchar();
148#endif
149
150 return( ret );
151}
Paul Bakker36713e82013-09-17 13:25:29 +0200152#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_CRL_PARSE_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000153 POLARSSL_FS_IO */