quic_tls.h 3.6 KB

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