diff options
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/openssl/nseq.c | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/src/usr.bin/openssl/nseq.c b/src/usr.bin/openssl/nseq.c index 6bc58185c0..6de9ea56be 100644 --- a/src/usr.bin/openssl/nseq.c +++ b/src/usr.bin/openssl/nseq.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: nseq.c,v 1.2 2014/08/28 14:23:52 jsing Exp $ */ | 1 | /* $OpenBSD: nseq.c,v 1.3 2015/07/21 16:41:34 jsing Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 1999. | 3 | * project 1999. |
| 4 | */ | 4 | */ |
| @@ -64,75 +64,86 @@ | |||
| 64 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
| 65 | #include <openssl/pem.h> | 65 | #include <openssl/pem.h> |
| 66 | 66 | ||
| 67 | static struct { | ||
| 68 | char *infile; | ||
| 69 | char *outfile; | ||
| 70 | int toseq; | ||
| 71 | } nseq_config; | ||
| 72 | |||
| 73 | static struct option nseq_options[] = { | ||
| 74 | { | ||
| 75 | .name = "in", | ||
| 76 | .argname = "file", | ||
| 77 | .desc = "Input file to read from (default stdin)", | ||
| 78 | .type = OPTION_ARG, | ||
| 79 | .opt.arg = &nseq_config.infile, | ||
| 80 | }, | ||
| 81 | { | ||
| 82 | .name = "out", | ||
| 83 | .argname = "file", | ||
| 84 | .desc = "Output file to write to (default stdout)", | ||
| 85 | .type = OPTION_ARG, | ||
| 86 | .opt.arg = &nseq_config.outfile, | ||
| 87 | }, | ||
| 88 | { | ||
| 89 | .name = "toseq", | ||
| 90 | .desc = "Convert certificates to Netscape certificate sequence", | ||
| 91 | .type = OPTION_FLAG, | ||
| 92 | .opt.flag = &nseq_config.toseq, | ||
| 93 | }, | ||
| 94 | { NULL }, | ||
| 95 | }; | ||
| 96 | |||
| 97 | static void | ||
| 98 | nseq_usage() | ||
| 99 | { | ||
| 100 | fprintf(stderr, "usage: nseq [-in file] [-out file] [-toseq]\n"); | ||
| 101 | options_usage(nseq_options); | ||
| 102 | } | ||
| 103 | |||
| 67 | int nseq_main(int, char **); | 104 | int nseq_main(int, char **); |
| 68 | 105 | ||
| 69 | int | 106 | int |
| 70 | nseq_main(int argc, char **argv) | 107 | nseq_main(int argc, char **argv) |
| 71 | { | 108 | { |
| 72 | char **args, *infile = NULL, *outfile = NULL; | ||
| 73 | BIO *in = NULL, *out = NULL; | 109 | BIO *in = NULL, *out = NULL; |
| 74 | int toseq = 0; | ||
| 75 | X509 *x509 = NULL; | 110 | X509 *x509 = NULL; |
| 76 | NETSCAPE_CERT_SEQUENCE *seq = NULL; | 111 | NETSCAPE_CERT_SEQUENCE *seq = NULL; |
| 77 | int i, ret = 1; | 112 | int i, ret = 1; |
| 78 | int badarg = 0; | ||
| 79 | 113 | ||
| 80 | args = argv + 1; | 114 | memset(&nseq_config, 0, sizeof(nseq_config)); |
| 81 | while (!badarg && *args && *args[0] == '-') { | ||
| 82 | if (!strcmp(*args, "-toseq")) | ||
| 83 | toseq = 1; | ||
| 84 | else if (!strcmp(*args, "-in")) { | ||
| 85 | if (args[1]) { | ||
| 86 | args++; | ||
| 87 | infile = *args; | ||
| 88 | } else | ||
| 89 | badarg = 1; | ||
| 90 | } else if (!strcmp(*args, "-out")) { | ||
| 91 | if (args[1]) { | ||
| 92 | args++; | ||
| 93 | outfile = *args; | ||
| 94 | } else | ||
| 95 | badarg = 1; | ||
| 96 | } else | ||
| 97 | badarg = 1; | ||
| 98 | args++; | ||
| 99 | } | ||
| 100 | 115 | ||
| 101 | if (badarg) { | 116 | if (options_parse(argc, argv, nseq_options, NULL, NULL) != 0) { |
| 102 | BIO_printf(bio_err, "Netscape certificate sequence utility\n"); | 117 | nseq_usage(); |
| 103 | BIO_printf(bio_err, "Usage nseq [options]\n"); | ||
| 104 | BIO_printf(bio_err, "where options are\n"); | ||
| 105 | BIO_printf(bio_err, "-in file input file\n"); | ||
| 106 | BIO_printf(bio_err, "-out file output file\n"); | ||
| 107 | BIO_printf(bio_err, "-toseq output NS Sequence file\n"); | ||
| 108 | return (1); | 118 | return (1); |
| 109 | } | 119 | } |
| 110 | if (infile) { | 120 | |
| 111 | if (!(in = BIO_new_file(infile, "r"))) { | 121 | if (nseq_config.infile) { |
| 122 | if (!(in = BIO_new_file(nseq_config.infile, "r"))) { | ||
| 112 | BIO_printf(bio_err, | 123 | BIO_printf(bio_err, |
| 113 | "Can't open input file %s\n", infile); | 124 | "Can't open input file %s\n", nseq_config.infile); |
| 114 | goto end; | 125 | goto end; |
| 115 | } | 126 | } |
| 116 | } else | 127 | } else |
| 117 | in = BIO_new_fp(stdin, BIO_NOCLOSE); | 128 | in = BIO_new_fp(stdin, BIO_NOCLOSE); |
| 118 | 129 | ||
| 119 | if (outfile) { | 130 | if (nseq_config.outfile) { |
| 120 | if (!(out = BIO_new_file(outfile, "w"))) { | 131 | if (!(out = BIO_new_file(nseq_config.outfile, "w"))) { |
| 121 | BIO_printf(bio_err, | 132 | BIO_printf(bio_err, |
| 122 | "Can't open output file %s\n", outfile); | 133 | "Can't open output file %s\n", nseq_config.outfile); |
| 123 | goto end; | 134 | goto end; |
| 124 | } | 135 | } |
| 125 | } else { | 136 | } else { |
| 126 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 137 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
| 127 | } | 138 | } |
| 128 | if (toseq) { | 139 | if (nseq_config.toseq) { |
| 129 | seq = NETSCAPE_CERT_SEQUENCE_new(); | 140 | seq = NETSCAPE_CERT_SEQUENCE_new(); |
| 130 | seq->certs = sk_X509_new_null(); | 141 | seq->certs = sk_X509_new_null(); |
| 131 | while ((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL))) | 142 | while ((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL))) |
| 132 | sk_X509_push(seq->certs, x509); | 143 | sk_X509_push(seq->certs, x509); |
| 133 | 144 | ||
| 134 | if (!sk_X509_num(seq->certs)) { | 145 | if (!sk_X509_num(seq->certs)) { |
| 135 | BIO_printf(bio_err, "Error reading certs file %s\n", infile); | 146 | BIO_printf(bio_err, "Error reading certs file %s\n", nseq_config.infile); |
| 136 | ERR_print_errors(bio_err); | 147 | ERR_print_errors(bio_err); |
| 137 | goto end; | 148 | goto end; |
| 138 | } | 149 | } |
| @@ -141,7 +152,7 @@ nseq_main(int argc, char **argv) | |||
| 141 | goto end; | 152 | goto end; |
| 142 | } | 153 | } |
| 143 | if (!(seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL))) { | 154 | if (!(seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL))) { |
| 144 | BIO_printf(bio_err, "Error reading sequence file %s\n", infile); | 155 | BIO_printf(bio_err, "Error reading sequence file %s\n", nseq_config.infile); |
| 145 | ERR_print_errors(bio_err); | 156 | ERR_print_errors(bio_err); |
| 146 | goto end; | 157 | goto end; |
| 147 | } | 158 | } |
