| 1 |
/* |
| 2 |
* Copyright 1995-2024 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 |
/* |
| 34 |
* The NULL URI argument will activate any default URIs (presently none), |
| 35 |
* DO NOT pass the default CApath or CAfile, they're already handled above, |
| 36 |
* likely much more efficiently. |
| 37 |
*/ |
| 38 |
X509_LOOKUP_add_store_ex(lookup, NULL, libctx, propq); |
| 39 |
|
| 40 |
/* clear any errors */ |
| 41 |
ERR_clear_error(); |
| 42 |
|
| 43 |
return 1; |
| 44 |
} |
| 45 |
int X509_STORE_set_default_paths(X509_STORE *ctx) |
| 46 |
{ |
| 47 |
return X509_STORE_set_default_paths_ex(ctx, NULL, NULL); |
| 48 |
} |
| 49 |
|
| 50 |
int X509_STORE_load_file_ex(X509_STORE *ctx, const char *file, |
| 51 |
OSSL_LIB_CTX *libctx, const char *propq) |
| 52 |
{ |
| 53 |
X509_LOOKUP *lookup; |
| 54 |
|
| 55 |
if (file == NULL |
| 56 |
|| (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file())) == NULL |
| 57 |
|| X509_LOOKUP_load_file_ex(lookup, file, X509_FILETYPE_PEM, libctx, |
| 58 |
propq) |
| 59 |
<= 0) |
| 60 |
return 0; |
| 61 |
|
| 62 |
return 1; |
| 63 |
} |
| 64 |
|
| 65 |
int X509_STORE_load_file(X509_STORE *ctx, const char *file) |
| 66 |
{ |
| 67 |
return X509_STORE_load_file_ex(ctx, file, NULL, NULL); |
| 68 |
} |
| 69 |
|
| 70 |
int X509_STORE_load_path(X509_STORE *ctx, const char *path) |
| 71 |
{ |
| 72 |
X509_LOOKUP *lookup; |
| 73 |
|
| 74 |
if (path == NULL |
| 75 |
|| (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir())) == NULL |
| 76 |
|| X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) <= 0) |
| 77 |
return 0; |
| 78 |
|
| 79 |
return 1; |
| 80 |
} |
| 81 |
|
| 82 |
int X509_STORE_load_store_ex(X509_STORE *ctx, const char *uri, |
| 83 |
OSSL_LIB_CTX *libctx, const char *propq) |
| 84 |
{ |
| 85 |
X509_LOOKUP *lookup; |
| 86 |
|
| 87 |
if (uri == NULL |
| 88 |
|| (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store())) == NULL |
| 89 |
|| X509_LOOKUP_add_store_ex(lookup, uri, libctx, propq) == 0) |
| 90 |
return 0; |
| 91 |
|
| 92 |
return 1; |
| 93 |
} |
| 94 |
|
| 95 |
int X509_STORE_load_store(X509_STORE *ctx, const char *uri) |
| 96 |
{ |
| 97 |
return X509_STORE_load_store_ex(ctx, uri, NULL, NULL); |
| 98 |
} |
| 99 |
|
| 100 |
int X509_STORE_load_locations_ex(X509_STORE *ctx, const char *file, |
| 101 |
const char *path, OSSL_LIB_CTX *libctx, |
| 102 |
const char *propq) |
| 103 |
{ |
| 104 |
if (file == NULL && path == NULL) |
| 105 |
return 0; |
| 106 |
if (file != NULL && !X509_STORE_load_file_ex(ctx, file, libctx, propq)) |
| 107 |
return 0; |
| 108 |
if (path != NULL && !X509_STORE_load_path(ctx, path)) |
| 109 |
return 0; |
| 110 |
return 1; |
| 111 |
} |
| 112 |
|
| 113 |
int X509_STORE_load_locations(X509_STORE *ctx, const char *file, |
| 114 |
const char *path) |
| 115 |
{ |
| 116 |
return X509_STORE_load_locations_ex(ctx, file, path, NULL, NULL); |
| 117 |
} |