diff options
author | jsing <> | 2014-04-15 17:24:25 +0000 |
---|---|---|
committer | jsing <> | 2014-04-15 17:24:25 +0000 |
commit | efda9114d24acfc8cde043a206766226c8423d7a (patch) | |
tree | dae53bcdf3b21ee61081268fa287e81ea8dad726 /src | |
parent | 5e2db4ec770e5a5da3656f8278b74cca84f5e910 (diff) | |
download | openbsd-efda9114d24acfc8cde043a206766226c8423d7a.tar.gz openbsd-efda9114d24acfc8cde043a206766226c8423d7a.tar.bz2 openbsd-efda9114d24acfc8cde043a206766226c8423d7a.zip |
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using
tr and md5.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/x509/by_dir.c | 418 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/by_file.c | 272 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x_all.c | 749 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/by_dir.c | 418 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/by_file.c | 272 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x_all.c | 749 |
6 files changed, 1478 insertions, 1400 deletions
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c index f9d55c4e6d..b5512895a1 100644 --- a/src/lib/libcrypto/x509/by_dir.c +++ b/src/lib/libcrypto/x509/by_dir.c | |||
@@ -73,37 +73,34 @@ | |||
73 | #include <openssl/x509.h> | 73 | #include <openssl/x509.h> |
74 | 74 | ||
75 | 75 | ||
76 | typedef struct lookup_dir_hashes_st | 76 | typedef struct lookup_dir_hashes_st { |
77 | { | ||
78 | unsigned long hash; | 77 | unsigned long hash; |
79 | int suffix; | 78 | int suffix; |
80 | } BY_DIR_HASH; | 79 | } BY_DIR_HASH; |
81 | 80 | ||
82 | typedef struct lookup_dir_entry_st | 81 | typedef struct lookup_dir_entry_st { |
83 | { | ||
84 | char *dir; | 82 | char *dir; |
85 | int dir_type; | 83 | int dir_type; |
86 | STACK_OF(BY_DIR_HASH) *hashes; | 84 | STACK_OF(BY_DIR_HASH) *hashes; |
87 | } BY_DIR_ENTRY; | 85 | } BY_DIR_ENTRY; |
88 | 86 | ||
89 | typedef struct lookup_dir_st | 87 | typedef struct lookup_dir_st { |
90 | { | ||
91 | BUF_MEM *buffer; | 88 | BUF_MEM *buffer; |
92 | STACK_OF(BY_DIR_ENTRY) *dirs; | 89 | STACK_OF(BY_DIR_ENTRY) *dirs; |
93 | } BY_DIR; | 90 | } BY_DIR; |
94 | 91 | ||
95 | DECLARE_STACK_OF(BY_DIR_HASH) | 92 | DECLARE_STACK_OF(BY_DIR_HASH) |
96 | DECLARE_STACK_OF(BY_DIR_ENTRY) | 93 | DECLARE_STACK_OF(BY_DIR_ENTRY) |
97 | 94 | ||
98 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | 95 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
99 | char **ret); | 96 | char **ret); |
100 | static int new_dir(X509_LOOKUP *lu); | 97 | static int new_dir(X509_LOOKUP *lu); |
101 | static void free_dir(X509_LOOKUP *lu); | 98 | static void free_dir(X509_LOOKUP *lu); |
102 | static int add_cert_dir(BY_DIR *ctx,const char *dir,int type); | 99 | static int add_cert_dir(BY_DIR *ctx, const char *dir, int type); |
103 | static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, | 100 | static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, |
104 | X509_OBJECT *ret); | 101 | X509_OBJECT *ret); |
105 | X509_LOOKUP_METHOD x509_dir_lookup= | 102 | |
106 | { | 103 | X509_LOOKUP_METHOD x509_dir_lookup = { |
107 | "Load certs from files in a directory", | 104 | "Load certs from files in a directory", |
108 | new_dir, /* new */ | 105 | new_dir, /* new */ |
109 | free_dir, /* free */ | 106 | free_dir, /* free */ |
@@ -114,254 +111,237 @@ X509_LOOKUP_METHOD x509_dir_lookup= | |||
114 | NULL, /* get_by_issuer_serial */ | 111 | NULL, /* get_by_issuer_serial */ |
115 | NULL, /* get_by_fingerprint */ | 112 | NULL, /* get_by_fingerprint */ |
116 | NULL, /* get_by_alias */ | 113 | NULL, /* get_by_alias */ |
117 | }; | 114 | }; |
118 | 115 | ||
119 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void) | 116 | X509_LOOKUP_METHOD |
120 | { | 117 | *X509_LOOKUP_hash_dir(void) |
121 | return(&x509_dir_lookup); | 118 | { |
122 | } | 119 | return (&x509_dir_lookup); |
123 | 120 | } | |
124 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | 121 | |
125 | char **retp) | 122 | static int |
126 | { | 123 | dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
127 | int ret=0; | 124 | char **retp) |
125 | { | ||
126 | int ret = 0; | ||
128 | BY_DIR *ld; | 127 | BY_DIR *ld; |
129 | char *dir = NULL; | 128 | char *dir = NULL; |
130 | 129 | ||
131 | ld=(BY_DIR *)ctx->method_data; | 130 | ld = (BY_DIR *)ctx->method_data; |
132 | 131 | ||
133 | switch (cmd) | 132 | switch (cmd) { |
134 | { | ||
135 | case X509_L_ADD_DIR: | 133 | case X509_L_ADD_DIR: |
136 | if (argl == X509_FILETYPE_DEFAULT) | 134 | if (argl == X509_FILETYPE_DEFAULT) { |
137 | { | 135 | dir = (char *)getenv(X509_get_default_cert_dir_env()); |
138 | dir=(char *)getenv(X509_get_default_cert_dir_env()); | ||
139 | if (dir) | 136 | if (dir) |
140 | ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM); | 137 | ret = add_cert_dir(ld, dir, X509_FILETYPE_PEM); |
141 | else | 138 | else |
142 | ret=add_cert_dir(ld,X509_get_default_cert_dir(), | 139 | ret = add_cert_dir(ld, X509_get_default_cert_dir(), |
143 | X509_FILETYPE_PEM); | 140 | X509_FILETYPE_PEM); |
144 | if (!ret) | 141 | if (!ret) { |
145 | { | 142 | X509err(X509_F_DIR_CTRL, X509_R_LOADING_CERT_DIR); |
146 | X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR); | ||
147 | } | ||
148 | } | 143 | } |
149 | else | 144 | } else |
150 | ret=add_cert_dir(ld,argp,(int)argl); | 145 | ret = add_cert_dir(ld, argp,(int)argl); |
151 | break; | 146 | break; |
152 | } | ||
153 | return(ret); | ||
154 | } | 147 | } |
148 | return (ret); | ||
149 | } | ||
155 | 150 | ||
156 | static int new_dir(X509_LOOKUP *lu) | 151 | static int |
157 | { | 152 | new_dir(X509_LOOKUP *lu) |
153 | { | ||
158 | BY_DIR *a; | 154 | BY_DIR *a; |
159 | 155 | ||
160 | if ((a=(BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL) | 156 | if ((a = (BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL) |
161 | return(0); | 157 | return (0); |
162 | if ((a->buffer=BUF_MEM_new()) == NULL) | 158 | if ((a->buffer = BUF_MEM_new()) == NULL) { |
163 | { | ||
164 | OPENSSL_free(a); | 159 | OPENSSL_free(a); |
165 | return(0); | 160 | return (0); |
166 | } | ||
167 | a->dirs=NULL; | ||
168 | lu->method_data=(char *)a; | ||
169 | return(1); | ||
170 | } | 161 | } |
171 | 162 | a->dirs = NULL; | |
172 | static void by_dir_hash_free(BY_DIR_HASH *hash) | 163 | lu->method_data = (char *)a; |
173 | { | 164 | return (1); |
165 | } | ||
166 | |||
167 | static void | ||
168 | by_dir_hash_free(BY_DIR_HASH *hash) | ||
169 | { | ||
174 | OPENSSL_free(hash); | 170 | OPENSSL_free(hash); |
175 | } | 171 | } |
176 | 172 | ||
177 | static int by_dir_hash_cmp(const BY_DIR_HASH * const *a, | 173 | static int |
178 | const BY_DIR_HASH * const *b) | 174 | by_dir_hash_cmp(const BY_DIR_HASH * const *a, |
179 | { | 175 | const BY_DIR_HASH * const *b) |
176 | { | ||
180 | if ((*a)->hash > (*b)->hash) | 177 | if ((*a)->hash > (*b)->hash) |
181 | return 1; | 178 | return 1; |
182 | if ((*a)->hash < (*b)->hash) | 179 | if ((*a)->hash < (*b)->hash) |
183 | return -1; | 180 | return -1; |
184 | return 0; | 181 | return 0; |
185 | } | 182 | } |
186 | 183 | ||
187 | static void by_dir_entry_free(BY_DIR_ENTRY *ent) | 184 | static void |
188 | { | 185 | by_dir_entry_free(BY_DIR_ENTRY *ent) |
186 | { | ||
189 | if (ent->dir) | 187 | if (ent->dir) |
190 | OPENSSL_free(ent->dir); | 188 | OPENSSL_free(ent->dir); |
191 | if (ent->hashes) | 189 | if (ent->hashes) |
192 | sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); | 190 | sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); |
193 | OPENSSL_free(ent); | 191 | OPENSSL_free(ent); |
194 | } | 192 | } |
195 | 193 | ||
196 | static void free_dir(X509_LOOKUP *lu) | 194 | static void |
197 | { | 195 | free_dir(X509_LOOKUP *lu) |
196 | { | ||
198 | BY_DIR *a; | 197 | BY_DIR *a; |
199 | 198 | ||
200 | a=(BY_DIR *)lu->method_data; | 199 | a = (BY_DIR *)lu->method_data; |
201 | if (a->dirs != NULL) | 200 | if (a->dirs != NULL) |
202 | sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free); | 201 | sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free); |
203 | if (a->buffer != NULL) | 202 | if (a->buffer != NULL) |
204 | BUF_MEM_free(a->buffer); | 203 | BUF_MEM_free(a->buffer); |
205 | OPENSSL_free(a); | 204 | OPENSSL_free(a); |
205 | } | ||
206 | |||
207 | static int | ||
208 | add_cert_dir(BY_DIR *ctx, const char *dir, int type) | ||
209 | { | ||
210 | int j, len; | ||
211 | const char *s, *ss, *p; | ||
212 | |||
213 | if (dir == NULL || !*dir) { | ||
214 | X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY); | ||
215 | return 0; | ||
206 | } | 216 | } |
207 | 217 | ||
208 | static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) | 218 | s = dir; |
209 | { | 219 | p = s; |
210 | int j,len; | 220 | do { |
211 | const char *s,*ss,*p; | 221 | if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) { |
212 | |||
213 | if (dir == NULL || !*dir) | ||
214 | { | ||
215 | X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY); | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | s=dir; | ||
220 | p=s; | ||
221 | do | ||
222 | { | ||
223 | if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) | ||
224 | { | ||
225 | BY_DIR_ENTRY *ent; | 222 | BY_DIR_ENTRY *ent; |
226 | ss=s; | 223 | ss = s; |
227 | s=p+1; | 224 | s = p + 1; |
228 | len=(int)(p-ss); | 225 | len = (int)(p - ss); |
229 | if (len == 0) continue; | 226 | if (len == 0) |
230 | for (j=0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) | 227 | continue; |
231 | { | 228 | for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) { |
232 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j); | 229 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j); |
233 | if (strlen(ent->dir) == (size_t)len && | 230 | if (strlen(ent->dir) == (size_t)len && |
234 | strncmp(ent->dir,ss,(unsigned int)len) == 0) | 231 | strncmp(ent->dir, ss, |
232 | (unsigned int)len) == 0) | ||
235 | break; | 233 | break; |
236 | } | 234 | } |
237 | if (j < sk_BY_DIR_ENTRY_num(ctx->dirs)) | 235 | if (j < sk_BY_DIR_ENTRY_num(ctx->dirs)) |
238 | continue; | 236 | continue; |
239 | if (ctx->dirs == NULL) | 237 | if (ctx->dirs == NULL) { |
240 | { | ||
241 | ctx->dirs = sk_BY_DIR_ENTRY_new_null(); | 238 | ctx->dirs = sk_BY_DIR_ENTRY_new_null(); |
242 | if (!ctx->dirs) | 239 | if (!ctx->dirs) { |
243 | { | 240 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); |
244 | X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE); | ||
245 | return 0; | 241 | return 0; |
246 | } | ||
247 | } | 242 | } |
243 | } | ||
248 | ent = OPENSSL_malloc(sizeof(BY_DIR_ENTRY)); | 244 | ent = OPENSSL_malloc(sizeof(BY_DIR_ENTRY)); |
249 | if (!ent) | 245 | if (!ent) |
250 | return 0; | 246 | return 0; |
251 | ent->dir_type = type; | 247 | ent->dir_type = type; |
252 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); | 248 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); |
253 | ent->dir = OPENSSL_malloc((unsigned int)len+1); | 249 | ent->dir = OPENSSL_malloc((unsigned int)len + 1); |
254 | if (!ent->dir || !ent->hashes) | 250 | if (!ent->dir || !ent->hashes) { |
255 | { | ||
256 | by_dir_entry_free(ent); | 251 | by_dir_entry_free(ent); |
257 | return 0; | 252 | return 0; |
258 | } | 253 | } |
259 | strncpy(ent->dir,ss,(unsigned int)len); | 254 | strncpy(ent->dir, ss,(unsigned int)len); |
260 | ent->dir[len] = '\0'; | 255 | ent->dir[len] = '\0'; |
261 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) | 256 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { |
262 | { | ||
263 | by_dir_entry_free(ent); | 257 | by_dir_entry_free(ent); |
264 | return 0; | 258 | return 0; |
265 | } | ||
266 | } | 259 | } |
267 | } while (*p++ != '\0'); | 260 | } |
261 | } while (*p++ != '\0'); | ||
268 | return 1; | 262 | return 1; |
269 | } | 263 | } |
270 | 264 | ||
271 | static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | 265 | static int |
272 | X509_OBJECT *ret) | 266 | get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, |
273 | { | 267 | X509_OBJECT *ret) |
268 | { | ||
274 | BY_DIR *ctx; | 269 | BY_DIR *ctx; |
275 | union { | 270 | union { |
276 | struct { | 271 | struct { |
277 | X509 st_x509; | 272 | X509 st_x509; |
278 | X509_CINF st_x509_cinf; | 273 | X509_CINF st_x509_cinf; |
279 | } x509; | 274 | } x509; |
280 | struct { | 275 | struct { |
281 | X509_CRL st_crl; | 276 | X509_CRL st_crl; |
282 | X509_CRL_INFO st_crl_info; | 277 | X509_CRL_INFO st_crl_info; |
283 | } crl; | 278 | } crl; |
284 | } data; | 279 | } data; |
285 | int ok=0; | 280 | int ok = 0; |
286 | int i,j,k; | 281 | int i, j, k; |
287 | unsigned long h; | 282 | unsigned long h; |
288 | BUF_MEM *b=NULL; | 283 | BUF_MEM *b = NULL; |
289 | X509_OBJECT stmp,*tmp; | 284 | X509_OBJECT stmp, *tmp; |
290 | const char *postfix=""; | 285 | const char *postfix=""; |
291 | 286 | ||
292 | if (name == NULL) return(0); | 287 | if (name == NULL) |
288 | return (0); | ||
293 | 289 | ||
294 | stmp.type=type; | 290 | stmp.type = type; |
295 | if (type == X509_LU_X509) | 291 | if (type == X509_LU_X509) { |
296 | { | 292 | data.x509.st_x509.cert_info = &data.x509.st_x509_cinf; |
297 | data.x509.st_x509.cert_info= &data.x509.st_x509_cinf; | 293 | data.x509.st_x509_cinf.subject = name; |
298 | data.x509.st_x509_cinf.subject=name; | 294 | stmp.data.x509 = &data.x509.st_x509; |
299 | stmp.data.x509= &data.x509.st_x509; | ||
300 | postfix=""; | 295 | postfix=""; |
301 | } | 296 | } else if (type == X509_LU_CRL) { |
302 | else if (type == X509_LU_CRL) | 297 | data.crl.st_crl.crl = &data.crl.st_crl_info; |
303 | { | 298 | data.crl.st_crl_info.issuer = name; |
304 | data.crl.st_crl.crl= &data.crl.st_crl_info; | 299 | stmp.data.crl = &data.crl.st_crl; |
305 | data.crl.st_crl_info.issuer=name; | ||
306 | stmp.data.crl= &data.crl.st_crl; | ||
307 | postfix="r"; | 300 | postfix="r"; |
308 | } | 301 | } else { |
309 | else | 302 | X509err(X509_F_GET_CERT_BY_SUBJECT, X509_R_WRONG_LOOKUP_TYPE); |
310 | { | ||
311 | X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE); | ||
312 | goto finish; | 303 | goto finish; |
313 | } | 304 | } |
314 | 305 | ||
315 | if ((b=BUF_MEM_new()) == NULL) | 306 | if ((b = BUF_MEM_new()) == NULL) { |
316 | { | 307 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_BUF_LIB); |
317 | X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB); | ||
318 | goto finish; | 308 | goto finish; |
319 | } | 309 | } |
320 | 310 | ||
321 | ctx=(BY_DIR *)xl->method_data; | 311 | ctx = (BY_DIR *)xl->method_data; |
322 | 312 | ||
323 | h=X509_NAME_hash(name); | 313 | h = X509_NAME_hash(name); |
324 | for (i=0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++) | 314 | for (i = 0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++) { |
325 | { | ||
326 | BY_DIR_ENTRY *ent; | 315 | BY_DIR_ENTRY *ent; |
327 | int idx; | 316 | int idx; |
328 | BY_DIR_HASH htmp, *hent; | 317 | BY_DIR_HASH htmp, *hent; |
329 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i); | 318 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i); |
330 | j=strlen(ent->dir)+1+8+6+1+1; | 319 | j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1; |
331 | if (!BUF_MEM_grow(b,j)) | 320 | if (!BUF_MEM_grow(b, j)) { |
332 | { | 321 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); |
333 | X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE); | ||
334 | goto finish; | 322 | goto finish; |
335 | } | 323 | } |
336 | if (type == X509_LU_CRL && ent->hashes) | 324 | if (type == X509_LU_CRL && ent->hashes) { |
337 | { | ||
338 | htmp.hash = h; | 325 | htmp.hash = h; |
339 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); | 326 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); |
340 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); | 327 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); |
341 | if (idx >= 0) | 328 | if (idx >= 0) { |
342 | { | ||
343 | hent = sk_BY_DIR_HASH_value(ent->hashes, idx); | 329 | hent = sk_BY_DIR_HASH_value(ent->hashes, idx); |
344 | k = hent->suffix; | 330 | k = hent->suffix; |
345 | } | 331 | } else { |
346 | else | ||
347 | { | ||
348 | hent = NULL; | 332 | hent = NULL; |
349 | k=0; | 333 | k = 0; |
350 | } | ||
351 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); | ||
352 | } | 334 | } |
353 | else | 335 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); |
354 | { | 336 | } else { |
355 | k = 0; | 337 | k = 0; |
356 | hent = NULL; | 338 | hent = NULL; |
357 | } | 339 | } |
358 | for (;;) | 340 | for (;;) { |
359 | { | ||
360 | char c = '/'; | 341 | char c = '/'; |
361 | #ifdef OPENSSL_SYS_VMS | 342 | #ifdef OPENSSL_SYS_VMS |
362 | c = ent->dir[strlen(ent->dir)-1]; | 343 | c = ent->dir[strlen(ent->dir) - 1]; |
363 | if (c != ':' && c != '>' && c != ']') | 344 | if (c != ':' && c != '>' && c != ']') { |
364 | { | ||
365 | /* If no separator is present, we assume the | 345 | /* If no separator is present, we assume the |
366 | directory specifier is a logical name, and | 346 | directory specifier is a logical name, and |
367 | add a colon. We really should use better | 347 | add a colon. We really should use better |
@@ -369,112 +349,100 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | |||
369 | but this will do for now... | 349 | but this will do for now... |
370 | -- Richard Levitte */ | 350 | -- Richard Levitte */ |
371 | c = ':'; | 351 | c = ':'; |
372 | } | 352 | } else { |
373 | else | ||
374 | { | ||
375 | c = '\0'; | 353 | c = '\0'; |
376 | } | 354 | } |
377 | #endif | 355 | #endif |
378 | if (c == '\0') | 356 | if (c == '\0') { |
379 | { | ||
380 | /* This is special. When c == '\0', no | 357 | /* This is special. When c == '\0', no |
381 | directory separator should be added. */ | 358 | directory separator should be added. */ |
382 | (void) snprintf(b->data,b->max, | 359 | (void) snprintf(b->data, b->max, |
383 | "%s%08lx.%s%d",ent->dir,h, | 360 | "%s%08lx.%s%d", ent->dir, h, |
384 | postfix,k); | 361 | postfix, k); |
385 | } | 362 | } else { |
386 | else | 363 | (void) snprintf(b->data, b->max, |
387 | { | 364 | "%s%c%08lx.%s%d", ent->dir, c, h, |
388 | (void) snprintf(b->data,b->max, | 365 | postfix, k); |
389 | "%s%c%08lx.%s%d",ent->dir,c,h, | 366 | } |
390 | postfix,k); | ||
391 | } | ||
392 | #ifndef OPENSSL_NO_POSIX_IO | 367 | #ifndef OPENSSL_NO_POSIX_IO |
393 | #ifdef _WIN32 | 368 | #ifdef _WIN32 |
394 | #define stat _stat | 369 | #define stat _stat |
395 | #endif | 370 | #endif |
396 | { | 371 | { |
397 | struct stat st; | 372 | struct stat st; |
398 | if (stat(b->data,&st) < 0) | 373 | if (stat(b->data, &st) < 0) |
399 | break; | 374 | break; |
400 | } | 375 | } |
401 | #endif | 376 | #endif |
402 | /* found one. */ | 377 | /* found one. */ |
403 | if (type == X509_LU_X509) | 378 | if (type == X509_LU_X509) { |
404 | { | 379 | if ((X509_load_cert_file(xl, b->data, |
405 | if ((X509_load_cert_file(xl,b->data, | ||
406 | ent->dir_type)) == 0) | 380 | ent->dir_type)) == 0) |
407 | break; | 381 | break; |
408 | } | 382 | } else if (type == X509_LU_CRL) { |
409 | else if (type == X509_LU_CRL) | 383 | if ((X509_load_crl_file(xl, b->data, |
410 | { | ||
411 | if ((X509_load_crl_file(xl,b->data, | ||
412 | ent->dir_type)) == 0) | 384 | ent->dir_type)) == 0) |
413 | break; | 385 | break; |
414 | } | 386 | } |
415 | /* else case will caught higher up */ | 387 | /* else case will caught higher up */ |
416 | k++; | 388 | k++; |
417 | } | 389 | } |
418 | 390 | ||
419 | /* we have added it to the cache so now pull | 391 | /* we have added it to the cache so now pull |
420 | * it out again */ | 392 | * it out again */ |
421 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 393 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
422 | j = sk_X509_OBJECT_find(xl->store_ctx->objs,&stmp); | 394 | j = sk_X509_OBJECT_find(xl->store_ctx->objs, &stmp); |
423 | if(j != -1) tmp=sk_X509_OBJECT_value(xl->store_ctx->objs,j); | 395 | if (j != -1) |
424 | else tmp = NULL; | 396 | tmp = sk_X509_OBJECT_value(xl->store_ctx->objs, j); |
397 | else tmp = NULL; | ||
425 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 398 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
426 | 399 | ||
427 | 400 | ||
428 | /* If a CRL, update the last file suffix added for this */ | 401 | /* If a CRL, update the last file suffix added for this */ |
429 | 402 | ||
430 | if (type == X509_LU_CRL) | 403 | if (type == X509_LU_CRL) { |
431 | { | ||
432 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 404 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
433 | /* Look for entry again in case another thread added | 405 | /* Look for entry again in case another thread added |
434 | * an entry first. | 406 | * an entry first. |
435 | */ | 407 | */ |
436 | if (!hent) | 408 | if (!hent) { |
437 | { | ||
438 | htmp.hash = h; | 409 | htmp.hash = h; |
439 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); | 410 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); |
440 | if (idx >= 0) | 411 | if (idx >= 0) |
441 | hent = | 412 | hent = sk_BY_DIR_HASH_value( |
442 | sk_BY_DIR_HASH_value(ent->hashes, idx); | 413 | ent->hashes, idx); |
443 | } | 414 | } |
444 | if (!hent) | 415 | if (!hent) { |
445 | { | ||
446 | hent = OPENSSL_malloc(sizeof(BY_DIR_HASH)); | 416 | hent = OPENSSL_malloc(sizeof(BY_DIR_HASH)); |
447 | hent->hash = h; | 417 | hent->hash = h; |
448 | hent->suffix = k; | 418 | hent->suffix = k; |
449 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) | 419 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { |
450 | { | ||
451 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 420 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
452 | OPENSSL_free(hent); | 421 | OPENSSL_free(hent); |
453 | ok = 0; | 422 | ok = 0; |
454 | goto finish; | 423 | goto finish; |
455 | } | ||
456 | } | 424 | } |
457 | else if (hent->suffix < k) | 425 | } else if (hent->suffix < k) |
458 | hent->suffix = k; | 426 | hent->suffix = k; |
459 | 427 | ||
460 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 428 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
461 | 429 | ||
462 | } | 430 | } |
463 | 431 | ||
464 | if (tmp != NULL) | 432 | if (tmp != NULL) { |
465 | { | 433 | ok = 1; |
466 | ok=1; | 434 | ret->type = tmp->type; |
467 | ret->type=tmp->type; | 435 | memcpy(&ret->data, &tmp->data, sizeof(ret->data)); |
468 | memcpy(&ret->data,&tmp->data,sizeof(ret->data)); | ||
469 | /* If we were going to up the reference count, | 436 | /* If we were going to up the reference count, |
470 | * we would need to do it on a perl 'type' | 437 | * we would need to do it on a perl 'type' |
471 | * basis */ | 438 | * basis */ |
472 | /* CRYPTO_add(&tmp->data.x509->references,1, | 439 | /* CRYPTO_add(&tmp->data.x509->references,1, |
473 | CRYPTO_LOCK_X509);*/ | 440 | CRYPTO_LOCK_X509);*/ |
474 | goto finish; | 441 | goto finish; |
475 | } | ||
476 | } | 442 | } |
477 | finish: | ||
478 | if (b != NULL) BUF_MEM_free(b); | ||
479 | return(ok); | ||
480 | } | 443 | } |
444 | finish: | ||
445 | if (b != NULL) | ||
446 | BUF_MEM_free(b); | ||
447 | return (ok); | ||
448 | } | ||
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c index 57b08ee094..474d13bf0e 100644 --- a/src/lib/libcrypto/x509/by_file.c +++ b/src/lib/libcrypto/x509/by_file.c | |||
@@ -69,9 +69,9 @@ | |||
69 | #ifndef OPENSSL_NO_STDIO | 69 | #ifndef OPENSSL_NO_STDIO |
70 | 70 | ||
71 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, | 71 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, |
72 | long argl, char **ret); | 72 | long argl, char **ret); |
73 | X509_LOOKUP_METHOD x509_file_lookup= | 73 | |
74 | { | 74 | X509_LOOKUP_METHOD x509_file_lookup = { |
75 | "Load file into cache", | 75 | "Load file into cache", |
76 | NULL, /* new */ | 76 | NULL, /* new */ |
77 | NULL, /* free */ | 77 | NULL, /* free */ |
@@ -82,211 +82,199 @@ X509_LOOKUP_METHOD x509_file_lookup= | |||
82 | NULL, /* get_by_issuer_serial */ | 82 | NULL, /* get_by_issuer_serial */ |
83 | NULL, /* get_by_fingerprint */ | 83 | NULL, /* get_by_fingerprint */ |
84 | NULL, /* get_by_alias */ | 84 | NULL, /* get_by_alias */ |
85 | }; | 85 | }; |
86 | 86 | ||
87 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void) | 87 | X509_LOOKUP_METHOD |
88 | { | 88 | *X509_LOOKUP_file(void) |
89 | return(&x509_file_lookup); | 89 | { |
90 | } | 90 | return (&x509_file_lookup); |
91 | } | ||
91 | 92 | ||
92 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | 93 | static int |
93 | char **ret) | 94 | by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
94 | { | 95 | char **ret) |
95 | int ok=0; | 96 | { |
97 | int ok = 0; | ||
96 | char *file; | 98 | char *file; |
97 | 99 | ||
98 | switch (cmd) | 100 | switch (cmd) { |
99 | { | ||
100 | case X509_L_FILE_LOAD: | 101 | case X509_L_FILE_LOAD: |
101 | if (argl == X509_FILETYPE_DEFAULT) | 102 | if (argl == X509_FILETYPE_DEFAULT) { |
102 | { | ||
103 | file = (char *)getenv(X509_get_default_cert_file_env()); | 103 | file = (char *)getenv(X509_get_default_cert_file_env()); |
104 | if (file) | 104 | if (file) |
105 | ok = (X509_load_cert_crl_file(ctx,file, | 105 | ok = (X509_load_cert_crl_file(ctx, file, |
106 | X509_FILETYPE_PEM) != 0); | 106 | X509_FILETYPE_PEM) != 0); |
107 | |||
108 | else | 107 | else |
109 | ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(), | 108 | ok = (X509_load_cert_crl_file(ctx, |
110 | X509_FILETYPE_PEM) != 0); | 109 | X509_get_default_cert_file(), |
110 | X509_FILETYPE_PEM) != 0); | ||
111 | 111 | ||
112 | if (!ok) | 112 | if (!ok) { |
113 | { | 113 | X509err(X509_F_BY_FILE_CTRL, |
114 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); | 114 | X509_R_LOADING_DEFAULTS); |
115 | } | ||
116 | } | 115 | } |
117 | else | 116 | } else { |
118 | { | 117 | if (argl == X509_FILETYPE_PEM) |
119 | if(argl == X509_FILETYPE_PEM) | 118 | ok = (X509_load_cert_crl_file(ctx, argp, |
120 | ok = (X509_load_cert_crl_file(ctx,argp, | 119 | X509_FILETYPE_PEM) != 0); |
121 | X509_FILETYPE_PEM) != 0); | ||
122 | else | 120 | else |
123 | ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0); | 121 | ok = (X509_load_cert_file(ctx, |
124 | } | 122 | argp,(int)argl) != 0); |
125 | break; | ||
126 | } | 123 | } |
127 | return(ok); | 124 | break; |
128 | } | 125 | } |
126 | return (ok); | ||
127 | } | ||
129 | 128 | ||
130 | int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) | 129 | int |
131 | { | 130 | X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) |
132 | int ret=0; | 131 | { |
133 | BIO *in=NULL; | 132 | int ret = 0; |
134 | int i,count=0; | 133 | BIO *in = NULL; |
135 | X509 *x=NULL; | 134 | int i, count = 0; |
135 | X509 *x = NULL; | ||
136 | 136 | ||
137 | if (file == NULL) return(1); | 137 | if (file == NULL) |
138 | in=BIO_new(BIO_s_file_internal()); | 138 | return (1); |
139 | in = BIO_new(BIO_s_file_internal()); | ||
139 | 140 | ||
140 | if ((in == NULL) || (BIO_read_filename(in,file) <= 0)) | 141 | if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { |
141 | { | 142 | X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_SYS_LIB); |
142 | X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB); | ||
143 | goto err; | 143 | goto err; |
144 | } | 144 | } |
145 | 145 | ||
146 | if (type == X509_FILETYPE_PEM) | 146 | if (type == X509_FILETYPE_PEM) { |
147 | { | 147 | for (;;) { |
148 | for (;;) | 148 | x = PEM_read_bio_X509_AUX(in, NULL, NULL, NULL); |
149 | { | 149 | if (x == NULL) { |
150 | x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL); | ||
151 | if (x == NULL) | ||
152 | { | ||
153 | if ((ERR_GET_REASON(ERR_peek_last_error()) == | 150 | if ((ERR_GET_REASON(ERR_peek_last_error()) == |
154 | PEM_R_NO_START_LINE) && (count > 0)) | 151 | PEM_R_NO_START_LINE) && (count > 0)) { |
155 | { | ||
156 | ERR_clear_error(); | 152 | ERR_clear_error(); |
157 | break; | 153 | break; |
158 | } | 154 | } else { |
159 | else | ||
160 | { | ||
161 | X509err(X509_F_X509_LOAD_CERT_FILE, | 155 | X509err(X509_F_X509_LOAD_CERT_FILE, |
162 | ERR_R_PEM_LIB); | 156 | ERR_R_PEM_LIB); |
163 | goto err; | 157 | goto err; |
164 | } | ||
165 | } | 158 | } |
166 | i=X509_STORE_add_cert(ctx->store_ctx,x); | 159 | } |
167 | if (!i) goto err; | 160 | i = X509_STORE_add_cert(ctx->store_ctx, x); |
161 | if (!i) | ||
162 | goto err; | ||
168 | count++; | 163 | count++; |
169 | X509_free(x); | 164 | X509_free(x); |
170 | x=NULL; | 165 | x = NULL; |
171 | } | ||
172 | ret=count; | ||
173 | } | 166 | } |
174 | else if (type == X509_FILETYPE_ASN1) | 167 | ret = count; |
175 | { | 168 | } else if (type == X509_FILETYPE_ASN1) { |
176 | x=d2i_X509_bio(in,NULL); | 169 | x = d2i_X509_bio(in, NULL); |
177 | if (x == NULL) | 170 | if (x == NULL) { |
178 | { | 171 | X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_ASN1_LIB); |
179 | X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB); | ||
180 | goto err; | 172 | goto err; |
181 | } | ||
182 | i=X509_STORE_add_cert(ctx->store_ctx,x); | ||
183 | if (!i) goto err; | ||
184 | ret=i; | ||
185 | } | 173 | } |
186 | else | 174 | i = X509_STORE_add_cert(ctx->store_ctx, x); |
187 | { | 175 | if (!i) |
188 | X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE); | 176 | goto err; |
177 | ret = i; | ||
178 | } else { | ||
179 | X509err(X509_F_X509_LOAD_CERT_FILE, X509_R_BAD_X509_FILETYPE); | ||
189 | goto err; | 180 | goto err; |
190 | } | ||
191 | err: | ||
192 | if (x != NULL) X509_free(x); | ||
193 | if (in != NULL) BIO_free(in); | ||
194 | return(ret); | ||
195 | } | 181 | } |
182 | err: | ||
183 | if (x != NULL) | ||
184 | X509_free(x); | ||
185 | if (in != NULL) | ||
186 | BIO_free(in); | ||
187 | return (ret); | ||
188 | } | ||
196 | 189 | ||
197 | int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) | 190 | int |
198 | { | 191 | X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) |
199 | int ret=0; | 192 | { |
200 | BIO *in=NULL; | 193 | int ret = 0; |
201 | int i,count=0; | 194 | BIO *in = NULL; |
202 | X509_CRL *x=NULL; | 195 | int i, count = 0; |
196 | X509_CRL *x = NULL; | ||
203 | 197 | ||
204 | if (file == NULL) return(1); | 198 | if (file == NULL) |
205 | in=BIO_new(BIO_s_file_internal()); | 199 | return (1); |
200 | in = BIO_new(BIO_s_file_internal()); | ||
206 | 201 | ||
207 | if ((in == NULL) || (BIO_read_filename(in,file) <= 0)) | 202 | if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { |
208 | { | 203 | X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB); |
209 | X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB); | ||
210 | goto err; | 204 | goto err; |
211 | } | 205 | } |
212 | 206 | ||
213 | if (type == X509_FILETYPE_PEM) | 207 | if (type == X509_FILETYPE_PEM) { |
214 | { | 208 | for (;;) { |
215 | for (;;) | 209 | x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); |
216 | { | 210 | if (x == NULL) { |
217 | x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL); | ||
218 | if (x == NULL) | ||
219 | { | ||
220 | if ((ERR_GET_REASON(ERR_peek_last_error()) == | 211 | if ((ERR_GET_REASON(ERR_peek_last_error()) == |
221 | PEM_R_NO_START_LINE) && (count > 0)) | 212 | PEM_R_NO_START_LINE) && (count > 0)) { |
222 | { | ||
223 | ERR_clear_error(); | 213 | ERR_clear_error(); |
224 | break; | 214 | break; |
225 | } | 215 | } else { |
226 | else | ||
227 | { | ||
228 | X509err(X509_F_X509_LOAD_CRL_FILE, | 216 | X509err(X509_F_X509_LOAD_CRL_FILE, |
229 | ERR_R_PEM_LIB); | 217 | ERR_R_PEM_LIB); |
230 | goto err; | 218 | goto err; |
231 | } | ||
232 | } | 219 | } |
233 | i=X509_STORE_add_crl(ctx->store_ctx,x); | 220 | } |
234 | if (!i) goto err; | 221 | i = X509_STORE_add_crl(ctx->store_ctx, x); |
222 | if (!i) | ||
223 | goto err; | ||
235 | count++; | 224 | count++; |
236 | X509_CRL_free(x); | 225 | X509_CRL_free(x); |
237 | x=NULL; | 226 | x = NULL; |
238 | } | ||
239 | ret=count; | ||
240 | } | 227 | } |
241 | else if (type == X509_FILETYPE_ASN1) | 228 | ret = count; |
242 | { | 229 | } else if (type == X509_FILETYPE_ASN1) { |
243 | x=d2i_X509_CRL_bio(in,NULL); | 230 | x = d2i_X509_CRL_bio(in, NULL); |
244 | if (x == NULL) | 231 | if (x == NULL) { |
245 | { | 232 | X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB); |
246 | X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB); | ||
247 | goto err; | 233 | goto err; |
248 | } | ||
249 | i=X509_STORE_add_crl(ctx->store_ctx,x); | ||
250 | if (!i) goto err; | ||
251 | ret=i; | ||
252 | } | 234 | } |
253 | else | 235 | i = X509_STORE_add_crl(ctx->store_ctx, x); |
254 | { | 236 | if (!i) |
255 | X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE); | 237 | goto err; |
238 | ret = i; | ||
239 | } else { | ||
240 | X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE); | ||
256 | goto err; | 241 | goto err; |
257 | } | ||
258 | err: | ||
259 | if (x != NULL) X509_CRL_free(x); | ||
260 | if (in != NULL) BIO_free(in); | ||
261 | return(ret); | ||
262 | } | 242 | } |
243 | err: | ||
244 | if (x != NULL) | ||
245 | X509_CRL_free(x); | ||
246 | if (in != NULL) | ||
247 | BIO_free(in); | ||
248 | return (ret); | ||
249 | } | ||
263 | 250 | ||
264 | int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | 251 | int |
252 | X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | ||
265 | { | 253 | { |
266 | STACK_OF(X509_INFO) *inf; | 254 | STACK_OF(X509_INFO) *inf; |
267 | X509_INFO *itmp; | 255 | X509_INFO *itmp; |
268 | BIO *in; | 256 | BIO *in; |
269 | int i, count = 0; | 257 | int i, count = 0; |
270 | if(type != X509_FILETYPE_PEM) | 258 | if (type != X509_FILETYPE_PEM) |
271 | return X509_load_cert_file(ctx, file, type); | 259 | return X509_load_cert_file(ctx, file, type); |
272 | in = BIO_new_file(file, "r"); | 260 | in = BIO_new_file(file, "r"); |
273 | if(!in) { | 261 | if (!in) { |
274 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB); | 262 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_SYS_LIB); |
275 | return 0; | 263 | return 0; |
276 | } | 264 | } |
277 | inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); | 265 | inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); |
278 | BIO_free(in); | 266 | BIO_free(in); |
279 | if(!inf) { | 267 | if (!inf) { |
280 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); | 268 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB); |
281 | return 0; | 269 | return 0; |
282 | } | 270 | } |
283 | for(i = 0; i < sk_X509_INFO_num(inf); i++) { | 271 | for (i = 0; i < sk_X509_INFO_num(inf); i++) { |
284 | itmp = sk_X509_INFO_value(inf, i); | 272 | itmp = sk_X509_INFO_value(inf, i); |
285 | if(itmp->x509) { | 273 | if (itmp->x509) { |
286 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); | 274 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); |
287 | count++; | 275 | count++; |
288 | } | 276 | } |
289 | if(itmp->crl) { | 277 | if (itmp->crl) { |
290 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); | 278 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); |
291 | count++; | 279 | count++; |
292 | } | 280 | } |
@@ -295,6 +283,4 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | |||
295 | return count; | 283 | return count; |
296 | } | 284 | } |
297 | 285 | ||
298 | |||
299 | #endif /* OPENSSL_NO_STDIO */ | 286 | #endif /* OPENSSL_NO_STDIO */ |
300 | |||
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c index e06602d65a..59099f026f 100644 --- a/src/lib/libcrypto/x509/x_all.c +++ b/src/lib/libcrypto/x509/x_all.c | |||
@@ -70,468 +70,553 @@ | |||
70 | #include <openssl/dsa.h> | 70 | #include <openssl/dsa.h> |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | int X509_verify(X509 *a, EVP_PKEY *r) | 73 | int |
74 | { | 74 | X509_verify(X509 *a, EVP_PKEY *r) |
75 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg, | 75 | { |
76 | a->signature,a->cert_info,r)); | 76 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), a->sig_alg, |
77 | } | 77 | a->signature, a->cert_info, r)); |
78 | 78 | } | |
79 | int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) | 79 | |
80 | { | 80 | int |
81 | X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) | ||
82 | { | ||
81 | return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), | 83 | return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), |
82 | a->sig_alg,a->signature,a->req_info,r)); | 84 | a->sig_alg, a->signature, a->req_info, r)); |
83 | } | 85 | } |
84 | 86 | ||
85 | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) | 87 | int |
86 | { | 88 | NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) |
89 | { | ||
87 | return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), | 90 | return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), |
88 | a->sig_algor,a->signature,a->spkac,r)); | 91 | a->sig_algor, a->signature, a->spkac, r)); |
89 | } | 92 | } |
90 | 93 | ||
91 | int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) | 94 | int |
92 | { | 95 | X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) |
96 | { | ||
93 | x->cert_info->enc.modified = 1; | 97 | x->cert_info->enc.modified = 1; |
94 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature, | 98 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), |
95 | x->sig_alg, x->signature, x->cert_info,pkey,md)); | 99 | x->cert_info->signature, x->sig_alg, x->signature, |
96 | } | 100 | x->cert_info, pkey, md)); |
101 | } | ||
97 | 102 | ||
98 | int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) | 103 | int |
99 | { | 104 | X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) |
105 | { | ||
100 | x->cert_info->enc.modified = 1; | 106 | x->cert_info->enc.modified = 1; |
101 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), | 107 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), |
102 | x->cert_info->signature, | 108 | x->cert_info->signature, x->sig_alg, x->signature, |
103 | x->sig_alg, x->signature, x->cert_info, ctx); | 109 | x->cert_info, ctx); |
104 | } | 110 | } |
105 | 111 | ||
106 | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) | 112 | int |
107 | { | 113 | X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) |
108 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO),x->sig_alg, NULL, | 114 | { |
109 | x->signature, x->req_info,pkey,md)); | 115 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO), |
110 | } | 116 | x->sig_alg, NULL, x->signature, x->req_info, pkey, md)); |
111 | 117 | } | |
112 | int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) | 118 | |
113 | { | 119 | int |
120 | X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) | ||
121 | { | ||
114 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), | 122 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), |
115 | x->sig_alg, NULL, x->signature, x->req_info, ctx); | 123 | x->sig_alg, NULL, x->signature, x->req_info, ctx); |
116 | } | 124 | } |
117 | 125 | ||
118 | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) | 126 | int |
119 | { | 127 | X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) |
128 | { | ||
120 | x->crl->enc.modified = 1; | 129 | x->crl->enc.modified = 1; |
121 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO),x->crl->sig_alg, | 130 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO), x->crl->sig_alg, |
122 | x->sig_alg, x->signature, x->crl,pkey,md)); | 131 | x->sig_alg, x->signature, x->crl, pkey, md)); |
123 | } | 132 | } |
124 | 133 | ||
125 | int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) | 134 | int |
126 | { | 135 | X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) |
136 | { | ||
127 | x->crl->enc.modified = 1; | 137 | x->crl->enc.modified = 1; |
128 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), | 138 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), |
129 | x->crl->sig_alg, x->sig_alg, x->signature, x->crl, ctx); | 139 | x->crl->sig_alg, x->sig_alg, x->signature, x->crl, ctx); |
130 | } | 140 | } |
131 | 141 | ||
132 | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) | 142 | int |
133 | { | 143 | NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) |
134 | return(ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,NULL, | 144 | { |
135 | x->signature, x->spkac,pkey,md)); | 145 | return (ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), |
136 | } | 146 | x->sig_algor, NULL, x->signature, x->spkac, pkey, md)); |
147 | } | ||
137 | 148 | ||
138 | #ifndef OPENSSL_NO_FP_API | 149 | #ifndef OPENSSL_NO_FP_API |
139 | X509 *d2i_X509_fp(FILE *fp, X509 **x509) | 150 | X509 |
140 | { | 151 | *d2i_X509_fp(FILE *fp, X509 **x509) |
152 | { | ||
141 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); | 153 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); |
142 | } | 154 | } |
143 | 155 | ||
144 | int i2d_X509_fp(FILE *fp, X509 *x509) | 156 | int |
145 | { | 157 | i2d_X509_fp(FILE *fp, X509 *x509) |
158 | { | ||
146 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); | 159 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); |
147 | } | 160 | } |
148 | #endif | 161 | #endif |
149 | 162 | ||
150 | X509 *d2i_X509_bio(BIO *bp, X509 **x509) | 163 | X509 |
151 | { | 164 | *d2i_X509_bio(BIO *bp, X509 **x509) |
165 | { | ||
152 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); | 166 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); |
153 | } | 167 | } |
154 | 168 | ||
155 | int i2d_X509_bio(BIO *bp, X509 *x509) | 169 | int |
156 | { | 170 | i2d_X509_bio(BIO *bp, X509 *x509) |
171 | { | ||
157 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); | 172 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); |
158 | } | 173 | } |
159 | 174 | ||
160 | #ifndef OPENSSL_NO_FP_API | 175 | #ifndef OPENSSL_NO_FP_API |
161 | X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) | 176 | X509_CRL |
162 | { | 177 | *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) |
178 | { | ||
163 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); | 179 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
164 | } | 180 | } |
165 | 181 | ||
166 | int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) | 182 | int |
167 | { | 183 | i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) |
184 | { | ||
168 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); | 185 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
169 | } | 186 | } |
170 | #endif | 187 | #endif |
171 | 188 | ||
172 | X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) | 189 | X509_CRL |
173 | { | 190 | *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) |
191 | { | ||
174 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); | 192 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
175 | } | 193 | } |
176 | 194 | ||
177 | int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) | 195 | int |
178 | { | 196 | i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) |
197 | { | ||
179 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); | 198 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
180 | } | 199 | } |
181 | 200 | ||
182 | #ifndef OPENSSL_NO_FP_API | 201 | #ifndef OPENSSL_NO_FP_API |
183 | PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) | 202 | PKCS7 |
184 | { | 203 | *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) |
204 | { | ||
185 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); | 205 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
186 | } | 206 | } |
187 | 207 | ||
188 | int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) | 208 | int |
189 | { | 209 | i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) |
210 | { | ||
190 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); | 211 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
191 | } | 212 | } |
192 | #endif | 213 | #endif |
193 | 214 | ||
194 | PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) | 215 | PKCS7 |
195 | { | 216 | *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) |
217 | { | ||
196 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); | 218 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
197 | } | 219 | } |
198 | 220 | ||
199 | int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) | 221 | int |
200 | { | 222 | i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) |
223 | { | ||
201 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); | 224 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
202 | } | 225 | } |
203 | 226 | ||
204 | #ifndef OPENSSL_NO_FP_API | 227 | #ifndef OPENSSL_NO_FP_API |
205 | X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) | 228 | X509_REQ |
206 | { | 229 | *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) |
230 | { | ||
207 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); | 231 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
208 | } | 232 | } |
209 | 233 | ||
210 | int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) | 234 | int |
211 | { | 235 | i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) |
236 | { | ||
212 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); | 237 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
213 | } | 238 | } |
214 | #endif | 239 | #endif |
215 | 240 | ||
216 | X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) | 241 | X509_REQ |
217 | { | 242 | *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) |
243 | { | ||
218 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); | 244 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
219 | } | 245 | } |
220 | 246 | ||
221 | int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) | 247 | int |
222 | { | 248 | i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) |
249 | { | ||
223 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); | 250 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
224 | } | 251 | } |
225 | 252 | ||
226 | #ifndef OPENSSL_NO_RSA | 253 | #ifndef OPENSSL_NO_RSA |
227 | 254 | ||
228 | #ifndef OPENSSL_NO_FP_API | 255 | #ifndef OPENSSL_NO_FP_API |
229 | RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) | 256 | RSA |
230 | { | 257 | *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) |
258 | { | ||
231 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); | 259 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
232 | } | 260 | } |
233 | 261 | ||
234 | int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) | 262 | int |
235 | { | 263 | i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) |
264 | { | ||
236 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); | 265 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
237 | } | 266 | } |
238 | 267 | ||
239 | RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) | 268 | RSA |
240 | { | 269 | *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) |
270 | { | ||
241 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); | 271 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
242 | } | 272 | } |
243 | 273 | ||
244 | 274 | ||
245 | RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) | 275 | RSA |
246 | { | 276 | *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) |
247 | return ASN1_d2i_fp((void *(*)(void)) | 277 | { |
248 | RSA_new,(D2I_OF(void))d2i_RSA_PUBKEY, fp, | 278 | return ASN1_d2i_fp((void *(*)(void))RSA_new, |
249 | (void **)rsa); | 279 | (D2I_OF(void))d2i_RSA_PUBKEY, fp, (void **)rsa); |
250 | } | 280 | } |
251 | 281 | ||
252 | int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) | 282 | int |
253 | { | 283 | i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) |
284 | { | ||
254 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); | 285 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
255 | } | 286 | } |
256 | 287 | ||
257 | int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) | 288 | int |
258 | { | 289 | i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) |
259 | return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY,fp,rsa); | 290 | { |
260 | } | 291 | return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY, fp, rsa); |
292 | } | ||
261 | #endif | 293 | #endif |
262 | 294 | ||
263 | RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) | 295 | RSA |
264 | { | 296 | *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) |
297 | { | ||
265 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); | 298 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
266 | } | 299 | } |
267 | 300 | ||
268 | int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) | 301 | int |
269 | { | 302 | i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) |
303 | { | ||
270 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); | 304 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
271 | } | 305 | } |
272 | 306 | ||
273 | RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) | 307 | RSA |
274 | { | 308 | *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) |
309 | { | ||
275 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); | 310 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
276 | } | 311 | } |
277 | 312 | ||
278 | 313 | ||
279 | RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) | 314 | RSA |
280 | { | 315 | *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) |
281 | return ASN1_d2i_bio_of(RSA,RSA_new,d2i_RSA_PUBKEY,bp,rsa); | 316 | { |
282 | } | 317 | return ASN1_d2i_bio_of(RSA, RSA_new, d2i_RSA_PUBKEY, bp, rsa); |
318 | } | ||
283 | 319 | ||
284 | int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) | 320 | int |
285 | { | 321 | i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) |
322 | { | ||
286 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); | 323 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
287 | } | 324 | } |
288 | 325 | ||
289 | int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) | 326 | int |
290 | { | 327 | i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) |
291 | return ASN1_i2d_bio_of(RSA,i2d_RSA_PUBKEY,bp,rsa); | 328 | { |
292 | } | 329 | return ASN1_i2d_bio_of(RSA, i2d_RSA_PUBKEY, bp, rsa); |
330 | } | ||
293 | #endif | 331 | #endif |
294 | 332 | ||
295 | #ifndef OPENSSL_NO_DSA | 333 | #ifndef OPENSSL_NO_DSA |
296 | #ifndef OPENSSL_NO_FP_API | 334 | #ifndef OPENSSL_NO_FP_API |
297 | DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) | 335 | DSA |
298 | { | 336 | *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) |
299 | return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSAPrivateKey,fp,dsa); | 337 | { |
300 | } | 338 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSAPrivateKey, fp, dsa); |
301 | 339 | } | |
302 | int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) | 340 | |
303 | { | 341 | int |
304 | return ASN1_i2d_fp_of_const(DSA,i2d_DSAPrivateKey,fp,dsa); | 342 | i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) |
305 | } | 343 | { |
306 | 344 | return ASN1_i2d_fp_of_const(DSA, i2d_DSAPrivateKey, fp, dsa); | |
307 | DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) | 345 | } |
308 | { | 346 | |
309 | return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSA_PUBKEY,fp,dsa); | 347 | DSA |
310 | } | 348 | *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) |
311 | 349 | { | |
312 | int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) | 350 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSA_PUBKEY, fp, dsa); |
313 | { | 351 | } |
314 | return ASN1_i2d_fp_of(DSA,i2d_DSA_PUBKEY,fp,dsa); | 352 | |
315 | } | 353 | int |
354 | i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) | ||
355 | { | ||
356 | return ASN1_i2d_fp_of(DSA, i2d_DSA_PUBKEY, fp, dsa); | ||
357 | } | ||
316 | #endif | 358 | #endif |
317 | 359 | ||
318 | DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) | 360 | DSA |
319 | { | 361 | *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) |
320 | return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAPrivateKey,bp,dsa | 362 | { |
321 | ); | 363 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSAPrivateKey, bp, dsa); |
322 | } | 364 | } |
323 | 365 | ||
324 | int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) | 366 | int |
325 | { | 367 | i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) |
326 | return ASN1_i2d_bio_of_const(DSA,i2d_DSAPrivateKey,bp,dsa); | 368 | { |
327 | } | 369 | return ASN1_i2d_bio_of_const(DSA, i2d_DSAPrivateKey, bp, dsa); |
370 | } | ||
328 | 371 | ||
329 | DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) | 372 | DSA |
330 | { | 373 | *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) |
331 | return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSA_PUBKEY,bp,dsa); | 374 | { |
332 | } | 375 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSA_PUBKEY, bp, dsa); |
376 | } | ||
333 | 377 | ||
334 | int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) | 378 | int |
335 | { | 379 | i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) |
336 | return ASN1_i2d_bio_of(DSA,i2d_DSA_PUBKEY,bp,dsa); | 380 | { |
337 | } | 381 | return ASN1_i2d_bio_of(DSA, i2d_DSA_PUBKEY, bp, dsa); |
382 | } | ||
338 | 383 | ||
339 | #endif | 384 | #endif |
340 | 385 | ||
341 | #ifndef OPENSSL_NO_EC | 386 | #ifndef OPENSSL_NO_EC |
342 | #ifndef OPENSSL_NO_FP_API | 387 | #ifndef OPENSSL_NO_FP_API |
343 | EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey) | 388 | EC_KEY |
344 | { | 389 | *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey) |
345 | return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,fp,eckey); | 390 | { |
346 | } | 391 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, fp, eckey); |
347 | 392 | } | |
348 | int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey) | 393 | |
349 | { | 394 | int |
350 | return ASN1_i2d_fp_of(EC_KEY,i2d_EC_PUBKEY,fp,eckey); | 395 | i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey) |
351 | } | 396 | { |
352 | 397 | return ASN1_i2d_fp_of(EC_KEY, i2d_EC_PUBKEY, fp, eckey); | |
353 | EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey) | 398 | } |
354 | { | 399 | |
355 | return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,fp,eckey); | 400 | EC_KEY |
356 | } | 401 | *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey) |
357 | 402 | { | |
358 | int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey) | 403 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, fp, eckey); |
359 | { | 404 | } |
360 | return ASN1_i2d_fp_of(EC_KEY,i2d_ECPrivateKey,fp,eckey); | 405 | |
361 | } | 406 | int |
407 | i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey) | ||
408 | { | ||
409 | return ASN1_i2d_fp_of(EC_KEY, i2d_ECPrivateKey, fp, eckey); | ||
410 | } | ||
362 | #endif | 411 | #endif |
363 | EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey) | 412 | EC_KEY |
364 | { | 413 | *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey) |
365 | return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,bp,eckey); | 414 | { |
366 | } | 415 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, bp, eckey); |
367 | 416 | } | |
368 | int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa) | 417 | |
369 | { | 418 | int |
370 | return ASN1_i2d_bio_of(EC_KEY,i2d_EC_PUBKEY,bp,ecdsa); | 419 | i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa) |
371 | } | 420 | { |
372 | 421 | return ASN1_i2d_bio_of(EC_KEY, i2d_EC_PUBKEY, bp, ecdsa); | |
373 | EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey) | 422 | } |
374 | { | 423 | |
375 | return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,bp,eckey); | 424 | EC_KEY |
376 | } | 425 | *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey) |
377 | 426 | { | |
378 | int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey) | 427 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, bp, eckey); |
379 | { | 428 | } |
380 | return ASN1_i2d_bio_of(EC_KEY,i2d_ECPrivateKey,bp,eckey); | 429 | |
381 | } | 430 | int |
431 | i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey) | ||
432 | { | ||
433 | return ASN1_i2d_bio_of(EC_KEY, i2d_ECPrivateKey, bp, eckey); | ||
434 | } | ||
382 | #endif | 435 | #endif |
383 | 436 | ||
384 | 437 | ||
385 | int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, | 438 | int |
386 | unsigned int *len) | 439 | X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
387 | { | 440 | unsigned int *len) |
441 | { | ||
388 | ASN1_BIT_STRING *key; | 442 | ASN1_BIT_STRING *key; |
389 | key = X509_get0_pubkey_bitstr(data); | 443 | key = X509_get0_pubkey_bitstr(data); |
390 | if(!key) return 0; | 444 | if (!key) |
445 | return 0; | ||
391 | return EVP_Digest(key->data, key->length, md, len, type, NULL); | 446 | return EVP_Digest(key->data, key->length, md, len, type, NULL); |
392 | } | 447 | } |
393 | 448 | ||
394 | int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, | 449 | int |
395 | unsigned int *len) | 450 | X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
396 | { | 451 | unsigned int *len) |
397 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509),type,(char *)data,md,len)); | 452 | { |
398 | } | 453 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509), type, (char *)data, |
399 | 454 | md, len)); | |
400 | int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, | 455 | } |
401 | unsigned int *len) | 456 | |
402 | { | 457 | int |
403 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL),type,(char *)data,md,len)); | 458 | X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, |
404 | } | 459 | unsigned int *len) |
405 | 460 | { | |
406 | int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, | 461 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, |
407 | unsigned int *len) | 462 | md, len)); |
408 | { | 463 | } |
409 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ),type,(char *)data,md,len)); | 464 | |
410 | } | 465 | int |
411 | 466 | X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, | |
412 | int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, | 467 | unsigned int *len) |
413 | unsigned int *len) | 468 | { |
414 | { | 469 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ), type,(char *)data, |
415 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME),type,(char *)data,md,len)); | 470 | md, len)); |
416 | } | 471 | } |
417 | 472 | ||
418 | int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type, | 473 | int |
419 | unsigned char *md, unsigned int *len) | 474 | X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, |
420 | { | 475 | unsigned int *len) |
421 | return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL),type, | 476 | { |
422 | (char *)data,md,len)); | 477 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME), type,(char *)data, |
423 | } | 478 | md, len)); |
479 | } | ||
480 | |||
481 | int | ||
482 | PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, | ||
483 | const EVP_MD *type, unsigned char *md, unsigned int *len) | ||
484 | { | ||
485 | return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL), type, | ||
486 | (char *)data, md, len)); | ||
487 | } | ||
424 | 488 | ||
425 | 489 | ||
426 | #ifndef OPENSSL_NO_FP_API | 490 | #ifndef OPENSSL_NO_FP_API |
427 | X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) | 491 | X509_SIG |
428 | { | 492 | *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) |
429 | return ASN1_d2i_fp_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,fp,p8); | 493 | { |
430 | } | 494 | return ASN1_d2i_fp_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, fp, p8); |
431 | 495 | } | |
432 | int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) | 496 | |
433 | { | 497 | int |
434 | return ASN1_i2d_fp_of(X509_SIG,i2d_X509_SIG,fp,p8); | 498 | i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) |
435 | } | 499 | { |
500 | return ASN1_i2d_fp_of(X509_SIG, i2d_X509_SIG, fp, p8); | ||
501 | } | ||
436 | #endif | 502 | #endif |
437 | 503 | ||
438 | X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) | 504 | X509_SIG |
439 | { | 505 | *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) |
440 | return ASN1_d2i_bio_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,bp,p8); | 506 | { |
441 | } | 507 | return ASN1_d2i_bio_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, bp, p8); |
508 | } | ||
442 | 509 | ||
443 | int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) | 510 | int |
444 | { | 511 | i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) |
445 | return ASN1_i2d_bio_of(X509_SIG,i2d_X509_SIG,bp,p8); | 512 | { |
446 | } | 513 | return ASN1_i2d_bio_of(X509_SIG, i2d_X509_SIG, bp, p8); |
514 | } | ||
447 | 515 | ||
448 | #ifndef OPENSSL_NO_FP_API | 516 | #ifndef OPENSSL_NO_FP_API |
449 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, | 517 | PKCS8_PRIV_KEY_INFO |
450 | PKCS8_PRIV_KEY_INFO **p8inf) | 518 | *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, |
451 | { | 519 | PKCS8_PRIV_KEY_INFO **p8inf) |
452 | return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new, | 520 | { |
453 | d2i_PKCS8_PRIV_KEY_INFO,fp,p8inf); | 521 | return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, |
454 | } | 522 | d2i_PKCS8_PRIV_KEY_INFO, fp, p8inf); |
455 | 523 | } | |
456 | int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) | 524 | |
457 | { | 525 | int |
458 | return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,fp, | 526 | i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) |
459 | p8inf); | 527 | { |
460 | } | 528 | return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, |
461 | 529 | fp, p8inf); | |
462 | int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) | 530 | } |
463 | { | 531 | |
532 | int | ||
533 | i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) | ||
534 | { | ||
464 | PKCS8_PRIV_KEY_INFO *p8inf; | 535 | PKCS8_PRIV_KEY_INFO *p8inf; |
465 | int ret; | 536 | int ret; |
466 | p8inf = EVP_PKEY2PKCS8(key); | 537 | p8inf = EVP_PKEY2PKCS8(key); |
467 | if(!p8inf) return 0; | 538 | if (!p8inf) |
539 | return 0; | ||
468 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); | 540 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); |
469 | PKCS8_PRIV_KEY_INFO_free(p8inf); | 541 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
470 | return ret; | 542 | return ret; |
471 | } | 543 | } |
472 | 544 | ||
473 | int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) | 545 | int |
474 | { | 546 | i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) |
475 | return ASN1_i2d_fp_of(EVP_PKEY,i2d_PrivateKey,fp,pkey); | 547 | { |
476 | } | 548 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PrivateKey, fp, pkey); |
549 | } | ||
477 | 550 | ||
478 | EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) | 551 | EVP_PKEY |
552 | *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) | ||
479 | { | 553 | { |
480 | return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,fp,a); | 554 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, |
555 | fp, a); | ||
481 | } | 556 | } |
482 | 557 | ||
483 | int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) | 558 | int |
484 | { | 559 | i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) |
485 | return ASN1_i2d_fp_of(EVP_PKEY,i2d_PUBKEY,fp,pkey); | 560 | { |
486 | } | 561 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PUBKEY, fp, pkey); |
562 | } | ||
487 | 563 | ||
488 | EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) | 564 | EVP_PKEY |
565 | *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) | ||
489 | { | 566 | { |
490 | return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,fp,a); | 567 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, fp, a); |
491 | } | 568 | } |
492 | 569 | ||
493 | #endif | 570 | #endif |
494 | 571 | ||
495 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, | 572 | PKCS8_PRIV_KEY_INFO |
496 | PKCS8_PRIV_KEY_INFO **p8inf) | 573 | *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, |
497 | { | 574 | PKCS8_PRIV_KEY_INFO **p8inf) |
498 | return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new, | 575 | { |
499 | d2i_PKCS8_PRIV_KEY_INFO,bp,p8inf); | 576 | return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, |
500 | } | 577 | d2i_PKCS8_PRIV_KEY_INFO, bp, p8inf); |
501 | 578 | } | |
502 | int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) | 579 | |
503 | { | 580 | int |
504 | return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,bp, | 581 | i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) |
505 | p8inf); | 582 | { |
506 | } | 583 | return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, |
507 | 584 | bp, p8inf); | |
508 | int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) | 585 | } |
509 | { | 586 | |
587 | int | ||
588 | i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) | ||
589 | { | ||
510 | PKCS8_PRIV_KEY_INFO *p8inf; | 590 | PKCS8_PRIV_KEY_INFO *p8inf; |
511 | int ret; | 591 | int ret; |
512 | p8inf = EVP_PKEY2PKCS8(key); | 592 | p8inf = EVP_PKEY2PKCS8(key); |
513 | if(!p8inf) return 0; | 593 | if (!p8inf) |
594 | return 0; | ||
514 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); | 595 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); |
515 | PKCS8_PRIV_KEY_INFO_free(p8inf); | 596 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
516 | return ret; | 597 | return ret; |
517 | } | 598 | } |
518 | 599 | ||
519 | int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) | 600 | int |
520 | { | 601 | i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) |
521 | return ASN1_i2d_bio_of(EVP_PKEY,i2d_PrivateKey,bp,pkey); | 602 | { |
522 | } | 603 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PrivateKey, bp, pkey); |
523 | 604 | } | |
524 | EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) | 605 | |
525 | { | 606 | EVP_PKEY |
526 | return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,bp,a); | 607 | *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) |
527 | } | 608 | { |
528 | 609 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, bp, a); | |
529 | int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) | 610 | } |
530 | { | 611 | |
531 | return ASN1_i2d_bio_of(EVP_PKEY,i2d_PUBKEY,bp,pkey); | 612 | int |
532 | } | 613 | i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) |
533 | 614 | { | |
534 | EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) | 615 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PUBKEY, bp, pkey); |
535 | { | 616 | } |
536 | return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,bp,a); | 617 | |
537 | } | 618 | EVP_PKEY |
619 | *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) | ||
620 | { | ||
621 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, bp, a); | ||
622 | } | ||
diff --git a/src/lib/libssl/src/crypto/x509/by_dir.c b/src/lib/libssl/src/crypto/x509/by_dir.c index f9d55c4e6d..b5512895a1 100644 --- a/src/lib/libssl/src/crypto/x509/by_dir.c +++ b/src/lib/libssl/src/crypto/x509/by_dir.c | |||
@@ -73,37 +73,34 @@ | |||
73 | #include <openssl/x509.h> | 73 | #include <openssl/x509.h> |
74 | 74 | ||
75 | 75 | ||
76 | typedef struct lookup_dir_hashes_st | 76 | typedef struct lookup_dir_hashes_st { |
77 | { | ||
78 | unsigned long hash; | 77 | unsigned long hash; |
79 | int suffix; | 78 | int suffix; |
80 | } BY_DIR_HASH; | 79 | } BY_DIR_HASH; |
81 | 80 | ||
82 | typedef struct lookup_dir_entry_st | 81 | typedef struct lookup_dir_entry_st { |
83 | { | ||
84 | char *dir; | 82 | char *dir; |
85 | int dir_type; | 83 | int dir_type; |
86 | STACK_OF(BY_DIR_HASH) *hashes; | 84 | STACK_OF(BY_DIR_HASH) *hashes; |
87 | } BY_DIR_ENTRY; | 85 | } BY_DIR_ENTRY; |
88 | 86 | ||
89 | typedef struct lookup_dir_st | 87 | typedef struct lookup_dir_st { |
90 | { | ||
91 | BUF_MEM *buffer; | 88 | BUF_MEM *buffer; |
92 | STACK_OF(BY_DIR_ENTRY) *dirs; | 89 | STACK_OF(BY_DIR_ENTRY) *dirs; |
93 | } BY_DIR; | 90 | } BY_DIR; |
94 | 91 | ||
95 | DECLARE_STACK_OF(BY_DIR_HASH) | 92 | DECLARE_STACK_OF(BY_DIR_HASH) |
96 | DECLARE_STACK_OF(BY_DIR_ENTRY) | 93 | DECLARE_STACK_OF(BY_DIR_ENTRY) |
97 | 94 | ||
98 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | 95 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
99 | char **ret); | 96 | char **ret); |
100 | static int new_dir(X509_LOOKUP *lu); | 97 | static int new_dir(X509_LOOKUP *lu); |
101 | static void free_dir(X509_LOOKUP *lu); | 98 | static void free_dir(X509_LOOKUP *lu); |
102 | static int add_cert_dir(BY_DIR *ctx,const char *dir,int type); | 99 | static int add_cert_dir(BY_DIR *ctx, const char *dir, int type); |
103 | static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, | 100 | static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, |
104 | X509_OBJECT *ret); | 101 | X509_OBJECT *ret); |
105 | X509_LOOKUP_METHOD x509_dir_lookup= | 102 | |
106 | { | 103 | X509_LOOKUP_METHOD x509_dir_lookup = { |
107 | "Load certs from files in a directory", | 104 | "Load certs from files in a directory", |
108 | new_dir, /* new */ | 105 | new_dir, /* new */ |
109 | free_dir, /* free */ | 106 | free_dir, /* free */ |
@@ -114,254 +111,237 @@ X509_LOOKUP_METHOD x509_dir_lookup= | |||
114 | NULL, /* get_by_issuer_serial */ | 111 | NULL, /* get_by_issuer_serial */ |
115 | NULL, /* get_by_fingerprint */ | 112 | NULL, /* get_by_fingerprint */ |
116 | NULL, /* get_by_alias */ | 113 | NULL, /* get_by_alias */ |
117 | }; | 114 | }; |
118 | 115 | ||
119 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void) | 116 | X509_LOOKUP_METHOD |
120 | { | 117 | *X509_LOOKUP_hash_dir(void) |
121 | return(&x509_dir_lookup); | 118 | { |
122 | } | 119 | return (&x509_dir_lookup); |
123 | 120 | } | |
124 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | 121 | |
125 | char **retp) | 122 | static int |
126 | { | 123 | dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
127 | int ret=0; | 124 | char **retp) |
125 | { | ||
126 | int ret = 0; | ||
128 | BY_DIR *ld; | 127 | BY_DIR *ld; |
129 | char *dir = NULL; | 128 | char *dir = NULL; |
130 | 129 | ||
131 | ld=(BY_DIR *)ctx->method_data; | 130 | ld = (BY_DIR *)ctx->method_data; |
132 | 131 | ||
133 | switch (cmd) | 132 | switch (cmd) { |
134 | { | ||
135 | case X509_L_ADD_DIR: | 133 | case X509_L_ADD_DIR: |
136 | if (argl == X509_FILETYPE_DEFAULT) | 134 | if (argl == X509_FILETYPE_DEFAULT) { |
137 | { | 135 | dir = (char *)getenv(X509_get_default_cert_dir_env()); |
138 | dir=(char *)getenv(X509_get_default_cert_dir_env()); | ||
139 | if (dir) | 136 | if (dir) |
140 | ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM); | 137 | ret = add_cert_dir(ld, dir, X509_FILETYPE_PEM); |
141 | else | 138 | else |
142 | ret=add_cert_dir(ld,X509_get_default_cert_dir(), | 139 | ret = add_cert_dir(ld, X509_get_default_cert_dir(), |
143 | X509_FILETYPE_PEM); | 140 | X509_FILETYPE_PEM); |
144 | if (!ret) | 141 | if (!ret) { |
145 | { | 142 | X509err(X509_F_DIR_CTRL, X509_R_LOADING_CERT_DIR); |
146 | X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR); | ||
147 | } | ||
148 | } | 143 | } |
149 | else | 144 | } else |
150 | ret=add_cert_dir(ld,argp,(int)argl); | 145 | ret = add_cert_dir(ld, argp,(int)argl); |
151 | break; | 146 | break; |
152 | } | ||
153 | return(ret); | ||
154 | } | 147 | } |
148 | return (ret); | ||
149 | } | ||
155 | 150 | ||
156 | static int new_dir(X509_LOOKUP *lu) | 151 | static int |
157 | { | 152 | new_dir(X509_LOOKUP *lu) |
153 | { | ||
158 | BY_DIR *a; | 154 | BY_DIR *a; |
159 | 155 | ||
160 | if ((a=(BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL) | 156 | if ((a = (BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL) |
161 | return(0); | 157 | return (0); |
162 | if ((a->buffer=BUF_MEM_new()) == NULL) | 158 | if ((a->buffer = BUF_MEM_new()) == NULL) { |
163 | { | ||
164 | OPENSSL_free(a); | 159 | OPENSSL_free(a); |
165 | return(0); | 160 | return (0); |
166 | } | ||
167 | a->dirs=NULL; | ||
168 | lu->method_data=(char *)a; | ||
169 | return(1); | ||
170 | } | 161 | } |
171 | 162 | a->dirs = NULL; | |
172 | static void by_dir_hash_free(BY_DIR_HASH *hash) | 163 | lu->method_data = (char *)a; |
173 | { | 164 | return (1); |
165 | } | ||
166 | |||
167 | static void | ||
168 | by_dir_hash_free(BY_DIR_HASH *hash) | ||
169 | { | ||
174 | OPENSSL_free(hash); | 170 | OPENSSL_free(hash); |
175 | } | 171 | } |
176 | 172 | ||
177 | static int by_dir_hash_cmp(const BY_DIR_HASH * const *a, | 173 | static int |
178 | const BY_DIR_HASH * const *b) | 174 | by_dir_hash_cmp(const BY_DIR_HASH * const *a, |
179 | { | 175 | const BY_DIR_HASH * const *b) |
176 | { | ||
180 | if ((*a)->hash > (*b)->hash) | 177 | if ((*a)->hash > (*b)->hash) |
181 | return 1; | 178 | return 1; |
182 | if ((*a)->hash < (*b)->hash) | 179 | if ((*a)->hash < (*b)->hash) |
183 | return -1; | 180 | return -1; |
184 | return 0; | 181 | return 0; |
185 | } | 182 | } |
186 | 183 | ||
187 | static void by_dir_entry_free(BY_DIR_ENTRY *ent) | 184 | static void |
188 | { | 185 | by_dir_entry_free(BY_DIR_ENTRY *ent) |
186 | { | ||
189 | if (ent->dir) | 187 | if (ent->dir) |
190 | OPENSSL_free(ent->dir); | 188 | OPENSSL_free(ent->dir); |
191 | if (ent->hashes) | 189 | if (ent->hashes) |
192 | sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); | 190 | sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); |
193 | OPENSSL_free(ent); | 191 | OPENSSL_free(ent); |
194 | } | 192 | } |
195 | 193 | ||
196 | static void free_dir(X509_LOOKUP *lu) | 194 | static void |
197 | { | 195 | free_dir(X509_LOOKUP *lu) |
196 | { | ||
198 | BY_DIR *a; | 197 | BY_DIR *a; |
199 | 198 | ||
200 | a=(BY_DIR *)lu->method_data; | 199 | a = (BY_DIR *)lu->method_data; |
201 | if (a->dirs != NULL) | 200 | if (a->dirs != NULL) |
202 | sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free); | 201 | sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free); |
203 | if (a->buffer != NULL) | 202 | if (a->buffer != NULL) |
204 | BUF_MEM_free(a->buffer); | 203 | BUF_MEM_free(a->buffer); |
205 | OPENSSL_free(a); | 204 | OPENSSL_free(a); |
205 | } | ||
206 | |||
207 | static int | ||
208 | add_cert_dir(BY_DIR *ctx, const char *dir, int type) | ||
209 | { | ||
210 | int j, len; | ||
211 | const char *s, *ss, *p; | ||
212 | |||
213 | if (dir == NULL || !*dir) { | ||
214 | X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY); | ||
215 | return 0; | ||
206 | } | 216 | } |
207 | 217 | ||
208 | static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) | 218 | s = dir; |
209 | { | 219 | p = s; |
210 | int j,len; | 220 | do { |
211 | const char *s,*ss,*p; | 221 | if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) { |
212 | |||
213 | if (dir == NULL || !*dir) | ||
214 | { | ||
215 | X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY); | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | s=dir; | ||
220 | p=s; | ||
221 | do | ||
222 | { | ||
223 | if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) | ||
224 | { | ||
225 | BY_DIR_ENTRY *ent; | 222 | BY_DIR_ENTRY *ent; |
226 | ss=s; | 223 | ss = s; |
227 | s=p+1; | 224 | s = p + 1; |
228 | len=(int)(p-ss); | 225 | len = (int)(p - ss); |
229 | if (len == 0) continue; | 226 | if (len == 0) |
230 | for (j=0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) | 227 | continue; |
231 | { | 228 | for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) { |
232 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j); | 229 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j); |
233 | if (strlen(ent->dir) == (size_t)len && | 230 | if (strlen(ent->dir) == (size_t)len && |
234 | strncmp(ent->dir,ss,(unsigned int)len) == 0) | 231 | strncmp(ent->dir, ss, |
232 | (unsigned int)len) == 0) | ||
235 | break; | 233 | break; |
236 | } | 234 | } |
237 | if (j < sk_BY_DIR_ENTRY_num(ctx->dirs)) | 235 | if (j < sk_BY_DIR_ENTRY_num(ctx->dirs)) |
238 | continue; | 236 | continue; |
239 | if (ctx->dirs == NULL) | 237 | if (ctx->dirs == NULL) { |
240 | { | ||
241 | ctx->dirs = sk_BY_DIR_ENTRY_new_null(); | 238 | ctx->dirs = sk_BY_DIR_ENTRY_new_null(); |
242 | if (!ctx->dirs) | 239 | if (!ctx->dirs) { |
243 | { | 240 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); |
244 | X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE); | ||
245 | return 0; | 241 | return 0; |
246 | } | ||
247 | } | 242 | } |
243 | } | ||
248 | ent = OPENSSL_malloc(sizeof(BY_DIR_ENTRY)); | 244 | ent = OPENSSL_malloc(sizeof(BY_DIR_ENTRY)); |
249 | if (!ent) | 245 | if (!ent) |
250 | return 0; | 246 | return 0; |
251 | ent->dir_type = type; | 247 | ent->dir_type = type; |
252 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); | 248 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); |
253 | ent->dir = OPENSSL_malloc((unsigned int)len+1); | 249 | ent->dir = OPENSSL_malloc((unsigned int)len + 1); |
254 | if (!ent->dir || !ent->hashes) | 250 | if (!ent->dir || !ent->hashes) { |
255 | { | ||
256 | by_dir_entry_free(ent); | 251 | by_dir_entry_free(ent); |
257 | return 0; | 252 | return 0; |
258 | } | 253 | } |
259 | strncpy(ent->dir,ss,(unsigned int)len); | 254 | strncpy(ent->dir, ss,(unsigned int)len); |
260 | ent->dir[len] = '\0'; | 255 | ent->dir[len] = '\0'; |
261 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) | 256 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { |
262 | { | ||
263 | by_dir_entry_free(ent); | 257 | by_dir_entry_free(ent); |
264 | return 0; | 258 | return 0; |
265 | } | ||
266 | } | 259 | } |
267 | } while (*p++ != '\0'); | 260 | } |
261 | } while (*p++ != '\0'); | ||
268 | return 1; | 262 | return 1; |
269 | } | 263 | } |
270 | 264 | ||
271 | static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | 265 | static int |
272 | X509_OBJECT *ret) | 266 | get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, |
273 | { | 267 | X509_OBJECT *ret) |
268 | { | ||
274 | BY_DIR *ctx; | 269 | BY_DIR *ctx; |
275 | union { | 270 | union { |
276 | struct { | 271 | struct { |
277 | X509 st_x509; | 272 | X509 st_x509; |
278 | X509_CINF st_x509_cinf; | 273 | X509_CINF st_x509_cinf; |
279 | } x509; | 274 | } x509; |
280 | struct { | 275 | struct { |
281 | X509_CRL st_crl; | 276 | X509_CRL st_crl; |
282 | X509_CRL_INFO st_crl_info; | 277 | X509_CRL_INFO st_crl_info; |
283 | } crl; | 278 | } crl; |
284 | } data; | 279 | } data; |
285 | int ok=0; | 280 | int ok = 0; |
286 | int i,j,k; | 281 | int i, j, k; |
287 | unsigned long h; | 282 | unsigned long h; |
288 | BUF_MEM *b=NULL; | 283 | BUF_MEM *b = NULL; |
289 | X509_OBJECT stmp,*tmp; | 284 | X509_OBJECT stmp, *tmp; |
290 | const char *postfix=""; | 285 | const char *postfix=""; |
291 | 286 | ||
292 | if (name == NULL) return(0); | 287 | if (name == NULL) |
288 | return (0); | ||
293 | 289 | ||
294 | stmp.type=type; | 290 | stmp.type = type; |
295 | if (type == X509_LU_X509) | 291 | if (type == X509_LU_X509) { |
296 | { | 292 | data.x509.st_x509.cert_info = &data.x509.st_x509_cinf; |
297 | data.x509.st_x509.cert_info= &data.x509.st_x509_cinf; | 293 | data.x509.st_x509_cinf.subject = name; |
298 | data.x509.st_x509_cinf.subject=name; | 294 | stmp.data.x509 = &data.x509.st_x509; |
299 | stmp.data.x509= &data.x509.st_x509; | ||
300 | postfix=""; | 295 | postfix=""; |
301 | } | 296 | } else if (type == X509_LU_CRL) { |
302 | else if (type == X509_LU_CRL) | 297 | data.crl.st_crl.crl = &data.crl.st_crl_info; |
303 | { | 298 | data.crl.st_crl_info.issuer = name; |
304 | data.crl.st_crl.crl= &data.crl.st_crl_info; | 299 | stmp.data.crl = &data.crl.st_crl; |
305 | data.crl.st_crl_info.issuer=name; | ||
306 | stmp.data.crl= &data.crl.st_crl; | ||
307 | postfix="r"; | 300 | postfix="r"; |
308 | } | 301 | } else { |
309 | else | 302 | X509err(X509_F_GET_CERT_BY_SUBJECT, X509_R_WRONG_LOOKUP_TYPE); |
310 | { | ||
311 | X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE); | ||
312 | goto finish; | 303 | goto finish; |
313 | } | 304 | } |
314 | 305 | ||
315 | if ((b=BUF_MEM_new()) == NULL) | 306 | if ((b = BUF_MEM_new()) == NULL) { |
316 | { | 307 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_BUF_LIB); |
317 | X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB); | ||
318 | goto finish; | 308 | goto finish; |
319 | } | 309 | } |
320 | 310 | ||
321 | ctx=(BY_DIR *)xl->method_data; | 311 | ctx = (BY_DIR *)xl->method_data; |
322 | 312 | ||
323 | h=X509_NAME_hash(name); | 313 | h = X509_NAME_hash(name); |
324 | for (i=0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++) | 314 | for (i = 0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++) { |
325 | { | ||
326 | BY_DIR_ENTRY *ent; | 315 | BY_DIR_ENTRY *ent; |
327 | int idx; | 316 | int idx; |
328 | BY_DIR_HASH htmp, *hent; | 317 | BY_DIR_HASH htmp, *hent; |
329 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i); | 318 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i); |
330 | j=strlen(ent->dir)+1+8+6+1+1; | 319 | j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1; |
331 | if (!BUF_MEM_grow(b,j)) | 320 | if (!BUF_MEM_grow(b, j)) { |
332 | { | 321 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); |
333 | X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE); | ||
334 | goto finish; | 322 | goto finish; |
335 | } | 323 | } |
336 | if (type == X509_LU_CRL && ent->hashes) | 324 | if (type == X509_LU_CRL && ent->hashes) { |
337 | { | ||
338 | htmp.hash = h; | 325 | htmp.hash = h; |
339 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); | 326 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); |
340 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); | 327 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); |
341 | if (idx >= 0) | 328 | if (idx >= 0) { |
342 | { | ||
343 | hent = sk_BY_DIR_HASH_value(ent->hashes, idx); | 329 | hent = sk_BY_DIR_HASH_value(ent->hashes, idx); |
344 | k = hent->suffix; | 330 | k = hent->suffix; |
345 | } | 331 | } else { |
346 | else | ||
347 | { | ||
348 | hent = NULL; | 332 | hent = NULL; |
349 | k=0; | 333 | k = 0; |
350 | } | ||
351 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); | ||
352 | } | 334 | } |
353 | else | 335 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); |
354 | { | 336 | } else { |
355 | k = 0; | 337 | k = 0; |
356 | hent = NULL; | 338 | hent = NULL; |
357 | } | 339 | } |
358 | for (;;) | 340 | for (;;) { |
359 | { | ||
360 | char c = '/'; | 341 | char c = '/'; |
361 | #ifdef OPENSSL_SYS_VMS | 342 | #ifdef OPENSSL_SYS_VMS |
362 | c = ent->dir[strlen(ent->dir)-1]; | 343 | c = ent->dir[strlen(ent->dir) - 1]; |
363 | if (c != ':' && c != '>' && c != ']') | 344 | if (c != ':' && c != '>' && c != ']') { |
364 | { | ||
365 | /* If no separator is present, we assume the | 345 | /* If no separator is present, we assume the |
366 | directory specifier is a logical name, and | 346 | directory specifier is a logical name, and |
367 | add a colon. We really should use better | 347 | add a colon. We really should use better |
@@ -369,112 +349,100 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | |||
369 | but this will do for now... | 349 | but this will do for now... |
370 | -- Richard Levitte */ | 350 | -- Richard Levitte */ |
371 | c = ':'; | 351 | c = ':'; |
372 | } | 352 | } else { |
373 | else | ||
374 | { | ||
375 | c = '\0'; | 353 | c = '\0'; |
376 | } | 354 | } |
377 | #endif | 355 | #endif |
378 | if (c == '\0') | 356 | if (c == '\0') { |
379 | { | ||
380 | /* This is special. When c == '\0', no | 357 | /* This is special. When c == '\0', no |
381 | directory separator should be added. */ | 358 | directory separator should be added. */ |
382 | (void) snprintf(b->data,b->max, | 359 | (void) snprintf(b->data, b->max, |
383 | "%s%08lx.%s%d",ent->dir,h, | 360 | "%s%08lx.%s%d", ent->dir, h, |
384 | postfix,k); | 361 | postfix, k); |
385 | } | 362 | } else { |
386 | else | 363 | (void) snprintf(b->data, b->max, |
387 | { | 364 | "%s%c%08lx.%s%d", ent->dir, c, h, |
388 | (void) snprintf(b->data,b->max, | 365 | postfix, k); |
389 | "%s%c%08lx.%s%d",ent->dir,c,h, | 366 | } |
390 | postfix,k); | ||
391 | } | ||
392 | #ifndef OPENSSL_NO_POSIX_IO | 367 | #ifndef OPENSSL_NO_POSIX_IO |
393 | #ifdef _WIN32 | 368 | #ifdef _WIN32 |
394 | #define stat _stat | 369 | #define stat _stat |
395 | #endif | 370 | #endif |
396 | { | 371 | { |
397 | struct stat st; | 372 | struct stat st; |
398 | if (stat(b->data,&st) < 0) | 373 | if (stat(b->data, &st) < 0) |
399 | break; | 374 | break; |
400 | } | 375 | } |
401 | #endif | 376 | #endif |
402 | /* found one. */ | 377 | /* found one. */ |
403 | if (type == X509_LU_X509) | 378 | if (type == X509_LU_X509) { |
404 | { | 379 | if ((X509_load_cert_file(xl, b->data, |
405 | if ((X509_load_cert_file(xl,b->data, | ||
406 | ent->dir_type)) == 0) | 380 | ent->dir_type)) == 0) |
407 | break; | 381 | break; |
408 | } | 382 | } else if (type == X509_LU_CRL) { |
409 | else if (type == X509_LU_CRL) | 383 | if ((X509_load_crl_file(xl, b->data, |
410 | { | ||
411 | if ((X509_load_crl_file(xl,b->data, | ||
412 | ent->dir_type)) == 0) | 384 | ent->dir_type)) == 0) |
413 | break; | 385 | break; |
414 | } | 386 | } |
415 | /* else case will caught higher up */ | 387 | /* else case will caught higher up */ |
416 | k++; | 388 | k++; |
417 | } | 389 | } |
418 | 390 | ||
419 | /* we have added it to the cache so now pull | 391 | /* we have added it to the cache so now pull |
420 | * it out again */ | 392 | * it out again */ |
421 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 393 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
422 | j = sk_X509_OBJECT_find(xl->store_ctx->objs,&stmp); | 394 | j = sk_X509_OBJECT_find(xl->store_ctx->objs, &stmp); |
423 | if(j != -1) tmp=sk_X509_OBJECT_value(xl->store_ctx->objs,j); | 395 | if (j != -1) |
424 | else tmp = NULL; | 396 | tmp = sk_X509_OBJECT_value(xl->store_ctx->objs, j); |
397 | else tmp = NULL; | ||
425 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 398 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
426 | 399 | ||
427 | 400 | ||
428 | /* If a CRL, update the last file suffix added for this */ | 401 | /* If a CRL, update the last file suffix added for this */ |
429 | 402 | ||
430 | if (type == X509_LU_CRL) | 403 | if (type == X509_LU_CRL) { |
431 | { | ||
432 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 404 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
433 | /* Look for entry again in case another thread added | 405 | /* Look for entry again in case another thread added |
434 | * an entry first. | 406 | * an entry first. |
435 | */ | 407 | */ |
436 | if (!hent) | 408 | if (!hent) { |
437 | { | ||
438 | htmp.hash = h; | 409 | htmp.hash = h; |
439 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); | 410 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); |
440 | if (idx >= 0) | 411 | if (idx >= 0) |
441 | hent = | 412 | hent = sk_BY_DIR_HASH_value( |
442 | sk_BY_DIR_HASH_value(ent->hashes, idx); | 413 | ent->hashes, idx); |
443 | } | 414 | } |
444 | if (!hent) | 415 | if (!hent) { |
445 | { | ||
446 | hent = OPENSSL_malloc(sizeof(BY_DIR_HASH)); | 416 | hent = OPENSSL_malloc(sizeof(BY_DIR_HASH)); |
447 | hent->hash = h; | 417 | hent->hash = h; |
448 | hent->suffix = k; | 418 | hent->suffix = k; |
449 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) | 419 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { |
450 | { | ||
451 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 420 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
452 | OPENSSL_free(hent); | 421 | OPENSSL_free(hent); |
453 | ok = 0; | 422 | ok = 0; |
454 | goto finish; | 423 | goto finish; |
455 | } | ||
456 | } | 424 | } |
457 | else if (hent->suffix < k) | 425 | } else if (hent->suffix < k) |
458 | hent->suffix = k; | 426 | hent->suffix = k; |
459 | 427 | ||
460 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 428 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
461 | 429 | ||
462 | } | 430 | } |
463 | 431 | ||
464 | if (tmp != NULL) | 432 | if (tmp != NULL) { |
465 | { | 433 | ok = 1; |
466 | ok=1; | 434 | ret->type = tmp->type; |
467 | ret->type=tmp->type; | 435 | memcpy(&ret->data, &tmp->data, sizeof(ret->data)); |
468 | memcpy(&ret->data,&tmp->data,sizeof(ret->data)); | ||
469 | /* If we were going to up the reference count, | 436 | /* If we were going to up the reference count, |
470 | * we would need to do it on a perl 'type' | 437 | * we would need to do it on a perl 'type' |
471 | * basis */ | 438 | * basis */ |
472 | /* CRYPTO_add(&tmp->data.x509->references,1, | 439 | /* CRYPTO_add(&tmp->data.x509->references,1, |
473 | CRYPTO_LOCK_X509);*/ | 440 | CRYPTO_LOCK_X509);*/ |
474 | goto finish; | 441 | goto finish; |
475 | } | ||
476 | } | 442 | } |
477 | finish: | ||
478 | if (b != NULL) BUF_MEM_free(b); | ||
479 | return(ok); | ||
480 | } | 443 | } |
444 | finish: | ||
445 | if (b != NULL) | ||
446 | BUF_MEM_free(b); | ||
447 | return (ok); | ||
448 | } | ||
diff --git a/src/lib/libssl/src/crypto/x509/by_file.c b/src/lib/libssl/src/crypto/x509/by_file.c index 57b08ee094..474d13bf0e 100644 --- a/src/lib/libssl/src/crypto/x509/by_file.c +++ b/src/lib/libssl/src/crypto/x509/by_file.c | |||
@@ -69,9 +69,9 @@ | |||
69 | #ifndef OPENSSL_NO_STDIO | 69 | #ifndef OPENSSL_NO_STDIO |
70 | 70 | ||
71 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, | 71 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, |
72 | long argl, char **ret); | 72 | long argl, char **ret); |
73 | X509_LOOKUP_METHOD x509_file_lookup= | 73 | |
74 | { | 74 | X509_LOOKUP_METHOD x509_file_lookup = { |
75 | "Load file into cache", | 75 | "Load file into cache", |
76 | NULL, /* new */ | 76 | NULL, /* new */ |
77 | NULL, /* free */ | 77 | NULL, /* free */ |
@@ -82,211 +82,199 @@ X509_LOOKUP_METHOD x509_file_lookup= | |||
82 | NULL, /* get_by_issuer_serial */ | 82 | NULL, /* get_by_issuer_serial */ |
83 | NULL, /* get_by_fingerprint */ | 83 | NULL, /* get_by_fingerprint */ |
84 | NULL, /* get_by_alias */ | 84 | NULL, /* get_by_alias */ |
85 | }; | 85 | }; |
86 | 86 | ||
87 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void) | 87 | X509_LOOKUP_METHOD |
88 | { | 88 | *X509_LOOKUP_file(void) |
89 | return(&x509_file_lookup); | 89 | { |
90 | } | 90 | return (&x509_file_lookup); |
91 | } | ||
91 | 92 | ||
92 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | 93 | static int |
93 | char **ret) | 94 | by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
94 | { | 95 | char **ret) |
95 | int ok=0; | 96 | { |
97 | int ok = 0; | ||
96 | char *file; | 98 | char *file; |
97 | 99 | ||
98 | switch (cmd) | 100 | switch (cmd) { |
99 | { | ||
100 | case X509_L_FILE_LOAD: | 101 | case X509_L_FILE_LOAD: |
101 | if (argl == X509_FILETYPE_DEFAULT) | 102 | if (argl == X509_FILETYPE_DEFAULT) { |
102 | { | ||
103 | file = (char *)getenv(X509_get_default_cert_file_env()); | 103 | file = (char *)getenv(X509_get_default_cert_file_env()); |
104 | if (file) | 104 | if (file) |
105 | ok = (X509_load_cert_crl_file(ctx,file, | 105 | ok = (X509_load_cert_crl_file(ctx, file, |
106 | X509_FILETYPE_PEM) != 0); | 106 | X509_FILETYPE_PEM) != 0); |
107 | |||
108 | else | 107 | else |
109 | ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(), | 108 | ok = (X509_load_cert_crl_file(ctx, |
110 | X509_FILETYPE_PEM) != 0); | 109 | X509_get_default_cert_file(), |
110 | X509_FILETYPE_PEM) != 0); | ||
111 | 111 | ||
112 | if (!ok) | 112 | if (!ok) { |
113 | { | 113 | X509err(X509_F_BY_FILE_CTRL, |
114 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); | 114 | X509_R_LOADING_DEFAULTS); |
115 | } | ||
116 | } | 115 | } |
117 | else | 116 | } else { |
118 | { | 117 | if (argl == X509_FILETYPE_PEM) |
119 | if(argl == X509_FILETYPE_PEM) | 118 | ok = (X509_load_cert_crl_file(ctx, argp, |
120 | ok = (X509_load_cert_crl_file(ctx,argp, | 119 | X509_FILETYPE_PEM) != 0); |
121 | X509_FILETYPE_PEM) != 0); | ||
122 | else | 120 | else |
123 | ok = (X509_load_cert_file(ctx,argp,(int)argl) != 0); | 121 | ok = (X509_load_cert_file(ctx, |
124 | } | 122 | argp,(int)argl) != 0); |
125 | break; | ||
126 | } | 123 | } |
127 | return(ok); | 124 | break; |
128 | } | 125 | } |
126 | return (ok); | ||
127 | } | ||
129 | 128 | ||
130 | int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) | 129 | int |
131 | { | 130 | X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) |
132 | int ret=0; | 131 | { |
133 | BIO *in=NULL; | 132 | int ret = 0; |
134 | int i,count=0; | 133 | BIO *in = NULL; |
135 | X509 *x=NULL; | 134 | int i, count = 0; |
135 | X509 *x = NULL; | ||
136 | 136 | ||
137 | if (file == NULL) return(1); | 137 | if (file == NULL) |
138 | in=BIO_new(BIO_s_file_internal()); | 138 | return (1); |
139 | in = BIO_new(BIO_s_file_internal()); | ||
139 | 140 | ||
140 | if ((in == NULL) || (BIO_read_filename(in,file) <= 0)) | 141 | if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { |
141 | { | 142 | X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_SYS_LIB); |
142 | X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB); | ||
143 | goto err; | 143 | goto err; |
144 | } | 144 | } |
145 | 145 | ||
146 | if (type == X509_FILETYPE_PEM) | 146 | if (type == X509_FILETYPE_PEM) { |
147 | { | 147 | for (;;) { |
148 | for (;;) | 148 | x = PEM_read_bio_X509_AUX(in, NULL, NULL, NULL); |
149 | { | 149 | if (x == NULL) { |
150 | x=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL); | ||
151 | if (x == NULL) | ||
152 | { | ||
153 | if ((ERR_GET_REASON(ERR_peek_last_error()) == | 150 | if ((ERR_GET_REASON(ERR_peek_last_error()) == |
154 | PEM_R_NO_START_LINE) && (count > 0)) | 151 | PEM_R_NO_START_LINE) && (count > 0)) { |
155 | { | ||
156 | ERR_clear_error(); | 152 | ERR_clear_error(); |
157 | break; | 153 | break; |
158 | } | 154 | } else { |
159 | else | ||
160 | { | ||
161 | X509err(X509_F_X509_LOAD_CERT_FILE, | 155 | X509err(X509_F_X509_LOAD_CERT_FILE, |
162 | ERR_R_PEM_LIB); | 156 | ERR_R_PEM_LIB); |
163 | goto err; | 157 | goto err; |
164 | } | ||
165 | } | 158 | } |
166 | i=X509_STORE_add_cert(ctx->store_ctx,x); | 159 | } |
167 | if (!i) goto err; | 160 | i = X509_STORE_add_cert(ctx->store_ctx, x); |
161 | if (!i) | ||
162 | goto err; | ||
168 | count++; | 163 | count++; |
169 | X509_free(x); | 164 | X509_free(x); |
170 | x=NULL; | 165 | x = NULL; |
171 | } | ||
172 | ret=count; | ||
173 | } | 166 | } |
174 | else if (type == X509_FILETYPE_ASN1) | 167 | ret = count; |
175 | { | 168 | } else if (type == X509_FILETYPE_ASN1) { |
176 | x=d2i_X509_bio(in,NULL); | 169 | x = d2i_X509_bio(in, NULL); |
177 | if (x == NULL) | 170 | if (x == NULL) { |
178 | { | 171 | X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_ASN1_LIB); |
179 | X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB); | ||
180 | goto err; | 172 | goto err; |
181 | } | ||
182 | i=X509_STORE_add_cert(ctx->store_ctx,x); | ||
183 | if (!i) goto err; | ||
184 | ret=i; | ||
185 | } | 173 | } |
186 | else | 174 | i = X509_STORE_add_cert(ctx->store_ctx, x); |
187 | { | 175 | if (!i) |
188 | X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE); | 176 | goto err; |
177 | ret = i; | ||
178 | } else { | ||
179 | X509err(X509_F_X509_LOAD_CERT_FILE, X509_R_BAD_X509_FILETYPE); | ||
189 | goto err; | 180 | goto err; |
190 | } | ||
191 | err: | ||
192 | if (x != NULL) X509_free(x); | ||
193 | if (in != NULL) BIO_free(in); | ||
194 | return(ret); | ||
195 | } | 181 | } |
182 | err: | ||
183 | if (x != NULL) | ||
184 | X509_free(x); | ||
185 | if (in != NULL) | ||
186 | BIO_free(in); | ||
187 | return (ret); | ||
188 | } | ||
196 | 189 | ||
197 | int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) | 190 | int |
198 | { | 191 | X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) |
199 | int ret=0; | 192 | { |
200 | BIO *in=NULL; | 193 | int ret = 0; |
201 | int i,count=0; | 194 | BIO *in = NULL; |
202 | X509_CRL *x=NULL; | 195 | int i, count = 0; |
196 | X509_CRL *x = NULL; | ||
203 | 197 | ||
204 | if (file == NULL) return(1); | 198 | if (file == NULL) |
205 | in=BIO_new(BIO_s_file_internal()); | 199 | return (1); |
200 | in = BIO_new(BIO_s_file_internal()); | ||
206 | 201 | ||
207 | if ((in == NULL) || (BIO_read_filename(in,file) <= 0)) | 202 | if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { |
208 | { | 203 | X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB); |
209 | X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB); | ||
210 | goto err; | 204 | goto err; |
211 | } | 205 | } |
212 | 206 | ||
213 | if (type == X509_FILETYPE_PEM) | 207 | if (type == X509_FILETYPE_PEM) { |
214 | { | 208 | for (;;) { |
215 | for (;;) | 209 | x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); |
216 | { | 210 | if (x == NULL) { |
217 | x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL); | ||
218 | if (x == NULL) | ||
219 | { | ||
220 | if ((ERR_GET_REASON(ERR_peek_last_error()) == | 211 | if ((ERR_GET_REASON(ERR_peek_last_error()) == |
221 | PEM_R_NO_START_LINE) && (count > 0)) | 212 | PEM_R_NO_START_LINE) && (count > 0)) { |
222 | { | ||
223 | ERR_clear_error(); | 213 | ERR_clear_error(); |
224 | break; | 214 | break; |
225 | } | 215 | } else { |
226 | else | ||
227 | { | ||
228 | X509err(X509_F_X509_LOAD_CRL_FILE, | 216 | X509err(X509_F_X509_LOAD_CRL_FILE, |
229 | ERR_R_PEM_LIB); | 217 | ERR_R_PEM_LIB); |
230 | goto err; | 218 | goto err; |
231 | } | ||
232 | } | 219 | } |
233 | i=X509_STORE_add_crl(ctx->store_ctx,x); | 220 | } |
234 | if (!i) goto err; | 221 | i = X509_STORE_add_crl(ctx->store_ctx, x); |
222 | if (!i) | ||
223 | goto err; | ||
235 | count++; | 224 | count++; |
236 | X509_CRL_free(x); | 225 | X509_CRL_free(x); |
237 | x=NULL; | 226 | x = NULL; |
238 | } | ||
239 | ret=count; | ||
240 | } | 227 | } |
241 | else if (type == X509_FILETYPE_ASN1) | 228 | ret = count; |
242 | { | 229 | } else if (type == X509_FILETYPE_ASN1) { |
243 | x=d2i_X509_CRL_bio(in,NULL); | 230 | x = d2i_X509_CRL_bio(in, NULL); |
244 | if (x == NULL) | 231 | if (x == NULL) { |
245 | { | 232 | X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB); |
246 | X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB); | ||
247 | goto err; | 233 | goto err; |
248 | } | ||
249 | i=X509_STORE_add_crl(ctx->store_ctx,x); | ||
250 | if (!i) goto err; | ||
251 | ret=i; | ||
252 | } | 234 | } |
253 | else | 235 | i = X509_STORE_add_crl(ctx->store_ctx, x); |
254 | { | 236 | if (!i) |
255 | X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE); | 237 | goto err; |
238 | ret = i; | ||
239 | } else { | ||
240 | X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE); | ||
256 | goto err; | 241 | goto err; |
257 | } | ||
258 | err: | ||
259 | if (x != NULL) X509_CRL_free(x); | ||
260 | if (in != NULL) BIO_free(in); | ||
261 | return(ret); | ||
262 | } | 242 | } |
243 | err: | ||
244 | if (x != NULL) | ||
245 | X509_CRL_free(x); | ||
246 | if (in != NULL) | ||
247 | BIO_free(in); | ||
248 | return (ret); | ||
249 | } | ||
263 | 250 | ||
264 | int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | 251 | int |
252 | X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | ||
265 | { | 253 | { |
266 | STACK_OF(X509_INFO) *inf; | 254 | STACK_OF(X509_INFO) *inf; |
267 | X509_INFO *itmp; | 255 | X509_INFO *itmp; |
268 | BIO *in; | 256 | BIO *in; |
269 | int i, count = 0; | 257 | int i, count = 0; |
270 | if(type != X509_FILETYPE_PEM) | 258 | if (type != X509_FILETYPE_PEM) |
271 | return X509_load_cert_file(ctx, file, type); | 259 | return X509_load_cert_file(ctx, file, type); |
272 | in = BIO_new_file(file, "r"); | 260 | in = BIO_new_file(file, "r"); |
273 | if(!in) { | 261 | if (!in) { |
274 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_SYS_LIB); | 262 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_SYS_LIB); |
275 | return 0; | 263 | return 0; |
276 | } | 264 | } |
277 | inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); | 265 | inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); |
278 | BIO_free(in); | 266 | BIO_free(in); |
279 | if(!inf) { | 267 | if (!inf) { |
280 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); | 268 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB); |
281 | return 0; | 269 | return 0; |
282 | } | 270 | } |
283 | for(i = 0; i < sk_X509_INFO_num(inf); i++) { | 271 | for (i = 0; i < sk_X509_INFO_num(inf); i++) { |
284 | itmp = sk_X509_INFO_value(inf, i); | 272 | itmp = sk_X509_INFO_value(inf, i); |
285 | if(itmp->x509) { | 273 | if (itmp->x509) { |
286 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); | 274 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); |
287 | count++; | 275 | count++; |
288 | } | 276 | } |
289 | if(itmp->crl) { | 277 | if (itmp->crl) { |
290 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); | 278 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); |
291 | count++; | 279 | count++; |
292 | } | 280 | } |
@@ -295,6 +283,4 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | |||
295 | return count; | 283 | return count; |
296 | } | 284 | } |
297 | 285 | ||
298 | |||
299 | #endif /* OPENSSL_NO_STDIO */ | 286 | #endif /* OPENSSL_NO_STDIO */ |
300 | |||
diff --git a/src/lib/libssl/src/crypto/x509/x_all.c b/src/lib/libssl/src/crypto/x509/x_all.c index e06602d65a..59099f026f 100644 --- a/src/lib/libssl/src/crypto/x509/x_all.c +++ b/src/lib/libssl/src/crypto/x509/x_all.c | |||
@@ -70,468 +70,553 @@ | |||
70 | #include <openssl/dsa.h> | 70 | #include <openssl/dsa.h> |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | int X509_verify(X509 *a, EVP_PKEY *r) | 73 | int |
74 | { | 74 | X509_verify(X509 *a, EVP_PKEY *r) |
75 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF),a->sig_alg, | 75 | { |
76 | a->signature,a->cert_info,r)); | 76 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), a->sig_alg, |
77 | } | 77 | a->signature, a->cert_info, r)); |
78 | 78 | } | |
79 | int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) | 79 | |
80 | { | 80 | int |
81 | X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) | ||
82 | { | ||
81 | return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), | 83 | return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), |
82 | a->sig_alg,a->signature,a->req_info,r)); | 84 | a->sig_alg, a->signature, a->req_info, r)); |
83 | } | 85 | } |
84 | 86 | ||
85 | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) | 87 | int |
86 | { | 88 | NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) |
89 | { | ||
87 | return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), | 90 | return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), |
88 | a->sig_algor,a->signature,a->spkac,r)); | 91 | a->sig_algor, a->signature, a->spkac, r)); |
89 | } | 92 | } |
90 | 93 | ||
91 | int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) | 94 | int |
92 | { | 95 | X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) |
96 | { | ||
93 | x->cert_info->enc.modified = 1; | 97 | x->cert_info->enc.modified = 1; |
94 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), x->cert_info->signature, | 98 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), |
95 | x->sig_alg, x->signature, x->cert_info,pkey,md)); | 99 | x->cert_info->signature, x->sig_alg, x->signature, |
96 | } | 100 | x->cert_info, pkey, md)); |
101 | } | ||
97 | 102 | ||
98 | int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) | 103 | int |
99 | { | 104 | X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) |
105 | { | ||
100 | x->cert_info->enc.modified = 1; | 106 | x->cert_info->enc.modified = 1; |
101 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), | 107 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), |
102 | x->cert_info->signature, | 108 | x->cert_info->signature, x->sig_alg, x->signature, |
103 | x->sig_alg, x->signature, x->cert_info, ctx); | 109 | x->cert_info, ctx); |
104 | } | 110 | } |
105 | 111 | ||
106 | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) | 112 | int |
107 | { | 113 | X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) |
108 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO),x->sig_alg, NULL, | 114 | { |
109 | x->signature, x->req_info,pkey,md)); | 115 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO), |
110 | } | 116 | x->sig_alg, NULL, x->signature, x->req_info, pkey, md)); |
111 | 117 | } | |
112 | int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) | 118 | |
113 | { | 119 | int |
120 | X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) | ||
121 | { | ||
114 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), | 122 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), |
115 | x->sig_alg, NULL, x->signature, x->req_info, ctx); | 123 | x->sig_alg, NULL, x->signature, x->req_info, ctx); |
116 | } | 124 | } |
117 | 125 | ||
118 | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) | 126 | int |
119 | { | 127 | X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) |
128 | { | ||
120 | x->crl->enc.modified = 1; | 129 | x->crl->enc.modified = 1; |
121 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO),x->crl->sig_alg, | 130 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO), x->crl->sig_alg, |
122 | x->sig_alg, x->signature, x->crl,pkey,md)); | 131 | x->sig_alg, x->signature, x->crl, pkey, md)); |
123 | } | 132 | } |
124 | 133 | ||
125 | int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) | 134 | int |
126 | { | 135 | X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) |
136 | { | ||
127 | x->crl->enc.modified = 1; | 137 | x->crl->enc.modified = 1; |
128 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), | 138 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), |
129 | x->crl->sig_alg, x->sig_alg, x->signature, x->crl, ctx); | 139 | x->crl->sig_alg, x->sig_alg, x->signature, x->crl, ctx); |
130 | } | 140 | } |
131 | 141 | ||
132 | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) | 142 | int |
133 | { | 143 | NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) |
134 | return(ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), x->sig_algor,NULL, | 144 | { |
135 | x->signature, x->spkac,pkey,md)); | 145 | return (ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), |
136 | } | 146 | x->sig_algor, NULL, x->signature, x->spkac, pkey, md)); |
147 | } | ||
137 | 148 | ||
138 | #ifndef OPENSSL_NO_FP_API | 149 | #ifndef OPENSSL_NO_FP_API |
139 | X509 *d2i_X509_fp(FILE *fp, X509 **x509) | 150 | X509 |
140 | { | 151 | *d2i_X509_fp(FILE *fp, X509 **x509) |
152 | { | ||
141 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); | 153 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); |
142 | } | 154 | } |
143 | 155 | ||
144 | int i2d_X509_fp(FILE *fp, X509 *x509) | 156 | int |
145 | { | 157 | i2d_X509_fp(FILE *fp, X509 *x509) |
158 | { | ||
146 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); | 159 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); |
147 | } | 160 | } |
148 | #endif | 161 | #endif |
149 | 162 | ||
150 | X509 *d2i_X509_bio(BIO *bp, X509 **x509) | 163 | X509 |
151 | { | 164 | *d2i_X509_bio(BIO *bp, X509 **x509) |
165 | { | ||
152 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); | 166 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); |
153 | } | 167 | } |
154 | 168 | ||
155 | int i2d_X509_bio(BIO *bp, X509 *x509) | 169 | int |
156 | { | 170 | i2d_X509_bio(BIO *bp, X509 *x509) |
171 | { | ||
157 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); | 172 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); |
158 | } | 173 | } |
159 | 174 | ||
160 | #ifndef OPENSSL_NO_FP_API | 175 | #ifndef OPENSSL_NO_FP_API |
161 | X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) | 176 | X509_CRL |
162 | { | 177 | *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) |
178 | { | ||
163 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); | 179 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
164 | } | 180 | } |
165 | 181 | ||
166 | int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) | 182 | int |
167 | { | 183 | i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) |
184 | { | ||
168 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); | 185 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); |
169 | } | 186 | } |
170 | #endif | 187 | #endif |
171 | 188 | ||
172 | X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) | 189 | X509_CRL |
173 | { | 190 | *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) |
191 | { | ||
174 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); | 192 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
175 | } | 193 | } |
176 | 194 | ||
177 | int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) | 195 | int |
178 | { | 196 | i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) |
197 | { | ||
179 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); | 198 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); |
180 | } | 199 | } |
181 | 200 | ||
182 | #ifndef OPENSSL_NO_FP_API | 201 | #ifndef OPENSSL_NO_FP_API |
183 | PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) | 202 | PKCS7 |
184 | { | 203 | *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) |
204 | { | ||
185 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); | 205 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
186 | } | 206 | } |
187 | 207 | ||
188 | int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) | 208 | int |
189 | { | 209 | i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) |
210 | { | ||
190 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); | 211 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); |
191 | } | 212 | } |
192 | #endif | 213 | #endif |
193 | 214 | ||
194 | PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) | 215 | PKCS7 |
195 | { | 216 | *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) |
217 | { | ||
196 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); | 218 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
197 | } | 219 | } |
198 | 220 | ||
199 | int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) | 221 | int |
200 | { | 222 | i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) |
223 | { | ||
201 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); | 224 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); |
202 | } | 225 | } |
203 | 226 | ||
204 | #ifndef OPENSSL_NO_FP_API | 227 | #ifndef OPENSSL_NO_FP_API |
205 | X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) | 228 | X509_REQ |
206 | { | 229 | *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) |
230 | { | ||
207 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); | 231 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
208 | } | 232 | } |
209 | 233 | ||
210 | int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) | 234 | int |
211 | { | 235 | i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) |
236 | { | ||
212 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); | 237 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); |
213 | } | 238 | } |
214 | #endif | 239 | #endif |
215 | 240 | ||
216 | X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) | 241 | X509_REQ |
217 | { | 242 | *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) |
243 | { | ||
218 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); | 244 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
219 | } | 245 | } |
220 | 246 | ||
221 | int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) | 247 | int |
222 | { | 248 | i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) |
249 | { | ||
223 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); | 250 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); |
224 | } | 251 | } |
225 | 252 | ||
226 | #ifndef OPENSSL_NO_RSA | 253 | #ifndef OPENSSL_NO_RSA |
227 | 254 | ||
228 | #ifndef OPENSSL_NO_FP_API | 255 | #ifndef OPENSSL_NO_FP_API |
229 | RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) | 256 | RSA |
230 | { | 257 | *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) |
258 | { | ||
231 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); | 259 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
232 | } | 260 | } |
233 | 261 | ||
234 | int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) | 262 | int |
235 | { | 263 | i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) |
264 | { | ||
236 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); | 265 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); |
237 | } | 266 | } |
238 | 267 | ||
239 | RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) | 268 | RSA |
240 | { | 269 | *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) |
270 | { | ||
241 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); | 271 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
242 | } | 272 | } |
243 | 273 | ||
244 | 274 | ||
245 | RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) | 275 | RSA |
246 | { | 276 | *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) |
247 | return ASN1_d2i_fp((void *(*)(void)) | 277 | { |
248 | RSA_new,(D2I_OF(void))d2i_RSA_PUBKEY, fp, | 278 | return ASN1_d2i_fp((void *(*)(void))RSA_new, |
249 | (void **)rsa); | 279 | (D2I_OF(void))d2i_RSA_PUBKEY, fp, (void **)rsa); |
250 | } | 280 | } |
251 | 281 | ||
252 | int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) | 282 | int |
253 | { | 283 | i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) |
284 | { | ||
254 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); | 285 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); |
255 | } | 286 | } |
256 | 287 | ||
257 | int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) | 288 | int |
258 | { | 289 | i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) |
259 | return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY,fp,rsa); | 290 | { |
260 | } | 291 | return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY, fp, rsa); |
292 | } | ||
261 | #endif | 293 | #endif |
262 | 294 | ||
263 | RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) | 295 | RSA |
264 | { | 296 | *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) |
297 | { | ||
265 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); | 298 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
266 | } | 299 | } |
267 | 300 | ||
268 | int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) | 301 | int |
269 | { | 302 | i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) |
303 | { | ||
270 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); | 304 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); |
271 | } | 305 | } |
272 | 306 | ||
273 | RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) | 307 | RSA |
274 | { | 308 | *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) |
309 | { | ||
275 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); | 310 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
276 | } | 311 | } |
277 | 312 | ||
278 | 313 | ||
279 | RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) | 314 | RSA |
280 | { | 315 | *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) |
281 | return ASN1_d2i_bio_of(RSA,RSA_new,d2i_RSA_PUBKEY,bp,rsa); | 316 | { |
282 | } | 317 | return ASN1_d2i_bio_of(RSA, RSA_new, d2i_RSA_PUBKEY, bp, rsa); |
318 | } | ||
283 | 319 | ||
284 | int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) | 320 | int |
285 | { | 321 | i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) |
322 | { | ||
286 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); | 323 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); |
287 | } | 324 | } |
288 | 325 | ||
289 | int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) | 326 | int |
290 | { | 327 | i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) |
291 | return ASN1_i2d_bio_of(RSA,i2d_RSA_PUBKEY,bp,rsa); | 328 | { |
292 | } | 329 | return ASN1_i2d_bio_of(RSA, i2d_RSA_PUBKEY, bp, rsa); |
330 | } | ||
293 | #endif | 331 | #endif |
294 | 332 | ||
295 | #ifndef OPENSSL_NO_DSA | 333 | #ifndef OPENSSL_NO_DSA |
296 | #ifndef OPENSSL_NO_FP_API | 334 | #ifndef OPENSSL_NO_FP_API |
297 | DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) | 335 | DSA |
298 | { | 336 | *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) |
299 | return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSAPrivateKey,fp,dsa); | 337 | { |
300 | } | 338 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSAPrivateKey, fp, dsa); |
301 | 339 | } | |
302 | int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) | 340 | |
303 | { | 341 | int |
304 | return ASN1_i2d_fp_of_const(DSA,i2d_DSAPrivateKey,fp,dsa); | 342 | i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) |
305 | } | 343 | { |
306 | 344 | return ASN1_i2d_fp_of_const(DSA, i2d_DSAPrivateKey, fp, dsa); | |
307 | DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) | 345 | } |
308 | { | 346 | |
309 | return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSA_PUBKEY,fp,dsa); | 347 | DSA |
310 | } | 348 | *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) |
311 | 349 | { | |
312 | int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) | 350 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSA_PUBKEY, fp, dsa); |
313 | { | 351 | } |
314 | return ASN1_i2d_fp_of(DSA,i2d_DSA_PUBKEY,fp,dsa); | 352 | |
315 | } | 353 | int |
354 | i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) | ||
355 | { | ||
356 | return ASN1_i2d_fp_of(DSA, i2d_DSA_PUBKEY, fp, dsa); | ||
357 | } | ||
316 | #endif | 358 | #endif |
317 | 359 | ||
318 | DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) | 360 | DSA |
319 | { | 361 | *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) |
320 | return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAPrivateKey,bp,dsa | 362 | { |
321 | ); | 363 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSAPrivateKey, bp, dsa); |
322 | } | 364 | } |
323 | 365 | ||
324 | int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) | 366 | int |
325 | { | 367 | i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) |
326 | return ASN1_i2d_bio_of_const(DSA,i2d_DSAPrivateKey,bp,dsa); | 368 | { |
327 | } | 369 | return ASN1_i2d_bio_of_const(DSA, i2d_DSAPrivateKey, bp, dsa); |
370 | } | ||
328 | 371 | ||
329 | DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) | 372 | DSA |
330 | { | 373 | *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) |
331 | return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSA_PUBKEY,bp,dsa); | 374 | { |
332 | } | 375 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSA_PUBKEY, bp, dsa); |
376 | } | ||
333 | 377 | ||
334 | int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) | 378 | int |
335 | { | 379 | i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) |
336 | return ASN1_i2d_bio_of(DSA,i2d_DSA_PUBKEY,bp,dsa); | 380 | { |
337 | } | 381 | return ASN1_i2d_bio_of(DSA, i2d_DSA_PUBKEY, bp, dsa); |
382 | } | ||
338 | 383 | ||
339 | #endif | 384 | #endif |
340 | 385 | ||
341 | #ifndef OPENSSL_NO_EC | 386 | #ifndef OPENSSL_NO_EC |
342 | #ifndef OPENSSL_NO_FP_API | 387 | #ifndef OPENSSL_NO_FP_API |
343 | EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey) | 388 | EC_KEY |
344 | { | 389 | *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey) |
345 | return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,fp,eckey); | 390 | { |
346 | } | 391 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, fp, eckey); |
347 | 392 | } | |
348 | int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey) | 393 | |
349 | { | 394 | int |
350 | return ASN1_i2d_fp_of(EC_KEY,i2d_EC_PUBKEY,fp,eckey); | 395 | i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey) |
351 | } | 396 | { |
352 | 397 | return ASN1_i2d_fp_of(EC_KEY, i2d_EC_PUBKEY, fp, eckey); | |
353 | EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey) | 398 | } |
354 | { | 399 | |
355 | return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,fp,eckey); | 400 | EC_KEY |
356 | } | 401 | *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey) |
357 | 402 | { | |
358 | int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey) | 403 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, fp, eckey); |
359 | { | 404 | } |
360 | return ASN1_i2d_fp_of(EC_KEY,i2d_ECPrivateKey,fp,eckey); | 405 | |
361 | } | 406 | int |
407 | i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey) | ||
408 | { | ||
409 | return ASN1_i2d_fp_of(EC_KEY, i2d_ECPrivateKey, fp, eckey); | ||
410 | } | ||
362 | #endif | 411 | #endif |
363 | EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey) | 412 | EC_KEY |
364 | { | 413 | *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey) |
365 | return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,bp,eckey); | 414 | { |
366 | } | 415 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, bp, eckey); |
367 | 416 | } | |
368 | int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa) | 417 | |
369 | { | 418 | int |
370 | return ASN1_i2d_bio_of(EC_KEY,i2d_EC_PUBKEY,bp,ecdsa); | 419 | i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa) |
371 | } | 420 | { |
372 | 421 | return ASN1_i2d_bio_of(EC_KEY, i2d_EC_PUBKEY, bp, ecdsa); | |
373 | EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey) | 422 | } |
374 | { | 423 | |
375 | return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,bp,eckey); | 424 | EC_KEY |
376 | } | 425 | *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey) |
377 | 426 | { | |
378 | int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey) | 427 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, bp, eckey); |
379 | { | 428 | } |
380 | return ASN1_i2d_bio_of(EC_KEY,i2d_ECPrivateKey,bp,eckey); | 429 | |
381 | } | 430 | int |
431 | i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey) | ||
432 | { | ||
433 | return ASN1_i2d_bio_of(EC_KEY, i2d_ECPrivateKey, bp, eckey); | ||
434 | } | ||
382 | #endif | 435 | #endif |
383 | 436 | ||
384 | 437 | ||
385 | int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, | 438 | int |
386 | unsigned int *len) | 439 | X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
387 | { | 440 | unsigned int *len) |
441 | { | ||
388 | ASN1_BIT_STRING *key; | 442 | ASN1_BIT_STRING *key; |
389 | key = X509_get0_pubkey_bitstr(data); | 443 | key = X509_get0_pubkey_bitstr(data); |
390 | if(!key) return 0; | 444 | if (!key) |
445 | return 0; | ||
391 | return EVP_Digest(key->data, key->length, md, len, type, NULL); | 446 | return EVP_Digest(key->data, key->length, md, len, type, NULL); |
392 | } | 447 | } |
393 | 448 | ||
394 | int X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, | 449 | int |
395 | unsigned int *len) | 450 | X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, |
396 | { | 451 | unsigned int *len) |
397 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509),type,(char *)data,md,len)); | 452 | { |
398 | } | 453 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509), type, (char *)data, |
399 | 454 | md, len)); | |
400 | int X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, | 455 | } |
401 | unsigned int *len) | 456 | |
402 | { | 457 | int |
403 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL),type,(char *)data,md,len)); | 458 | X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, |
404 | } | 459 | unsigned int *len) |
405 | 460 | { | |
406 | int X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, | 461 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, |
407 | unsigned int *len) | 462 | md, len)); |
408 | { | 463 | } |
409 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ),type,(char *)data,md,len)); | 464 | |
410 | } | 465 | int |
411 | 466 | X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, | |
412 | int X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, | 467 | unsigned int *len) |
413 | unsigned int *len) | 468 | { |
414 | { | 469 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ), type,(char *)data, |
415 | return(ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME),type,(char *)data,md,len)); | 470 | md, len)); |
416 | } | 471 | } |
417 | 472 | ||
418 | int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *type, | 473 | int |
419 | unsigned char *md, unsigned int *len) | 474 | X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, |
420 | { | 475 | unsigned int *len) |
421 | return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL),type, | 476 | { |
422 | (char *)data,md,len)); | 477 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME), type,(char *)data, |
423 | } | 478 | md, len)); |
479 | } | ||
480 | |||
481 | int | ||
482 | PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, | ||
483 | const EVP_MD *type, unsigned char *md, unsigned int *len) | ||
484 | { | ||
485 | return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL), type, | ||
486 | (char *)data, md, len)); | ||
487 | } | ||
424 | 488 | ||
425 | 489 | ||
426 | #ifndef OPENSSL_NO_FP_API | 490 | #ifndef OPENSSL_NO_FP_API |
427 | X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) | 491 | X509_SIG |
428 | { | 492 | *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) |
429 | return ASN1_d2i_fp_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,fp,p8); | 493 | { |
430 | } | 494 | return ASN1_d2i_fp_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, fp, p8); |
431 | 495 | } | |
432 | int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) | 496 | |
433 | { | 497 | int |
434 | return ASN1_i2d_fp_of(X509_SIG,i2d_X509_SIG,fp,p8); | 498 | i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) |
435 | } | 499 | { |
500 | return ASN1_i2d_fp_of(X509_SIG, i2d_X509_SIG, fp, p8); | ||
501 | } | ||
436 | #endif | 502 | #endif |
437 | 503 | ||
438 | X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) | 504 | X509_SIG |
439 | { | 505 | *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) |
440 | return ASN1_d2i_bio_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,bp,p8); | 506 | { |
441 | } | 507 | return ASN1_d2i_bio_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, bp, p8); |
508 | } | ||
442 | 509 | ||
443 | int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) | 510 | int |
444 | { | 511 | i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) |
445 | return ASN1_i2d_bio_of(X509_SIG,i2d_X509_SIG,bp,p8); | 512 | { |
446 | } | 513 | return ASN1_i2d_bio_of(X509_SIG, i2d_X509_SIG, bp, p8); |
514 | } | ||
447 | 515 | ||
448 | #ifndef OPENSSL_NO_FP_API | 516 | #ifndef OPENSSL_NO_FP_API |
449 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, | 517 | PKCS8_PRIV_KEY_INFO |
450 | PKCS8_PRIV_KEY_INFO **p8inf) | 518 | *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, |
451 | { | 519 | PKCS8_PRIV_KEY_INFO **p8inf) |
452 | return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new, | 520 | { |
453 | d2i_PKCS8_PRIV_KEY_INFO,fp,p8inf); | 521 | return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, |
454 | } | 522 | d2i_PKCS8_PRIV_KEY_INFO, fp, p8inf); |
455 | 523 | } | |
456 | int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) | 524 | |
457 | { | 525 | int |
458 | return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,fp, | 526 | i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) |
459 | p8inf); | 527 | { |
460 | } | 528 | return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, |
461 | 529 | fp, p8inf); | |
462 | int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) | 530 | } |
463 | { | 531 | |
532 | int | ||
533 | i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) | ||
534 | { | ||
464 | PKCS8_PRIV_KEY_INFO *p8inf; | 535 | PKCS8_PRIV_KEY_INFO *p8inf; |
465 | int ret; | 536 | int ret; |
466 | p8inf = EVP_PKEY2PKCS8(key); | 537 | p8inf = EVP_PKEY2PKCS8(key); |
467 | if(!p8inf) return 0; | 538 | if (!p8inf) |
539 | return 0; | ||
468 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); | 540 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); |
469 | PKCS8_PRIV_KEY_INFO_free(p8inf); | 541 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
470 | return ret; | 542 | return ret; |
471 | } | 543 | } |
472 | 544 | ||
473 | int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) | 545 | int |
474 | { | 546 | i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) |
475 | return ASN1_i2d_fp_of(EVP_PKEY,i2d_PrivateKey,fp,pkey); | 547 | { |
476 | } | 548 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PrivateKey, fp, pkey); |
549 | } | ||
477 | 550 | ||
478 | EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) | 551 | EVP_PKEY |
552 | *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) | ||
479 | { | 553 | { |
480 | return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,fp,a); | 554 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, |
555 | fp, a); | ||
481 | } | 556 | } |
482 | 557 | ||
483 | int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) | 558 | int |
484 | { | 559 | i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) |
485 | return ASN1_i2d_fp_of(EVP_PKEY,i2d_PUBKEY,fp,pkey); | 560 | { |
486 | } | 561 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PUBKEY, fp, pkey); |
562 | } | ||
487 | 563 | ||
488 | EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) | 564 | EVP_PKEY |
565 | *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) | ||
489 | { | 566 | { |
490 | return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,fp,a); | 567 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, fp, a); |
491 | } | 568 | } |
492 | 569 | ||
493 | #endif | 570 | #endif |
494 | 571 | ||
495 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, | 572 | PKCS8_PRIV_KEY_INFO |
496 | PKCS8_PRIV_KEY_INFO **p8inf) | 573 | *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, |
497 | { | 574 | PKCS8_PRIV_KEY_INFO **p8inf) |
498 | return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new, | 575 | { |
499 | d2i_PKCS8_PRIV_KEY_INFO,bp,p8inf); | 576 | return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, |
500 | } | 577 | d2i_PKCS8_PRIV_KEY_INFO, bp, p8inf); |
501 | 578 | } | |
502 | int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) | 579 | |
503 | { | 580 | int |
504 | return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,bp, | 581 | i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) |
505 | p8inf); | 582 | { |
506 | } | 583 | return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, |
507 | 584 | bp, p8inf); | |
508 | int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) | 585 | } |
509 | { | 586 | |
587 | int | ||
588 | i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) | ||
589 | { | ||
510 | PKCS8_PRIV_KEY_INFO *p8inf; | 590 | PKCS8_PRIV_KEY_INFO *p8inf; |
511 | int ret; | 591 | int ret; |
512 | p8inf = EVP_PKEY2PKCS8(key); | 592 | p8inf = EVP_PKEY2PKCS8(key); |
513 | if(!p8inf) return 0; | 593 | if (!p8inf) |
594 | return 0; | ||
514 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); | 595 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); |
515 | PKCS8_PRIV_KEY_INFO_free(p8inf); | 596 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
516 | return ret; | 597 | return ret; |
517 | } | 598 | } |
518 | 599 | ||
519 | int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) | 600 | int |
520 | { | 601 | i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) |
521 | return ASN1_i2d_bio_of(EVP_PKEY,i2d_PrivateKey,bp,pkey); | 602 | { |
522 | } | 603 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PrivateKey, bp, pkey); |
523 | 604 | } | |
524 | EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) | 605 | |
525 | { | 606 | EVP_PKEY |
526 | return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,bp,a); | 607 | *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) |
527 | } | 608 | { |
528 | 609 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, bp, a); | |
529 | int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) | 610 | } |
530 | { | 611 | |
531 | return ASN1_i2d_bio_of(EVP_PKEY,i2d_PUBKEY,bp,pkey); | 612 | int |
532 | } | 613 | i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) |
533 | 614 | { | |
534 | EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) | 615 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PUBKEY, bp, pkey); |
535 | { | 616 | } |
536 | return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,bp,a); | 617 | |
537 | } | 618 | EVP_PKEY |
619 | *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) | ||
620 | { | ||
621 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, bp, a); | ||
622 | } | ||