s2n_client_ems.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_client_ems_recv(struct s2n_connection *conn, struct s2n_stuffer *extension);
  21. static bool s2n_client_ems_should_send(struct s2n_connection *conn);
  22. /**
  23. *= https://tools.ietf.org/rfc/rfc7627#section-5.1
  24. *#
  25. *# This document defines a new TLS extension, "extended_master_secret"
  26. *# (with extension type 0x0017), which is used to signal both client and
  27. *# server to use the extended master secret computation. The
  28. *# "extension_data" field of this extension is empty. Thus, the entire
  29. *# encoding of the extension is 00 17 00 00 (in hexadecimal.)
  30. **/
  31. const s2n_extension_type s2n_client_ems_extension = {
  32. .iana_value = TLS_EXTENSION_EMS,
  33. .is_response = false,
  34. .send = s2n_extension_send_noop,
  35. .recv = s2n_client_ems_recv,
  36. .should_send = s2n_client_ems_should_send,
  37. .if_missing = s2n_extension_noop_if_missing,
  38. };
  39. static int s2n_client_ems_recv(struct s2n_connection *conn, struct s2n_stuffer *extension)
  40. {
  41. POSIX_ENSURE_REF(conn);
  42. /* Read nothing. The extension just needs to exist without data. */
  43. POSIX_ENSURE(s2n_stuffer_data_available(extension) == 0, S2N_ERR_UNSUPPORTED_EXTENSION);
  44. conn->ems_negotiated = true;
  45. return S2N_SUCCESS;
  46. }
  47. /**
  48. *= https://www.rfc-editor.org/rfc/rfc7627#section-5.3
  49. *= type=exception
  50. *# When offering an abbreviated handshake, the client MUST send the
  51. *# "extended_master_secret" extension in its ClientHello.
  52. *
  53. * We added an exception here in order to prevent a drop in
  54. * session resumption rates during deployment. Eventually clients
  55. * will be forced to do a full handshake as sessions expire and pick up EMS at that point.
  56. **/
  57. static bool s2n_client_ems_should_send(struct s2n_connection *conn)
  58. {
  59. /* Don't send this extension if the previous session did not negotiate EMS */
  60. if (conn && conn->set_session && !conn->ems_negotiated) {
  61. return false;
  62. } else {
  63. return true;
  64. }
  65. }