x509_d2.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 1995-2016 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. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/crypto.h>
  12. #include <openssl/x509.h>
  13. int X509_STORE_set_default_paths(X509_STORE *ctx)
  14. {
  15. X509_LOOKUP *lookup;
  16. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
  17. if (lookup == NULL)
  18. return 0;
  19. X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
  20. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
  21. if (lookup == NULL)
  22. return 0;
  23. X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
  24. /* clear any errors */
  25. ERR_clear_error();
  26. return 1;
  27. }
  28. int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
  29. const char *path)
  30. {
  31. X509_LOOKUP *lookup;
  32. if (file != NULL) {
  33. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
  34. if (lookup == NULL)
  35. return 0;
  36. if (X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM) != 1)
  37. return 0;
  38. }
  39. if (path != NULL) {
  40. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
  41. if (lookup == NULL)
  42. return 0;
  43. if (X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1)
  44. return 0;
  45. }
  46. if ((path == NULL) && (file == NULL))
  47. return 0;
  48. return 1;
  49. }