summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem/pem_info.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pem/pem_info.c')
-rw-r--r--src/lib/libcrypto/pem/pem_info.c60
1 files changed, 24 insertions, 36 deletions
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 4b69833b62..fec18a4c2e 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -58,20 +58,17 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pem.h" 65#include <openssl/pem.h>
66 66
67#ifndef NO_FP_API 67#ifndef NO_FP_API
68STACK *PEM_X509_INFO_read(fp,sk,cb) 68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
69FILE *fp;
70STACK *sk;
71int (*cb)();
72 { 69 {
73 BIO *b; 70 BIO *b;
74 STACK *ret; 71 STACK_OF(X509_INFO) *ret;
75 72
76 if ((b=BIO_new(BIO_s_file())) == NULL) 73 if ((b=BIO_new(BIO_s_file())) == NULL)
77 { 74 {
@@ -79,29 +76,26 @@ int (*cb)();
79 return(0); 76 return(0);
80 } 77 }
81 BIO_set_fp(b,fp,BIO_NOCLOSE); 78 BIO_set_fp(b,fp,BIO_NOCLOSE);
82 ret=PEM_X509_INFO_read_bio(b,sk,cb); 79 ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
83 BIO_free(b); 80 BIO_free(b);
84 return(ret); 81 return(ret);
85 } 82 }
86#endif 83#endif
87 84
88STACK *PEM_X509_INFO_read_bio(bp,sk,cb) 85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
89BIO *bp;
90STACK *sk;
91int (*cb)();
92 { 86 {
93 X509_INFO *xi=NULL; 87 X509_INFO *xi=NULL;
94 char *name=NULL,*header=NULL,**pp; 88 char *name=NULL,*header=NULL,**pp;
95 unsigned char *data=NULL,*p; 89 unsigned char *data=NULL,*p;
96 long len,error=0; 90 long len,error=0;
97 int ok=0; 91 int ok=0;
98 STACK *ret=NULL; 92 STACK_OF(X509_INFO) *ret=NULL;
99 unsigned int i,raw; 93 unsigned int i,raw;
100 char *(*d2i)(); 94 char *(*d2i)();
101 95
102 if (sk == NULL) 96 if (sk == NULL)
103 { 97 {
104 if ((ret=sk_new_null()) == NULL) 98 if ((ret=sk_X509_INFO_new_null()) == NULL)
105 { 99 {
106 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); 100 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
107 goto err; 101 goto err;
@@ -132,7 +126,7 @@ start:
132 d2i=(char *(*)())d2i_X509; 126 d2i=(char *(*)())d2i_X509;
133 if (xi->x509 != NULL) 127 if (xi->x509 != NULL)
134 { 128 {
135 if (!sk_push(ret,(char *)xi)) goto err; 129 if (!sk_X509_INFO_push(ret,xi)) goto err;
136 if ((xi=X509_INFO_new()) == NULL) goto err; 130 if ((xi=X509_INFO_new()) == NULL) goto err;
137 goto start; 131 goto start;
138 } 132 }
@@ -143,7 +137,7 @@ start:
143 d2i=(char *(*)())d2i_X509_CRL; 137 d2i=(char *(*)())d2i_X509_CRL;
144 if (xi->crl != NULL) 138 if (xi->crl != NULL)
145 { 139 {
146 if (!sk_push(ret,(char *)xi)) goto err; 140 if (!sk_X509_INFO_push(ret,xi)) goto err;
147 if ((xi=X509_INFO_new()) == NULL) goto err; 141 if ((xi=X509_INFO_new()) == NULL) goto err;
148 goto start; 142 goto start;
149 } 143 }
@@ -156,7 +150,7 @@ start:
156 d2i=(char *(*)())d2i_RSAPrivateKey; 150 d2i=(char *(*)())d2i_RSAPrivateKey;
157 if (xi->x_pkey != NULL) 151 if (xi->x_pkey != NULL)
158 { 152 {
159 if (!sk_push(ret,(char *)xi)) goto err; 153 if (!sk_X509_INFO_push(ret,xi)) goto err;
160 if ((xi=X509_INFO_new()) == NULL) goto err; 154 if ((xi=X509_INFO_new()) == NULL) goto err;
161 goto start; 155 goto start;
162 } 156 }
@@ -180,7 +174,7 @@ start:
180 d2i=(char *(*)())d2i_DSAPrivateKey; 174 d2i=(char *(*)())d2i_DSAPrivateKey;
181 if (xi->x_pkey != NULL) 175 if (xi->x_pkey != NULL)
182 { 176 {
183 if (!sk_push(ret,(char *)xi)) goto err; 177 if (!sk_X509_INFO_push(ret,xi)) goto err;
184 if ((xi=X509_INFO_new()) == NULL) goto err; 178 if ((xi=X509_INFO_new()) == NULL) goto err;
185 goto start; 179 goto start;
186 } 180 }
@@ -211,7 +205,7 @@ start:
211 205
212 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) 206 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
213 goto err; 207 goto err;
214 if (!PEM_do_header(&cipher,data,&len,cb)) 208 if (!PEM_do_header(&cipher,data,&len,cb,u))
215 goto err; 209 goto err;
216 p=data; 210 p=data;
217 if (d2i(pp,&p,len) == NULL) 211 if (d2i(pp,&p,len) == NULL)
@@ -246,7 +240,7 @@ start:
246 if ((xi->x509 != NULL) || (xi->crl != NULL) || 240 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
247 (xi->x_pkey != NULL) || (xi->enc_data != NULL)) 241 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
248 { 242 {
249 if (!sk_push(ret,(char *)xi)) goto err; 243 if (!sk_X509_INFO_push(ret,xi)) goto err;
250 xi=NULL; 244 xi=NULL;
251 } 245 }
252 ok=1; 246 ok=1;
@@ -254,12 +248,12 @@ err:
254 if (xi != NULL) X509_INFO_free(xi); 248 if (xi != NULL) X509_INFO_free(xi);
255 if (!ok) 249 if (!ok)
256 { 250 {
257 for (i=0; ((int)i)<sk_num(ret); i++) 251 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
258 { 252 {
259 xi=(X509_INFO *)sk_value(ret,i); 253 xi=sk_X509_INFO_value(ret,i);
260 X509_INFO_free(xi); 254 X509_INFO_free(xi);
261 } 255 }
262 if (ret != sk) sk_free(ret); 256 if (ret != sk) sk_X509_INFO_free(ret);
263 ret=NULL; 257 ret=NULL;
264 } 258 }
265 259
@@ -271,19 +265,13 @@ err:
271 265
272 266
273/* A TJH addition */ 267/* A TJH addition */
274int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb) 268int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
275BIO *bp; 269 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
276X509_INFO *xi;
277EVP_CIPHER *enc;
278unsigned char *kstr;
279int klen;
280int (*cb)();
281 { 270 {
282 EVP_CIPHER_CTX ctx; 271 EVP_CIPHER_CTX ctx;
283 int i,ret=0; 272 int i,ret=0;
284 unsigned char *data=NULL; 273 unsigned char *data=NULL;
285 char *objstr=NULL; 274 const char *objstr=NULL;
286#define PEM_BUFSIZE 1024
287 char buf[PEM_BUFSIZE]; 275 char buf[PEM_BUFSIZE];
288 unsigned char *iv=NULL; 276 unsigned char *iv=NULL;
289 277
@@ -340,7 +328,7 @@ int (*cb)();
340 /* normal optionally encrypted stuff */ 328 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp, 329 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa, 330 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb)<=0) 331 enc,kstr,klen,cb,u)<=0)
344 goto err; 332 goto err;
345#endif 333#endif
346 } 334 }