2014-07-29 00:33:39 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap 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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <openssl/err.h>
|
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
#include "mbag.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "conn.h"
|
2014-08-16 00:33:33 +02:00
|
|
|
#include "sock.h"
|
|
|
|
#include "dtls_openssl.h"
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-06 21:51:50 +01:00
|
|
|
int dtls_openssl_accept(struct conn *conn)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!conn->dtls_data)
|
2015-02-06 21:51:50 +01:00
|
|
|
conn->dtls_data =
|
|
|
|
dtls_openssl_data_create(conn, DTLSv1_server_method(),
|
|
|
|
dtls_openssl_bio_method());
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-06 21:51:50 +01:00
|
|
|
struct dtls_openssl_data *d = (struct dtls_openssl_data *) conn->dtls_data;
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!d)
|
|
|
|
return 0;
|
|
|
|
|
2015-02-06 21:51:50 +01:00
|
|
|
int i, rc;
|
|
|
|
for (i = 0; i < conn->wait_dtls; i++) {
|
2014-07-11 22:12:11 +02:00
|
|
|
rc = SSL_accept(d->ssl);
|
2015-02-06 21:51:50 +01:00
|
|
|
if (rc == 1) {
|
2014-07-11 22:12:11 +02:00
|
|
|
conn->read = dtls_openssl_read;
|
|
|
|
conn->write = dtls_openssl_write;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-16 12:40:14 +02:00
|
|
|
rc = dtls_openssl_log_error_queue("DTLS accept error:");
|
2014-08-16 00:33:33 +02:00
|
|
|
if (rc)
|
|
|
|
return 0;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2015-02-06 21:51:50 +01:00
|
|
|
cw_log(LOG_ERR, "DTLS Error: Timeout while establishing session with %s.",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&conn->addr, sock_buf));
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|