s2n_psk.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "api/s2n.h"
  17. #include "crypto/s2n_hmac.h"
  18. #include "stuffer/s2n_stuffer.h"
  19. #include "tls/s2n_early_data.h"
  20. #include "utils/s2n_array.h"
  21. #include "utils/s2n_blob.h"
  22. #include "utils/s2n_result.h"
  23. typedef enum {
  24. S2N_PSK_TYPE_RESUMPTION = 0,
  25. S2N_PSK_TYPE_EXTERNAL,
  26. } s2n_psk_type;
  27. typedef enum {
  28. S2N_PSK_KE_UNKNOWN = 0,
  29. S2N_PSK_KE,
  30. S2N_PSK_DHE_KE,
  31. } s2n_psk_key_exchange_mode;
  32. struct s2n_psk {
  33. s2n_psk_type type;
  34. struct s2n_blob identity;
  35. struct s2n_blob secret;
  36. s2n_hmac_algorithm hmac_alg;
  37. uint32_t ticket_age_add;
  38. uint64_t ticket_issue_time;
  39. struct s2n_blob early_secret;
  40. struct s2n_early_data_config early_data_config;
  41. /* This field is used with session tickets to track the lifetime
  42. * of the original full handshake across multiple tickets.
  43. * See https://tools.ietf.org/rfc/rfc8446#section-4.6.1
  44. */
  45. uint64_t keying_material_expiration;
  46. };
  47. S2N_RESULT s2n_psk_init(struct s2n_psk *psk, s2n_psk_type type);
  48. S2N_CLEANUP_RESULT s2n_psk_wipe(struct s2n_psk *psk);
  49. S2N_RESULT s2n_psk_clone(struct s2n_psk *new_psk, struct s2n_psk *original_psk);
  50. struct s2n_psk_parameters {
  51. s2n_psk_type type;
  52. struct s2n_array psk_list;
  53. uint16_t binder_list_size;
  54. uint16_t chosen_psk_wire_index;
  55. struct s2n_psk *chosen_psk;
  56. s2n_psk_key_exchange_mode psk_ke_mode;
  57. };
  58. S2N_RESULT s2n_psk_parameters_init(struct s2n_psk_parameters *params);
  59. S2N_RESULT s2n_psk_parameters_offered_psks_size(struct s2n_psk_parameters *params, uint32_t *size);
  60. S2N_CLEANUP_RESULT s2n_psk_parameters_wipe(struct s2n_psk_parameters *params);
  61. S2N_CLEANUP_RESULT s2n_psk_parameters_wipe_secrets(struct s2n_psk_parameters *params);
  62. struct s2n_offered_psk {
  63. struct s2n_blob identity;
  64. uint16_t wire_index;
  65. uint32_t obfuscated_ticket_age;
  66. };
  67. struct s2n_offered_psk_list {
  68. struct s2n_connection *conn;
  69. struct s2n_stuffer wire_data;
  70. uint16_t wire_index;
  71. };
  72. S2N_RESULT s2n_finish_psk_extension(struct s2n_connection *conn);
  73. int s2n_psk_calculate_binder_hash(struct s2n_connection *conn, s2n_hmac_algorithm hmac_alg,
  74. const struct s2n_blob *partial_client_hello, struct s2n_blob *output_binder_hash);
  75. int s2n_psk_calculate_binder(struct s2n_psk *psk, const struct s2n_blob *binder_hash,
  76. struct s2n_blob *output_binder);
  77. int s2n_psk_verify_binder(struct s2n_connection *conn, struct s2n_psk *psk,
  78. const struct s2n_blob *partial_client_hello, struct s2n_blob *binder_to_verify);
  79. S2N_RESULT s2n_connection_set_psk_type(struct s2n_connection *conn, s2n_psk_type type);
  80. S2N_RESULT s2n_psk_validate_keying_material(struct s2n_connection *conn);