s2n_client_hello.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <stdint.h>
  17. #include "api/s2n.h"
  18. #include "stuffer/s2n_stuffer.h"
  19. #include "tls/extensions/s2n_extension_list.h"
  20. #include "utils/s2n_array.h"
  21. /*
  22. * the 'data' pointers in the below blobs
  23. * point to data in the raw_message stuffer
  24. */
  25. struct s2n_client_hello {
  26. struct s2n_blob raw_message;
  27. s2n_parsed_extensions_list extensions;
  28. struct s2n_blob cipher_suites;
  29. struct s2n_blob session_id;
  30. unsigned int callback_invoked : 1;
  31. unsigned int callback_async_blocked : 1;
  32. unsigned int callback_async_done : 1;
  33. /*
  34. * Marks if the client hello has been parsed.
  35. *
  36. * While a client_hello is only parsed once, it is possible to parse
  37. * two different client_hello during a single handshake if the server
  38. * issues a hello retry.
  39. */
  40. unsigned int parsed : 1;
  41. /*
  42. * SSLv2 ClientHellos have a different format.
  43. * Cipher suites are each three bytes instead of two.
  44. * And due to how s2n-tls parses the record,
  45. * the raw_message will not contain the protocol version.
  46. */
  47. unsigned int sslv2 : 1;
  48. /*
  49. * The memory for this structure can be either owned by the application
  50. * or tied to and managed by a connection.
  51. *
  52. * If owned by the application, it can be freed using s2n_client_hello_free.
  53. * Otherwise, it is freed with s2n_connection_free.
  54. *
  55. * We could simplify this by moving the client hello structure off of the
  56. * connection structure.
  57. */
  58. unsigned int alloced : 1;
  59. };
  60. int s2n_client_hello_free_raw_message(struct s2n_client_hello *client_hello);
  61. struct s2n_client_hello *s2n_connection_get_client_hello(struct s2n_connection *conn);
  62. ssize_t s2n_client_hello_get_raw_message_length(struct s2n_client_hello *ch);
  63. ssize_t s2n_client_hello_get_raw_message(struct s2n_client_hello *ch, uint8_t *out, uint32_t max_length);
  64. ssize_t s2n_client_hello_get_cipher_suites_length(struct s2n_client_hello *ch);
  65. ssize_t s2n_client_hello_get_cipher_suites(struct s2n_client_hello *ch, uint8_t *out, uint32_t max_length);
  66. int s2n_client_hello_get_parsed_extension(s2n_tls_extension_type extension_type,
  67. s2n_parsed_extensions_list *parsed_extension_list, s2n_parsed_extension **parsed_extension);
  68. ssize_t s2n_client_hello_get_extensions_length(struct s2n_client_hello *ch);
  69. ssize_t s2n_client_hello_get_extensions(struct s2n_client_hello *ch, uint8_t *out, uint32_t max_length);