1 | /*
|
---|
2 | * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License 2.0 (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 <stdio.h>
|
---|
11 | #include "internal/cryptlib.h"
|
---|
12 | #include <openssl/crypto.h>
|
---|
13 | #include <openssl/x509.h>
|
---|
14 |
|
---|
15 | int X509_STORE_set_default_paths_ex(X509_STORE *ctx, OSSL_LIB_CTX *libctx,
|
---|
16 | const char *propq)
|
---|
17 | {
|
---|
18 | X509_LOOKUP *lookup;
|
---|
19 |
|
---|
20 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
|
---|
21 | if (lookup == NULL)
|
---|
22 | return 0;
|
---|
23 | X509_LOOKUP_load_file_ex(lookup, NULL, X509_FILETYPE_DEFAULT, libctx, propq);
|
---|
24 |
|
---|
25 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
|
---|
26 | if (lookup == NULL)
|
---|
27 | return 0;
|
---|
28 | X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
|
---|
29 |
|
---|
30 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store());
|
---|
31 | if (lookup == NULL)
|
---|
32 | return 0;
|
---|
33 | X509_LOOKUP_add_store_ex(lookup, NULL, libctx, propq);
|
---|
34 |
|
---|
35 | /* clear any errors */
|
---|
36 | ERR_clear_error();
|
---|
37 |
|
---|
38 | return 1;
|
---|
39 | }
|
---|
40 | int X509_STORE_set_default_paths(X509_STORE *ctx)
|
---|
41 | {
|
---|
42 | return X509_STORE_set_default_paths_ex(ctx, NULL, NULL);
|
---|
43 | }
|
---|
44 |
|
---|
45 | int X509_STORE_load_file_ex(X509_STORE *ctx, const char *file,
|
---|
46 | OSSL_LIB_CTX *libctx, const char *propq)
|
---|
47 | {
|
---|
48 | X509_LOOKUP *lookup;
|
---|
49 |
|
---|
50 | if (file == NULL
|
---|
51 | || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file())) == NULL
|
---|
52 | || X509_LOOKUP_load_file_ex(lookup, file, X509_FILETYPE_PEM, libctx,
|
---|
53 | propq) <= 0)
|
---|
54 | return 0;
|
---|
55 |
|
---|
56 | return 1;
|
---|
57 | }
|
---|
58 |
|
---|
59 | int X509_STORE_load_file(X509_STORE *ctx, const char *file)
|
---|
60 | {
|
---|
61 | return X509_STORE_load_file_ex(ctx, file, NULL, NULL);
|
---|
62 | }
|
---|
63 |
|
---|
64 | int X509_STORE_load_path(X509_STORE *ctx, const char *path)
|
---|
65 | {
|
---|
66 | X509_LOOKUP *lookup;
|
---|
67 |
|
---|
68 | if (path == NULL
|
---|
69 | || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir())) == NULL
|
---|
70 | || X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) <= 0)
|
---|
71 | return 0;
|
---|
72 |
|
---|
73 | return 1;
|
---|
74 | }
|
---|
75 |
|
---|
76 | int X509_STORE_load_store_ex(X509_STORE *ctx, const char *uri,
|
---|
77 | OSSL_LIB_CTX *libctx, const char *propq)
|
---|
78 | {
|
---|
79 | X509_LOOKUP *lookup;
|
---|
80 |
|
---|
81 | if (uri == NULL
|
---|
82 | || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store())) == NULL
|
---|
83 | || X509_LOOKUP_add_store_ex(lookup, uri, libctx, propq) == 0)
|
---|
84 | return 0;
|
---|
85 |
|
---|
86 | return 1;
|
---|
87 | }
|
---|
88 |
|
---|
89 | int X509_STORE_load_store(X509_STORE *ctx, const char *uri)
|
---|
90 | {
|
---|
91 | return X509_STORE_load_store_ex(ctx, uri, NULL, NULL);
|
---|
92 | }
|
---|
93 |
|
---|
94 | int X509_STORE_load_locations_ex(X509_STORE *ctx, const char *file,
|
---|
95 | const char *path, OSSL_LIB_CTX *libctx,
|
---|
96 | const char *propq)
|
---|
97 | {
|
---|
98 | if (file == NULL && path == NULL)
|
---|
99 | return 0;
|
---|
100 | if (file != NULL && !X509_STORE_load_file_ex(ctx, file, libctx, propq))
|
---|
101 | return 0;
|
---|
102 | if (path != NULL && !X509_STORE_load_path(ctx, path))
|
---|
103 | return 0;
|
---|
104 | return 1;
|
---|
105 | }
|
---|
106 |
|
---|
107 | int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
|
---|
108 | const char *path)
|
---|
109 | {
|
---|
110 | return X509_STORE_load_locations_ex(ctx, file, path, NULL, NULL);
|
---|
111 | }
|
---|