| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <errno.h> |
| 17 |
|
| 18 |
#include "api/s2n.h" |
| 19 |
#include "s2n_test.h" |
| 20 |
#include "testlib/s2n_testlib.h" |
| 21 |
#include "tls/s2n_connection.h" |
| 22 |
|
| 23 |
#define RANDOM_ERRNO 150 |
| 24 |
|
| 25 |
int fake_recv(void *io_context, uint8_t *buf, uint32_t len) |
| 26 |
{ |
| 27 |
|
| 28 |
errno = EAGAIN; |
| 29 |
return -1; |
| 30 |
} |
| 31 |
|
| 32 |
int fake_send(void *io_context, const uint8_t *buf, uint32_t len) |
| 33 |
{ |
| 34 |
|
| 35 |
errno = ENOENT; |
| 36 |
return -1; |
| 37 |
} |
| 38 |
|
| 39 |
int main(int argc, char **argv) |
| 40 |
{ |
| 41 |
struct s2n_connection *conn = NULL; |
| 42 |
s2n_blocked_status blocked; |
| 43 |
|
| 44 |
BEGIN_TEST(); |
| 45 |
EXPECT_SUCCESS(s2n_disable_tls13_in_test()); |
| 46 |
|
| 47 |
|
| 48 |
{ |
| 49 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 50 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 51 |
|
| 52 |
|
| 53 |
EXPECT_SUCCESS(s2n_connection_set_recv_cb(conn, &fake_recv)); |
| 54 |
EXPECT_SUCCESS(s2n_connection_set_send_cb(conn, &fake_send)); |
| 55 |
|
| 56 |
|
| 57 |
EXPECT_EQUAL(s2n_negotiate(conn, &blocked), -1); |
| 58 |
EXPECT_EQUAL(errno, ENOENT); |
| 59 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO); |
| 60 |
s2n_errno = 0; |
| 61 |
|
| 62 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
{ |
| 70 |
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT)); |
| 71 |
EXPECT_OK(s2n_connection_set_tls12_security_policy(conn)); |
| 72 |
|
| 73 |
|
| 74 |
errno = RANDOM_ERRNO; |
| 75 |
|
| 76 |
|
| 77 |
conn->recv = NULL; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
EXPECT_EQUAL(s2n_negotiate(conn, &blocked), -1); |
| 82 |
EXPECT_EQUAL(errno, 0); |
| 83 |
EXPECT_EQUAL(s2n_errno, S2N_ERR_IO); |
| 84 |
s2n_errno = 0; |
| 85 |
|
| 86 |
EXPECT_SUCCESS(s2n_connection_free(conn)); |
| 87 |
}; |
| 88 |
|
| 89 |
END_TEST(); |
| 90 |
} |