Debian Codegraph @

crt/s2n/tests/unit/s2n_handshake_io_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 #include "utils/s2n_result.h"
20
21 bool s2n_custom_send_fn_called = false;
22 static int s2n_expect_concurrent_error_send_fn(void *io_context, const uint8_t *buf, uint32_t len)
23 {
24 struct s2n_connection *conn = (struct s2n_connection *) io_context;
25 s2n_custom_send_fn_called = true;
26
27 s2n_blocked_status blocked = S2N_NOT_BLOCKED;
28 ssize_t result = s2n_negotiate(conn, &blocked);
29 EXPECT_FAILURE_WITH_ERRNO(result, S2N_ERR_REENTRANCY);
30 return result;
31 }
32
33 int main(int argc, char **argv)
34 {
35 BEGIN_TEST();
36
37 /* s2n_negotiate can't be called recursively */
38 {
39 /* Setup connections */
40 struct s2n_connection *conn = NULL;
41 EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
42 EXPECT_OK(s2n_connection_set_tls12_security_policy(conn));
43 EXPECT_OK(s2n_connection_set_secrets(conn));
44
45 /* Setup bad callback */
46 EXPECT_SUCCESS(s2n_connection_set_send_cb(conn, s2n_expect_concurrent_error_send_fn));
47 EXPECT_SUCCESS(s2n_connection_set_send_ctx(conn, (void *) conn));
48
49 /* Negotiate. When we attempt to send the ClientHello, the send callback
50 * should fail due to a reentrancy error.
51 */
52 s2n_custom_send_fn_called = false;
53 s2n_blocked_status blocked = S2N_NOT_BLOCKED;
54 EXPECT_FAILURE_WITH_ERRNO(s2n_negotiate(conn, &blocked), S2N_ERR_IO);
55 EXPECT_TRUE(s2n_custom_send_fn_called);
56
57 /* Cleanup */
58 EXPECT_SUCCESS(s2n_connection_free(conn));
59 };
60
61 END_TEST();
62 }