diff options
author | reyk <> | 2015-01-22 09:06:39 +0000 |
---|---|---|
committer | reyk <> | 2015-01-22 09:06:39 +0000 |
commit | ca23f8d50feee83817e664343b752ce0b985dfb5 (patch) | |
tree | 36f1b0fc5da8868b5097698833f099e006a10cb8 /src | |
parent | 65761bc9c2faf702c095e77e75e6c713cb579cd8 (diff) | |
download | openbsd-ca23f8d50feee83817e664343b752ce0b985dfb5.tar.gz openbsd-ca23f8d50feee83817e664343b752ce0b985dfb5.tar.bz2 openbsd-ca23f8d50feee83817e664343b752ce0b985dfb5.zip |
Add X509_STORE_load_mem() to load certificates from a memory buffer
instead of disk. OpenSSL didn't provide a built-in API from loading
certificates in a chroot'ed process that doesn't have direct access to
the files. X509_STORE_load_mem() provides a new backend that will be
used by libssl and libtls to implement such privsep-friendly
functionality.
Adopted for LibreSSL based on older code from relayd (by pyr@ and myself)
With feedback and OK bluhm@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/crypto/Makefile | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto/shlib_version | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/shlib_version | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/by_mem.c | 138 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_d2.c | 22 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_vfy.h | 9 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/by_mem.c | 138 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_d2.c | 22 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_vfy.h | 9 |
9 files changed, 338 insertions, 8 deletions
diff --git a/src/lib/libcrypto/crypto/Makefile b/src/lib/libcrypto/crypto/Makefile index f1e54659e6..84b8a6e953 100644 --- a/src/lib/libcrypto/crypto/Makefile +++ b/src/lib/libcrypto/crypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.51 2014/12/03 22:14:38 bcook Exp $ | 1 | # $OpenBSD: Makefile,v 1.52 2015/01/22 09:06:39 reyk Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | 4 | ||
@@ -256,7 +256,7 @@ SRCS+= x509_obj.c x509_req.c x509spki.c x509_vfy.c | |||
256 | SRCS+= x509_set.c x509cset.c x509rset.c x509_err.c | 256 | SRCS+= x509_set.c x509cset.c x509rset.c x509_err.c |
257 | SRCS+= x509name.c x509_v3.c x509_ext.c x509_att.c | 257 | SRCS+= x509name.c x509_v3.c x509_ext.c x509_att.c |
258 | SRCS+= x509type.c x509_lu.c x_all.c x509_txt.c | 258 | SRCS+= x509type.c x509_lu.c x_all.c x509_txt.c |
259 | SRCS+= x509_trs.c by_file.c by_dir.c x509_vpm.c | 259 | SRCS+= x509_trs.c by_file.c by_dir.c by_mem.c x509_vpm.c |
260 | 260 | ||
261 | # x509v3/ | 261 | # x509v3/ |
262 | SRCS+= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c v3_lib.c | 262 | SRCS+= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c v3_lib.c |
diff --git a/src/lib/libcrypto/crypto/shlib_version b/src/lib/libcrypto/crypto/shlib_version index ac20b1fad5..06b524dace 100644 --- a/src/lib/libcrypto/crypto/shlib_version +++ b/src/lib/libcrypto/crypto/shlib_version | |||
@@ -1,2 +1,2 @@ | |||
1 | major=30 | 1 | major=30 |
2 | minor=3 | 2 | minor=4 |
diff --git a/src/lib/libcrypto/shlib_version b/src/lib/libcrypto/shlib_version index ac20b1fad5..06b524dace 100644 --- a/src/lib/libcrypto/shlib_version +++ b/src/lib/libcrypto/shlib_version | |||
@@ -1,2 +1,2 @@ | |||
1 | major=30 | 1 | major=30 |
2 | minor=3 | 2 | minor=4 |
diff --git a/src/lib/libcrypto/x509/by_mem.c b/src/lib/libcrypto/x509/by_mem.c new file mode 100644 index 0000000000..6a6ae96131 --- /dev/null +++ b/src/lib/libcrypto/x509/by_mem.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* $OpenBSD: by_mem.c,v 1.1 2015/01/22 09:06:39 reyk Exp $ */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <sys/uio.h> | ||
60 | #include <errno.h> | ||
61 | #include <stdio.h> | ||
62 | #include <time.h> | ||
63 | #include <unistd.h> | ||
64 | |||
65 | #include <openssl/buffer.h> | ||
66 | #include <openssl/err.h> | ||
67 | #include <openssl/pem.h> | ||
68 | #include <openssl/lhash.h> | ||
69 | #include <openssl/x509.h> | ||
70 | |||
71 | static int by_mem_ctrl(X509_LOOKUP *, int, const char *, long, char **); | ||
72 | |||
73 | X509_LOOKUP_METHOD x509_mem_lookup = { | ||
74 | "Load cert from memory", | ||
75 | NULL, /* new */ | ||
76 | NULL, /* free */ | ||
77 | NULL, /* init */ | ||
78 | NULL, /* shutdown */ | ||
79 | by_mem_ctrl, /* ctrl */ | ||
80 | NULL, /* get_by_subject */ | ||
81 | NULL, /* get_by_issuer_serial */ | ||
82 | NULL, /* get_by_fingerprint */ | ||
83 | NULL, /* get_by_alias */ | ||
84 | }; | ||
85 | |||
86 | X509_LOOKUP_METHOD * | ||
87 | X509_LOOKUP_mem(void) | ||
88 | { | ||
89 | return (&x509_mem_lookup); | ||
90 | } | ||
91 | |||
92 | static int | ||
93 | by_mem_ctrl(X509_LOOKUP *lu, int cmd, const char *buf, | ||
94 | long type, char **ret) | ||
95 | { | ||
96 | STACK_OF(X509_INFO) *inf = NULL; | ||
97 | const struct iovec *iov; | ||
98 | X509_INFO *itmp; | ||
99 | BIO *in = NULL; | ||
100 | int i, count = 0, ok = 0; | ||
101 | |||
102 | iov = (const struct iovec *)buf; | ||
103 | |||
104 | if (!(cmd == X509_L_MEM && type == X509_FILETYPE_PEM)) | ||
105 | goto done; | ||
106 | |||
107 | if ((in = BIO_new_mem_buf(iov->iov_base, iov->iov_len)) == NULL) | ||
108 | goto done; | ||
109 | |||
110 | if ((inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL)) == NULL) | ||
111 | goto done; | ||
112 | |||
113 | for (i = 0; i < sk_X509_INFO_num(inf); i++) { | ||
114 | itmp = sk_X509_INFO_value(inf, i); | ||
115 | if (itmp->x509) { | ||
116 | ok = X509_STORE_add_cert(lu->store_ctx, itmp->x509); | ||
117 | if (!ok) | ||
118 | goto done; | ||
119 | count++; | ||
120 | } | ||
121 | if (itmp->crl) { | ||
122 | ok = X509_STORE_add_crl(lu->store_ctx, itmp->crl); | ||
123 | if (!ok) | ||
124 | goto done; | ||
125 | count++; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | ok = count != 0; | ||
130 | done: | ||
131 | if (count == 0) | ||
132 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); | ||
133 | if (inf != NULL) | ||
134 | sk_X509_INFO_pop_free(inf, X509_INFO_free); | ||
135 | if (in != NULL) | ||
136 | BIO_free(in); | ||
137 | return (ok); | ||
138 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c index cc22f4f470..5b0f80adda 100644 --- a/src/lib/libcrypto/x509/x509_d2.c +++ b/src/lib/libcrypto/x509/x509_d2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_d2.c,v 1.9 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: x509_d2.c,v 1.10 2015/01/22 09:06:39 reyk Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <sys/uio.h> | ||
60 | 61 | ||
61 | #include <openssl/crypto.h> | 62 | #include <openssl/crypto.h> |
62 | #include <openssl/err.h> | 63 | #include <openssl/err.h> |
@@ -106,3 +107,22 @@ X509_STORE_load_locations(X509_STORE *ctx, const char *file, const char *path) | |||
106 | return (0); | 107 | return (0); |
107 | return (1); | 108 | return (1); |
108 | } | 109 | } |
110 | |||
111 | int | ||
112 | X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len) | ||
113 | { | ||
114 | X509_LOOKUP *lookup; | ||
115 | struct iovec iov; | ||
116 | |||
117 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_mem()); | ||
118 | if (lookup == NULL) | ||
119 | return (0); | ||
120 | |||
121 | iov.iov_base = buf; | ||
122 | iov.iov_len = len; | ||
123 | |||
124 | if (X509_LOOKUP_add_mem(lookup, &iov, X509_FILETYPE_PEM) != 1) | ||
125 | return (0); | ||
126 | |||
127 | return (1); | ||
128 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h index 5b411ca678..500b520495 100644 --- a/src/lib/libcrypto/x509/x509_vfy.h +++ b/src/lib/libcrypto/x509/x509_vfy.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_vfy.h,v 1.13 2014/07/10 22:45:58 jsing Exp $ */ | 1 | /* $OpenBSD: x509_vfy.h,v 1.14 2015/01/22 09:06:39 reyk Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -286,6 +286,7 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); | |||
286 | 286 | ||
287 | #define X509_L_FILE_LOAD 1 | 287 | #define X509_L_FILE_LOAD 1 |
288 | #define X509_L_ADD_DIR 2 | 288 | #define X509_L_ADD_DIR 2 |
289 | #define X509_L_MEM 3 | ||
289 | 290 | ||
290 | #define X509_LOOKUP_load_file(x,name,type) \ | 291 | #define X509_LOOKUP_load_file(x,name,type) \ |
291 | X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) | 292 | X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) |
@@ -293,6 +294,10 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); | |||
293 | #define X509_LOOKUP_add_dir(x,name,type) \ | 294 | #define X509_LOOKUP_add_dir(x,name,type) \ |
294 | X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) | 295 | X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) |
295 | 296 | ||
297 | #define X509_LOOKUP_add_mem(x,iov,type) \ | ||
298 | X509_LOOKUP_ctrl((x),X509_L_MEM,(const char *)(iov),\ | ||
299 | (long)(type),NULL) | ||
300 | |||
296 | #define X509_V_OK 0 | 301 | #define X509_V_OK 0 |
297 | /* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */ | 302 | /* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */ |
298 | 303 | ||
@@ -436,6 +441,7 @@ X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); | |||
436 | 441 | ||
437 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); | 442 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); |
438 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void); | 443 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void); |
444 | X509_LOOKUP_METHOD *X509_LOOKUP_mem(void); | ||
439 | 445 | ||
440 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); | 446 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); |
441 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); | 447 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); |
@@ -466,6 +472,7 @@ int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); | |||
466 | 472 | ||
467 | int X509_STORE_load_locations (X509_STORE *ctx, | 473 | int X509_STORE_load_locations (X509_STORE *ctx, |
468 | const char *file, const char *dir); | 474 | const char *file, const char *dir); |
475 | int X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len); | ||
469 | int X509_STORE_set_default_paths(X509_STORE *ctx); | 476 | int X509_STORE_set_default_paths(X509_STORE *ctx); |
470 | 477 | ||
471 | int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 478 | int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
diff --git a/src/lib/libssl/src/crypto/x509/by_mem.c b/src/lib/libssl/src/crypto/x509/by_mem.c new file mode 100644 index 0000000000..6a6ae96131 --- /dev/null +++ b/src/lib/libssl/src/crypto/x509/by_mem.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* $OpenBSD: by_mem.c,v 1.1 2015/01/22 09:06:39 reyk Exp $ */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <sys/uio.h> | ||
60 | #include <errno.h> | ||
61 | #include <stdio.h> | ||
62 | #include <time.h> | ||
63 | #include <unistd.h> | ||
64 | |||
65 | #include <openssl/buffer.h> | ||
66 | #include <openssl/err.h> | ||
67 | #include <openssl/pem.h> | ||
68 | #include <openssl/lhash.h> | ||
69 | #include <openssl/x509.h> | ||
70 | |||
71 | static int by_mem_ctrl(X509_LOOKUP *, int, const char *, long, char **); | ||
72 | |||
73 | X509_LOOKUP_METHOD x509_mem_lookup = { | ||
74 | "Load cert from memory", | ||
75 | NULL, /* new */ | ||
76 | NULL, /* free */ | ||
77 | NULL, /* init */ | ||
78 | NULL, /* shutdown */ | ||
79 | by_mem_ctrl, /* ctrl */ | ||
80 | NULL, /* get_by_subject */ | ||
81 | NULL, /* get_by_issuer_serial */ | ||
82 | NULL, /* get_by_fingerprint */ | ||
83 | NULL, /* get_by_alias */ | ||
84 | }; | ||
85 | |||
86 | X509_LOOKUP_METHOD * | ||
87 | X509_LOOKUP_mem(void) | ||
88 | { | ||
89 | return (&x509_mem_lookup); | ||
90 | } | ||
91 | |||
92 | static int | ||
93 | by_mem_ctrl(X509_LOOKUP *lu, int cmd, const char *buf, | ||
94 | long type, char **ret) | ||
95 | { | ||
96 | STACK_OF(X509_INFO) *inf = NULL; | ||
97 | const struct iovec *iov; | ||
98 | X509_INFO *itmp; | ||
99 | BIO *in = NULL; | ||
100 | int i, count = 0, ok = 0; | ||
101 | |||
102 | iov = (const struct iovec *)buf; | ||
103 | |||
104 | if (!(cmd == X509_L_MEM && type == X509_FILETYPE_PEM)) | ||
105 | goto done; | ||
106 | |||
107 | if ((in = BIO_new_mem_buf(iov->iov_base, iov->iov_len)) == NULL) | ||
108 | goto done; | ||
109 | |||
110 | if ((inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL)) == NULL) | ||
111 | goto done; | ||
112 | |||
113 | for (i = 0; i < sk_X509_INFO_num(inf); i++) { | ||
114 | itmp = sk_X509_INFO_value(inf, i); | ||
115 | if (itmp->x509) { | ||
116 | ok = X509_STORE_add_cert(lu->store_ctx, itmp->x509); | ||
117 | if (!ok) | ||
118 | goto done; | ||
119 | count++; | ||
120 | } | ||
121 | if (itmp->crl) { | ||
122 | ok = X509_STORE_add_crl(lu->store_ctx, itmp->crl); | ||
123 | if (!ok) | ||
124 | goto done; | ||
125 | count++; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | ok = count != 0; | ||
130 | done: | ||
131 | if (count == 0) | ||
132 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); | ||
133 | if (inf != NULL) | ||
134 | sk_X509_INFO_pop_free(inf, X509_INFO_free); | ||
135 | if (in != NULL) | ||
136 | BIO_free(in); | ||
137 | return (ok); | ||
138 | } | ||
diff --git a/src/lib/libssl/src/crypto/x509/x509_d2.c b/src/lib/libssl/src/crypto/x509/x509_d2.c index cc22f4f470..5b0f80adda 100644 --- a/src/lib/libssl/src/crypto/x509/x509_d2.c +++ b/src/lib/libssl/src/crypto/x509/x509_d2.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_d2.c,v 1.9 2014/07/11 08:44:49 jsing Exp $ */ | 1 | /* $OpenBSD: x509_d2.c,v 1.10 2015/01/22 09:06:39 reyk Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <sys/uio.h> | ||
60 | 61 | ||
61 | #include <openssl/crypto.h> | 62 | #include <openssl/crypto.h> |
62 | #include <openssl/err.h> | 63 | #include <openssl/err.h> |
@@ -106,3 +107,22 @@ X509_STORE_load_locations(X509_STORE *ctx, const char *file, const char *path) | |||
106 | return (0); | 107 | return (0); |
107 | return (1); | 108 | return (1); |
108 | } | 109 | } |
110 | |||
111 | int | ||
112 | X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len) | ||
113 | { | ||
114 | X509_LOOKUP *lookup; | ||
115 | struct iovec iov; | ||
116 | |||
117 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_mem()); | ||
118 | if (lookup == NULL) | ||
119 | return (0); | ||
120 | |||
121 | iov.iov_base = buf; | ||
122 | iov.iov_len = len; | ||
123 | |||
124 | if (X509_LOOKUP_add_mem(lookup, &iov, X509_FILETYPE_PEM) != 1) | ||
125 | return (0); | ||
126 | |||
127 | return (1); | ||
128 | } | ||
diff --git a/src/lib/libssl/src/crypto/x509/x509_vfy.h b/src/lib/libssl/src/crypto/x509/x509_vfy.h index 5b411ca678..500b520495 100644 --- a/src/lib/libssl/src/crypto/x509/x509_vfy.h +++ b/src/lib/libssl/src/crypto/x509/x509_vfy.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_vfy.h,v 1.13 2014/07/10 22:45:58 jsing Exp $ */ | 1 | /* $OpenBSD: x509_vfy.h,v 1.14 2015/01/22 09:06:39 reyk Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -286,6 +286,7 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); | |||
286 | 286 | ||
287 | #define X509_L_FILE_LOAD 1 | 287 | #define X509_L_FILE_LOAD 1 |
288 | #define X509_L_ADD_DIR 2 | 288 | #define X509_L_ADD_DIR 2 |
289 | #define X509_L_MEM 3 | ||
289 | 290 | ||
290 | #define X509_LOOKUP_load_file(x,name,type) \ | 291 | #define X509_LOOKUP_load_file(x,name,type) \ |
291 | X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) | 292 | X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) |
@@ -293,6 +294,10 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); | |||
293 | #define X509_LOOKUP_add_dir(x,name,type) \ | 294 | #define X509_LOOKUP_add_dir(x,name,type) \ |
294 | X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) | 295 | X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) |
295 | 296 | ||
297 | #define X509_LOOKUP_add_mem(x,iov,type) \ | ||
298 | X509_LOOKUP_ctrl((x),X509_L_MEM,(const char *)(iov),\ | ||
299 | (long)(type),NULL) | ||
300 | |||
296 | #define X509_V_OK 0 | 301 | #define X509_V_OK 0 |
297 | /* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */ | 302 | /* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */ |
298 | 303 | ||
@@ -436,6 +441,7 @@ X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); | |||
436 | 441 | ||
437 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); | 442 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); |
438 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void); | 443 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void); |
444 | X509_LOOKUP_METHOD *X509_LOOKUP_mem(void); | ||
439 | 445 | ||
440 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); | 446 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); |
441 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); | 447 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); |
@@ -466,6 +472,7 @@ int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); | |||
466 | 472 | ||
467 | int X509_STORE_load_locations (X509_STORE *ctx, | 473 | int X509_STORE_load_locations (X509_STORE *ctx, |
468 | const char *file, const char *dir); | 474 | const char *file, const char *dir); |
475 | int X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len); | ||
469 | int X509_STORE_set_default_paths(X509_STORE *ctx); | 476 | int X509_STORE_set_default_paths(X509_STORE *ctx); |
470 | 477 | ||
471 | int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 478 | int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |