store_local.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright 2016-2021 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 close;
  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. CRYPTO_RWLOCK *lock;
  91. OSSL_FUNC_store_open_fn *p_open;
  92. OSSL_FUNC_store_attach_fn *p_attach;
  93. OSSL_FUNC_store_settable_ctx_params_fn *p_settable_ctx_params;
  94. OSSL_FUNC_store_set_ctx_params_fn *p_set_ctx_params;
  95. OSSL_FUNC_store_load_fn *p_load;
  96. OSSL_FUNC_store_eof_fn *p_eof;
  97. OSSL_FUNC_store_close_fn *p_close;
  98. OSSL_FUNC_store_export_object_fn *p_export_object;
  99. };
  100. DEFINE_LHASH_OF(OSSL_STORE_LOADER);
  101. const OSSL_STORE_LOADER *ossl_store_get0_loader_int(const char *scheme);
  102. void ossl_store_destroy_loaders_int(void);
  103. #ifdef OPENSSL_NO_DEPRECATED_3_0
  104. /* struct ossl_store_loader_ctx_st is defined differently by each loader */
  105. typedef struct ossl_store_loader_ctx_st OSSL_STORE_LOADER_CTX;
  106. #endif
  107. /*-
  108. * OSSL_STORE_CTX stuff
  109. * ---------------------
  110. */
  111. struct ossl_store_ctx_st {
  112. const OSSL_STORE_LOADER *loader; /* legacy */
  113. OSSL_STORE_LOADER *fetched_loader;
  114. OSSL_STORE_LOADER_CTX *loader_ctx;
  115. OSSL_STORE_post_process_info_fn post_process;
  116. void *post_process_data;
  117. int expected_type;
  118. char *properties;
  119. /* 0 before the first STORE_load(), 1 otherwise */
  120. int loading;
  121. /* 1 on load error, only valid for fetched loaders */
  122. int error_flag;
  123. /*
  124. * Cache of stuff, to be able to return the contents of a PKCS#12
  125. * blob, one object at a time.
  126. */
  127. STACK_OF(OSSL_STORE_INFO) *cached_info;
  128. struct ossl_passphrase_data_st pwdata;
  129. };
  130. /*-
  131. * 'file' scheme stuff
  132. * -------------------
  133. */
  134. OSSL_STORE_LOADER_CTX *ossl_store_file_attach_pem_bio_int(BIO *bp);
  135. int ossl_store_file_detach_pem_bio_int(OSSL_STORE_LOADER_CTX *ctx);
  136. /*-
  137. * Provider stuff
  138. * -------------------
  139. */
  140. OSSL_STORE_LOADER *ossl_store_loader_fetch(OSSL_LIB_CTX *libctx,
  141. const char *scheme,
  142. const char *properties);
  143. OSSL_STORE_LOADER *ossl_store_loader_fetch_by_number(OSSL_LIB_CTX *libctx,
  144. int scheme_id,
  145. const char *properties);
  146. /* Standard function to handle the result from OSSL_FUNC_store_load() */
  147. struct ossl_load_result_data_st {
  148. OSSL_STORE_INFO *v; /* To be filled in */
  149. OSSL_STORE_CTX *ctx;
  150. };
  151. OSSL_CALLBACK ossl_store_handle_load_result;