1*cedac418Stb /* $OpenBSD: x509_d2.c,v 1.12 2023/02/16 08:38:17 tb Exp $ */
25b37fcf3Sryker /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
35b37fcf3Sryker * All rights reserved.
45b37fcf3Sryker *
55b37fcf3Sryker * This package is an SSL implementation written
65b37fcf3Sryker * by Eric Young (eay@cryptsoft.com).
75b37fcf3Sryker * The implementation was written so as to conform with Netscapes SSL.
85b37fcf3Sryker *
95b37fcf3Sryker * This library is free for commercial and non-commercial use as long as
105b37fcf3Sryker * the following conditions are aheared to. The following conditions
115b37fcf3Sryker * apply to all code found in this distribution, be it the RC4, RSA,
125b37fcf3Sryker * lhash, DES, etc., code; not just the SSL code. The SSL documentation
135b37fcf3Sryker * included with this distribution is covered by the same copyright terms
145b37fcf3Sryker * except that the holder is Tim Hudson (tjh@cryptsoft.com).
155b37fcf3Sryker *
165b37fcf3Sryker * Copyright remains Eric Young's, and as such any Copyright notices in
175b37fcf3Sryker * the code are not to be removed.
185b37fcf3Sryker * If this package is used in a product, Eric Young should be given attribution
195b37fcf3Sryker * as the author of the parts of the library used.
205b37fcf3Sryker * This can be in the form of a textual message at program startup or
215b37fcf3Sryker * in documentation (online or textual) provided with the package.
225b37fcf3Sryker *
235b37fcf3Sryker * Redistribution and use in source and binary forms, with or without
245b37fcf3Sryker * modification, are permitted provided that the following conditions
255b37fcf3Sryker * are met:
265b37fcf3Sryker * 1. Redistributions of source code must retain the copyright
275b37fcf3Sryker * notice, this list of conditions and the following disclaimer.
285b37fcf3Sryker * 2. Redistributions in binary form must reproduce the above copyright
295b37fcf3Sryker * notice, this list of conditions and the following disclaimer in the
305b37fcf3Sryker * documentation and/or other materials provided with the distribution.
315b37fcf3Sryker * 3. All advertising materials mentioning features or use of this software
325b37fcf3Sryker * must display the following acknowledgement:
335b37fcf3Sryker * "This product includes cryptographic software written by
345b37fcf3Sryker * Eric Young (eay@cryptsoft.com)"
355b37fcf3Sryker * The word 'cryptographic' can be left out if the rouines from the library
365b37fcf3Sryker * being used are not cryptographic related :-).
375b37fcf3Sryker * 4. If you include any Windows specific code (or a derivative thereof) from
385b37fcf3Sryker * the apps directory (application code) you must include an acknowledgement:
395b37fcf3Sryker * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
405b37fcf3Sryker *
415b37fcf3Sryker * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
425b37fcf3Sryker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
435b37fcf3Sryker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
445b37fcf3Sryker * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
455b37fcf3Sryker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
465b37fcf3Sryker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
475b37fcf3Sryker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
485b37fcf3Sryker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
495b37fcf3Sryker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
505b37fcf3Sryker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
515b37fcf3Sryker * SUCH DAMAGE.
525b37fcf3Sryker *
535b37fcf3Sryker * The licence and distribution terms for any publically available version or
545b37fcf3Sryker * derivative of this code cannot be changed. i.e. this code cannot simply be
555b37fcf3Sryker * copied and put under another distribution licence
565b37fcf3Sryker * [including the GNU Public Licence.]
575b37fcf3Sryker */
585b37fcf3Sryker
595b37fcf3Sryker #include <stdio.h>
60e0d5ea16Sreyk #include <sys/uio.h>
61b6ab114eSjsing
62913ec974Sbeck #include <openssl/crypto.h>
63b6ab114eSjsing #include <openssl/err.h>
64913ec974Sbeck #include <openssl/x509.h>
655b37fcf3Sryker
662e46ec26Sjsing int
X509_STORE_set_default_paths(X509_STORE * ctx)672e46ec26Sjsing X509_STORE_set_default_paths(X509_STORE *ctx)
685b37fcf3Sryker {
695b37fcf3Sryker X509_LOOKUP *lookup;
705b37fcf3Sryker
715b37fcf3Sryker lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
722e46ec26Sjsing if (lookup == NULL)
732e46ec26Sjsing return (0);
745b37fcf3Sryker X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
755b37fcf3Sryker
765b37fcf3Sryker lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
772e46ec26Sjsing if (lookup == NULL)
782e46ec26Sjsing return (0);
795b37fcf3Sryker X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
805b37fcf3Sryker
815b37fcf3Sryker /* clear any errors */
825b37fcf3Sryker ERR_clear_error();
835b37fcf3Sryker
845b37fcf3Sryker return (1);
855b37fcf3Sryker }
86*cedac418Stb LCRYPTO_ALIAS(X509_STORE_set_default_paths);
875b37fcf3Sryker
882e46ec26Sjsing int
X509_STORE_load_locations(X509_STORE * ctx,const char * file,const char * path)892e46ec26Sjsing X509_STORE_load_locations(X509_STORE *ctx, const char *file, const char *path)
905b37fcf3Sryker {
915b37fcf3Sryker X509_LOOKUP *lookup;
925b37fcf3Sryker
937609e5c6Stedu if (file != NULL) {
945b37fcf3Sryker lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
952e46ec26Sjsing if (lookup == NULL)
962e46ec26Sjsing return (0);
97ba5406e9Sbeck if (X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM) != 1)
98ba5406e9Sbeck return (0);
995b37fcf3Sryker }
1007609e5c6Stedu if (path != NULL) {
1015b37fcf3Sryker lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
1022e46ec26Sjsing if (lookup == NULL)
1032e46ec26Sjsing return (0);
104ba5406e9Sbeck if (X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1)
105ba5406e9Sbeck return (0);
1065b37fcf3Sryker }
1075b37fcf3Sryker if ((path == NULL) && (file == NULL))
1085b37fcf3Sryker return (0);
1095b37fcf3Sryker return (1);
1105b37fcf3Sryker }
111*cedac418Stb LCRYPTO_ALIAS(X509_STORE_load_locations);
112e0d5ea16Sreyk
113e0d5ea16Sreyk int
X509_STORE_load_mem(X509_STORE * ctx,void * buf,int len)114e0d5ea16Sreyk X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len)
115e0d5ea16Sreyk {
116e0d5ea16Sreyk X509_LOOKUP *lookup;
117e0d5ea16Sreyk struct iovec iov;
118e0d5ea16Sreyk
119e0d5ea16Sreyk lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_mem());
120e0d5ea16Sreyk if (lookup == NULL)
121e0d5ea16Sreyk return (0);
122e0d5ea16Sreyk
123e0d5ea16Sreyk iov.iov_base = buf;
124e0d5ea16Sreyk iov.iov_len = len;
125e0d5ea16Sreyk
126e0d5ea16Sreyk if (X509_LOOKUP_add_mem(lookup, &iov, X509_FILETYPE_PEM) != 1)
127e0d5ea16Sreyk return (0);
128e0d5ea16Sreyk
129e0d5ea16Sreyk return (1);
130e0d5ea16Sreyk }
131*cedac418Stb LCRYPTO_ALIAS(X509_STORE_load_mem);
132