diff options
Diffstat (limited to 'src/lib/libcrypto/x509/by_file.c')
-rw-r--r-- | src/lib/libcrypto/x509/by_file.c | 106 |
1 files changed, 61 insertions, 45 deletions
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c index 09ebb9bf08..92e00d2d73 100644 --- a/src/lib/libcrypto/x509/by_file.c +++ b/src/lib/libcrypto/x509/by_file.c | |||
@@ -59,24 +59,17 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <time.h> | 60 | #include <time.h> |
61 | #include <errno.h> | 61 | #include <errno.h> |
62 | #include <sys/types.h> | ||
63 | #include <sys/stat.h> | ||
64 | 62 | ||
65 | #include "cryptlib.h" | 63 | #include "cryptlib.h" |
66 | #include "lhash.h" | 64 | #include <openssl/lhash.h> |
67 | #include "buffer.h" | 65 | #include <openssl/buffer.h> |
68 | #include "x509.h" | 66 | #include <openssl/x509.h> |
69 | #include "pem.h" | 67 | #include <openssl/pem.h> |
70 | 68 | ||
71 | #ifndef NO_STDIO | 69 | #ifndef OPENSSL_NO_STDIO |
72 | |||
73 | #ifndef NOPROTO | ||
74 | static int by_file_ctrl(X509_LOOKUP *ctx,int cmd,char *argc, | ||
75 | long argl,char **ret); | ||
76 | #else | ||
77 | static int by_file_ctrl(); | ||
78 | #endif | ||
79 | 70 | ||
71 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, | ||
72 | long argl, char **ret); | ||
80 | X509_LOOKUP_METHOD x509_file_lookup= | 73 | X509_LOOKUP_METHOD x509_file_lookup= |
81 | { | 74 | { |
82 | "Load file into cache", | 75 | "Load file into cache", |
@@ -91,19 +84,15 @@ X509_LOOKUP_METHOD x509_file_lookup= | |||
91 | NULL, /* get_by_alias */ | 84 | NULL, /* get_by_alias */ |
92 | }; | 85 | }; |
93 | 86 | ||
94 | X509_LOOKUP_METHOD *X509_LOOKUP_file() | 87 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void) |
95 | { | 88 | { |
96 | return(&x509_file_lookup); | 89 | return(&x509_file_lookup); |
97 | } | 90 | } |
98 | 91 | ||
99 | static int by_file_ctrl(ctx,cmd,argp,argl,ret) | 92 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
100 | X509_LOOKUP *ctx; | 93 | char **ret) |
101 | int cmd; | ||
102 | char *argp; | ||
103 | long argl; | ||
104 | char **ret; | ||
105 | { | 94 | { |
106 | int ok=0,ok2=0; | 95 | int ok=0; |
107 | char *file; | 96 | char *file; |
108 | 97 | ||
109 | switch (cmd) | 98 | switch (cmd) |
@@ -111,37 +100,33 @@ char **ret; | |||
111 | case X509_L_FILE_LOAD: | 100 | case X509_L_FILE_LOAD: |
112 | if (argl == X509_FILETYPE_DEFAULT) | 101 | if (argl == X509_FILETYPE_DEFAULT) |
113 | { | 102 | { |
114 | ok=X509_load_cert_file(ctx,X509_get_default_cert_file(), | 103 | ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(), |
115 | X509_FILETYPE_PEM); | 104 | X509_FILETYPE_PEM) != 0); |
116 | ok2=X509_load_crl_file(ctx,X509_get_default_cert_file(), | 105 | if (!ok) |
117 | X509_FILETYPE_PEM); | ||
118 | if (!ok || !ok2) | ||
119 | { | 106 | { |
120 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); | 107 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); |
121 | } | 108 | } |
122 | else | 109 | else |
123 | { | 110 | { |
124 | file=(char *)Getenv(X509_get_default_cert_file_env()); | 111 | file=(char *)Getenv(X509_get_default_cert_file_env()); |
125 | ok=X509_load_cert_file(ctx,file, | 112 | ok = (X509_load_cert_crl_file(ctx,file, |
126 | X509_FILETYPE_PEM); | 113 | X509_FILETYPE_PEM) != 0); |
127 | ok2=X509_load_crl_file(ctx,file, | ||
128 | X509_FILETYPE_PEM); | ||
129 | } | 114 | } |
130 | } | 115 | } |
131 | else | 116 | else |
132 | { | 117 | { |
133 | ok=X509_load_cert_file(ctx,argp,(int)argl); | 118 | if(argl == X509_FILETYPE_PEM) |
134 | ok2=X509_load_crl_file(ctx,argp,(int)argl); | 119 | ok = (X509_load_cert_crl_file(ctx,argp, |
120 | X509_FILETYPE_PEM) != 0); | ||
121 | else | ||
122 | ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0); | ||
135 | } | 123 | } |
136 | break; | 124 | break; |
137 | } | 125 | } |
138 | return((ok && ok2)?ok:0); | 126 | return(ok); |
139 | } | 127 | } |
140 | 128 | ||
141 | int X509_load_cert_file(ctx,file,type) | 129 | int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) |
142 | X509_LOOKUP *ctx; | ||
143 | char *file; | ||
144 | int type; | ||
145 | { | 130 | { |
146 | int ret=0; | 131 | int ret=0; |
147 | BIO *in=NULL; | 132 | BIO *in=NULL; |
@@ -161,7 +146,7 @@ int type; | |||
161 | { | 146 | { |
162 | for (;;) | 147 | for (;;) |
163 | { | 148 | { |
164 | x=PEM_read_bio_X509(in,NULL,NULL); | 149 | x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL); |
165 | if (x == NULL) | 150 | if (x == NULL) |
166 | { | 151 | { |
167 | if ((ERR_GET_REASON(ERR_peek_error()) == | 152 | if ((ERR_GET_REASON(ERR_peek_error()) == |
@@ -208,10 +193,7 @@ err: | |||
208 | return(ret); | 193 | return(ret); |
209 | } | 194 | } |
210 | 195 | ||
211 | int X509_load_crl_file(ctx,file,type) | 196 | int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) |
212 | X509_LOOKUP *ctx; | ||
213 | char *file; | ||
214 | int type; | ||
215 | { | 197 | { |
216 | int ret=0; | 198 | int ret=0; |
217 | BIO *in=NULL; | 199 | BIO *in=NULL; |
@@ -231,7 +213,7 @@ int type; | |||
231 | { | 213 | { |
232 | for (;;) | 214 | for (;;) |
233 | { | 215 | { |
234 | x=PEM_read_bio_X509_CRL(in,NULL,NULL); | 216 | x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL); |
235 | if (x == NULL) | 217 | if (x == NULL) |
236 | { | 218 | { |
237 | if ((ERR_GET_REASON(ERR_peek_error()) == | 219 | if ((ERR_GET_REASON(ERR_peek_error()) == |
@@ -278,5 +260,39 @@ err: | |||
278 | return(ret); | 260 | return(ret); |
279 | } | 261 | } |
280 | 262 | ||
281 | #endif /* NO_STDIO */ | 263 | int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) |
264 | { | ||
265 | STACK_OF(X509_INFO) *inf; | ||
266 | X509_INFO *itmp; | ||
267 | BIO *in; | ||
268 | int i, count = 0; | ||
269 | if(type != X509_FILETYPE_PEM) | ||
270 | return X509_load_cert_file(ctx, file, type); | ||
271 | in = BIO_new_file(file, "r"); | ||
272 | if(!in) { | ||
273 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB); | ||
274 | return 0; | ||
275 | } | ||
276 | inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); | ||
277 | BIO_free(in); | ||
278 | if(!inf) { | ||
279 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); | ||
280 | return 0; | ||
281 | } | ||
282 | for(i = 0; i < sk_X509_INFO_num(inf); i++) { | ||
283 | itmp = sk_X509_INFO_value(inf, i); | ||
284 | if(itmp->x509) { | ||
285 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); | ||
286 | count++; | ||
287 | } else if(itmp->crl) { | ||
288 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); | ||
289 | count++; | ||
290 | } | ||
291 | } | ||
292 | sk_X509_INFO_pop_free(inf, X509_INFO_free); | ||
293 | return count; | ||
294 | } | ||
295 | |||
296 | |||
297 | #endif /* OPENSSL_NO_STDIO */ | ||
282 | 298 | ||