1 /*
2  *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3  *
4  *  Copyright (c) 2015 Attila Molnar <attilamolnar@hush.com>
5  *  Copyright (c) 2015 Adam <Adam@anope.org>
6  *  Copyright (c) 2015-2021 ircd-hybrid development team
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21  *  USA
22  */
23 
24 /*! \file tls.h
25  * \brief A header for generic TLS functions
26  * \version $Id: tls.h 9858 2021-01-01 04:43:42Z michael $
27  */
28 
29 #ifndef INCLUDED_tls_h
30 #define INCLUDED_tls_h
31 
32 #ifdef HAVE_LIBCRYPTO
33 #include "tls_openssl.h"
34 #elif defined(HAVE_LIBGNUTLS)
35 #include "tls_gnutls.h"
36 #elif defined(HAVE_LIBWOLFSSL)
37 #include "tls_wolfssl.h"
38 #else
39 #include "tls_none.h"
40 #endif
41 
42 enum { TLS_HANDSHAKE_TIMEOUT = 5 };  /**< Time in seconds for the TLS handshake to time out */
43 
44 typedef enum _tls_role
45 {
46   TLS_ROLE_SERVER,
47   TLS_ROLE_CLIENT
48 } tls_role_t;
49 
50 typedef enum _tls_handshake_status
51 {
52   TLS_HANDSHAKE_DONE,
53   TLS_HANDSHAKE_WANT_READ,
54   TLS_HANDSHAKE_WANT_WRITE,
55   TLS_HANDSHAKE_ERROR
56 } tls_handshake_status_t;
57 
58 extern bool tls_is_initialized(void);
59 extern void tls_init(void);
60 extern bool tls_new_credentials(void);
61 
62 extern const char *tls_get_cipher(const tls_data_t *);
63 extern const char *tls_get_version(void);
64 
65 extern bool tls_isusing(tls_data_t *);
66 extern bool tls_new(tls_data_t *, int, tls_role_t);
67 extern void tls_free(tls_data_t *);
68 
69 extern tls_handshake_status_t tls_handshake(tls_data_t *, tls_role_t, const char **);
70 extern ssize_t tls_read(tls_data_t *, char *, size_t, bool *);
71 extern ssize_t tls_write(tls_data_t *, const char *, size_t, bool *);
72 
73 extern void tls_shutdown(tls_data_t *);
74 
75 extern bool tls_set_ciphers(tls_data_t *, const char *);
76 
77 extern bool tls_verify_certificate(tls_data_t *, tls_md_t, char **);
78 
79 #endif  /* INCLUDED_tls_h */
80