| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/err.h> |
| 16 | #include <openssl/x509.h> |
| 17 |
| 18 |
| 19 | int X509_STORE_set_default_paths(X509_STORE *ctx) { |
| 20 | X509_LOOKUP *lookup; |
| 21 |
| 22 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file()); |
| 23 | if (lookup == NULL) { |
| 24 | return 0; |
| 25 | } |
| 26 | X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT); |
| 27 |
| 28 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir()); |
| 29 | if (lookup == NULL) { |
| 30 | return 0; |
| 31 | } |
| 32 | X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); |
| 33 |
| 34 | // clear any errors |
| 35 | ERR_clear_error(); |
| 36 |
| 37 | return 1; |
| 38 | } |
| 39 |
| 40 | int X509_STORE_load_locations(X509_STORE *ctx, const char *file, |
| 41 | const char *path) { |
| 42 | X509_LOOKUP *lookup; |
| 43 |
| 44 | if (file != NULL) { |
| 45 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file()); |
| 46 | if (lookup == NULL) { |
| 47 | return 0; |
| 48 | } |
| 49 | if (X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM) != 1) { |
| 50 | return 0; |
| 51 | } |
| 52 | } |
| 53 | if (path != NULL) { |
| 54 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir()); |
| 55 | if (lookup == NULL) { |
| 56 | return 0; |
| 57 | } |
| 58 | if (X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1) { |
| 59 | return 0; |
| 60 | } |
| 61 | } |
| 62 | if ((path == NULL) && (file == NULL)) { |
| 63 | return 0; |
| 64 | } |
| 65 | return 1; |
| 66 | } |
| 67 |