store_local.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright 2016-2023 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 <openssl/core_dispatch.h>
  10. #include "internal/thread_once.h"
  11. #include "internal/refcount.h"
  12. #include <openssl/dsa.h>
  13. #include <openssl/engine.h>
  14. #include <openssl/evp.h>
  15. #include <openssl/lhash.h>
  16. #include <openssl/x509.h>
  17. #include <openssl/store.h>
  18. #include "internal/passphrase.h"
  19. /*-
  20. * OSSL_STORE_INFO stuff
  21. * ---------------------
  22. */
  23. struct ossl_store_info_st {
  24. int type;
  25. union {
  26. void *data; /* used internally as generic pointer */
  27. struct {
  28. char *name;
  29. char *desc;
  30. } name; /* when type == OSSL_STORE_INFO_NAME */
  31. EVP_PKEY *params; /* when type == OSSL_STORE_INFO_PARAMS */
  32. EVP_PKEY *pubkey; /* when type == OSSL_STORE_INFO_PUBKEY */
  33. EVP_PKEY *pkey; /* when type == OSSL_STORE_INFO_PKEY */
  34. X509 *x509; /* when type == OSSL_STORE_INFO_CERT */
  35. X509_CRL *crl; /* when type == OSSL_STORE_INFO_CRL */
  36. } _;
  37. };
  38. DEFINE_STACK_OF(OSSL_STORE_INFO)
  39. /*-
  40. * OSSL_STORE_SEARCH stuff
  41. * -----------------------
  42. */
  43. struct ossl_store_search_st {
  44. int search_type;
  45. /*
  46. * Used by OSSL_STORE_SEARCH_BY_NAME and
  47. * OSSL_STORE_SEARCH_BY_ISSUER_SERIAL
  48. */
  49. X509_NAME *name;
  50. /* Used by OSSL_STORE_SEARCH_BY_ISSUER_SERIAL */
  51. const ASN1_INTEGER *serial;
  52. /* Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT */
  53. const EVP_MD *digest;
  54. /*
  55. * Used by OSSL_STORE_SEARCH_BY_KEY_FINGERPRINT and
  56. * OSSL_STORE_SEARCH_BY_ALIAS
  57. */
  58. const unsigned char *string;
  59. size_t stringlength;
  60. };
  61. /*-
  62. * OSSL_STORE_LOADER stuff
  63. * -----------------------
  64. */
  65. int ossl_store_register_loader_int(OSSL_STORE_LOADER *loader);
  66. OSSL_STORE_LOADER *ossl_store_unregister_loader_int(const char *scheme);
  67. /* loader stuff */
  68. struct ossl_store_loader_st {
  69. #ifndef OPENSSL_NO_DEPRECATED_3_0
  70. /* Legacy stuff */
  71. const char *scheme;
  72. ENGINE *engine;
  73. OSSL_STORE_open_fn open;
  74. OSSL_STORE_attach_fn attach;
  75. OSSL_STORE_ctrl_fn ctrl;
  76. OSSL_STORE_expect_fn expect;
  77. OSSL_STORE_find_fn find;
  78. OSSL_STORE_load_fn load;
  79. OSSL_STORE_eof_fn eof;
  80. OSSL_STORE_error_fn error;
  81. OSSL_STORE_close_fn closefn;
  82. OSSL_STORE_open_ex_fn open_ex;
  83. #endif
  84. /* Provider stuff */
  85. OSSL_PROVIDER *prov;
  86. int scheme_id;
  87. const char *propdef;
  88. const char *description;
  89. CRYPTO_REF_COUNT refcnt;
  90. OSSL_FUNC_store_open_fn *p_open;
  91. OSSL_FUNC_store_attach_fn *p_attach;
  92. OSSL_FUNC_store_settable_ctx_params_fn *p_settable_ctx_params;
  93. OSSL_FUNC_store_set_ctx_params_fn *p_set_ctx_params;
  94. OSSL_FUNC_store_load_fn *p_load;
  95. OSSL_FUNC_store_eof_fn *p_eof;
  96. OSSL_FUNC_store_close_fn *p_close;
  97. OSSL_FUNC_store_export_object_fn *p_export_object;
  98. OSSL_FUNC_store_delete_fn *p_delete;
  99. OSSL_FUNC_store_open_ex_fn *p_open_ex;
  100. };
  101. DEFINE_LHASH_OF_EX(OSSL_STORE_LOADER);
  102. const OSSL_STORE_LOADER *ossl_store_get0_loader_int(const char *scheme);
  103. void ossl_store_destroy_loaders_int(void);
  104. #ifdef OPENSSL_NO_DEPRECATED_3_0
  105. /* struct ossl_store_loader_ctx_st is defined differently by each loader */
  106. typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX;
  107. #endif
  108. /*-
  109. * OSSL_STORE_CTX stuff
  110. * ---------------------
  111. */
  112. struct ossl_store_ctx_st {
  113. const OSSL_STORE_LOADER *loader; /* legacy */
  114. OSSL_STORE_LOADER *fetched_loader;
  115. OSSL_STORE_LOADER_CTX *loader_ctx;
  116. OSSL_STORE_post_process_info_fn post_process;
  117. void *post_process_data;
  118. int expected_type;
  119. char *properties;
  120. /* 0 before the first STORE_load(), 1 otherwise */
  121. int loading;
  122. /* 1 on load error, only valid for fetched loaders */
  123. int error_flag;
  124. /*
  125. * Cache of stuff, to be able to return the contents of a PKCS#12
  126. * blob, one object at a time.
  127. */
  128. STACK_OF(OSSL_STORE_INFO) *cached_info;
  129. struct ossl_passphrase_data_st pwdata;
  130. };
  131. /*-
  132. * 'file' scheme stuff
  133. * -------------------
  134. */
  135. OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp);
  136. int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx);
  137. /*-
  138. * Provider stuff
  139. * -------------------
  140. */
  141. OSSL_STORE_LOADER *ossl_store_loader_fetch(OSSL_LIB_CTX *libctx,
  142. const char *scheme,
  143. const char *properties);
  144. /* Standard function to handle the result from OSSL_FUNC_store_load() */
  145. struct ossl_load_result_data_st {
  146. OSSL_STORE_INFO *v; /* To be filled in */
  147. OSSL_STORE_CTX *ctx;
  148. };
  149. OSSL_CALLBACK ossl_store_handle_load_result;