@@ -964,6 +964,58 @@ int main(int argc, char **argv)
964
964
EXPECT_SUCCESS (s2n_config_free (client_config ));
965
965
}
966
966
967
+ /* s2n_decrypt_session_ticket fails to decrypt when presented with a valid ticket_key, valid iv and invalid encrypted blob */
968
+ {
969
+ EXPECT_NOT_NULL (server_conn = s2n_connection_new (S2N_SERVER ));
970
+ EXPECT_NOT_NULL (server_config = s2n_config_new ());
971
+
972
+ /* Add Session Ticket key on the server config */
973
+ EXPECT_SUCCESS (s2n_config_set_session_tickets_onoff (server_config , 1 ));
974
+ EXPECT_SUCCESS (s2n_config_add_ticket_crypto_key (server_config , ticket_key_name1 , strlen ((char * )ticket_key_name1 ), ticket_key1 , sizeof (ticket_key1 ), 0 ));
975
+ EXPECT_SUCCESS (s2n_connection_set_config (server_conn , server_config ));
976
+
977
+ /* Setup stuffers value containing the valid key name, valid iv and invalid encrypted blob */
978
+ GUARD (s2n_stuffer_write_bytes (& server_conn -> client_ticket_to_decrypt , ticket_key_name1 , sizeof (ticket_key_name1 )));
979
+
980
+ uint8_t valid_iv [S2N_TLS_GCM_IV_LEN ] = {0 };
981
+ GUARD (s2n_stuffer_write_bytes (& server_conn -> client_ticket_to_decrypt , valid_iv , sizeof (valid_iv )));
982
+
983
+ uint8_t invalid_en_data [S2N_STATE_SIZE_IN_BYTES + S2N_TLS_GCM_TAG_LEN ] = {0 };
984
+ GUARD (s2n_stuffer_write_bytes (& server_conn -> client_ticket_to_decrypt , invalid_en_data , sizeof (invalid_en_data )));
985
+
986
+ server_conn -> session_ticket_status = S2N_DECRYPT_TICKET ;
987
+ EXPECT_FAILURE_WITH_ERRNO (s2n_decrypt_session_ticket (server_conn ), S2N_ERR_DECRYPT );
988
+
989
+ EXPECT_SUCCESS (s2n_connection_free (server_conn ));
990
+ EXPECT_SUCCESS (s2n_config_free (server_config ));
991
+ }
992
+
993
+ /* s2n_decrypt_session_ticket fails with a key not found error when presented with an invalid ticket_key, valid iv and invalid encrypted blob */
994
+ {
995
+ EXPECT_NOT_NULL (server_conn = s2n_connection_new (S2N_SERVER ));
996
+ EXPECT_NOT_NULL (server_config = s2n_config_new ());
997
+
998
+ /* Add Session Ticket key on the server config */
999
+ EXPECT_SUCCESS (s2n_config_set_session_tickets_onoff (server_config , 1 ));
1000
+ EXPECT_SUCCESS (s2n_config_add_ticket_crypto_key (server_config , ticket_key_name1 , strlen ((char * )ticket_key_name1 ), ticket_key1 , sizeof (ticket_key1 ), 0 ));
1001
+ EXPECT_SUCCESS (s2n_connection_set_config (server_conn , server_config ));
1002
+
1003
+ /* Setup stuffers value containing the invalid key name, valid iv and invalid encrypted blob */
1004
+ GUARD (s2n_stuffer_write_bytes (& server_conn -> client_ticket_to_decrypt , ticket_key_name2 , sizeof (ticket_key_name2 )));
1005
+
1006
+ uint8_t valid_iv [S2N_TLS_GCM_IV_LEN ] = {0 };
1007
+ GUARD (s2n_stuffer_write_bytes (& server_conn -> client_ticket_to_decrypt , valid_iv , sizeof (valid_iv )));
1008
+
1009
+ uint8_t invalid_en_data [S2N_STATE_SIZE_IN_BYTES + S2N_TLS_GCM_TAG_LEN ] = {0 };
1010
+ GUARD (s2n_stuffer_write_bytes (& server_conn -> client_ticket_to_decrypt , invalid_en_data , sizeof (invalid_en_data )));
1011
+
1012
+ server_conn -> session_ticket_status = S2N_DECRYPT_TICKET ;
1013
+ EXPECT_FAILURE_WITH_ERRNO (s2n_decrypt_session_ticket (server_conn ), S2N_ERR_KEY_USED_IN_SESSION_TICKET_NOT_FOUND );
1014
+
1015
+ EXPECT_SUCCESS (s2n_connection_free (server_conn ));
1016
+ EXPECT_SUCCESS (s2n_config_free (server_config ));
1017
+ }
1018
+
967
1019
EXPECT_SUCCESS (s2n_io_pair_close (& io_pair ));
968
1020
EXPECT_SUCCESS (s2n_cert_chain_and_key_free (chain_and_key ));
969
1021
free (cert_chain );
0 commit comments