2011-02-12 16:27:28 +01:00
|
|
|
/*
|
|
|
|
* CRL reading application
|
|
|
|
*
|
2013-06-25 16:37:45 +02:00
|
|
|
* Copyright (C) 2006-2013, Brainspark B.V.
|
2011-02-12 16:27:28 +01:00
|
|
|
*
|
|
|
|
* This file is part of PolarSSL (http://www.polarssl.org)
|
|
|
|
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CRT_SECURE_NO_DEPRECATE
|
|
|
|
#define _CRT_SECURE_NO_DEPRECATE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-05-26 15:16:06 +02:00
|
|
|
#include "polarssl/config.h"
|
|
|
|
|
2013-09-16 13:49:26 +02:00
|
|
|
#include "polarssl/x509_crl.h"
|
2011-02-12 16:27:28 +01:00
|
|
|
|
2013-09-09 15:59:20 +02:00
|
|
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
2013-09-16 13:49:26 +02:00
|
|
|
!defined(POLARSSL_X509_CRL_PARSE_C) || !defined(POLARSSL_FS_IO)
|
2013-09-09 15:59:20 +02:00
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
((void) argc);
|
|
|
|
((void) argv);
|
|
|
|
|
|
|
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
2013-09-16 13:49:26 +02:00
|
|
|
"POLARSSL_X509_CRL_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
2013-09-09 15:59:20 +02:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2011-02-12 16:27:28 +01:00
|
|
|
#define DFL_FILENAME "crl.pem"
|
|
|
|
#define DFL_DEBUG_LEVEL 0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* global options
|
|
|
|
*/
|
|
|
|
struct options
|
|
|
|
{
|
2013-06-24 13:01:08 +02:00
|
|
|
const char *filename; /* filename of the certificate file */
|
2011-02-12 16:27:28 +01:00
|
|
|
} opt;
|
|
|
|
|
|
|
|
#define USAGE \
|
|
|
|
"\n usage: crl_app param=<>...\n" \
|
|
|
|
"\n acceptable parameters:\n" \
|
2011-10-12 12:15:05 +02:00
|
|
|
" filename=%%s default: crl.pem\n" \
|
2011-02-12 16:27:28 +01:00
|
|
|
"\n"
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2011-12-05 15:34:12 +01:00
|
|
|
unsigned char buf[100000];
|
2011-02-12 16:27:28 +01:00
|
|
|
x509_crl crl;
|
|
|
|
int i, j, n;
|
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set to sane values
|
|
|
|
*/
|
2013-09-18 11:58:25 +02:00
|
|
|
x509_crl_init( &crl );
|
2011-02-12 16:27:28 +01:00
|
|
|
|
|
|
|
if( argc == 0 )
|
|
|
|
{
|
|
|
|
usage:
|
|
|
|
printf( USAGE );
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt.filename = DFL_FILENAME;
|
|
|
|
|
|
|
|
for( i = 1; i < argc; i++ )
|
|
|
|
{
|
|
|
|
n = strlen( argv[i] );
|
|
|
|
|
|
|
|
for( j = 0; j < n; j++ )
|
|
|
|
{
|
|
|
|
if( argv[i][j] >= 'A' && argv[i][j] <= 'Z' )
|
|
|
|
argv[i][j] |= 0x20;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = argv[i];
|
|
|
|
if( ( q = strchr( p, '=' ) ) == NULL )
|
|
|
|
goto usage;
|
|
|
|
*q++ = '\0';
|
|
|
|
|
|
|
|
if( strcmp( p, "filename" ) == 0 )
|
|
|
|
opt.filename = q;
|
|
|
|
else
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1.1. Load the CRL
|
|
|
|
*/
|
|
|
|
printf( "\n . Loading the CRL ..." );
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
ret = x509parse_crlfile( &crl, opt.filename );
|
|
|
|
|
|
|
|
if( ret != 0 )
|
|
|
|
{
|
|
|
|
printf( " failed\n ! x509parse_crl returned %d\n\n", ret );
|
|
|
|
x509_crl_free( &crl );
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf( " ok\n" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1.2 Print the CRL
|
|
|
|
*/
|
|
|
|
printf( " . CRL information ...\n" );
|
|
|
|
ret = x509parse_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
|
|
|
|
if( ret == -1 )
|
|
|
|
{
|
|
|
|
printf( " failed\n ! x509parse_crl_info returned %d\n\n", ret );
|
|
|
|
x509_crl_free( &crl );
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf( "%s\n", buf );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
x509_crl_free( &crl );
|
|
|
|
|
2011-11-18 15:26:47 +01:00
|
|
|
#if defined(_WIN32)
|
2011-02-12 16:27:28 +01:00
|
|
|
printf( " + Press Enter to exit this program.\n" );
|
|
|
|
fflush( stdout ); getchar();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return( ret );
|
|
|
|
}
|
2013-09-17 13:25:29 +02:00
|
|
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_X509_CRL_PARSE_C &&
|
2011-05-26 15:16:06 +02:00
|
|
|
POLARSSL_FS_IO */
|