| 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 | /* Target Functions: s2n_deserialize_resumption_state |
| 17 | * This test fuzzes the deserialization logic for our session tickets. This occurs after |
| 18 | * the ticket has been decrypted with the server ticket key. Technically it's not |
| 19 | * necessary to fuzz decrypted values, however, in the event that an attacker is |
| 20 | * able to get a valid ticket key, we want to make sure these functions can't cause damage. |
| 21 | */ |
| 22 | |
| 23 | #include "api/s2n.h" |
| 24 | #include "s2n_test.h" |
| 25 | #include "stuffer/s2n_stuffer.h" |
| 26 | #include "tls/s2n_resume.h" |
| 27 | #include "utils/s2n_safety.h" |
| 28 | |
| 29 | int s2n_fuzz_test(const uint8_t *buf, size_t len) |
| 30 | { |
| 31 | /* We need at least one byte of input to set parameters */ |
| 32 | S2N_FUZZ_ENSURE_MIN_LEN(len, 1); |
| 33 | |
| 34 | DEFER_CLEANUP(struct s2n_stuffer fuzzed_ticket = { 0 }, s2n_stuffer_free); |
| 35 | POSIX_GUARD(s2n_stuffer_alloc(&fuzzed_ticket, len)); |
| 36 | POSIX_GUARD(s2n_stuffer_write_bytes(&fuzzed_ticket, buf, len)); |
| 37 | |
| 38 | /* A session ticket is sent along with the Client Hello, so there's not much set up needed for the server */ |
| 39 | DEFER_CLEANUP(struct s2n_connection *server_conn = s2n_connection_new(S2N_SERVER), s2n_connection_ptr_free); |
| 40 | POSIX_ENSURE_REF(server_conn); |
| 41 | POSIX_GUARD(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING)); |
| 42 | |
| 43 | uint8_t test_data[] = "test psk identity"; |
| 44 | struct s2n_blob test_blob = { 0 }; |
| 45 | POSIX_GUARD(s2n_blob_init(&test_blob, test_data, sizeof(test_data))); |
| 46 | |
| 47 | /* Ignore the result of this function */ |
| 48 | s2n_result_ignore(s2n_deserialize_resumption_state(server_conn, &test_blob, &fuzzed_ticket)); |
| 49 | |
| 50 | return S2N_SUCCESS; |
| 51 | } |
| 52 | |
| 53 | S2N_FUZZ_TARGET(NULL, s2n_fuzz_test, NULL) |