s2n_quic_support.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #pragma once
  16. #include "api/s2n.h"
  17. /*
  18. * APIs intended to support an external implementation of the QUIC protocol:
  19. * https://datatracker.ietf.org/wg/quic/about/
  20. *
  21. * QUIC requires access to parts of S2N not usually surfaced to customers. These APIs change
  22. * the behavior of S2N in potentially dangerous ways and should only be used by implementations
  23. * of the QUIC protocol.
  24. *
  25. * Additionally, all QUIC APIs are considered experimental and are subject to change without
  26. * notice. They should only be used for testing purposes.
  27. */
  28. S2N_API int s2n_config_enable_quic(struct s2n_config *config);
  29. S2N_API int s2n_connection_enable_quic(struct s2n_connection *conn);
  30. S2N_API bool s2n_connection_is_quic_enabled(struct s2n_connection *conn);
  31. /*
  32. * Set the data to be sent in the quic_transport_parameters extension.
  33. * The data provided will be copied into a buffer owned by S2N.
  34. */
  35. S2N_API int s2n_connection_set_quic_transport_parameters(struct s2n_connection *conn,
  36. const uint8_t *data_buffer, uint16_t data_len);
  37. /*
  38. * Retrieve the data from the peer's quic_transport_parameters extension.
  39. * data_buffer will be set to a buffer owned by S2N which will be freed when the connection is freed.
  40. * data_len will be set to the length of the data returned.
  41. *
  42. * S2N treats the extension data as opaque bytes and performs no validation.
  43. */
  44. S2N_API int s2n_connection_get_quic_transport_parameters(struct s2n_connection *conn,
  45. const uint8_t **data_buffer, uint16_t *data_len);
  46. typedef enum {
  47. S2N_CLIENT_EARLY_TRAFFIC_SECRET = 0,
  48. S2N_CLIENT_HANDSHAKE_TRAFFIC_SECRET,
  49. S2N_SERVER_HANDSHAKE_TRAFFIC_SECRET,
  50. S2N_CLIENT_APPLICATION_TRAFFIC_SECRET,
  51. S2N_SERVER_APPLICATION_TRAFFIC_SECRET,
  52. S2N_EXPORTER_SECRET,
  53. } s2n_secret_type_t;
  54. /*
  55. * Called when S2N begins using a new key.
  56. *
  57. * The memory pointed to by "secret" will be wiped after this method returns and should be copied by
  58. * the application if necessary. The application should also be very careful managing the memory and
  59. * lifespan of the secret: if the secret is compromised, TLS is compromised.
  60. */
  61. typedef int (*s2n_secret_cb)(void *context, struct s2n_connection *conn,
  62. s2n_secret_type_t secret_type, uint8_t *secret, uint8_t secret_size);
  63. /*
  64. * Set the function to be called when S2N begins using a new key.
  65. *
  66. * The callback function will ONLY be triggered if QUIC is enabled. This API is not intended to be
  67. * used outside of a QUIC implementation.
  68. */
  69. S2N_API int s2n_connection_set_secret_callback(struct s2n_connection *conn, s2n_secret_cb cb_func, void *ctx);
  70. /*
  71. * Return the TLS alert that S2N-TLS would send, if S2N-TLS sent specific alerts.
  72. *
  73. * S2N-TLS only sends generic close_notify alerts for security reasons, and TLS never
  74. * sends alerts when used by QUIC. This method returns the alert that would have been
  75. * sent if S2N-TLS sent specific alerts as defined in the protocol specifications.
  76. *
  77. * WARNING: this method is still considered experimental and will not always report
  78. * the correct alert description. It may be used for testing and logging, but
  79. * not relied on for production logic.
  80. */
  81. S2N_API int s2n_error_get_alert(int error, uint8_t *alert);
  82. /* Attempts to read and process a post-handshake message from QUIC. This function
  83. * should be called when post-handshake messages in QUIC have been received.
  84. */
  85. S2N_API int s2n_recv_quic_post_handshake_message(struct s2n_connection *conn, s2n_blocked_status *blocked);