Debian Codegraph @

crt/s2n/tests/unit/s2n_tls13_keys_test.c

raw symbols SCIP
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 #include "crypto/s2n_tls13_keys.h"
17
18 #include <string.h>
19
20 #include "crypto/s2n_hkdf.h"
21 #include "crypto/s2n_hmac.h"
22 #include "s2n_test.h"
23 #include "stuffer/s2n_stuffer.h"
24 #include "testlib/s2n_testlib.h"
25 #include "tls/s2n_tls13_handshake.h"
26 #include "utils/s2n_blob.h"
27 #include "utils/s2n_safety.h"
28
29 int main(int argc, char **argv)
30 {
31 BEGIN_TEST();
32
33 /*
34 * Test s2n_tls13_update_application_traffic_secret
35 *
36 * This test checks the new secret produced by the s2n_tls13_update_application_traffic_secret
37 * is the same one that is produced by openssl when starting with the same application secret.
38 */
39 {
40 /* KeyUpdate Vectors from Openssl s_client implementation of KeyUpdate. The ciphersuite
41 * that produced this secret was s2n_tls13_aes_256_gcm_sha384.
42 */
43 S2N_BLOB_FROM_HEX(application_secret,
44 "4bc28934ddd802b00f479e14a72d7725dab45d32b3b145f29"
45 "e4c5b56677560eb5236b168c71c5c75aa52f3e20ee89bfb");
46 S2N_BLOB_FROM_HEX(updated_application_secret,
47 "ee85dd54781bd4d8a100589a9fe6ac9a3797b811e977f549cd"
48 "531be2441d7c63e2b9729d145c11d84af35957727565a4");
49
50 struct s2n_connection *server_conn = NULL;
51 EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
52 server_conn->actual_protocol_version = S2N_TLS13;
53 server_conn->secure->cipher_suite = &s2n_tls13_aes_256_gcm_sha384;
54
55 /* get tls13 key context */
56 s2n_tls13_connection_keys(keys, server_conn);
57
58 s2n_stack_blob(app_secret_update, keys.size, S2N_TLS13_SECRET_MAX_LEN);
59
60 /* Derives next generation of traffic secret */
61 EXPECT_SUCCESS(s2n_tls13_update_application_traffic_secret(&keys, &application_secret, &app_secret_update));
62
63 /* Check the new secret is what was expected */
64 S2N_BLOB_EXPECT_EQUAL(app_secret_update, updated_application_secret);
65
66 EXPECT_SUCCESS(s2n_connection_free(server_conn));
67 };
68
69 END_TEST();
70 }