]>
Commit | Line | Data |
---|---|---|
b1322259 | 1 | /* |
00c405b3 | 2 | * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
3e4b43b9 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
ec577822 BM |
12 | #include <openssl/crypto.h> |
13 | #include <openssl/x509.h> | |
d02b48c6 | 14 | |
6725682d SL |
15 | int X509_STORE_set_default_paths_with_libctx(X509_STORE *ctx, |
16 | OPENSSL_CTX *libctx, | |
17 | const char *propq) | |
0f113f3e MC |
18 | { |
19 | X509_LOOKUP *lookup; | |
20 | ||
21 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file()); | |
22 | if (lookup == NULL) | |
26a7d938 | 23 | return 0; |
6725682d SL |
24 | X509_LOOKUP_load_file_with_libctx(lookup, NULL, X509_FILETYPE_DEFAULT, |
25 | libctx, propq); | |
d02b48c6 | 26 | |
0f113f3e MC |
27 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir()); |
28 | if (lookup == NULL) | |
26a7d938 | 29 | return 0; |
0f113f3e | 30 | X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); |
d02b48c6 | 31 | |
6dcb100f RL |
32 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store()); |
33 | if (lookup == NULL) | |
34 | return 0; | |
6725682d | 35 | X509_LOOKUP_add_store_with_libctx(lookup, NULL, libctx, propq); |
6dcb100f | 36 | |
0f113f3e MC |
37 | /* clear any errors */ |
38 | ERR_clear_error(); | |
d02b48c6 | 39 | |
208fb891 | 40 | return 1; |
0f113f3e | 41 | } |
6725682d SL |
42 | int X509_STORE_set_default_paths(X509_STORE *ctx) |
43 | { | |
44 | return X509_STORE_set_default_paths_with_libctx(ctx, NULL, NULL); | |
45 | } | |
d02b48c6 | 46 | |
6725682d SL |
47 | int X509_STORE_load_file_with_libctx(X509_STORE *ctx, const char *file, |
48 | OPENSSL_CTX *libctx, const char *propq) | |
6dcb100f RL |
49 | { |
50 | X509_LOOKUP *lookup; | |
51 | ||
52 | if (file == NULL | |
53 | || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file())) == NULL | |
6725682d SL |
54 | || X509_LOOKUP_load_file_with_libctx(lookup, file, X509_FILETYPE_PEM, |
55 | libctx, propq) == 0) | |
6dcb100f RL |
56 | return 0; |
57 | ||
58 | return 1; | |
59 | } | |
60 | ||
6725682d SL |
61 | int X509_STORE_load_file(X509_STORE *ctx, const char *file) |
62 | { | |
63 | return X509_STORE_load_file_with_libctx(ctx, file, NULL, NULL); | |
64 | } | |
65 | ||
6dcb100f | 66 | int X509_STORE_load_path(X509_STORE *ctx, const char *path) |
0f113f3e MC |
67 | { |
68 | X509_LOOKUP *lookup; | |
d02b48c6 | 69 | |
6dcb100f RL |
70 | if (path == NULL |
71 | || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir())) == NULL | |
72 | || X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) == 0) | |
73 | return 0; | |
74 | ||
75 | return 1; | |
76 | } | |
77 | ||
6725682d SL |
78 | int X509_STORE_load_store_with_libctx(X509_STORE *ctx, const char *uri, |
79 | OPENSSL_CTX *libctx, const char *propq) | |
6dcb100f RL |
80 | { |
81 | X509_LOOKUP *lookup; | |
82 | ||
83 | if (uri == NULL | |
84 | || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store())) == NULL | |
6725682d | 85 | || X509_LOOKUP_add_store_with_libctx(lookup, uri, libctx, propq) == 0) |
6dcb100f RL |
86 | return 0; |
87 | ||
88 | return 1; | |
89 | } | |
90 | ||
6725682d SL |
91 | int X509_STORE_load_store(X509_STORE *ctx, const char *uri) |
92 | { | |
93 | return X509_STORE_load_store_with_libctx(ctx, uri, NULL, NULL); | |
94 | } | |
95 | ||
96 | int X509_STORE_load_locations_with_libctx(X509_STORE *ctx, const char *file, | |
97 | const char *path, | |
98 | OPENSSL_CTX *libctx, const char *propq) | |
6dcb100f RL |
99 | { |
100 | if (file == NULL && path == NULL) | |
101 | return 0; | |
6725682d SL |
102 | if (file != NULL && !X509_STORE_load_file_with_libctx(ctx, file, |
103 | libctx, propq)) | |
6dcb100f RL |
104 | return 0; |
105 | if (path != NULL && !X509_STORE_load_path(ctx, path)) | |
26a7d938 | 106 | return 0; |
208fb891 | 107 | return 1; |
0f113f3e | 108 | } |
6725682d SL |
109 | |
110 | int X509_STORE_load_locations(X509_STORE *ctx, const char *file, | |
111 | const char *path) | |
112 | { | |
113 | return X509_STORE_load_locations_with_libctx(ctx, file, path, NULL, NULL); | |
114 | } |