os/ossrv/ssl/tsrc/BC/libcrypto/topenssl/src/nseq.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ssl/tsrc/BC/libcrypto/topenssl/src/nseq.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,170 @@
     1.4 +/* nseq.c */
     1.5 +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
     1.6 + * project 1999.
     1.7 + */
     1.8 +/* ====================================================================
     1.9 + * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
    1.10 + *
    1.11 + * Redistribution and use in source and binary forms, with or without
    1.12 + * modification, are permitted provided that the following conditions
    1.13 + * are met:
    1.14 + *
    1.15 + * 1. Redistributions of source code must retain the above copyright
    1.16 + *    notice, this list of conditions and the following disclaimer. 
    1.17 + *
    1.18 + * 2. Redistributions in binary form must reproduce the above copyright
    1.19 + *    notice, this list of conditions and the following disclaimer in
    1.20 + *    the documentation and/or other materials provided with the
    1.21 + *    distribution.
    1.22 + *
    1.23 + * 3. All advertising materials mentioning features or use of this
    1.24 + *    software must display the following acknowledgment:
    1.25 + *    "This product includes software developed by the OpenSSL Project
    1.26 + *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
    1.27 + *
    1.28 + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
    1.29 + *    endorse or promote products derived from this software without
    1.30 + *    prior written permission. For written permission, please contact
    1.31 + *    licensing@OpenSSL.org.
    1.32 + *
    1.33 + * 5. Products derived from this software may not be called "OpenSSL"
    1.34 + *    nor may "OpenSSL" appear in their names without prior written
    1.35 + *    permission of the OpenSSL Project.
    1.36 + *
    1.37 + * 6. Redistributions of any form whatsoever must retain the following
    1.38 + *    acknowledgment:
    1.39 + *    "This product includes software developed by the OpenSSL Project
    1.40 + *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
    1.41 + *
    1.42 + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
    1.43 + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    1.45 + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
    1.46 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.47 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    1.48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    1.49 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.50 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.51 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.52 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    1.53 + * OF THE POSSIBILITY OF SUCH DAMAGE.
    1.54 + * ====================================================================
    1.55 + *
    1.56 + * This product includes cryptographic software written by Eric Young
    1.57 + * (eay@cryptsoft.com).  This product includes software written by Tim
    1.58 + * Hudson (tjh@cryptsoft.com).
    1.59 + *
    1.60 + */
    1.61 +
    1.62 +#include <stdio.h>
    1.63 +#include <string.h>
    1.64 +#include "apps.h"
    1.65 +#include <openssl/pem.h>
    1.66 +#include <openssl/err.h>
    1.67 +
    1.68 +
    1.69 +#undef PROG
    1.70 +#define PROG nseq_main
    1.71 +
    1.72 +int MAIN(int, char **);
    1.73 +
    1.74 +int MAIN(int argc, char **argv)
    1.75 +{
    1.76 +	char **args, *infile = NULL, *outfile = NULL;
    1.77 +	BIO *in = NULL, *out = NULL;
    1.78 +	int toseq = 0;
    1.79 +	X509 *x509 = NULL;
    1.80 +	NETSCAPE_CERT_SEQUENCE *seq = NULL;
    1.81 +	int i, ret = 1;
    1.82 +	int badarg = 0;
    1.83 +	if (bio_err == NULL) 
    1.84 +	bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
    1.85 +	ERR_load_crypto_strings();
    1.86 +	args = argv + 1;
    1.87 +	while (!badarg && *args && *args[0] == '-') {
    1.88 +		if (!strcmp (*args, "-toseq")) toseq = 1;
    1.89 +		else if (!strcmp (*args, "-in")) {
    1.90 +			if (args[1]) {
    1.91 +				args++;
    1.92 +				infile = *args;
    1.93 +			} else badarg = 1;
    1.94 +		} else if (!strcmp (*args, "-out")) {
    1.95 +			if (args[1]) {
    1.96 +				args++;
    1.97 +				outfile = *args;
    1.98 +			} else badarg = 1;
    1.99 +		} else badarg = 1;
   1.100 +		args++;
   1.101 +	}
   1.102 +
   1.103 +	if (badarg) {
   1.104 +		BIO_printf (bio_err, "Netscape certificate sequence utility\n");
   1.105 +		BIO_printf (bio_err, "Usage nseq [options]\n");
   1.106 +		BIO_printf (bio_err, "where options are\n");
   1.107 +		BIO_printf (bio_err, "-in file  input file\n");
   1.108 +		BIO_printf (bio_err, "-out file output file\n");
   1.109 +		BIO_printf (bio_err, "-toseq    output NS Sequence file\n");
   1.110 +		OPENSSL_EXIT(1);
   1.111 +	}
   1.112 +
   1.113 +	if (infile) {
   1.114 +		if (!(in = BIO_new_file (infile, "r"))) {
   1.115 +			BIO_printf (bio_err,
   1.116 +				 "Can't open input file %s\n", infile);
   1.117 +			goto end;
   1.118 +		}
   1.119 +	} else 
   1.120 +
   1.121 +	in = BIO_new_fp(stdin, BIO_NOCLOSE);
   1.122 +	if (outfile) {
   1.123 +		if (!(out = BIO_new_file (outfile, "w"))) {
   1.124 +			BIO_printf (bio_err,
   1.125 +				 "Can't open output file %s\n", outfile);
   1.126 +			goto end;
   1.127 +		}
   1.128 +	} else {
   1.129 +		out = BIO_new_fp(stdout, BIO_NOCLOSE);
   1.130 +#ifdef OPENSSL_SYS_VMS
   1.131 +		{
   1.132 +		BIO *tmpbio = BIO_new(BIO_f_linebuffer());
   1.133 +		out = BIO_push(tmpbio, out);
   1.134 +		}
   1.135 +#endif
   1.136 +	}
   1.137 +	if (toseq) {
   1.138 +		seq = NETSCAPE_CERT_SEQUENCE_new();
   1.139 +		seq->certs = sk_X509_new_null();
   1.140 +		while((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL))) 
   1.141 +		    sk_X509_push(seq->certs,x509);
   1.142 +
   1.143 +		if(!sk_X509_num(seq->certs))
   1.144 +		{
   1.145 +			BIO_printf (bio_err, "Error reading certs file %s\n", infile);
   1.146 +			ERR_print_errors(bio_err);
   1.147 +			goto end;
   1.148 +		}
   1.149 +		PEM_write_bio_NETSCAPE_CERT_SEQUENCE(out, seq);
   1.150 +		ret = 0;
   1.151 +		goto end;
   1.152 +	}
   1.153 +
   1.154 +	if (!(seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL))) {
   1.155 +		BIO_printf (bio_err, "Error reading sequence file %s\n", infile);
   1.156 +		ERR_print_errors(bio_err);
   1.157 +		goto end;
   1.158 +	}
   1.159 +
   1.160 +	for(i = 0; i < sk_X509_num(seq->certs); i++) {
   1.161 +		x509 = sk_X509_value(seq->certs, i);
   1.162 +		dump_cert_text(out, x509);
   1.163 +		PEM_write_bio_X509(out, x509);
   1.164 +	}
   1.165 +	ret = 0;
   1.166 +end:
   1.167 +	BIO_free(in);
   1.168 +	BIO_free_all(out);
   1.169 +	NETSCAPE_CERT_SEQUENCE_free(seq);
   1.170 +
   1.171 +	OPENSSL_EXIT(ret);
   1.172 +}
   1.173 +