x509_d2.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 1995-2020 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. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store());
  25. if (lookup == NULL)
  26. return 0;
  27. X509_LOOKUP_add_store(lookup, NULL);
  28. /* clear any errors */
  29. ERR_clear_error();
  30. return 1;
  31. }
  32. int X509_STORE_load_file(X509_STORE *ctx, const char *file)
  33. {
  34. X509_LOOKUP *lookup;
  35. if (file == NULL
  36. || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file())) == NULL
  37. || X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM) == 0)
  38. return 0;
  39. return 1;
  40. }
  41. int X509_STORE_load_path(X509_STORE *ctx, const char *path)
  42. {
  43. X509_LOOKUP *lookup;
  44. if (path == NULL
  45. || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir())) == NULL
  46. || X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) == 0)
  47. return 0;
  48. return 1;
  49. }
  50. int X509_STORE_load_store(X509_STORE *ctx, const char *uri)
  51. {
  52. X509_LOOKUP *lookup;
  53. if (uri == NULL
  54. || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store())) == NULL
  55. || X509_LOOKUP_add_store(lookup, uri) == 0)
  56. return 0;
  57. return 1;
  58. }
  59. int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
  60. const char *path)
  61. {
  62. if (file == NULL && path == NULL)
  63. return 0;
  64. if (file != NULL && !X509_STORE_load_file(ctx, file))
  65. return 0;
  66. if (path != NULL && !X509_STORE_load_path(ctx, path))
  67. return 0;
  68. return 1;
  69. }