diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/n_pkey.c')
-rw-r--r-- | src/lib/libcrypto/asn1/n_pkey.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c index 60bc437938..766b51c538 100644 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
@@ -56,9 +56,9 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef OPENSSL_NO_RSA | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
61 | #ifndef OPENSSL_NO_RSA | ||
62 | #include <openssl/rsa.h> | 62 | #include <openssl/rsa.h> |
63 | #include <openssl/objects.h> | 63 | #include <openssl/objects.h> |
64 | #include <openssl/asn1t.h> | 64 | #include <openssl/asn1t.h> |
@@ -107,20 +107,14 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY) | |||
107 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | 107 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) |
108 | 108 | ||
109 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | 109 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, |
110 | int (*cb)(char *buf, int len, const char *prompt, | 110 | int (*cb)(), int sgckey); |
111 | int verify), | ||
112 | int sgckey); | ||
113 | 111 | ||
114 | int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, | 112 | int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)()) |
115 | int (*cb)(char *buf, int len, const char *prompt, | ||
116 | int verify)) | ||
117 | { | 113 | { |
118 | return i2d_RSA_NET(a, pp, cb, 0); | 114 | return i2d_RSA_NET(a, pp, cb, 0); |
119 | } | 115 | } |
120 | 116 | ||
121 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, | 117 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey) |
122 | int (*cb)(char *buf, int len, const char *prompt, int verify), | ||
123 | int sgckey) | ||
124 | { | 118 | { |
125 | int i, j, ret = 0; | 119 | int i, j, ret = 0; |
126 | int rsalen, pkeylen, olen; | 120 | int rsalen, pkeylen, olen; |
@@ -170,7 +164,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
170 | /* Since its RC4 encrypted length is actual length */ | 164 | /* Since its RC4 encrypted length is actual length */ |
171 | if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL) | 165 | if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL) |
172 | { | 166 | { |
173 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 167 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); |
174 | goto err; | 168 | goto err; |
175 | } | 169 | } |
176 | 170 | ||
@@ -180,13 +174,13 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
180 | 174 | ||
181 | if ((zz=OPENSSL_malloc(pkeylen)) == NULL) | 175 | if ((zz=OPENSSL_malloc(pkeylen)) == NULL) |
182 | { | 176 | { |
183 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 177 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); |
184 | goto err; | 178 | goto err; |
185 | } | 179 | } |
186 | 180 | ||
187 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) | 181 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) |
188 | { | 182 | { |
189 | ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); | 183 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); |
190 | goto err; | 184 | goto err; |
191 | } | 185 | } |
192 | enckey->enckey->digest->data = zz; | 186 | enckey->enckey->digest->data = zz; |
@@ -197,10 +191,10 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
197 | 191 | ||
198 | if (cb == NULL) | 192 | if (cb == NULL) |
199 | cb=EVP_read_pw_string; | 193 | cb=EVP_read_pw_string; |
200 | i=cb((char *)buf,256,"Enter Private Key password:",1); | 194 | i=cb(buf,256,"Enter Private Key password:",1); |
201 | if (i != 0) | 195 | if (i != 0) |
202 | { | 196 | { |
203 | ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); | 197 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ); |
204 | goto err; | 198 | goto err; |
205 | } | 199 | } |
206 | i = strlen((char *)buf); | 200 | i = strlen((char *)buf); |
@@ -230,16 +224,12 @@ err: | |||
230 | } | 224 | } |
231 | 225 | ||
232 | 226 | ||
233 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | 227 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)()) |
234 | int (*cb)(char *buf, int len, const char *prompt, | ||
235 | int verify)) | ||
236 | { | 228 | { |
237 | return d2i_RSA_NET(a, pp, length, cb, 0); | 229 | return d2i_RSA_NET(a, pp, length, cb, 0); |
238 | } | 230 | } |
239 | 231 | ||
240 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | 232 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey) |
241 | int (*cb)(char *buf, int len, const char *prompt, int verify), | ||
242 | int sgckey) | ||
243 | { | 233 | { |
244 | RSA *ret=NULL; | 234 | RSA *ret=NULL; |
245 | const unsigned char *p, *kp; | 235 | const unsigned char *p, *kp; |
@@ -249,20 +239,20 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
249 | 239 | ||
250 | enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); | 240 | enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); |
251 | if(!enckey) { | 241 | if(!enckey) { |
252 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); | 242 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR); |
253 | return NULL; | 243 | return NULL; |
254 | } | 244 | } |
255 | 245 | ||
256 | if ((enckey->os->length != 11) || (strncmp("private-key", | 246 | if ((enckey->os->length != 11) || (strncmp("private-key", |
257 | (char *)enckey->os->data,11) != 0)) | 247 | (char *)enckey->os->data,11) != 0)) |
258 | { | 248 | { |
259 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); | 249 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING); |
260 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 250 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
261 | return NULL; | 251 | return NULL; |
262 | } | 252 | } |
263 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) | 253 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) |
264 | { | 254 | { |
265 | ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | 255 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); |
266 | goto err; | 256 | goto err; |
267 | } | 257 | } |
268 | kp = enckey->enckey->digest->data; | 258 | kp = enckey->enckey->digest->data; |
@@ -279,8 +269,7 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | |||
279 | } | 269 | } |
280 | 270 | ||
281 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | 271 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, |
282 | int (*cb)(char *buf, int len, const char *prompt, | 272 | int (*cb)(), int sgckey) |
283 | int verify), int sgckey) | ||
284 | { | 273 | { |
285 | NETSCAPE_PKEY *pkey=NULL; | 274 | NETSCAPE_PKEY *pkey=NULL; |
286 | RSA *ret=NULL; | 275 | RSA *ret=NULL; |
@@ -290,10 +279,10 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
290 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 279 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
291 | EVP_CIPHER_CTX ctx; | 280 | EVP_CIPHER_CTX ctx; |
292 | 281 | ||
293 | i=cb((char *)buf,256,"Enter Private Key password:",0); | 282 | i=cb(buf,256,"Enter Private Key password:",0); |
294 | if (i != 0) | 283 | if (i != 0) |
295 | { | 284 | { |
296 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); | 285 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ); |
297 | goto err; | 286 | goto err; |
298 | } | 287 | } |
299 | 288 | ||
@@ -318,14 +307,14 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
318 | 307 | ||
319 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) | 308 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) |
320 | { | 309 | { |
321 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | 310 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); |
322 | goto err; | 311 | goto err; |
323 | } | 312 | } |
324 | 313 | ||
325 | zz=pkey->private_key->data; | 314 | zz=pkey->private_key->data; |
326 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) | 315 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) |
327 | { | 316 | { |
328 | ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | 317 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); |
329 | goto err; | 318 | goto err; |
330 | } | 319 | } |
331 | err: | 320 | err: |