summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509_d2.c
diff options
context:
space:
mode:
authorreyk <>2015-01-22 09:06:39 +0000
committerreyk <>2015-01-22 09:06:39 +0000
commitca23f8d50feee83817e664343b752ce0b985dfb5 (patch)
tree36f1b0fc5da8868b5097698833f099e006a10cb8 /src/lib/libcrypto/x509/x509_d2.c
parent65761bc9c2faf702c095e77e75e6c713cb579cd8 (diff)
downloadopenbsd-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/lib/libcrypto/x509/x509_d2.c')
-rw-r--r--src/lib/libcrypto/x509/x509_d2.c22
1 files changed, 21 insertions, 1 deletions
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
111int
112X509_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}