s2n_server_ems.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <stdint.h>
  16. #include <sys/param.h>
  17. #include "tls/extensions/s2n_ems.h"
  18. #include "tls/s2n_tls.h"
  19. #include "utils/s2n_safety.h"
  20. static int s2n_server_ems_recv(struct s2n_connection *conn, struct s2n_stuffer *extension);
  21. static bool s2n_server_ems_should_send(struct s2n_connection *conn);
  22. static int s2n_server_ems_if_missing(struct s2n_connection *conn);
  23. /**
  24. *= https://tools.ietf.org/rfc/rfc7627#section-5.1
  25. *#
  26. *# This document defines a new TLS extension, "extended_master_secret"
  27. *# (with extension type 0x0017), which is used to signal both client and
  28. *# server to use the extended master secret computation. The
  29. *# "extension_data" field of this extension is empty. Thus, the entire
  30. *# encoding of the extension is 00 17 00 00 (in hexadecimal.)
  31. **/
  32. const s2n_extension_type s2n_server_ems_extension = {
  33. .iana_value = TLS_EXTENSION_EMS,
  34. .is_response = true,
  35. .send = s2n_extension_send_noop,
  36. .recv = s2n_server_ems_recv,
  37. .should_send = s2n_server_ems_should_send,
  38. .if_missing = s2n_server_ems_if_missing,
  39. };
  40. static int s2n_server_ems_recv(struct s2n_connection *conn, struct s2n_stuffer *extension)
  41. {
  42. POSIX_ENSURE_REF(conn);
  43. /* Read nothing. The extension just needs to exist without any data. */
  44. POSIX_ENSURE(s2n_stuffer_data_available(extension) == 0, S2N_ERR_UNSUPPORTED_EXTENSION);
  45. conn->ems_negotiated = true;
  46. return S2N_SUCCESS;
  47. }
  48. static bool s2n_server_ems_should_send(struct s2n_connection *conn)
  49. {
  50. return conn && conn->actual_protocol_version < S2N_TLS13;
  51. }
  52. static int s2n_server_ems_if_missing(struct s2n_connection *conn)
  53. {
  54. POSIX_ENSURE_REF(conn);
  55. /**
  56. *= https://tools.ietf.org/rfc/rfc7627#section-5.3
  57. *# If the original session used the extension but the new ServerHello
  58. *# does not contain the extension, the client MUST abort the
  59. *# handshake.
  60. **/
  61. POSIX_ENSURE(!conn->ems_negotiated, S2N_ERR_MISSING_EXTENSION);
  62. return S2N_SUCCESS;
  63. }