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