xref: /onnv-gate/usr/src/common/openssl/apps/crl.c (revision 2139:6243c3338933)
10Sstevel@tonic-gate /* apps/crl.c */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate  * All rights reserved.
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * This package is an SSL implementation written
60Sstevel@tonic-gate  * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate  * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate  * the following conditions are aheared to.  The following conditions
110Sstevel@tonic-gate  * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
130Sstevel@tonic-gate  * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate  *
160Sstevel@tonic-gate  * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate  * the code are not to be removed.
180Sstevel@tonic-gate  * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate  * as the author of the parts of the library used.
200Sstevel@tonic-gate  * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate  * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate  *
230Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate  * are met:
260Sstevel@tonic-gate  * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate  *    must display the following acknowledgement:
330Sstevel@tonic-gate  *    "This product includes cryptographic software written by
340Sstevel@tonic-gate  *     Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate  *    The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate  *    being used are not cryptographic related :-).
370Sstevel@tonic-gate  * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate  *    the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate  * SUCH DAMAGE.
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate  * derivative of this code cannot be changed.  i.e. this code cannot simply be
550Sstevel@tonic-gate  * copied and put under another distribution licence
560Sstevel@tonic-gate  * [including the GNU Public Licence.]
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #include <stdio.h>
600Sstevel@tonic-gate #include <stdlib.h>
610Sstevel@tonic-gate #include <string.h>
620Sstevel@tonic-gate #include "apps.h"
630Sstevel@tonic-gate #include <openssl/bio.h>
640Sstevel@tonic-gate #include <openssl/err.h>
650Sstevel@tonic-gate #include <openssl/x509.h>
660Sstevel@tonic-gate #include <openssl/x509v3.h>
670Sstevel@tonic-gate #include <openssl/pem.h>
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #undef PROG
700Sstevel@tonic-gate #define PROG	crl_main
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #undef POSTFIX
730Sstevel@tonic-gate #define	POSTFIX	".rvk"
740Sstevel@tonic-gate 
75*2139Sjp161948 static const char *crl_usage[]={
760Sstevel@tonic-gate "usage: crl args\n",
770Sstevel@tonic-gate "\n",
780Sstevel@tonic-gate " -inform arg     - input format - default PEM (DER or PEM)\n",
790Sstevel@tonic-gate " -outform arg    - output format - default PEM\n",
800Sstevel@tonic-gate " -text           - print out a text format version\n",
810Sstevel@tonic-gate " -in arg         - input file - default stdin\n",
820Sstevel@tonic-gate " -out arg        - output file - default stdout\n",
830Sstevel@tonic-gate " -hash           - print hash value\n",
840Sstevel@tonic-gate " -fingerprint    - print the crl fingerprint\n",
850Sstevel@tonic-gate " -issuer         - print issuer DN\n",
860Sstevel@tonic-gate " -lastupdate     - lastUpdate field\n",
870Sstevel@tonic-gate " -nextupdate     - nextUpdate field\n",
880Sstevel@tonic-gate " -noout          - no CRL output\n",
890Sstevel@tonic-gate " -CAfile  name   - verify CRL using certificates in file \"name\"\n",
900Sstevel@tonic-gate " -CApath  dir    - verify CRL using certificates in \"dir\"\n",
910Sstevel@tonic-gate " -nameopt arg    - various certificate name options\n",
920Sstevel@tonic-gate NULL
930Sstevel@tonic-gate };
940Sstevel@tonic-gate 
950Sstevel@tonic-gate static X509_CRL *load_crl(char *file, int format);
960Sstevel@tonic-gate static BIO *bio_out=NULL;
970Sstevel@tonic-gate 
980Sstevel@tonic-gate int MAIN(int, char **);
990Sstevel@tonic-gate 
MAIN(int argc,char ** argv)1000Sstevel@tonic-gate int MAIN(int argc, char **argv)
1010Sstevel@tonic-gate 	{
1020Sstevel@tonic-gate 	unsigned long nmflag = 0;
1030Sstevel@tonic-gate 	X509_CRL *x=NULL;
1040Sstevel@tonic-gate 	char *CAfile = NULL, *CApath = NULL;
1050Sstevel@tonic-gate 	int ret=1,i,num,badops=0;
1060Sstevel@tonic-gate 	BIO *out=NULL;
1070Sstevel@tonic-gate 	int informat,outformat;
1080Sstevel@tonic-gate 	char *infile=NULL,*outfile=NULL;
1090Sstevel@tonic-gate 	int hash=0,issuer=0,lastupdate=0,nextupdate=0,noout=0,text=0;
1100Sstevel@tonic-gate 	int fingerprint = 0;
111*2139Sjp161948 	const char **pp;
1120Sstevel@tonic-gate 	X509_STORE *store = NULL;
1130Sstevel@tonic-gate 	X509_STORE_CTX ctx;
1140Sstevel@tonic-gate 	X509_LOOKUP *lookup = NULL;
1150Sstevel@tonic-gate 	X509_OBJECT xobj;
1160Sstevel@tonic-gate 	EVP_PKEY *pkey;
1170Sstevel@tonic-gate 	int do_ver = 0;
118*2139Sjp161948 	const EVP_MD *md_alg,*digest=EVP_sha1();
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	apps_startup();
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	if (bio_err == NULL)
1230Sstevel@tonic-gate 		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
1240Sstevel@tonic-gate 			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	if (!load_config(bio_err, NULL))
1270Sstevel@tonic-gate 		goto end;
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	if (bio_out == NULL)
1300Sstevel@tonic-gate 		if ((bio_out=BIO_new(BIO_s_file())) != NULL)
1310Sstevel@tonic-gate 			{
1320Sstevel@tonic-gate 			BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
1330Sstevel@tonic-gate #ifdef OPENSSL_SYS_VMS
1340Sstevel@tonic-gate 			{
1350Sstevel@tonic-gate 			BIO *tmpbio = BIO_new(BIO_f_linebuffer());
1360Sstevel@tonic-gate 			bio_out = BIO_push(tmpbio, bio_out);
1370Sstevel@tonic-gate 			}
1380Sstevel@tonic-gate #endif
1390Sstevel@tonic-gate 			}
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	informat=FORMAT_PEM;
1420Sstevel@tonic-gate 	outformat=FORMAT_PEM;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	argc--;
1450Sstevel@tonic-gate 	argv++;
1460Sstevel@tonic-gate 	num=0;
1470Sstevel@tonic-gate 	while (argc >= 1)
1480Sstevel@tonic-gate 		{
1490Sstevel@tonic-gate #ifdef undef
1500Sstevel@tonic-gate 		if	(strcmp(*argv,"-p") == 0)
1510Sstevel@tonic-gate 			{
1520Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1530Sstevel@tonic-gate 			if (!args_from_file(++argv,Nargc,Nargv)) { goto end; }*/
1540Sstevel@tonic-gate 			}
1550Sstevel@tonic-gate #endif
1560Sstevel@tonic-gate 		if 	(strcmp(*argv,"-inform") == 0)
1570Sstevel@tonic-gate 			{
1580Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1590Sstevel@tonic-gate 			informat=str2fmt(*(++argv));
1600Sstevel@tonic-gate 			}
1610Sstevel@tonic-gate 		else if (strcmp(*argv,"-outform") == 0)
1620Sstevel@tonic-gate 			{
1630Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1640Sstevel@tonic-gate 			outformat=str2fmt(*(++argv));
1650Sstevel@tonic-gate 			}
1660Sstevel@tonic-gate 		else if (strcmp(*argv,"-in") == 0)
1670Sstevel@tonic-gate 			{
1680Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1690Sstevel@tonic-gate 			infile= *(++argv);
1700Sstevel@tonic-gate 			}
1710Sstevel@tonic-gate 		else if (strcmp(*argv,"-out") == 0)
1720Sstevel@tonic-gate 			{
1730Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1740Sstevel@tonic-gate 			outfile= *(++argv);
1750Sstevel@tonic-gate 			}
1760Sstevel@tonic-gate 		else if (strcmp(*argv,"-CApath") == 0)
1770Sstevel@tonic-gate 			{
1780Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1790Sstevel@tonic-gate 			CApath = *(++argv);
1800Sstevel@tonic-gate 			do_ver = 1;
1810Sstevel@tonic-gate 			}
1820Sstevel@tonic-gate 		else if (strcmp(*argv,"-CAfile") == 0)
1830Sstevel@tonic-gate 			{
1840Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1850Sstevel@tonic-gate 			CAfile = *(++argv);
1860Sstevel@tonic-gate 			do_ver = 1;
1870Sstevel@tonic-gate 			}
1880Sstevel@tonic-gate 		else if (strcmp(*argv,"-verify") == 0)
1890Sstevel@tonic-gate 			do_ver = 1;
1900Sstevel@tonic-gate 		else if (strcmp(*argv,"-text") == 0)
1910Sstevel@tonic-gate 			text = 1;
1920Sstevel@tonic-gate 		else if (strcmp(*argv,"-hash") == 0)
1930Sstevel@tonic-gate 			hash= ++num;
1940Sstevel@tonic-gate 		else if (strcmp(*argv,"-nameopt") == 0)
1950Sstevel@tonic-gate 			{
1960Sstevel@tonic-gate 			if (--argc < 1) goto bad;
1970Sstevel@tonic-gate 			if (!set_name_ex(&nmflag, *(++argv))) goto bad;
1980Sstevel@tonic-gate 			}
1990Sstevel@tonic-gate 		else if (strcmp(*argv,"-issuer") == 0)
2000Sstevel@tonic-gate 			issuer= ++num;
2010Sstevel@tonic-gate 		else if (strcmp(*argv,"-lastupdate") == 0)
2020Sstevel@tonic-gate 			lastupdate= ++num;
2030Sstevel@tonic-gate 		else if (strcmp(*argv,"-nextupdate") == 0)
2040Sstevel@tonic-gate 			nextupdate= ++num;
2050Sstevel@tonic-gate 		else if (strcmp(*argv,"-noout") == 0)
2060Sstevel@tonic-gate 			noout= ++num;
2070Sstevel@tonic-gate 		else if (strcmp(*argv,"-fingerprint") == 0)
2080Sstevel@tonic-gate 			fingerprint= ++num;
2090Sstevel@tonic-gate 		else if ((md_alg=EVP_get_digestbyname(*argv + 1)))
2100Sstevel@tonic-gate 			{
2110Sstevel@tonic-gate 			/* ok */
2120Sstevel@tonic-gate 			digest=md_alg;
2130Sstevel@tonic-gate 			}
2140Sstevel@tonic-gate 		else
2150Sstevel@tonic-gate 			{
2160Sstevel@tonic-gate 			BIO_printf(bio_err,"unknown option %s\n",*argv);
2170Sstevel@tonic-gate 			badops=1;
2180Sstevel@tonic-gate 			break;
2190Sstevel@tonic-gate 			}
2200Sstevel@tonic-gate 		argc--;
2210Sstevel@tonic-gate 		argv++;
2220Sstevel@tonic-gate 		}
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	if (badops)
2250Sstevel@tonic-gate 		{
2260Sstevel@tonic-gate bad:
2270Sstevel@tonic-gate 		for (pp=crl_usage; (*pp != NULL); pp++)
2280Sstevel@tonic-gate 			BIO_printf(bio_err,"%s",*pp);
2290Sstevel@tonic-gate 		goto end;
2300Sstevel@tonic-gate 		}
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 	ERR_load_crypto_strings();
2330Sstevel@tonic-gate 	x=load_crl(infile,informat);
2340Sstevel@tonic-gate 	if (x == NULL) { goto end; }
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 	if(do_ver) {
2370Sstevel@tonic-gate 		store = X509_STORE_new();
2380Sstevel@tonic-gate 		lookup=X509_STORE_add_lookup(store,X509_LOOKUP_file());
2390Sstevel@tonic-gate 		if (lookup == NULL) goto end;
2400Sstevel@tonic-gate 		if (!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM))
2410Sstevel@tonic-gate 			X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 		lookup=X509_STORE_add_lookup(store,X509_LOOKUP_hash_dir());
2440Sstevel@tonic-gate 		if (lookup == NULL) goto end;
2450Sstevel@tonic-gate 		if (!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM))
2460Sstevel@tonic-gate 			X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
2470Sstevel@tonic-gate 		ERR_clear_error();
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 		if(!X509_STORE_CTX_init(&ctx, store, NULL, NULL)) {
2500Sstevel@tonic-gate 			BIO_printf(bio_err,
2510Sstevel@tonic-gate 				"Error initialising X509 store\n");
2520Sstevel@tonic-gate 			goto end;
2530Sstevel@tonic-gate 		}
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 		i = X509_STORE_get_by_subject(&ctx, X509_LU_X509,
2560Sstevel@tonic-gate 					X509_CRL_get_issuer(x), &xobj);
2570Sstevel@tonic-gate 		if(i <= 0) {
2580Sstevel@tonic-gate 			BIO_printf(bio_err,
2590Sstevel@tonic-gate 				"Error getting CRL issuer certificate\n");
2600Sstevel@tonic-gate 			goto end;
2610Sstevel@tonic-gate 		}
2620Sstevel@tonic-gate 		pkey = X509_get_pubkey(xobj.data.x509);
2630Sstevel@tonic-gate 		X509_OBJECT_free_contents(&xobj);
2640Sstevel@tonic-gate 		if(!pkey) {
2650Sstevel@tonic-gate 			BIO_printf(bio_err,
2660Sstevel@tonic-gate 				"Error getting CRL issuer public key\n");
2670Sstevel@tonic-gate 			goto end;
2680Sstevel@tonic-gate 		}
2690Sstevel@tonic-gate 		i = X509_CRL_verify(x, pkey);
2700Sstevel@tonic-gate 		EVP_PKEY_free(pkey);
2710Sstevel@tonic-gate 		if(i < 0) goto end;
2720Sstevel@tonic-gate 		if(i == 0) BIO_printf(bio_err, "verify failure\n");
2730Sstevel@tonic-gate 		else BIO_printf(bio_err, "verify OK\n");
2740Sstevel@tonic-gate 	}
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	if (num)
2770Sstevel@tonic-gate 		{
2780Sstevel@tonic-gate 		for (i=1; i<=num; i++)
2790Sstevel@tonic-gate 			{
2800Sstevel@tonic-gate 			if (issuer == i)
2810Sstevel@tonic-gate 				{
2820Sstevel@tonic-gate 				print_name(bio_out, "issuer=", X509_CRL_get_issuer(x), nmflag);
2830Sstevel@tonic-gate 				}
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 			if (hash == i)
2860Sstevel@tonic-gate 				{
2870Sstevel@tonic-gate 				BIO_printf(bio_out,"%08lx\n",
2880Sstevel@tonic-gate 					X509_NAME_hash(X509_CRL_get_issuer(x)));
2890Sstevel@tonic-gate 				}
2900Sstevel@tonic-gate 			if (lastupdate == i)
2910Sstevel@tonic-gate 				{
2920Sstevel@tonic-gate 				BIO_printf(bio_out,"lastUpdate=");
2930Sstevel@tonic-gate 				ASN1_TIME_print(bio_out,
2940Sstevel@tonic-gate 						X509_CRL_get_lastUpdate(x));
2950Sstevel@tonic-gate 				BIO_printf(bio_out,"\n");
2960Sstevel@tonic-gate 				}
2970Sstevel@tonic-gate 			if (nextupdate == i)
2980Sstevel@tonic-gate 				{
2990Sstevel@tonic-gate 				BIO_printf(bio_out,"nextUpdate=");
3000Sstevel@tonic-gate 				if (X509_CRL_get_nextUpdate(x))
3010Sstevel@tonic-gate 					ASN1_TIME_print(bio_out,
3020Sstevel@tonic-gate 						X509_CRL_get_nextUpdate(x));
3030Sstevel@tonic-gate 				else
3040Sstevel@tonic-gate 					BIO_printf(bio_out,"NONE");
3050Sstevel@tonic-gate 				BIO_printf(bio_out,"\n");
3060Sstevel@tonic-gate 				}
3070Sstevel@tonic-gate 			if (fingerprint == i)
3080Sstevel@tonic-gate 				{
3090Sstevel@tonic-gate 				int j;
3100Sstevel@tonic-gate 				unsigned int n;
3110Sstevel@tonic-gate 				unsigned char md[EVP_MAX_MD_SIZE];
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate 				if (!X509_CRL_digest(x,digest,md,&n))
3140Sstevel@tonic-gate 					{
3150Sstevel@tonic-gate 					BIO_printf(bio_err,"out of memory\n");
3160Sstevel@tonic-gate 					goto end;
3170Sstevel@tonic-gate 					}
3180Sstevel@tonic-gate 				BIO_printf(bio_out,"%s Fingerprint=",
3190Sstevel@tonic-gate 						OBJ_nid2sn(EVP_MD_type(digest)));
3200Sstevel@tonic-gate 				for (j=0; j<(int)n; j++)
3210Sstevel@tonic-gate 					{
3220Sstevel@tonic-gate 					BIO_printf(bio_out,"%02X%c",md[j],
3230Sstevel@tonic-gate 						(j+1 == (int)n)
3240Sstevel@tonic-gate 						?'\n':':');
3250Sstevel@tonic-gate 					}
3260Sstevel@tonic-gate 				}
3270Sstevel@tonic-gate 			}
3280Sstevel@tonic-gate 		}
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	out=BIO_new(BIO_s_file());
3310Sstevel@tonic-gate 	if (out == NULL)
3320Sstevel@tonic-gate 		{
3330Sstevel@tonic-gate 		ERR_print_errors(bio_err);
3340Sstevel@tonic-gate 		goto end;
3350Sstevel@tonic-gate 		}
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 	if (outfile == NULL)
3380Sstevel@tonic-gate 		{
3390Sstevel@tonic-gate 		BIO_set_fp(out,stdout,BIO_NOCLOSE);
3400Sstevel@tonic-gate #ifdef OPENSSL_SYS_VMS
3410Sstevel@tonic-gate 		{
3420Sstevel@tonic-gate 		BIO *tmpbio = BIO_new(BIO_f_linebuffer());
3430Sstevel@tonic-gate 		out = BIO_push(tmpbio, out);
3440Sstevel@tonic-gate 		}
3450Sstevel@tonic-gate #endif
3460Sstevel@tonic-gate 		}
3470Sstevel@tonic-gate 	else
3480Sstevel@tonic-gate 		{
3490Sstevel@tonic-gate 		if (BIO_write_filename(out,outfile) <= 0)
3500Sstevel@tonic-gate 			{
3510Sstevel@tonic-gate 			perror(outfile);
3520Sstevel@tonic-gate 			goto end;
3530Sstevel@tonic-gate 			}
3540Sstevel@tonic-gate 		}
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	if (text) X509_CRL_print(out, x);
3570Sstevel@tonic-gate 
358*2139Sjp161948 	if (noout)
359*2139Sjp161948 		{
360*2139Sjp161948 		ret = 0;
361*2139Sjp161948 		goto end;
362*2139Sjp161948 		}
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 	if 	(outformat == FORMAT_ASN1)
3650Sstevel@tonic-gate 		i=(int)i2d_X509_CRL_bio(out,x);
3660Sstevel@tonic-gate 	else if (outformat == FORMAT_PEM)
3670Sstevel@tonic-gate 		i=PEM_write_bio_X509_CRL(out,x);
3680Sstevel@tonic-gate 	else
3690Sstevel@tonic-gate 		{
3700Sstevel@tonic-gate 		BIO_printf(bio_err,"bad output format specified for outfile\n");
3710Sstevel@tonic-gate 		goto end;
3720Sstevel@tonic-gate 		}
3730Sstevel@tonic-gate 	if (!i) { BIO_printf(bio_err,"unable to write CRL\n"); goto end; }
3740Sstevel@tonic-gate 	ret=0;
3750Sstevel@tonic-gate end:
3760Sstevel@tonic-gate 	BIO_free_all(out);
3770Sstevel@tonic-gate 	BIO_free_all(bio_out);
3780Sstevel@tonic-gate 	bio_out=NULL;
3790Sstevel@tonic-gate 	X509_CRL_free(x);
3800Sstevel@tonic-gate 	if(store) {
3810Sstevel@tonic-gate 		X509_STORE_CTX_cleanup(&ctx);
3820Sstevel@tonic-gate 		X509_STORE_free(store);
3830Sstevel@tonic-gate 	}
3840Sstevel@tonic-gate 	apps_shutdown();
3850Sstevel@tonic-gate 	OPENSSL_EXIT(ret);
3860Sstevel@tonic-gate 	}
3870Sstevel@tonic-gate 
load_crl(char * infile,int format)3880Sstevel@tonic-gate static X509_CRL *load_crl(char *infile, int format)
3890Sstevel@tonic-gate 	{
3900Sstevel@tonic-gate 	X509_CRL *x=NULL;
3910Sstevel@tonic-gate 	BIO *in=NULL;
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	in=BIO_new(BIO_s_file());
3940Sstevel@tonic-gate 	if (in == NULL)
3950Sstevel@tonic-gate 		{
3960Sstevel@tonic-gate 		ERR_print_errors(bio_err);
3970Sstevel@tonic-gate 		goto end;
3980Sstevel@tonic-gate 		}
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate 	if (infile == NULL)
4010Sstevel@tonic-gate 		BIO_set_fp(in,stdin,BIO_NOCLOSE);
4020Sstevel@tonic-gate 	else
4030Sstevel@tonic-gate 		{
4040Sstevel@tonic-gate 		if (BIO_read_filename(in,infile) <= 0)
4050Sstevel@tonic-gate 			{
4060Sstevel@tonic-gate 			perror(infile);
4070Sstevel@tonic-gate 			goto end;
4080Sstevel@tonic-gate 			}
4090Sstevel@tonic-gate 		}
4100Sstevel@tonic-gate 	if 	(format == FORMAT_ASN1)
4110Sstevel@tonic-gate 		x=d2i_X509_CRL_bio(in,NULL);
4120Sstevel@tonic-gate 	else if (format == FORMAT_PEM)
4130Sstevel@tonic-gate 		x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
4140Sstevel@tonic-gate 	else	{
4150Sstevel@tonic-gate 		BIO_printf(bio_err,"bad input format specified for input crl\n");
4160Sstevel@tonic-gate 		goto end;
4170Sstevel@tonic-gate 		}
4180Sstevel@tonic-gate 	if (x == NULL)
4190Sstevel@tonic-gate 		{
4200Sstevel@tonic-gate 		BIO_printf(bio_err,"unable to load CRL\n");
4210Sstevel@tonic-gate 		ERR_print_errors(bio_err);
4220Sstevel@tonic-gate 		goto end;
4230Sstevel@tonic-gate 		}
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate end:
4260Sstevel@tonic-gate 	BIO_free(in);
4270Sstevel@tonic-gate 	return(x);
4280Sstevel@tonic-gate 	}
4290Sstevel@tonic-gate 
430