esp_asio_openssl_stubs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ESP_ASIO_OPENSSL_STUBS_H
  7. #define _ESP_ASIO_OPENSSL_STUBS_H
  8. /**
  9. * @note This header contains openssl API which are NOT implemented, and are only provided
  10. * as stubs or no-operations to get the ASIO library compiled and working with most
  11. * practical use cases as an embedded application on ESP platform
  12. */
  13. #if defined(ASIO_USE_WOLFSSL)
  14. #include "wolfssl/ssl.h"
  15. // esp-wolfssl disables filesystem by default, but the ssl filesystem functions are needed for the ASIO to compile
  16. // - so we could either configure wolfSSL to use filesystem
  17. // - or use the default wolfSSL and declare the filesystem functions -- preferred option, as whenever
  18. // the filesystem functions are used from app code (potential security impact if private keys in a filesystem)
  19. // compilation fails with linking errors.
  20. #if defined(NO_FILESYSTEM)
  21. // WolfSSL methods that are not included in standard esp-wolfssl config, must be defined here
  22. // as function stubs, so ASIO compiles, but would get link errors, if these functions were used.
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. typedef struct WOLFSSL_CTX WOLFSSL_CTX;
  27. void wolfSSL_CTX_set_verify_depth(WOLFSSL_CTX *ctx,int depth);
  28. int SSL_CTX_load_verify_locations(WOLFSSL_CTX*, const char*, const char*);
  29. int SSL_CTX_use_certificate_file(WOLFSSL_CTX*, const char*, int);
  30. int SSL_CTX_use_certificate_chain_file(WOLFSSL_CTX*, const char*);
  31. int SSL_CTX_use_PrivateKey_file(WOLFSSL_CTX*, const char*, int);
  32. int SSL_CTX_use_RSAPrivateKey_file(WOLFSSL_CTX*, const char*, int);
  33. #if defined(__cplusplus)
  34. } /* extern C */
  35. #endif
  36. #endif // NO_FILESYSTEM
  37. #elif defined(ASIO_USE_ESP_OPENSSL)
  38. #include "internal/ssl_x509.h"
  39. #include "internal/ssl_pkey.h"
  40. #include "mbedtls/pem.h"
  41. #include <stdint.h>
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. // The most applicable OpenSSL version wrtt ASIO usage
  46. #define OPENSSL_VERSION_NUMBER 0x10100001L
  47. // SSLv2 methods not supported
  48. // OpenSSL port supports: TLS_ANY, TLS_1, TLS_1_1, TLS_1_2, SSL_3
  49. #define OPENSSL_NO_SSL2
  50. #define SSL2_VERSION 0x0002
  51. #define SSL_R_SHORT_READ 219
  52. #define SSL_OP_ALL 0
  53. #define SSL_OP_SINGLE_DH_USE 0
  54. #define SSL_OP_NO_COMPRESSION 0
  55. // Translates mbedTLS PEM parse error, used by ASIO
  56. #define PEM_R_NO_START_LINE -MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT
  57. #define SSL_OP_NO_SSLv2 0x01000000L
  58. #define SSL_OP_NO_SSLv3 0x02000000L
  59. #define SSL_OP_NO_TLSv1 0x04000000L
  60. #define X509_FILETYPE_PEM 1
  61. #define X509_FILETYPE_ASN1 2
  62. #define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
  63. #define SSL_FILETYPE_PEM X509_FILETYPE_PEM
  64. #define NID_subject_alt_name 85
  65. #define GEN_DNS 2
  66. #define GEN_IPADD 7
  67. #define V_ASN1_OCTET_STRING 4
  68. #define V_ASN1_IA5STRING 22
  69. #define NID_commonName 13
  70. #define SSL_CTX_get_app_data(ctx) ((void*)SSL_CTX_get_ex_data(ctx, 0))
  71. /**
  72. * @brief Frees DH object -- not implemented
  73. *
  74. * Current implementation calls SSL_ASSERT
  75. *
  76. * @param r DH object
  77. */
  78. void DH_free(DH *r);
  79. /**
  80. * @brief Frees GENERAL_NAMES -- not implemented
  81. *
  82. * Current implementation calls SSL_ASSERT
  83. *
  84. * @param r GENERAL_NAMES object
  85. */
  86. void GENERAL_NAMES_free(GENERAL_NAMES * gens);
  87. /**
  88. * @brief Returns subject name from X509 -- not implemented
  89. *
  90. * Current implementation calls SSL_ASSERT
  91. *
  92. * @param r X509 object
  93. */
  94. X509_NAME *X509_get_subject_name(X509 *a);
  95. /**
  96. * @brief API provaded as declaration only
  97. *
  98. */
  99. int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
  100. /**
  101. * @brief API provaded as declaration only
  102. *
  103. */
  104. int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos);
  105. /**
  106. * @brief API provaded as declaration only
  107. *
  108. */
  109. X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
  110. /**
  111. * @brief API provaded as declaration only
  112. *
  113. */
  114. ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
  115. /**
  116. * @brief API provaded as declaration only
  117. *
  118. */
  119. void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
  120. /**
  121. * @brief API provaded as declaration only
  122. *
  123. */
  124. X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
  125. /**
  126. * @brief Reads DH params from a bio object -- not implemented
  127. *
  128. * Current implementation calls SSL_ASSERT
  129. */
  130. DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
  131. /**
  132. * @brief API provaded as declaration only
  133. *
  134. */
  135. void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
  136. /**
  137. * @brief Sets DH params to ssl ctx -- not implemented
  138. *
  139. * Current implementation calls SSL_ASSERT
  140. */
  141. int SSL_CTX_set_tmp_dh(SSL_CTX *ctx, const DH *dh);
  142. /**
  143. * @brief API provaded as declaration only
  144. *
  145. */
  146. void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *data);
  147. /**
  148. * @brief API provaded as declaration only
  149. *
  150. */
  151. void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
  152. /**
  153. * @brief Clears any existing chain associated with the current certificate of ctx.
  154. *
  155. */
  156. int SSL_CTX_clear_chain_certs(SSL_CTX *ctx);
  157. #if defined(__cplusplus)
  158. } /* extern C */
  159. #endif
  160. #endif /* ASIO_USE_ESP_OPENSSL, ASIO_USE_WOLFSSL */
  161. #endif /* _ESP_ASIO_OPENSSL_STUBS_H */