2
0

x509_d2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_ex(X509_STORE *ctx, OSSL_LIB_CTX *libctx,
  14. const char *propq)
  15. {
  16. X509_LOOKUP *lookup;
  17. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file());
  18. if (lookup == NULL)
  19. return 0;
  20. X509_LOOKUP_load_file_ex(lookup, NULL, X509_FILETYPE_DEFAULT, libctx, propq);
  21. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir());
  22. if (lookup == NULL)
  23. return 0;
  24. X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
  25. lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store());
  26. if (lookup == NULL)
  27. return 0;
  28. X509_LOOKUP_add_store_ex(lookup, NULL, libctx, propq);
  29. /* clear any errors */
  30. ERR_clear_error();
  31. return 1;
  32. }
  33. int X509_STORE_set_default_paths(X509_STORE *ctx)
  34. {
  35. return X509_STORE_set_default_paths_ex(ctx, NULL, NULL);
  36. }
  37. int X509_STORE_load_file_ex(X509_STORE *ctx, const char *file,
  38. OSSL_LIB_CTX *libctx, const char *propq)
  39. {
  40. X509_LOOKUP *lookup;
  41. if (file == NULL
  42. || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file())) == NULL
  43. || X509_LOOKUP_load_file_ex(lookup, file, X509_FILETYPE_PEM, libctx,
  44. propq) <= 0)
  45. return 0;
  46. return 1;
  47. }
  48. int X509_STORE_load_file(X509_STORE *ctx, const char *file)
  49. {
  50. return X509_STORE_load_file_ex(ctx, file, NULL, NULL);
  51. }
  52. int X509_STORE_load_path(X509_STORE *ctx, const char *path)
  53. {
  54. X509_LOOKUP *lookup;
  55. if (path == NULL
  56. || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir())) == NULL
  57. || X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) <= 0)
  58. return 0;
  59. return 1;
  60. }
  61. int X509_STORE_load_store_ex(X509_STORE *ctx, const char *uri,
  62. OSSL_LIB_CTX *libctx, const char *propq)
  63. {
  64. X509_LOOKUP *lookup;
  65. if (uri == NULL
  66. || (lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_store())) == NULL
  67. || X509_LOOKUP_add_store_ex(lookup, uri, libctx, propq) == 0)
  68. return 0;
  69. return 1;
  70. }
  71. int X509_STORE_load_store(X509_STORE *ctx, const char *uri)
  72. {
  73. return X509_STORE_load_store_ex(ctx, uri, NULL, NULL);
  74. }
  75. int X509_STORE_load_locations_ex(X509_STORE *ctx, const char *file,
  76. const char *path, OSSL_LIB_CTX *libctx,
  77. const char *propq)
  78. {
  79. if (file == NULL && path == NULL)
  80. return 0;
  81. if (file != NULL && !X509_STORE_load_file_ex(ctx, file, libctx, propq))
  82. return 0;
  83. if (path != NULL && !X509_STORE_load_path(ctx, path))
  84. return 0;
  85. return 1;
  86. }
  87. int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
  88. const char *path)
  89. {
  90. return X509_STORE_load_locations_ex(ctx, file, path, NULL, NULL);
  91. }