2016-03-12 09:52:14 +01:00
|
|
|
/*
|
|
|
|
This file is part of actube.
|
2015-02-09 22:04:14 +01:00
|
|
|
|
2016-03-12 09:52:14 +01:00
|
|
|
actube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Implements dtls_gnutls_connect
|
|
|
|
*/
|
2015-03-23 07:48:27 +01:00
|
|
|
|
|
|
|
#include "gnutls/dtls.h"
|
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
#include "mbag.h"
|
2015-02-09 22:04:14 +01:00
|
|
|
#include "dtls.h"
|
|
|
|
#include "dtls_gnutls.h"
|
|
|
|
|
|
|
|
#include "conn.h"
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-02-09 22:04:14 +01:00
|
|
|
|
2015-04-14 07:42:23 +02:00
|
|
|
#include "sock.h"
|
2016-03-12 09:52:14 +01:00
|
|
|
/**
|
|
|
|
* Establish a DTLS connection using gnutls library
|
|
|
|
* @see #dtls_connect
|
|
|
|
*/
|
2015-02-09 22:04:14 +01:00
|
|
|
int dtls_gnutls_connect(struct conn *conn)
|
|
|
|
{
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2016-03-06 11:07:25 +01:00
|
|
|
struct dtls_gnutls_data *d;
|
|
|
|
d = dtls_gnutls_data_create(conn,
|
|
|
|
GNUTLS_CLIENT | GNUTLS_DATAGRAM | GNUTLS_NONBLOCK);
|
2015-02-09 22:04:14 +01:00
|
|
|
|
2016-03-12 03:56:48 +01:00
|
|
|
if (!d)
|
|
|
|
return 0;
|
|
|
|
|
2016-03-06 11:07:25 +01:00
|
|
|
// gnutls_dh_set_prime_bits(d->session, 512);
|
2016-03-12 22:30:12 +01:00
|
|
|
/*#if GNUTLS_VERSION_NUMBER >= 0x030100
|
2016-03-06 11:07:25 +01:00
|
|
|
gnutls_handshake_set_timeout(d->session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
|
2015-03-12 23:21:57 +01:00
|
|
|
|
2016-03-06 11:07:25 +01:00
|
|
|
gnutls_dtls_set_data_mtu(d->session, 1500);
|
2015-04-30 08:36:40 +02:00
|
|
|
#endif
|
2016-03-06 11:07:25 +01:00
|
|
|
gnutls_dtls_set_mtu(d->session, 1500);
|
2016-03-12 22:30:12 +01:00
|
|
|
*/
|
2015-03-23 07:48:27 +01:00
|
|
|
|
2016-03-06 11:07:25 +01:00
|
|
|
int rc;
|
2016-03-12 09:52:14 +01:00
|
|
|
cw_dbg(DBG_DTLS,"Starting handshake");
|
2015-02-09 22:04:14 +01:00
|
|
|
do {
|
|
|
|
rc = gnutls_handshake(d->session);
|
2016-03-06 11:07:25 +01:00
|
|
|
} while (rc == GNUTLS_E_AGAIN);
|
2015-02-09 22:04:14 +01:00
|
|
|
|
2016-03-06 11:07:25 +01:00
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
cw_log(LOG_ERR, "DTLS (gnutls) Can't connect to %s: %s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&conn->addr,sock_buf), gnutls_strerror(rc));
|
2015-02-09 22:04:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-03-12 23:21:57 +01:00
|
|
|
|
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
cw_dbg(DBG_DTLS, "Handshake with %s successful", sock_addr2str(&conn->addr,sock_buf));
|
2015-03-12 23:21:57 +01:00
|
|
|
|
2016-03-06 11:07:25 +01:00
|
|
|
conn->dtls_data = d;
|
2015-03-12 23:21:57 +01:00
|
|
|
conn->read = dtls_gnutls_read;
|
|
|
|
conn->write = dtls_gnutls_write;
|
|
|
|
|
2016-03-06 11:07:25 +01:00
|
|
|
|
2015-02-09 22:04:14 +01:00
|
|
|
return 1;
|
|
|
|
}
|