diff options
Diffstat (limited to 'src/lib/libcrypto/pem/pem_info.c')
-rw-r--r-- | src/lib/libcrypto/pem/pem_info.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c index 3a273f6f70..1b2be527ed 100644 --- a/src/lib/libcrypto/pem/pem_info.c +++ b/src/lib/libcrypto/pem/pem_info.c | |||
@@ -98,8 +98,8 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe | |||
98 | long len,error=0; | 98 | long len,error=0; |
99 | int ok=0; | 99 | int ok=0; |
100 | STACK_OF(X509_INFO) *ret=NULL; | 100 | STACK_OF(X509_INFO) *ret=NULL; |
101 | unsigned int i,raw; | 101 | unsigned int i,raw,ptype; |
102 | d2i_of_void *d2i; | 102 | d2i_of_void *d2i = 0; |
103 | 103 | ||
104 | if (sk == NULL) | 104 | if (sk == NULL) |
105 | { | 105 | { |
@@ -116,6 +116,7 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe | |||
116 | for (;;) | 116 | for (;;) |
117 | { | 117 | { |
118 | raw=0; | 118 | raw=0; |
119 | ptype = 0; | ||
119 | i=PEM_read_bio(bp,&name,&header,&data,&len); | 120 | i=PEM_read_bio(bp,&name,&header,&data,&len); |
120 | if (i == 0) | 121 | if (i == 0) |
121 | { | 122 | { |
@@ -166,7 +167,6 @@ start: | |||
166 | #ifndef OPENSSL_NO_RSA | 167 | #ifndef OPENSSL_NO_RSA |
167 | if (strcmp(name,PEM_STRING_RSA) == 0) | 168 | if (strcmp(name,PEM_STRING_RSA) == 0) |
168 | { | 169 | { |
169 | d2i=(D2I_OF(void))d2i_RSAPrivateKey; | ||
170 | if (xi->x_pkey != NULL) | 170 | if (xi->x_pkey != NULL) |
171 | { | 171 | { |
172 | if (!sk_X509_INFO_push(ret,xi)) goto err; | 172 | if (!sk_X509_INFO_push(ret,xi)) goto err; |
@@ -178,10 +178,8 @@ start: | |||
178 | xi->enc_len=0; | 178 | xi->enc_len=0; |
179 | 179 | ||
180 | xi->x_pkey=X509_PKEY_new(); | 180 | xi->x_pkey=X509_PKEY_new(); |
181 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | 181 | ptype=EVP_PKEY_RSA; |
182 | goto err; | 182 | pp=&xi->x_pkey->dec_pkey; |
183 | xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA; | ||
184 | pp=&(xi->x_pkey->dec_pkey->pkey.rsa); | ||
185 | if ((int)strlen(header) > 10) /* assume encrypted */ | 183 | if ((int)strlen(header) > 10) /* assume encrypted */ |
186 | raw=1; | 184 | raw=1; |
187 | } | 185 | } |
@@ -202,10 +200,8 @@ start: | |||
202 | xi->enc_len=0; | 200 | xi->enc_len=0; |
203 | 201 | ||
204 | xi->x_pkey=X509_PKEY_new(); | 202 | xi->x_pkey=X509_PKEY_new(); |
205 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | 203 | ptype = EVP_PKEY_DSA; |
206 | goto err; | 204 | pp=&xi->x_pkey->dec_pkey; |
207 | xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA; | ||
208 | pp=&xi->x_pkey->dec_pkey->pkey.dsa; | ||
209 | if ((int)strlen(header) > 10) /* assume encrypted */ | 205 | if ((int)strlen(header) > 10) /* assume encrypted */ |
210 | raw=1; | 206 | raw=1; |
211 | } | 207 | } |
@@ -226,10 +222,8 @@ start: | |||
226 | xi->enc_len=0; | 222 | xi->enc_len=0; |
227 | 223 | ||
228 | xi->x_pkey=X509_PKEY_new(); | 224 | xi->x_pkey=X509_PKEY_new(); |
229 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | 225 | ptype = EVP_PKEY_EC; |
230 | goto err; | 226 | pp=&xi->x_pkey->dec_pkey; |
231 | xi->x_pkey->dec_pkey->type=EVP_PKEY_EC; | ||
232 | pp=&(xi->x_pkey->dec_pkey->pkey.ec); | ||
233 | if ((int)strlen(header) > 10) /* assume encrypted */ | 227 | if ((int)strlen(header) > 10) /* assume encrypted */ |
234 | raw=1; | 228 | raw=1; |
235 | } | 229 | } |
@@ -251,7 +245,15 @@ start: | |||
251 | if (!PEM_do_header(&cipher,data,&len,cb,u)) | 245 | if (!PEM_do_header(&cipher,data,&len,cb,u)) |
252 | goto err; | 246 | goto err; |
253 | p=data; | 247 | p=data; |
254 | if (d2i(pp,&p,len) == NULL) | 248 | if (ptype) |
249 | { | ||
250 | if (!d2i_PrivateKey(ptype, pp, &p, len)) | ||
251 | { | ||
252 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); | ||
253 | goto err; | ||
254 | } | ||
255 | } | ||
256 | else if (d2i(pp,&p,len) == NULL) | ||
255 | { | 257 | { |
256 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); | 258 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); |
257 | goto err; | 259 | goto err; |
@@ -337,6 +339,12 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, | |||
337 | { | 339 | { |
338 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) | 340 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) |
339 | { | 341 | { |
342 | if (enc == NULL) | ||
343 | { | ||
344 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_CIPHER_IS_NULL); | ||
345 | goto err; | ||
346 | } | ||
347 | |||
340 | /* copy from weirdo names into more normal things */ | 348 | /* copy from weirdo names into more normal things */ |
341 | iv=xi->enc_cipher.iv; | 349 | iv=xi->enc_cipher.iv; |
342 | data=(unsigned char *)xi->enc_data; | 350 | data=(unsigned char *)xi->enc_data; |