2 * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
14 #include <openssl/pem.h>
15 #include <openssl/err.h>
19 typedef enum OPTION_choice {
20 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
21 OPT_TOSEQ, OPT_IN, OPT_OUT,
25 const OPTIONS nseq_options[] = {
26 OPT_SECTION("General"),
27 {"help", OPT_HELP, '-', "Display this summary"},
30 {"in", OPT_IN, '<', "Input file"},
32 OPT_SECTION("Output"),
33 {"toseq", OPT_TOSEQ, '-', "Output NS Sequence file"},
34 {"out", OPT_OUT, '>', "Output file"},
40 int nseq_main(int argc, char **argv)
42 BIO *in = NULL, *out = NULL;
44 NETSCAPE_CERT_SEQUENCE *seq = NULL;
46 int toseq = 0, ret = 1, i;
47 char *infile = NULL, *outfile = NULL, *prog;
49 prog = opt_init(argc, argv, nseq_options);
50 while ((o = opt_next()) != OPT_EOF) {
55 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
59 opt_help(nseq_options);
76 argc = opt_num_rest();
80 in = bio_open_default(infile, 'r', FORMAT_PEM);
83 out = bio_open_default(outfile, 'w', FORMAT_PEM);
88 seq = NETSCAPE_CERT_SEQUENCE_new();
91 seq->certs = sk_X509_new_null();
92 if (seq->certs == NULL)
94 while ((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
95 if (!sk_X509_push(seq->certs, x509))
99 if (!sk_X509_num(seq->certs)) {
100 BIO_printf(bio_err, "%s: Error reading certs file %s\n",
102 ERR_print_errors(bio_err);
105 PEM_write_bio_NETSCAPE_CERT_SEQUENCE(out, seq);
110 seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL);
112 BIO_printf(bio_err, "%s: Error reading sequence file %s\n",
114 ERR_print_errors(bio_err);
118 for (i = 0; i < sk_X509_num(seq->certs); i++) {
119 x509 = sk_X509_value(seq->certs, i);
120 dump_cert_text(out, x509);
121 PEM_write_bio_X509(out, x509);
127 NETSCAPE_CERT_SEQUENCE_free(seq);