1 /*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #include <openssl/err.h>
11 #include <openssl/x509.h>
12
13
X509_STORE_set_default_paths(X509_STORE * ctx)14 int X509_STORE_set_default_paths(X509_STORE *ctx) {
15 X509_LOOKUP *lookup;
16
17 lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
18 if (lookup == NULL) {
19 return 0;
20 }
21 X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
22
23 lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
24 if (lookup == NULL) {
25 return 0;
26 }
27 X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
28
29 // clear any errors
30 ERR_clear_error();
31
32 return 1;
33 }
34
X509_STORE_load_locations(X509_STORE * ctx,const char * file,const char * path)35 int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
36 const char *path) {
37 X509_LOOKUP *lookup;
38
39 if (file != NULL) {
40 lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
41 if (lookup == NULL) {
42 return 0;
43 }
44 if (X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM) != 1) {
45 return 0;
46 }
47 }
48 if (path != NULL) {
49 lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
50 if (lookup == NULL) {
51 return 0;
52 }
53 if (X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1) {
54 return 0;
55 }
56 }
57 if ((path == NULL) && (file == NULL)) {
58 return 0;
59 }
60 return 1;
61 }
62