s2n_server_server_name.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_server_name.h"
  16. #include "stuffer/s2n_stuffer.h"
  17. #include "tls/s2n_connection.h"
  18. static bool s2n_server_name_should_send(struct s2n_connection *conn);
  19. static int s2n_server_name_send(struct s2n_connection *conn, struct s2n_stuffer *out);
  20. static int s2n_server_name_recv(struct s2n_connection *conn, struct s2n_stuffer *extension);
  21. const s2n_extension_type s2n_server_server_name_extension = {
  22. .iana_value = TLS_EXTENSION_SERVER_NAME,
  23. .is_response = true,
  24. .send = s2n_server_name_send,
  25. .recv = s2n_server_name_recv,
  26. .should_send = s2n_server_name_should_send,
  27. .if_missing = s2n_extension_noop_if_missing,
  28. };
  29. static bool s2n_server_name_should_send(struct s2n_connection *conn)
  30. {
  31. return conn && conn->server_name_used && !IS_RESUMPTION_HANDSHAKE(conn);
  32. }
  33. static int s2n_server_name_send(struct s2n_connection *conn, struct s2n_stuffer *out)
  34. {
  35. /* Write nothing. The extension just needs to exist. */
  36. return S2N_SUCCESS;
  37. }
  38. static int s2n_server_name_recv(struct s2n_connection *conn, struct s2n_stuffer *extension)
  39. {
  40. POSIX_ENSURE_REF(conn);
  41. /* Read nothing. The extension just needs to exist. */
  42. conn->server_name_used = 1;
  43. return S2N_SUCCESS;
  44. }