summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2015-04-11 15:21:42 +0000
committerjsing <>2015-04-11 15:21:42 +0000
commitb70f6df50abc2463189672756ec288ee88ece543 (patch)
tree5a400ec34823e1c91a39a4087d1c7c6ea3747bac
parent8a98fefea13a82a7e7355353723c8ee1722456e7 (diff)
downloadopenbsd-b70f6df50abc2463189672756ec288ee88ece543.tar.gz
openbsd-b70f6df50abc2463189672756ec288ee88ece543.tar.bz2
openbsd-b70f6df50abc2463189672756ec288ee88ece543.zip
Convert openssl(1) pkeyparam to new option handling.
-rw-r--r--src/usr.bin/openssl/pkeyparam.c135
1 files changed, 74 insertions, 61 deletions
diff --git a/src/usr.bin/openssl/pkeyparam.c b/src/usr.bin/openssl/pkeyparam.c
index d9e4085e25..2521362804 100644
--- a/src/usr.bin/openssl/pkeyparam.c
+++ b/src/usr.bin/openssl/pkeyparam.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pkeyparam.c,v 1.3 2014/08/28 14:25:48 jsing Exp $ */ 1/* $OpenBSD: pkeyparam.c,v 1.4 2015/04/11 15:21:42 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 2006 3 * project 2006
4 */ 4 */
@@ -65,83 +65,96 @@
65#include <openssl/evp.h> 65#include <openssl/evp.h>
66#include <openssl/pem.h> 66#include <openssl/pem.h>
67 67
68struct {
69#ifndef OPENSSL_NO_ENGINE
70 char *engine;
71#endif
72 char *infile;
73 int noout;
74 char *outfile;
75 int text;
76} pkeyparam_config;
77
78struct option pkeyparam_options[] = {
79#ifndef OPENSSL_NO_ENGINE
80 {
81 .name = "engine",
82 .argname = "id",
83 .desc = "Use the engine specified by the given identifier",
84 .type = OPTION_ARG,
85 .opt.arg = &pkeyparam_config.engine,
86 },
87#endif
88 {
89 .name = "in",
90 .argname = "file",
91 .desc = "Input file (default stdin)",
92 .type = OPTION_ARG,
93 .opt.arg = &pkeyparam_config.infile,
94 },
95 {
96 .name = "noout",
97 .desc = "Do not print encoded version of the parameters",
98 .type = OPTION_FLAG,
99 .opt.flag = &pkeyparam_config.noout,
100 },
101 {
102 .name = "out",
103 .argname = "file",
104 .desc = "Output file (default stdout)",
105 .type = OPTION_ARG,
106 .opt.arg = &pkeyparam_config.outfile,
107 },
108 {
109 .name = "text",
110 .desc = "Print out the parameters in plain text",
111 .type = OPTION_FLAG,
112 .opt.flag = &pkeyparam_config.text,
113 },
114 { NULL },
115};
116
117static void
118pkeyparam_usage()
119{
120 fprintf(stderr,
121 "usage: pkeyparam [-engine id] [-in file] [-noout] [-out file] "
122 "[-text]\n");
123 options_usage(pkeyparam_options);
124}
125
68int pkeyparam_main(int, char **); 126int pkeyparam_main(int, char **);
69 127
70int 128int
71pkeyparam_main(int argc, char **argv) 129pkeyparam_main(int argc, char **argv)
72{ 130{
73 char **args, *infile = NULL, *outfile = NULL;
74 BIO *in = NULL, *out = NULL; 131 BIO *in = NULL, *out = NULL;
75 int text = 0, noout = 0;
76 EVP_PKEY *pkey = NULL; 132 EVP_PKEY *pkey = NULL;
77 int badarg = 0;
78#ifndef OPENSSL_NO_ENGINE
79 char *engine = NULL;
80#endif
81 int ret = 1; 133 int ret = 1;
82 134
83 args = argv + 1; 135 memset(&pkeyparam_config, 0, sizeof(pkeyparam_config));
84 while (!badarg && *args && *args[0] == '-') {
85 if (!strcmp(*args, "-in")) {
86 if (args[1]) {
87 args++;
88 infile = *args;
89 } else
90 badarg = 1;
91 } else if (!strcmp(*args, "-out")) {
92 if (args[1]) {
93 args++;
94 outfile = *args;
95 } else
96 badarg = 1;
97 }
98#ifndef OPENSSL_NO_ENGINE
99 else if (strcmp(*args, "-engine") == 0) {
100 if (!args[1])
101 goto bad;
102 engine = *(++args);
103 }
104#endif
105 136
106 else if (strcmp(*args, "-text") == 0) 137 if (options_parse(argc, argv, pkeyparam_options, NULL, NULL) != 0) {
107 text = 1; 138 pkeyparam_usage();
108 else if (strcmp(*args, "-noout") == 0) 139 return (1);
109 noout = 1;
110 args++;
111 } 140 }
112 141
113 if (badarg) {
114#ifndef OPENSSL_NO_ENGINE
115bad:
116#endif
117 BIO_printf(bio_err, "Usage pkeyparam [options]\n");
118 BIO_printf(bio_err, "where options are\n");
119 BIO_printf(bio_err, "-in file input file\n");
120 BIO_printf(bio_err, "-out file output file\n");
121 BIO_printf(bio_err, "-text print parameters as text\n");
122 BIO_printf(bio_err, "-noout don't output encoded parameters\n");
123#ifndef OPENSSL_NO_ENGINE 142#ifndef OPENSSL_NO_ENGINE
124 BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n"); 143 setup_engine(bio_err, pkeyparam_config.engine, 0);
125#endif
126 return 1;
127 }
128#ifndef OPENSSL_NO_ENGINE
129 setup_engine(bio_err, engine, 0);
130#endif 144#endif
131 145
132 if (infile) { 146 if (pkeyparam_config.infile) {
133 if (!(in = BIO_new_file(infile, "r"))) { 147 if (!(in = BIO_new_file(pkeyparam_config.infile, "r"))) {
134 BIO_printf(bio_err, 148 BIO_printf(bio_err, "Can't open input file %s\n",
135 "Can't open input file %s\n", infile); 149 pkeyparam_config.infile);
136 goto end;
137 } 150 }
138 } else 151 } else
139 in = BIO_new_fp(stdin, BIO_NOCLOSE); 152 in = BIO_new_fp(stdin, BIO_NOCLOSE);
140 153
141 if (outfile) { 154 if (pkeyparam_config.outfile) {
142 if (!(out = BIO_new_file(outfile, "w"))) { 155 if (!(out = BIO_new_file(pkeyparam_config.outfile, "w"))) {
143 BIO_printf(bio_err, 156 BIO_printf(bio_err, "Can't open output file %s\n",
144 "Can't open output file %s\n", outfile); 157 pkeyparam_config.outfile);
145 goto end; 158 goto end;
146 } 159 }
147 } else { 160 } else {
@@ -154,10 +167,10 @@ bad:
154 ERR_print_errors(bio_err); 167 ERR_print_errors(bio_err);
155 goto end; 168 goto end;
156 } 169 }
157 if (!noout) 170 if (!pkeyparam_config.noout)
158 PEM_write_bio_Parameters(out, pkey); 171 PEM_write_bio_Parameters(out, pkey);
159 172
160 if (text) 173 if (pkeyparam_config.text)
161 EVP_PKEY_print_params(out, pkey, 0, NULL); 174 EVP_PKEY_print_params(out, pkey, 0, NULL);
162 175
163 ret = 0; 176 ret = 0;