Branch data Line data Source code
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 : : 16 : : #pragma once 17 : : 18 : : #include "stuffer/s2n_stuffer.h" 19 : : #include "tls/s2n_crypto_constants.h" 20 : : #include "utils/s2n_blob.h" 21 : : 22 : 2823 : #define S2N_STATE_LIFETIME_IN_NANOS 54000000000000 /* 15 hours */ 23 : 125 : #define S2N_TLS12_STATE_SIZE_IN_BYTES (1 + 8 + 1 + S2N_TLS_CIPHER_SUITE_LEN + S2N_TLS_SECRET_LEN + 1) 24 : 1186 : #define S2N_TLS13_FIXED_STATE_SIZE 29 25 : 386 : #define S2N_TLS13_FIXED_EARLY_DATA_STATE_SIZE 3 26 : : 27 : : /* This is used in session ticket validation. This controls how far in the future 28 : : * the session ticket issue time can be while still being accepted. 29 : : */ 30 : : #define MAX_ALLOWED_CLOCK_SKEW_SEC 3600 31 : 5 : #define S2N_TLS_SESSION_CACHE_TTL (6 * 60 * 60) 32 : 209 : #define S2N_TICKET_KEY_NAME_LEN 16 33 : : #define S2N_TICKET_AAD_IMPLICIT_LEN 12 34 : : #define S2N_TICKET_AAD_LEN (S2N_TICKET_AAD_IMPLICIT_LEN + S2N_TICKET_KEY_NAME_LEN) 35 : 141 : #define S2N_AES256_KEY_LEN 32 36 : 1959 : #define ONE_SEC_IN_NANOS 1000000000 37 : 227 : #define ONE_MILLISEC_IN_NANOS 1000000 38 : 3422436 : #define ONE_WEEK_IN_SEC 604800 39 : 51 : #define S2N_TICKET_INFO_SIZE 32 40 : 51 : #define S2N_TICKET_VERSION_SIZE 1 41 : 51 : #define S2N_TLS12_TICKET_SIZE_IN_BYTES (S2N_TICKET_VERSION_SIZE + S2N_TICKET_KEY_NAME_LEN \ 42 : 51 : + S2N_TICKET_INFO_SIZE + S2N_TLS_GCM_IV_LEN + S2N_TLS12_STATE_SIZE_IN_BYTES + S2N_TLS_GCM_TAG_LEN) 43 : : 44 : 2823 : #define S2N_TICKET_ENCRYPT_DECRYPT_KEY_LIFETIME_IN_NANOS 7200000000000 /* 2 hours */ 45 : 2823 : #define S2N_TICKET_DECRYPT_KEY_LIFETIME_IN_NANOS 46800000000000 /* 13 hours */ 46 : 451 : #define S2N_STATE_FORMAT_LEN 1 47 : : #define S2N_TICKET_LIFETIME_HINT_LEN 4 48 : 441 : #define S2N_SESSION_TICKET_SIZE_LEN 2 49 : : #define S2N_GREATER_OR_EQUAL 1 50 : : #define S2N_LESS_THAN -1 51 : : 52 : : #define S2N_TLS12_SESSION_SIZE S2N_STATE_FORMAT_LEN + S2N_SESSION_TICKET_SIZE_LEN \ 53 : : + S2N_TLS12_TICKET_SIZE_IN_BYTES + S2N_TLS12_STATE_SIZE_IN_BYTES 54 : : 55 : : struct s2n_connection; 56 : : struct s2n_config; 57 : : 58 : : struct s2n_ticket_key { 59 : : unsigned char key_name[S2N_TICKET_KEY_NAME_LEN]; 60 : : uint8_t aes_key[S2N_AES256_KEY_LEN]; 61 : : uint8_t implicit_aad[S2N_TICKET_AAD_IMPLICIT_LEN]; 62 : : uint64_t intro_timestamp; 63 : : }; 64 : : 65 : : struct s2n_ticket_key_weight { 66 : : double key_weight; 67 : : uint8_t key_index; 68 : : }; 69 : : 70 : : struct s2n_ticket_fields { 71 : : struct s2n_blob session_secret; 72 : : uint32_t ticket_age_add; 73 : : }; 74 : : 75 : : struct s2n_session_ticket { 76 : : struct s2n_blob ticket_data; 77 : : uint32_t session_lifetime; 78 : : }; 79 : : 80 : : struct s2n_ticket_key *s2n_find_ticket_key(struct s2n_config *config, const uint8_t name[S2N_TICKET_KEY_NAME_LEN]); 81 : : struct s2n_ticket_key *s2n_get_ticket_encrypt_decrypt_key(struct s2n_config *config); 82 : : S2N_RESULT s2n_resume_encrypt_session_ticket(struct s2n_connection *conn, struct s2n_ticket_key *key, struct s2n_stuffer *to); 83 : : S2N_RESULT s2n_resume_decrypt_session(struct s2n_connection *conn, struct s2n_stuffer *from); 84 : : S2N_RESULT s2n_config_is_encrypt_key_available(struct s2n_config *config); 85 : : int s2n_verify_unique_ticket_key(struct s2n_config *config, uint8_t *hash, uint16_t *insert_index); 86 : : int s2n_config_wipe_expired_ticket_crypto_keys(struct s2n_config *config, int8_t expired_key_index); 87 : : int s2n_config_store_ticket_key(struct s2n_config *config, struct s2n_ticket_key *key); 88 : : 89 : : typedef enum { 90 : : S2N_STATE_WITH_SESSION_ID = 0, 91 : : S2N_STATE_WITH_SESSION_TICKET 92 : : } s2n_client_tls_session_state_format; 93 : : 94 : : typedef enum { 95 : : S2N_SERIALIZED_FORMAT_TLS12_V1 = 1, 96 : : S2N_SERIALIZED_FORMAT_TLS13_V1, 97 : : S2N_SERIALIZED_FORMAT_TLS12_V2, 98 : : S2N_SERIALIZED_FORMAT_TLS12_V3, 99 : : S2N_SERIALIZED_FORMAT_TLS13_V2, 100 : : } s2n_serial_format_version; 101 : : 102 : : /* Used to specify the format of the ticket schema before encryption. 103 : : * 104 : : * This makes it easier to make changes to the ticket schema in the future 105 : : * as it allows us to interpret and parse all ticket schemas. 106 : : **/ 107 : : typedef enum { 108 : : S2N_PRE_ENCRYPTED_STATE_V1 = 1, 109 : : } s2n_pre_encrypted_state; 110 : : 111 : : int s2n_allowed_to_cache_connection(struct s2n_connection *conn); 112 : : int s2n_resume_from_cache(struct s2n_connection *conn); 113 : : S2N_RESULT s2n_store_to_cache(struct s2n_connection *conn); 114 : : S2N_RESULT s2n_connection_get_session_state_size(struct s2n_connection *conn, size_t *state_size); 115 : : S2N_RESULT s2n_deserialize_resumption_state(struct s2n_connection *conn, struct s2n_blob *psk_identity, 116 : : struct s2n_stuffer *from);