Debian Codegraph @

crt/s2n/tests/unit/s2n_cipher_info_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 "api/s2n.h"
17 #include "s2n_test.h"
18 #include "testlib/s2n_testlib.h"
19
20 int main(int argc, char **argv)
21 {
22 BEGIN_TEST();
23
24 struct s2n_connection *conn = NULL;
25 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
26 EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(conn, "test_all"));
27
28 uint8_t iana_value[2] = { 0 };
29
30 /* Make sure the call fails before the connection has negotiated the cipher suite */
31 EXPECT_FAILURE(s2n_connection_get_cipher_iana_value(conn, &iana_value[0], &iana_value[1]));
32
33 const struct s2n_security_policy *security_policy = conn->security_policy_override;
34 EXPECT_NOT_NULL(security_policy);
35
36 const struct s2n_cipher_preferences *cipher_preferences = security_policy->cipher_preferences;
37 EXPECT_NOT_NULL(cipher_preferences);
38
39 /* Verify the cipher info functions work for every cipher suite */
40 for (size_t cipher_idx = 0; cipher_idx < cipher_preferences->count; cipher_idx++) {
41 struct s2n_cipher_suite *expected_cipher = cipher_preferences->suites[cipher_idx];
42 conn->secure->cipher_suite = expected_cipher;
43
44 EXPECT_STRING_EQUAL(s2n_connection_get_cipher(conn), expected_cipher->name);
45 EXPECT_SUCCESS(s2n_connection_get_cipher_iana_value(conn, &iana_value[0], &iana_value[1]));
46 EXPECT_EQUAL(memcmp(expected_cipher->iana_value, iana_value, sizeof(iana_value)), 0);
47 }
48
49 EXPECT_SUCCESS(s2n_connection_free(conn));
50
51 END_TEST();
52 return S2N_SUCCESS;
53 }