Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * CRL reading application |
| 3 | * |
Paul Bakker | 530927b | 2015-02-13 14:24:10 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | e12abf9 | 2015-01-28 17:13:45 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (https://polarssl.org) |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 7 | * |
| 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 Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 31 | #include "polarssl/config.h" |
| 32 | |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 33 | #include "polarssl/x509.h" |
| 34 | |
| 35 | #define DFL_FILENAME "crl.pem" |
| 36 | #define DFL_DEBUG_LEVEL 0 |
| 37 | |
| 38 | /* |
| 39 | * global options |
| 40 | */ |
| 41 | struct options |
| 42 | { |
Paul Bakker | e0225e4 | 2013-06-06 12:52:24 +0200 | [diff] [blame] | 43 | const char *filename; /* filename of the certificate file */ |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 44 | int debug_level; /* level of debugging */ |
| 45 | } opt; |
| 46 | |
| 47 | void 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 Bakker | d3b486a | 2011-10-12 10:15:05 +0000 | [diff] [blame] | 59 | " filename=%%s default: crl.pem\n" \ |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 60 | " debug_level=%%d default: 0 (disabled)\n" \ |
| 61 | "\n" |
| 62 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 63 | #if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \ |
| 64 | !defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO) |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 65 | int main( int argc, char *argv[] ) |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 66 | { |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 67 | ((void) argc); |
| 68 | ((void) argv); |
| 69 | |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 70 | 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 Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 75 | int main( int argc, char *argv[] ) |
| 76 | { |
| 77 | int ret = 0; |
Paul Bakker | b8ba90b | 2011-12-05 14:34:12 +0000 | [diff] [blame] | 78 | unsigned char buf[100000]; |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 79 | x509_crl crl; |
Paul Bakker | 256a4af | 2013-11-30 15:13:02 +0100 | [diff] [blame] | 80 | int i; |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 81 | 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 Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 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; |
| 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 | |
| 148 | exit: |
| 149 | x509_crl_free( &crl ); |
| 150 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 151 | #if defined(_WIN32) |
Paul Bakker | a9507c0 | 2011-02-12 15:27:28 +0000 | [diff] [blame] | 152 | printf( " + Press Enter to exit this program.\n" ); |
| 153 | fflush( stdout ); getchar(); |
| 154 | #endif |
| 155 | |
| 156 | return( ret ); |
| 157 | } |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 158 | #endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_PARSE_C && |
| 159 | POLARSSL_FS_IO */ |