]>
git.ipfire.org Git - thirdparty/openssl.git/blob - apps/nseq.c
2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
13 #include <openssl/pem.h>
14 #include <openssl/err.h>
16 typedef enum OPTION_choice
{
17 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
18 OPT_TOSEQ
, OPT_IN
, OPT_OUT
21 const OPTIONS nseq_options
[] = {
22 {"help", OPT_HELP
, '-', "Display this summary"},
23 {"toseq", OPT_TOSEQ
, '-', "Output NS Sequence file"},
24 {"in", OPT_IN
, '<', "Input file"},
25 {"out", OPT_OUT
, '>', "Output file"},
29 int nseq_main(int argc
, char **argv
)
31 BIO
*in
= NULL
, *out
= NULL
;
33 NETSCAPE_CERT_SEQUENCE
*seq
= NULL
;
35 int toseq
= 0, ret
= 1, i
;
36 char *infile
= NULL
, *outfile
= NULL
, *prog
;
38 prog
= opt_init(argc
, argv
, nseq_options
);
39 while ((o
= opt_next()) != OPT_EOF
) {
44 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
48 opt_help(nseq_options
);
61 argc
= opt_num_rest();
65 in
= bio_open_default(infile
, 'r', FORMAT_PEM
);
68 out
= bio_open_default(outfile
, 'w', FORMAT_PEM
);
73 seq
= NETSCAPE_CERT_SEQUENCE_new();
76 seq
->certs
= sk_X509_new_null();
77 if (seq
->certs
== NULL
)
79 while ((x509
= PEM_read_bio_X509(in
, NULL
, NULL
, NULL
)))
80 sk_X509_push(seq
->certs
, x509
);
82 if (!sk_X509_num(seq
->certs
)) {
83 BIO_printf(bio_err
, "%s: Error reading certs file %s\n",
85 ERR_print_errors(bio_err
);
88 PEM_write_bio_NETSCAPE_CERT_SEQUENCE(out
, seq
);
93 seq
= PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in
, NULL
, NULL
, NULL
);
95 BIO_printf(bio_err
, "%s: Error reading sequence file %s\n",
97 ERR_print_errors(bio_err
);
101 for (i
= 0; i
< sk_X509_num(seq
->certs
); i
++) {
102 x509
= sk_X509_value(seq
->certs
, i
);
103 dump_cert_text(out
, x509
);
104 PEM_write_bio_X509(out
, x509
);
110 NETSCAPE_CERT_SEQUENCE_free(seq
);