blob: b98e743dd02409c5dc18a0b7378662760fb79973 [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 Bakkera9507c02011-02-12 15:27:28 +000036#include "polarssl/x509.h"
37
38#define DFL_FILENAME "crl.pem"
39#define DFL_DEBUG_LEVEL 0
40
41/*
42 * global options
43 */
44struct options
45{
Paul Bakkeref3f8c72013-06-24 13:01:08 +020046 const char *filename; /* filename of the certificate file */
Paul Bakkera9507c02011-02-12 15:27:28 +000047} opt;
48
Paul Bakkera9507c02011-02-12 15:27:28 +000049#define USAGE \
50 "\n usage: crl_app param=<>...\n" \
51 "\n acceptable parameters:\n" \
Paul Bakkerd3b486a2011-10-12 10:15:05 +000052 " filename=%%s default: crl.pem\n" \
Paul Bakkera9507c02011-02-12 15:27:28 +000053 "\n"
54
Paul Bakker5690efc2011-05-26 13:16:06 +000055#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
56 !defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
Paul Bakkercce9d772011-11-18 14:26:47 +000057int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +000058{
Paul Bakkercce9d772011-11-18 14:26:47 +000059 ((void) argc);
60 ((void) argv);
61
Paul Bakker5690efc2011-05-26 13:16:06 +000062 printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
63 "POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
64 return( 0 );
65}
66#else
Paul Bakkera9507c02011-02-12 15:27:28 +000067int main( int argc, char *argv[] )
68{
69 int ret = 0;
Paul Bakkerb8ba90b2011-12-05 14:34:12 +000070 unsigned char buf[100000];
Paul Bakkera9507c02011-02-12 15:27:28 +000071 x509_crl crl;
72 int i, j, n;
73 char *p, *q;
74
75 /*
76 * Set to sane values
77 */
78 memset( &crl, 0, sizeof( x509_crl ) );
79
80 if( argc == 0 )
81 {
82 usage:
83 printf( USAGE );
84 goto exit;
85 }
86
87 opt.filename = DFL_FILENAME;
Paul Bakkera9507c02011-02-12 15:27:28 +000088
89 for( i = 1; i < argc; i++ )
90 {
91 n = strlen( argv[i] );
92
93 for( j = 0; j < n; j++ )
94 {
95 if( argv[i][j] >= 'A' && argv[i][j] <= 'Z' )
96 argv[i][j] |= 0x20;
97 }
98
99 p = argv[i];
100 if( ( q = strchr( p, '=' ) ) == NULL )
101 goto usage;
102 *q++ = '\0';
103
104 if( strcmp( p, "filename" ) == 0 )
105 opt.filename = q;
Paul Bakkera9507c02011-02-12 15:27:28 +0000106 else
107 goto usage;
108 }
109
110 /*
111 * 1.1. Load the CRL
112 */
113 printf( "\n . Loading the CRL ..." );
114 fflush( stdout );
115
116 ret = x509parse_crlfile( &crl, opt.filename );
117
118 if( ret != 0 )
119 {
120 printf( " failed\n ! x509parse_crl returned %d\n\n", ret );
121 x509_crl_free( &crl );
122 goto exit;
123 }
124
125 printf( " ok\n" );
126
127 /*
128 * 1.2 Print the CRL
129 */
130 printf( " . CRL information ...\n" );
131 ret = x509parse_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
132 if( ret == -1 )
133 {
134 printf( " failed\n ! x509parse_crl_info returned %d\n\n", ret );
135 x509_crl_free( &crl );
136 goto exit;
137 }
138
139 printf( "%s\n", buf );
140
141exit:
142 x509_crl_free( &crl );
143
Paul Bakkercce9d772011-11-18 14:26:47 +0000144#if defined(_WIN32)
Paul Bakkera9507c02011-02-12 15:27:28 +0000145 printf( " + Press Enter to exit this program.\n" );
146 fflush( stdout ); getchar();
147#endif
148
149 return( ret );
150}
Paul Bakker5690efc2011-05-26 13:16:06 +0000151#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_PARSE_C &&
152 POLARSSL_FS_IO */