aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmo-pcap/osmo_tls.h
blob: 063773942ffda812fa726b094a9fb9a6ba9e6473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * osmo-pcap TLS code
 *
 * (C) 2016 by Holger Hans Peter Freyther <holger@moiji-mobile.com>
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#pragma once

#include <gnutls/gnutls.h>
#include <gnutls/abstract.h>

#include <stdbool.h>
#include <stdint.h>

struct osmo_fd;
struct osmo_wqueue;
struct osmo_pcap_client;
struct osmo_pcap_conn;
struct osmo_pcap_server;

struct osmo_tls_session {
	bool in_use;
	bool need_handshake;
	bool need_resend;
	gnutls_session_t session;

	/* any credentials */
	bool anon_alloc;
	gnutls_anon_client_credentials_t anon_cred;
	bool anon_serv_alloc;
	gnutls_anon_server_credentials_t anon_serv_cred;

	/* a x509 cert credential */
	bool cert_alloc;
	gnutls_certificate_credentials_t cert_cred;

	/* the private certificate */
	bool pcert_alloc;
	gnutls_pcert_st pcert;

	/* the private key in _RAM_ */
	bool privk_alloc;
	gnutls_privkey_t privk;

	struct osmo_wqueue *wqueue;

	int (*read)(struct osmo_tls_session *session);
	void (*error)(struct osmo_tls_session *session);
	void (*handshake_done)(struct osmo_tls_session *session);
};

void osmo_tls_init(void);

bool osmo_tls_init_client_session(struct osmo_pcap_client *client);


bool osmo_tls_init_server_session(struct osmo_pcap_conn *conn, struct osmo_pcap_server *server);
void osmo_tls_release(struct osmo_tls_session *);

int osmo_tls_client_bfd_cb(struct osmo_fd *fd, unsigned int what);

size_t osmo_tls_pending(struct osmo_tls_session *session);
void osmo_tls_server_init(struct osmo_pcap_server *server);

void osmo_tls_dh_load(struct osmo_pcap_server *server);
void osmo_tls_dh_generate(struct osmo_pcap_server *server);