2 * TLS module - main server part
4 * Copyright (C) 2005-2010 iptelorg GmbH
6 * This file is part of Kamailio, a free SIP server.
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 /** main tls part (implements the tls hooks that are called from the tcp code).
32 #include "../../core/tcp_conn.h"
33 #include "tls_domain.h"
34 #include "tls_ct_wrq.h"
36 enum tls_conn_states {
44 unsigned int pos; /* current position */
45 unsigned int size; /* total size (buf) */
50 #define F_TLS_CON_WR_WANTS_RD 1 /* write wants read */
51 #define F_TLS_CON_HANDSHAKED 2 /* connection is handshaked */
52 #define F_TLS_CON_RENEGOTIATION 4 /* renegotiation by clinet */
54 struct tls_extra_data {
55 tls_domains_cfg_t* cfg; /* Configuration used for this connection */
56 SSL* ssl; /* SSL context used for the connection */
57 BIO* rwbio; /* bio used for read/write
58 * (openssl code might add buffering BIOs so
59 * it's better to remember our original BIO) */
61 struct tls_rd_buf* enc_rd_buf;
63 enum tls_conn_states state;
67 /* return true if write wants read */
68 #define tls_write_wants_read(tls_ed) (tls_ed->flags & F_TLS_CON_WR_WANTS_RD)
72 * Called when new tcp connection is accepted
74 int tls_h_tcpconn_init_f(struct tcp_connection *c, int sock);
77 * clean the extra data upon connection shut down
79 void tls_h_tcpconn_clean_f(struct tcp_connection *c);
82 * shut down the TLS connection
84 void tls_h_tcpconn_close_f(struct tcp_connection *c, int fd);
86 int tls_h_encode_f(struct tcp_connection *c, const char ** pbuf,
87 unsigned int* plen, const char** rest_buf, unsigned int* rest_len,
88 snd_flags_t* send_flags) ;
90 int tls_h_read_f(struct tcp_connection *c, int* flags);
92 int tls_h_fix_read_conn(struct tcp_connection *c);
94 int tls_connect(struct tcp_connection *c, int* error);
95 int tls_accept(struct tcp_connection *c, int* error);
97 void tls_lookup_event_routes(void);
98 #endif /* _TLS_SERVER_H */