| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
|
| 20 |
#include "api/s2n.h" |
| 21 |
|
| 22 |
#define GUARD_EXIT_NULL(x) \ |
| 23 |
do { \ |
| 24 |
if (x == NULL) { \ |
| 25 |
fprintf(stderr, "NULL pointer encountered\n"); \ |
| 26 |
exit(1); \ |
| 27 |
} \ |
| 28 |
} while (0) |
| 29 |
|
| 30 |
#define GUARD_EXIT(x, msg) \ |
| 31 |
do { \ |
| 32 |
if ((x) < 0) { \ |
| 33 |
print_s2n_error(msg); \ |
| 34 |
exit(1); \ |
| 35 |
} \ |
| 36 |
} while (0) |
| 37 |
|
| 38 |
#define ENSURE_EXIT(x, msg) \ |
| 39 |
do { \ |
| 40 |
if (!(x)) { \ |
| 41 |
fprintf(stderr, "%s\n", msg); \ |
| 42 |
exit(1); \ |
| 43 |
} \ |
| 44 |
} while (0) |
| 45 |
|
| 46 |
#define GUARD_RETURN_NULL(x) \ |
| 47 |
do { \ |
| 48 |
if (x == NULL) { \ |
| 49 |
fprintf(stderr, "NULL pointer encountered\n"); \ |
| 50 |
return -1; \ |
| 51 |
} \ |
| 52 |
} while (0) |
| 53 |
|
| 54 |
#define GUARD_RETURN(x, msg) \ |
| 55 |
do { \ |
| 56 |
if ((x) < 0) { \ |
| 57 |
print_s2n_error(msg); \ |
| 58 |
return -1; \ |
| 59 |
} \ |
| 60 |
} while (0) |
| 61 |
|
| 62 |
#define ENSURE_RETURN(x, msg) \ |
| 63 |
do { \ |
| 64 |
if (!(x)) { \ |
| 65 |
fprintf(stderr, "%s\n", msg); \ |
| 66 |
return -1; \ |
| 67 |
} \ |
| 68 |
} while (0) |
| 69 |
|
| 70 |
#define S2N_MAX_PSK_LIST_LENGTH 10 |
| 71 |
#define MAX_KEY_LEN 32 |
| 72 |
#define MAX_VAL_LEN 255 |
| 73 |
|
| 74 |
struct session_cache_entry { |
| 75 |
uint8_t key[MAX_KEY_LEN]; |
| 76 |
uint8_t key_len; |
| 77 |
uint8_t value[MAX_VAL_LEN]; |
| 78 |
uint8_t value_len; |
| 79 |
}; |
| 80 |
|
| 81 |
struct verify_data { |
| 82 |
const char *trusted_host; |
| 83 |
}; |
| 84 |
|
| 85 |
struct conn_settings { |
| 86 |
unsigned mutual_auth : 1; |
| 87 |
unsigned self_service_blinding : 1; |
| 88 |
unsigned only_negotiate : 1; |
| 89 |
unsigned prefer_throughput : 1; |
| 90 |
unsigned prefer_low_latency : 1; |
| 91 |
unsigned enable_mfl : 1; |
| 92 |
unsigned session_ticket : 1; |
| 93 |
unsigned session_cache : 1; |
| 94 |
unsigned insecure : 1; |
| 95 |
unsigned use_corked_io : 1; |
| 96 |
unsigned https_server : 1; |
| 97 |
uint32_t https_bench; |
| 98 |
int max_conns; |
| 99 |
const char *ca_dir; |
| 100 |
const char *ca_file; |
| 101 |
const char *serialize_out; |
| 102 |
const char *deserialize_in; |
| 103 |
char *psk_optarg_list[S2N_MAX_PSK_LIST_LENGTH]; |
| 104 |
size_t psk_list_len; |
| 105 |
}; |
| 106 |
|
| 107 |
void print_s2n_error(const char *app_error); |
| 108 |
void send_data(struct s2n_connection *conn, int sockfd, const char *data, uint64_t len, s2n_blocked_status *blocked); |
| 109 |
int echo(struct s2n_connection *conn, int sockfd, bool *stop_echo); |
| 110 |
int wait_for_event(int fd, s2n_blocked_status blocked); |
| 111 |
int negotiate(struct s2n_connection *conn, int sockfd); |
| 112 |
int renegotiate(struct s2n_connection *conn, int sockfd); |
| 113 |
int wait_for_shutdown(struct s2n_connection *conn, int sockfd); |
| 114 |
int early_data_recv(struct s2n_connection *conn); |
| 115 |
int early_data_send(struct s2n_connection *conn, uint8_t *data, uint32_t len); |
| 116 |
int print_connection_info(struct s2n_connection *conn); |
| 117 |
int https(struct s2n_connection *conn, uint32_t bench); |
| 118 |
int key_log_callback(void *ctx, struct s2n_connection *conn, uint8_t *logline, size_t len); |
| 119 |
|
| 120 |
int cache_store_callback(struct s2n_connection *conn, void *ctx, uint64_t ttl, const void *key, uint64_t key_size, const void *value, uint64_t value_size); |
| 121 |
int cache_retrieve_callback(struct s2n_connection *conn, void *ctx, const void *key, uint64_t key_size, void *value, uint64_t *value_size); |
| 122 |
int cache_delete_callback(struct s2n_connection *conn, void *ctx, const void *key, uint64_t key_size); |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
int write_array_to_file(const char *path, uint8_t *data, size_t length); |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
int get_file_size(const char *path, size_t *length); |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
int load_file_to_array(const char *path, uint8_t *data, size_t max_length); |
| 153 |
char *load_file_to_cstring(const char *path); |
| 154 |
int s2n_str_hex_to_bytes(const unsigned char *hex, uint8_t *out_bytes, uint32_t max_out_bytes_len); |
| 155 |
int s2n_setup_external_psk_list(struct s2n_connection *conn, char *psk_optarg_list[S2N_MAX_PSK_LIST_LENGTH], size_t psk_list_len); |
| 156 |
uint8_t unsafe_verify_host(const char *host_name, size_t host_name_len, void *data); |
| 157 |
int s2n_setup_server_connection(struct s2n_connection *conn, int fd, struct s2n_config *config, struct conn_settings settings); |
| 158 |
int s2n_set_common_server_config(int max_early_data, struct s2n_config *config, struct conn_settings conn_settings, const char *cipher_prefs, const char *session_ticket_key_file_path); |
| 159 |
int s2n_connection_serialize_out(struct s2n_connection *conn, const char *file_path); |
| 160 |
int s2n_connection_deserialize_in(struct s2n_connection *conn, const char *file_path); |