pkeyparam.c (256281) | pkeyparam.c (280304) |
---|---|
1/* apps/pkeyparam.c */ | 1/* apps/pkeyparam.c */ |
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3 * project 2006 | 2/* 3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project 4 * 2006 |
4 */ 5/* ==================================================================== 6 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright | 5 */ 6/* ==================================================================== 7 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright |
13 * notice, this list of conditions and the following disclaimer. | 14 * notice, this list of conditions and the following disclaimer. |
14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. All advertising materials mentioning features or use of this 21 * software must display the following acknowledgment: --- 40 unchanged lines hidden (view full) --- 62#include <openssl/err.h> 63#include <openssl/evp.h> 64 65#define PROG pkeyparam_main 66 67int MAIN(int, char **); 68 69int MAIN(int argc, char **argv) | 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. All advertising materials mentioning features or use of this 22 * software must display the following acknowledgment: --- 40 unchanged lines hidden (view full) --- 63#include <openssl/err.h> 64#include <openssl/evp.h> 65 66#define PROG pkeyparam_main 67 68int MAIN(int, char **); 69 70int MAIN(int argc, char **argv) |
70 { 71 char **args, *infile = NULL, *outfile = NULL; 72 BIO *in = NULL, *out = NULL; 73 int text = 0, noout = 0; 74 EVP_PKEY *pkey=NULL; 75 int badarg = 0; | 71{ 72 char **args, *infile = NULL, *outfile = NULL; 73 BIO *in = NULL, *out = NULL; 74 int text = 0, noout = 0; 75 EVP_PKEY *pkey = NULL; 76 int badarg = 0; |
76#ifndef OPENSSL_NO_ENGINE | 77#ifndef OPENSSL_NO_ENGINE |
77 char *engine=NULL; | 78 char *engine = NULL; |
78#endif | 79#endif |
79 int ret = 1; | 80 int ret = 1; |
80 | 81 |
81 if (bio_err == NULL) 82 bio_err = BIO_new_fp (stderr, BIO_NOCLOSE); | 82 if (bio_err == NULL) 83 bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); |
83 | 84 |
84 if (!load_config(bio_err, NULL)) 85 goto end; | 85 if (!load_config(bio_err, NULL)) 86 goto end; |
86 | 87 |
87 ERR_load_crypto_strings(); 88 OpenSSL_add_all_algorithms(); 89 args = argv + 1; 90 while (!badarg && *args && *args[0] == '-') 91 { 92 if (!strcmp (*args, "-in")) 93 { 94 if (args[1]) 95 { 96 args++; 97 infile = *args; 98 } 99 else badarg = 1; 100 } 101 else if (!strcmp (*args, "-out")) 102 { 103 if (args[1]) 104 { 105 args++; 106 outfile = *args; 107 } 108 else badarg = 1; 109 } | 88 ERR_load_crypto_strings(); 89 OpenSSL_add_all_algorithms(); 90 args = argv + 1; 91 while (!badarg && *args && *args[0] == '-') { 92 if (!strcmp(*args, "-in")) { 93 if (args[1]) { 94 args++; 95 infile = *args; 96 } else 97 badarg = 1; 98 } else if (!strcmp(*args, "-out")) { 99 if (args[1]) { 100 args++; 101 outfile = *args; 102 } else 103 badarg = 1; 104 } |
110#ifndef OPENSSL_NO_ENGINE | 105#ifndef OPENSSL_NO_ENGINE |
111 else if (strcmp(*args,"-engine") == 0) 112 { 113 if (!args[1]) goto bad; 114 engine= *(++args); 115 } | 106 else if (strcmp(*args, "-engine") == 0) { 107 if (!args[1]) 108 goto bad; 109 engine = *(++args); 110 } |
116#endif 117 | 111#endif 112 |
118 else if (strcmp(*args,"-text") == 0) 119 text=1; 120 else if (strcmp(*args,"-noout") == 0) 121 noout=1; 122 args++; 123 } | 113 else if (strcmp(*args, "-text") == 0) 114 text = 1; 115 else if (strcmp(*args, "-noout") == 0) 116 noout = 1; 117 args++; 118 } |
124 | 119 |
125 if (badarg) 126 { | 120 if (badarg) { |
127#ifndef OPENSSL_NO_ENGINE | 121#ifndef OPENSSL_NO_ENGINE |
128 bad: | 122 bad: |
129#endif | 123#endif |
130 BIO_printf(bio_err, "Usage pkeyparam [options]\n"); 131 BIO_printf(bio_err, "where options are\n"); 132 BIO_printf(bio_err, "-in file input file\n"); 133 BIO_printf(bio_err, "-out file output file\n"); 134 BIO_printf(bio_err, "-text print parameters as text\n"); 135 BIO_printf(bio_err, "-noout don't output encoded parameters\n"); | 124 BIO_printf(bio_err, "Usage pkeyparam [options]\n"); 125 BIO_printf(bio_err, "where options are\n"); 126 BIO_printf(bio_err, "-in file input file\n"); 127 BIO_printf(bio_err, "-out file output file\n"); 128 BIO_printf(bio_err, "-text print parameters as text\n"); 129 BIO_printf(bio_err, 130 "-noout don't output encoded parameters\n"); |
136#ifndef OPENSSL_NO_ENGINE | 131#ifndef OPENSSL_NO_ENGINE |
137 BIO_printf(bio_err, "-engine e use engine e, possibly a hardware device.\n"); | 132 BIO_printf(bio_err, 133 "-engine e use engine e, possibly a hardware device.\n"); |
138#endif | 134#endif |
139 return 1; 140 } 141 | 135 return 1; 136 } |
142#ifndef OPENSSL_NO_ENGINE | 137#ifndef OPENSSL_NO_ENGINE |
143 setup_engine(bio_err, engine, 0); | 138 setup_engine(bio_err, engine, 0); |
144#endif 145 | 139#endif 140 |
146 if (infile) 147 { 148 if (!(in = BIO_new_file (infile, "r"))) 149 { 150 BIO_printf(bio_err, 151 "Can't open input file %s\n", infile); 152 goto end; 153 } 154 } 155 else 156 in = BIO_new_fp (stdin, BIO_NOCLOSE); | 141 if (infile) { 142 if (!(in = BIO_new_file(infile, "r"))) { 143 BIO_printf(bio_err, "Can't open input file %s\n", infile); 144 goto end; 145 } 146 } else 147 in = BIO_new_fp(stdin, BIO_NOCLOSE); |
157 | 148 |
158 if (outfile) 159 { 160 if (!(out = BIO_new_file (outfile, "w"))) 161 { 162 BIO_printf(bio_err, 163 "Can't open output file %s\n", outfile); 164 goto end; 165 } 166 } 167 else 168 { 169 out = BIO_new_fp (stdout, BIO_NOCLOSE); | 149 if (outfile) { 150 if (!(out = BIO_new_file(outfile, "w"))) { 151 BIO_printf(bio_err, "Can't open output file %s\n", outfile); 152 goto end; 153 } 154 } else { 155 out = BIO_new_fp(stdout, BIO_NOCLOSE); |
170#ifdef OPENSSL_SYS_VMS | 156#ifdef OPENSSL_SYS_VMS |
171 { 172 BIO *tmpbio = BIO_new(BIO_f_linebuffer()); 173 out = BIO_push(tmpbio, out); 174 } | 157 { 158 BIO *tmpbio = BIO_new(BIO_f_linebuffer()); 159 out = BIO_push(tmpbio, out); 160 } |
175#endif | 161#endif |
176 } | 162 } |
177 | 163 |
178 pkey = PEM_read_bio_Parameters(in, NULL); 179 if (!pkey) 180 { 181 BIO_printf(bio_err, "Error reading parameters\n"); 182 ERR_print_errors(bio_err); 183 goto end; 184 } | 164 pkey = PEM_read_bio_Parameters(in, NULL); 165 if (!pkey) { 166 BIO_printf(bio_err, "Error reading parameters\n"); 167 ERR_print_errors(bio_err); 168 goto end; 169 } |
185 | 170 |
186 if (!noout) 187 PEM_write_bio_Parameters(out,pkey); | 171 if (!noout) 172 PEM_write_bio_Parameters(out, pkey); |
188 | 173 |
189 if (text) 190 EVP_PKEY_print_params(out, pkey, 0, NULL); | 174 if (text) 175 EVP_PKEY_print_params(out, pkey, 0, NULL); |
191 | 176 |
192 ret = 0; | 177 ret = 0; |
193 | 178 |
194 end: 195 EVP_PKEY_free(pkey); 196 BIO_free_all(out); 197 BIO_free(in); | 179 end: 180 EVP_PKEY_free(pkey); 181 BIO_free_all(out); 182 BIO_free(in); |
198 | 183 |
199 return ret; 200 } | 184 return ret; 185} |