ngtcp2_crypto_quictls.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2019 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGTCP2_CRYPTO_QUICTLS_H
  26. #define NGTCP2_CRYPTO_QUICTLS_H
  27. #include <ngtcp2/ngtcp2.h>
  28. #include <openssl/ssl.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /**
  33. * @macrosection
  34. *
  35. * quictls specific error codes
  36. */
  37. /**
  38. * @macro
  39. *
  40. * :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP` is the
  41. * error code which indicates that TLS handshake routine is
  42. * interrupted by X509 certificate lookup. See
  43. * :macro:`SSL_ERROR_WANT_X509_LOOKUP` error description from
  44. * `SSL_do_handshake`.
  45. */
  46. #define NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP -10001
  47. /**
  48. * @macro
  49. *
  50. * :macro:`NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB` is the
  51. * error code which indicates that TLS handshake routine is
  52. * interrupted by client hello callback. See
  53. * :macro:`SSL_ERROR_WANT_CLIENT_HELLO_CB` error description from
  54. * `SSL_do_handshake`.
  55. */
  56. #define NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_CLIENT_HELLO_CB -10002
  57. /**
  58. * @function
  59. *
  60. * `ngtcp2_crypto_quictls_from_ossl_encryption_level` translates
  61. * |ossl_level| to :type:`ngtcp2_encryption_level`. This function is
  62. * only available for quictls backend.
  63. */
  64. NGTCP2_EXTERN ngtcp2_encryption_level
  65. ngtcp2_crypto_quictls_from_ossl_encryption_level(
  66. OSSL_ENCRYPTION_LEVEL ossl_level);
  67. /**
  68. * @function
  69. *
  70. * `ngtcp2_crypto_quictls_from_ngtcp2_encryption_level` translates
  71. * |encryption_level| to OSSL_ENCRYPTION_LEVEL. This function is only
  72. * available for quictls backend.
  73. */
  74. NGTCP2_EXTERN OSSL_ENCRYPTION_LEVEL
  75. ngtcp2_crypto_quictls_from_ngtcp2_encryption_level(
  76. ngtcp2_encryption_level encryption_level);
  77. /**
  78. * @function
  79. *
  80. * `ngtcp2_crypto_quictls_configure_server_context` configures
  81. * |ssl_ctx| for server side QUIC connection. It performs the
  82. * following modifications:
  83. *
  84. * - Set minimum and maximum TLS version to TLSv1.3.
  85. * - Set SSL_QUIC_METHOD by calling SSL_CTX_set_quic_method.
  86. *
  87. * Application must set a pointer to :type:`ngtcp2_crypto_conn_ref` to
  88. * SSL object by calling SSL_set_app_data, and
  89. * :type:`ngtcp2_crypto_conn_ref` object must have
  90. * :member:`ngtcp2_crypto_conn_ref.get_conn` field assigned to get
  91. * :type:`ngtcp2_conn`.
  92. *
  93. * It returns 0 if it succeeds, or -1.
  94. */
  95. NGTCP2_EXTERN int
  96. ngtcp2_crypto_quictls_configure_server_context(SSL_CTX *ssl_ctx);
  97. /**
  98. * @function
  99. *
  100. * `ngtcp2_crypto_quictls_configure_client_context` configures
  101. * |ssl_ctx| for client side QUIC connection. It performs the
  102. * following modifications:
  103. *
  104. * - Set minimum and maximum TLS version to TLSv1.3.
  105. * - Set SSL_QUIC_METHOD by calling SSL_CTX_set_quic_method.
  106. *
  107. * Application must set a pointer to :type:`ngtcp2_crypto_conn_ref` to
  108. * SSL object by calling SSL_set_app_data, and
  109. * :type:`ngtcp2_crypto_conn_ref` object must have
  110. * :member:`ngtcp2_crypto_conn_ref.get_conn` field assigned to get
  111. * :type:`ngtcp2_conn`.
  112. *
  113. * It returns 0 if it succeeds, or -1.
  114. */
  115. NGTCP2_EXTERN int
  116. ngtcp2_crypto_quictls_configure_client_context(SSL_CTX *ssl_ctx);
  117. /**
  118. * @function
  119. *
  120. * `ngtcp2_crypto_quictls_init` initializes libngtcp2_crypto_quictls
  121. * library. This initialization is optional. For quictls >= 3.0, it
  122. * is highly recommended to call this function before any use of
  123. * libngtcp2_crypto library API to workaround the performance
  124. * regression. Note that calling this function does not solve all
  125. * performance issues introduced in 3.x. For quictls 1.1.1, this
  126. * function does nothing, and always succeeds.
  127. *
  128. * This function returns 0 if it succeeds, or -1.
  129. */
  130. NGTCP2_EXTERN int ngtcp2_crypto_quictls_init(void);
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. #endif /* NGTCP2_CRYPTO_QUICTLS_H */