quic_tls.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2022-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. #ifndef OSSL_QUIC_TLS_H
  10. # define OSSL_QUIC_TLS_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_stream.h"
  13. # include "internal/quic_predef.h"
  14. # ifndef OPENSSL_NO_QUIC
  15. typedef struct quic_tls_args_st {
  16. /*
  17. * The "inner" SSL object for the QUIC Connection. Contains an
  18. * SSL_CONNECTION
  19. */
  20. SSL *s;
  21. /*
  22. * Called to send data on the crypto stream. We use a callback rather than
  23. * passing the crypto stream QUIC_SSTREAM directly because this lets the CSM
  24. * dynamically select the correct outgoing crypto stream based on the
  25. * current EL.
  26. */
  27. int (*crypto_send_cb)(const unsigned char *buf, size_t buf_len,
  28. size_t *consumed, void *arg);
  29. void *crypto_send_cb_arg;
  30. /*
  31. * Call to receive crypto stream data. A pointer to the underlying buffer
  32. * is provided, and subsequently released to avoid unnecessary copying of
  33. * data.
  34. */
  35. int (*crypto_recv_rcd_cb)(const unsigned char **buf, size_t *bytes_read,
  36. void *arg);
  37. void *crypto_recv_rcd_cb_arg;
  38. int (*crypto_release_rcd_cb)(size_t bytes_read, void *arg);
  39. void *crypto_release_rcd_cb_arg;
  40. /* Called when a traffic secret is available for a given encryption level. */
  41. int (*yield_secret_cb)(uint32_t enc_level, int direction /* 0=RX, 1=TX */,
  42. uint32_t suite_id, EVP_MD *md,
  43. const unsigned char *secret, size_t secret_len,
  44. void *arg);
  45. void *yield_secret_cb_arg;
  46. /*
  47. * Called when we receive transport parameters from the peer.
  48. *
  49. * Note: These parameters are not authenticated until the handshake is
  50. * marked as completed.
  51. */
  52. int (*got_transport_params_cb)(const unsigned char *params,
  53. size_t params_len,
  54. void *arg);
  55. void *got_transport_params_cb_arg;
  56. /*
  57. * Called when the handshake has been completed as far as the handshake
  58. * protocol is concerned, meaning that the connection has been
  59. * authenticated.
  60. */
  61. int (*handshake_complete_cb)(void *arg);
  62. void *handshake_complete_cb_arg;
  63. /*
  64. * Called when something has gone wrong with the connection as far as the
  65. * handshake layer is concerned, meaning that it should be immediately torn
  66. * down. Note that this may happen at any time, including after a connection
  67. * has been fully established.
  68. */
  69. int (*alert_cb)(void *arg, unsigned char alert_code);
  70. void *alert_cb_arg;
  71. /* Set to 1 if we are running in the server role. */
  72. int is_server;
  73. } QUIC_TLS_ARGS;
  74. QUIC_TLS *ossl_quic_tls_new(const QUIC_TLS_ARGS *args);
  75. void ossl_quic_tls_free(QUIC_TLS *qtls);
  76. /* Advance the state machine */
  77. int ossl_quic_tls_tick(QUIC_TLS *qtls);
  78. int ossl_quic_tls_set_transport_params(QUIC_TLS *qtls,
  79. const unsigned char *transport_params,
  80. size_t transport_params_len);
  81. int ossl_quic_tls_get_error(QUIC_TLS *qtls,
  82. uint64_t *error_code,
  83. const char **error_msg,
  84. ERR_STATE **error_state);
  85. int ossl_quic_tls_is_cert_request(QUIC_TLS *qtls);
  86. int ossl_quic_tls_has_bad_max_early_data(QUIC_TLS *qtls);
  87. # endif
  88. #endif