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.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 9e4af29c95..3a273f6f70 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -63,6 +63,12 @@
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65#include <openssl/pem.h> 65#include <openssl/pem.h>
66#ifndef OPENSSL_NO_RSA
67#include <openssl/rsa.h>
68#endif
69#ifndef OPENSSL_NO_DSA
70#include <openssl/dsa.h>
71#endif
66 72
67#ifndef OPENSSL_NO_FP_API 73#ifndef OPENSSL_NO_FP_API
68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) 74STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
@@ -85,13 +91,15 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_p
85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) 91STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
86 { 92 {
87 X509_INFO *xi=NULL; 93 X509_INFO *xi=NULL;
88 char *name=NULL,*header=NULL,**pp; 94 char *name=NULL,*header=NULL;
89 unsigned char *data=NULL,*p; 95 void *pp;
96 unsigned char *data=NULL;
97 const unsigned char *p;
90 long len,error=0; 98 long len,error=0;
91 int ok=0; 99 int ok=0;
92 STACK_OF(X509_INFO) *ret=NULL; 100 STACK_OF(X509_INFO) *ret=NULL;
93 unsigned int i,raw; 101 unsigned int i,raw;
94 char *(*d2i)(); 102 d2i_of_void *d2i;
95 103
96 if (sk == NULL) 104 if (sk == NULL)
97 { 105 {
@@ -123,42 +131,42 @@ start:
123 if ( (strcmp(name,PEM_STRING_X509) == 0) || 131 if ( (strcmp(name,PEM_STRING_X509) == 0) ||
124 (strcmp(name,PEM_STRING_X509_OLD) == 0)) 132 (strcmp(name,PEM_STRING_X509_OLD) == 0))
125 { 133 {
126 d2i=(char *(*)())d2i_X509; 134 d2i=(D2I_OF(void))d2i_X509;
127 if (xi->x509 != NULL) 135 if (xi->x509 != NULL)
128 { 136 {
129 if (!sk_X509_INFO_push(ret,xi)) goto err; 137 if (!sk_X509_INFO_push(ret,xi)) goto err;
130 if ((xi=X509_INFO_new()) == NULL) goto err; 138 if ((xi=X509_INFO_new()) == NULL) goto err;
131 goto start; 139 goto start;
132 } 140 }
133 pp=(char **)&(xi->x509); 141 pp=&(xi->x509);
134 } 142 }
135 else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0)) 143 else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0))
136 { 144 {
137 d2i=(char *(*)())d2i_X509_AUX; 145 d2i=(D2I_OF(void))d2i_X509_AUX;
138 if (xi->x509 != NULL) 146 if (xi->x509 != NULL)
139 { 147 {
140 if (!sk_X509_INFO_push(ret,xi)) goto err; 148 if (!sk_X509_INFO_push(ret,xi)) goto err;
141 if ((xi=X509_INFO_new()) == NULL) goto err; 149 if ((xi=X509_INFO_new()) == NULL) goto err;
142 goto start; 150 goto start;
143 } 151 }
144 pp=(char **)&(xi->x509); 152 pp=&(xi->x509);
145 } 153 }
146 else if (strcmp(name,PEM_STRING_X509_CRL) == 0) 154 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
147 { 155 {
148 d2i=(char *(*)())d2i_X509_CRL; 156 d2i=(D2I_OF(void))d2i_X509_CRL;
149 if (xi->crl != NULL) 157 if (xi->crl != NULL)
150 { 158 {
151 if (!sk_X509_INFO_push(ret,xi)) goto err; 159 if (!sk_X509_INFO_push(ret,xi)) goto err;
152 if ((xi=X509_INFO_new()) == NULL) goto err; 160 if ((xi=X509_INFO_new()) == NULL) goto err;
153 goto start; 161 goto start;
154 } 162 }
155 pp=(char **)&(xi->crl); 163 pp=&(xi->crl);
156 } 164 }
157 else 165 else
158#ifndef OPENSSL_NO_RSA 166#ifndef OPENSSL_NO_RSA
159 if (strcmp(name,PEM_STRING_RSA) == 0) 167 if (strcmp(name,PEM_STRING_RSA) == 0)
160 { 168 {
161 d2i=(char *(*)())d2i_RSAPrivateKey; 169 d2i=(D2I_OF(void))d2i_RSAPrivateKey;
162 if (xi->x_pkey != NULL) 170 if (xi->x_pkey != NULL)
163 { 171 {
164 if (!sk_X509_INFO_push(ret,xi)) goto err; 172 if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -173,7 +181,7 @@ start:
173 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 181 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
174 goto err; 182 goto err;
175 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA; 183 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
176 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa); 184 pp=&(xi->x_pkey->dec_pkey->pkey.rsa);
177 if ((int)strlen(header) > 10) /* assume encrypted */ 185 if ((int)strlen(header) > 10) /* assume encrypted */
178 raw=1; 186 raw=1;
179 } 187 }
@@ -182,7 +190,7 @@ start:
182#ifndef OPENSSL_NO_DSA 190#ifndef OPENSSL_NO_DSA
183 if (strcmp(name,PEM_STRING_DSA) == 0) 191 if (strcmp(name,PEM_STRING_DSA) == 0)
184 { 192 {
185 d2i=(char *(*)())d2i_DSAPrivateKey; 193 d2i=(D2I_OF(void))d2i_DSAPrivateKey;
186 if (xi->x_pkey != NULL) 194 if (xi->x_pkey != NULL)
187 { 195 {
188 if (!sk_X509_INFO_push(ret,xi)) goto err; 196 if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -197,12 +205,36 @@ start:
197 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 205 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
198 goto err; 206 goto err;
199 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA; 207 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
200 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa); 208 pp=&xi->x_pkey->dec_pkey->pkey.dsa;
201 if ((int)strlen(header) > 10) /* assume encrypted */ 209 if ((int)strlen(header) > 10) /* assume encrypted */
202 raw=1; 210 raw=1;
203 } 211 }
204 else 212 else
205#endif 213#endif
214#ifndef OPENSSL_NO_EC
215 if (strcmp(name,PEM_STRING_ECPRIVATEKEY) == 0)
216 {
217 d2i=(D2I_OF(void))d2i_ECPrivateKey;
218 if (xi->x_pkey != NULL)
219 {
220 if (!sk_X509_INFO_push(ret,xi)) goto err;
221 if ((xi=X509_INFO_new()) == NULL) goto err;
222 goto start;
223 }
224
225 xi->enc_data=NULL;
226 xi->enc_len=0;
227
228 xi->x_pkey=X509_PKEY_new();
229 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
230 goto err;
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 */
234 raw=1;
235 }
236 else
237#endif
206 { 238 {
207 d2i=NULL; 239 d2i=NULL;
208 pp=NULL; 240 pp=NULL;