Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * CRL reading application |
| 3 | * |
Paul Bakker | 3c5ef71 | 2013-06-25 16:37:45 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 5 | * |
| 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 Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 34 | #include "polarssl/config.h" |
| 35 | |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 36 | #include "polarssl/x509.h" |
| 37 | |
Paul Bakker | 80d44fe | 2013-09-09 15:59:20 +0200 | [diff] [blame^] | 38 | #if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \ |
| 39 | !defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO) |
| 40 | int 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 " |
| 46 | "POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n"); |
| 47 | return( 0 ); |
| 48 | } |
| 49 | #else |
| 50 | |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 51 | #define DFL_FILENAME "crl.pem" |
| 52 | #define DFL_DEBUG_LEVEL 0 |
| 53 | |
| 54 | /* |
| 55 | * global options |
| 56 | */ |
| 57 | struct options |
| 58 | { |
Paul Bakker | ef3f8c7 | 2013-06-24 13:01:08 +0200 | [diff] [blame] | 59 | const char *filename; /* filename of the certificate file */ |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 60 | } opt; |
| 61 | |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 62 | #define USAGE \ |
| 63 | "\n usage: crl_app param=<>...\n" \ |
| 64 | "\n acceptable parameters:\n" \ |
Paul Bakker | d3b486a | 2011-10-12 10:15:05 +0000 | [diff] [blame] | 65 | " filename=%%s default: crl.pem\n" \ |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 66 | "\n" |
| 67 | |
| 68 | int main( int argc, char *argv[] ) |
| 69 | { |
| 70 | int ret = 0; |
Paul Bakker | b8ba90b | 2011-12-05 14:34:12 +0000 | [diff] [blame] | 71 | unsigned char buf[100000]; |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 72 | x509_crl crl; |
| 73 | int i, j, n; |
| 74 | char *p, *q; |
| 75 | |
| 76 | /* |
| 77 | * Set to sane values |
| 78 | */ |
| 79 | memset( &crl, 0, sizeof( x509_crl ) ); |
| 80 | |
| 81 | if( argc == 0 ) |
| 82 | { |
| 83 | usage: |
| 84 | printf( USAGE ); |
| 85 | goto exit; |
| 86 | } |
| 87 | |
| 88 | opt.filename = DFL_FILENAME; |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 89 | |
| 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 Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 107 | 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 | |
| 142 | exit: |
| 143 | x509_crl_free( &crl ); |
| 144 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 145 | #if defined(_WIN32) |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 146 | printf( " + Press Enter to exit this program.\n" ); |
| 147 | fflush( stdout ); getchar(); |
| 148 | #endif |
| 149 | |
| 150 | return( ret ); |
| 151 | } |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 152 | #endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_PARSE_C && |
| 153 | POLARSSL_FS_IO */ |