Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: openssl/crypto/pem/pem_info.c

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/crypto/pem/pem_err.c ('k') | openssl/crypto/pem/pem_lib.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* crypto/pem/pem_info.c */ 1 /* crypto/pem/pem_info.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe m_password_cb *cb, void *u) 91 STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe m_password_cb *cb, void *u)
92 { 92 {
93 X509_INFO *xi=NULL; 93 X509_INFO *xi=NULL;
94 char *name=NULL,*header=NULL; 94 char *name=NULL,*header=NULL;
95 void *pp; 95 void *pp;
96 unsigned char *data=NULL; 96 unsigned char *data=NULL;
97 const unsigned char *p; 97 const unsigned char *p;
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 {
106 if ((ret=sk_X509_INFO_new_null()) == NULL) 106 if ((ret=sk_X509_INFO_new_null()) == NULL)
107 { 107 {
108 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE ); 108 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE );
109 goto err; 109 goto err;
110 } 110 }
111 } 111 }
112 else 112 else
113 ret=sk; 113 ret=sk;
114 114
115 if ((xi=X509_INFO_new()) == NULL) goto err; 115 if ((xi=X509_INFO_new()) == NULL) goto err;
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 {
122 error=ERR_GET_REASON(ERR_peek_last_error()); 123 error=ERR_GET_REASON(ERR_peek_last_error());
123 if (error == PEM_R_NO_START_LINE) 124 if (error == PEM_R_NO_START_LINE)
124 { 125 {
125 ERR_clear_error(); 126 ERR_clear_error();
126 break; 127 break;
127 } 128 }
128 goto err; 129 goto err;
(...skipping 30 matching lines...) Expand all
159 if (!sk_X509_INFO_push(ret,xi)) goto err; 160 if (!sk_X509_INFO_push(ret,xi)) goto err;
160 if ((xi=X509_INFO_new()) == NULL) goto err; 161 if ((xi=X509_INFO_new()) == NULL) goto err;
161 goto start; 162 goto start;
162 } 163 }
163 pp=&(xi->crl); 164 pp=&(xi->crl);
164 } 165 }
165 else 166 else
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;
173 if ((xi=X509_INFO_new()) == NULL) goto err; 173 if ((xi=X509_INFO_new()) == NULL) goto err;
174 goto start; 174 goto start;
175 } 175 }
176 176
177 xi->enc_data=NULL; 177 xi->enc_data=NULL;
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 }
188 else 186 else
189 #endif 187 #endif
190 #ifndef OPENSSL_NO_DSA 188 #ifndef OPENSSL_NO_DSA
191 if (strcmp(name,PEM_STRING_DSA) == 0) 189 if (strcmp(name,PEM_STRING_DSA) == 0)
192 { 190 {
193 d2i=(D2I_OF(void))d2i_DSAPrivateKey; 191 d2i=(D2I_OF(void))d2i_DSAPrivateKey;
194 if (xi->x_pkey != NULL) 192 if (xi->x_pkey != NULL)
195 { 193 {
196 if (!sk_X509_INFO_push(ret,xi)) goto err; 194 if (!sk_X509_INFO_push(ret,xi)) goto err;
197 if ((xi=X509_INFO_new()) == NULL) goto err; 195 if ((xi=X509_INFO_new()) == NULL) goto err;
198 goto start; 196 goto start;
199 } 197 }
200 198
201 xi->enc_data=NULL; 199 xi->enc_data=NULL;
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 }
212 else 208 else
213 #endif 209 #endif
214 #ifndef OPENSSL_NO_EC 210 #ifndef OPENSSL_NO_EC
215 if (strcmp(name,PEM_STRING_ECPRIVATEKEY) == 0) 211 if (strcmp(name,PEM_STRING_ECPRIVATEKEY) == 0)
216 { 212 {
217 d2i=(D2I_OF(void))d2i_ECPrivateKey; 213 d2i=(D2I_OF(void))d2i_ECPrivateKey;
218 if (xi->x_pkey != NULL) 214 if (xi->x_pkey != NULL)
219 { 215 {
220 if (!sk_X509_INFO_push(ret,xi)) goto err ; 216 if (!sk_X509_INFO_push(ret,xi)) goto err ;
221 if ((xi=X509_INFO_new()) == NULL) goto e rr; 217 if ((xi=X509_INFO_new()) == NULL) goto e rr;
222 goto start; 218 goto start;
223 } 219 }
224 220
225 xi->enc_data=NULL; 221 xi->enc_data=NULL;
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 }
236 else 230 else
237 #endif 231 #endif
238 { 232 {
239 d2i=NULL; 233 d2i=NULL;
240 pp=NULL; 234 pp=NULL;
241 } 235 }
242 236
243 if (d2i != NULL) 237 if (d2i != NULL)
244 { 238 {
245 if (!raw) 239 if (!raw)
246 { 240 {
247 EVP_CIPHER_INFO cipher; 241 EVP_CIPHER_INFO cipher;
248 242
249 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) 243 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
250 goto err; 244 goto err;
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;
258 } 260 }
259 } 261 }
260 else 262 else
261 { /* encrypted RSA data */ 263 { /* encrypted RSA data */
262 if (!PEM_get_EVP_CIPHER_INFO(header, 264 if (!PEM_get_EVP_CIPHER_INFO(header,
263 &xi->enc_cipher)) goto err; 265 &xi->enc_cipher)) goto err;
264 xi->enc_data=(char *)data; 266 xi->enc_data=(char *)data;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 332
331 /* now for the fun part ... if we have a private key then 333 /* now for the fun part ... if we have a private key then
332 * we have to be able to handle a not-yet-decrypted key 334 * we have to be able to handle a not-yet-decrypted key
333 * being written out correctly ... if it is decrypted or 335 * being written out correctly ... if it is decrypted or
334 * it is non-encrypted then we use the base code 336 * it is non-encrypted then we use the base code
335 */ 337 */
336 if (xi->x_pkey!=NULL) 338 if (xi->x_pkey!=NULL)
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_CIPHE R_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;
343 i=xi->enc_len; 351 i=xi->enc_len;
344 352
345 /* we take the encryption data from the 353 /* we take the encryption data from the
346 * internal stuff rather than what the 354 * internal stuff rather than what the
347 * user has passed us ... as we have to 355 * user has passed us ... as we have to
348 * match exactly for some strange reason 356 * match exactly for some strange reason
349 */ 357 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 * base library --tjh 396 * base library --tjh
389 */ 397 */
390 398
391 ret=1; 399 ret=1;
392 400
393 err: 401 err:
394 OPENSSL_cleanse((char *)&ctx,sizeof(ctx)); 402 OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
395 OPENSSL_cleanse(buf,PEM_BUFSIZE); 403 OPENSSL_cleanse(buf,PEM_BUFSIZE);
396 return(ret); 404 return(ret);
397 } 405 }
OLDNEW
« no previous file with comments | « openssl/crypto/pem/pem_err.c ('k') | openssl/crypto/pem/pem_lib.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698