s2n_server_session_ticket.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "tls/extensions/s2n_server_session_ticket.h"
  16. #include "stuffer/s2n_stuffer.h"
  17. #include "tls/s2n_connection.h"
  18. #include "tls/s2n_tls.h"
  19. #include "tls/s2n_tls_parameters.h"
  20. static bool s2n_session_ticket_should_send(struct s2n_connection *conn);
  21. static int s2n_session_ticket_recv(struct s2n_connection *conn, struct s2n_stuffer *extension);
  22. const s2n_extension_type s2n_server_session_ticket_extension = {
  23. .iana_value = TLS_EXTENSION_SESSION_TICKET,
  24. .is_response = true,
  25. .send = s2n_extension_send_noop,
  26. .recv = s2n_session_ticket_recv,
  27. .should_send = s2n_session_ticket_should_send,
  28. .if_missing = s2n_extension_noop_if_missing,
  29. };
  30. static bool s2n_session_ticket_should_send(struct s2n_connection *conn)
  31. {
  32. return s2n_server_sending_nst(conn) && s2n_connection_get_protocol_version(conn) < S2N_TLS13;
  33. }
  34. static int s2n_session_ticket_recv(struct s2n_connection *conn, struct s2n_stuffer *extension)
  35. {
  36. /* Read nothing. The extension just needs to exist. */
  37. POSIX_ENSURE_REF(conn);
  38. conn->session_ticket_status = S2N_NEW_TICKET;
  39. return S2N_SUCCESS;
  40. }
  41. /* Old-style extension functions -- remove after extensions refactor is complete */
  42. int s2n_recv_server_session_ticket_ext(struct s2n_connection *conn, struct s2n_stuffer *extension)
  43. {
  44. return s2n_extension_recv(&s2n_server_session_ticket_extension, conn, extension);
  45. }