1/*
2 * tls.h
3 *
4 * Copyright (C) 2016 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#pragma once
24
25#include "socket.h"
26
27struct cf_tls_info_s;
28typedef struct cf_tls_info_s cf_tls_info;
29
30typedef struct cf_tls_spec_s {
31 char *ca_file;
32 char *ca_path;
33 char *cert_blacklist;
34 char *cert_file;
35 char *cipher_suite;
36 char *key_file;
37 char *key_file_password;
38 char *pw_string;
39 char *name;
40 char *protocols;
41} cf_tls_spec;
42
43void tls_check_init();
44
45void tls_cleanup();
46void tls_thread_cleanup();
47
48void tls_socket_init(cf_socket *sock);
49void tls_socket_term(cf_socket *sock);
50int tls_socket_shutdown(cf_socket *sock);
51void tls_socket_close(cf_socket *sock);
52
53char *tls_read_password(const char *path);
54cf_tls_info *tls_config_server_context(cf_tls_spec *tspec, bool auth_client, uint32_t n_peer_names, char **peer_names);
55cf_tls_info *tls_config_intra_context(cf_tls_spec *tspec, const char *which);
56
57void tls_socket_prepare_server(cf_tls_info *info, cf_socket *sock);
58void tls_socket_prepare_client(cf_tls_info *info, cf_socket *sock);
59
60static inline bool tls_socket_needs_handshake(cf_socket *sock)
61{
62 return sock->state == CF_SOCKET_STATE_TLS_HANDSHAKE;
63}
64
65void tls_socket_must_not_have_data(cf_socket *sock, const char *caller);
66
67int tls_socket_accept(cf_socket *sock);
68int tls_socket_connect(cf_socket *sock);
69int tls_socket_accept_block(cf_socket *sock);
70int tls_socket_connect_block(cf_socket *sock);
71
72int tls_socket_recv(cf_socket *sock, void *buf, size_t sz, int32_t flags,
73 uint64_t timeout_msec);
74
75int tls_socket_send(cf_socket *sock, void const *buf, size_t sz, int32_t flags,
76 uint64_t timeout_msec);
77
78int tls_socket_pending(cf_socket *sock);
79