- Added crl_app program to allow easy reading and printing of X509 CRLs from file

This commit is contained in:
Paul Bakker 2011-02-12 15:27:28 +00:00
parent 96743fc5f5
commit a9507c063b
4 changed files with 165 additions and 2 deletions

View File

@ -4,6 +4,8 @@ PolarSSL ChangeLog
Features Features
* Parsing PEM private keys encrypted with DES and AES * Parsing PEM private keys encrypted with DES and AES
are now supported as well (Fixes ticket #5) are now supported as well (Fixes ticket #5)
* Added crl_app program to allow easy reading and
printing of X509 CRLs from file
Changes Changes
* Parsing of PEM files moved to separate module (Fixes * Parsing of PEM files moved to separate module (Fixes

View File

@ -18,7 +18,7 @@ APPS = aes/aescrypt2 aes/crypt_and_hash \
ssl/ssl_server random/gen_random \ ssl/ssl_server random/gen_random \
test/ssl_cert_test test/benchmark \ test/ssl_cert_test test/benchmark \
test/selftest test/ssl_test \ test/selftest test/ssl_test \
x509/cert_app x509/cert_app x509/crl_app
.SILENT: .SILENT:
@ -116,6 +116,10 @@ x509/cert_app: x509/cert_app.c ../library/libpolarssl.a
echo " CC x509/cert_app.c" echo " CC x509/cert_app.c"
$(CC) $(CFLAGS) $(OFLAGS) x509/cert_app.c $(LDFLAGS) -o $@ $(CC) $(CFLAGS) $(OFLAGS) x509/cert_app.c $(LDFLAGS) -o $@
x509/crl_app: x509/crl_app.c ../library/libpolarssl.a
echo " CC x509/crl_app.c"
$(CC) $(CFLAGS) $(OFLAGS) x509/crl_app.c $(LDFLAGS) -o $@
clean: clean:
rm -f $(APPS) rm -f $(APPS)

View File

@ -9,6 +9,9 @@ endif(USE_PKCS11_HELPER_LIBRARY)
add_executable(cert_app cert_app.c) add_executable(cert_app cert_app.c)
target_link_libraries(cert_app ${libs}) target_link_libraries(cert_app ${libs})
INSTALL(TARGETS cert_app add_executable(crl_app crl_app.c)
target_link_libraries(crl_app ${libs})
INSTALL(TARGETS cert_app crl_app
DESTINATION "bin" DESTINATION "bin"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

154
programs/x509/crl_app.c Normal file
View File

@ -0,0 +1,154 @@
/*
* CRL reading application
*
* Copyright (C) 2006-2010, Brainspark B.V.
*
* 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>
#include "polarssl/x509.h"
#define DFL_FILENAME "crl.pem"
#define DFL_DEBUG_LEVEL 0
/*
* global options
*/
struct options
{
char *filename; /* filename of the certificate file */
int debug_level; /* level of debugging */
} opt;
void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
#define USAGE \
"\n usage: crl_app param=<>...\n" \
"\n acceptable parameters:\n" \
" filename=%%s default: cert.crt\n" \
" debug_level=%%d default: 0 (disabled)\n" \
"\n"
int main( int argc, char *argv[] )
{
int ret = 0;
unsigned char buf[1024];
x509_crl crl;
int i, j, n;
char *p, *q;
/*
* Set to sane values
*/
memset( &crl, 0, sizeof( x509_crl ) );
if( argc == 0 )
{
usage:
printf( USAGE );
goto exit;
}
opt.filename = DFL_FILENAME;
opt.debug_level = DFL_DEBUG_LEVEL;
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 if( strcmp( p, "debug_level" ) == 0 )
{
opt.debug_level = atoi( q );
if( opt.debug_level < 0 || opt.debug_level > 65535 )
goto usage;
}
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 );
#ifdef WIN32
printf( " + Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
return( ret );
}