actube/src/capwap/dtls_openssl_accept.c

87 lines
2.1 KiB
C

/*
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/>.
*/
#include <openssl/err.h>
#include "conn.h"
#include "sock.h"
#include "dtls_openssl.h"
#include "cw_log.h"
extern int dtls_openssl_log_error_queue(const char *txt);
static BIO_METHOD bio_methods = {
BIO_TYPE_DGRAM,
"cw packet",
dtls_openssl_bio_write,
dtls_openssl_bio_read,
dtls_openssl_bio_puts,
NULL, // dgram_gets
dtls_openssl_bio_ctrl,
dtls_openssl_bio_new,
dtls_openssl_bio_free,
NULL,
};
/*
static unsigned int psk_server_cb(SSL *ssl,const char *identity, unsigned char * psk, unsigned int max_psk_len)
{
BIO * b = SSL_get_rbio(ssl);
struct conn * conn = b->ptr;
int l = conn->dtls_psk_len < max_psk_len ? conn->dtls_psk_len : max_psk_len;
memcpy(psk,conn->dtls_psk,l);
return l;
}
*/
int dtls_openssl_accept(struct conn * conn)
{
if (!conn->dtls_data)
conn->dtls_data = dtls_openssl_data_create(conn,DTLSv1_server_method(),&bio_methods);
struct dtls_openssl_data * d = (struct dtls_openssl_data*)conn->dtls_data;
if (!d)
return 0;
// if (conn->dtls_psk)
// SSL_set_psk_server_callback( d->ssl, psk_server_cb);
int i,rc;
for (i=0; i<conn->dtls_wait_timer; i++){
rc = SSL_accept(d->ssl);
if (rc == 1)
{
conn->read = dtls_openssl_read;
conn->write = dtls_openssl_write;
return 1;
}
rc = dtls_openssl_log_error_queue("DTLS accept error:");
if (rc)
return 0;
}
cw_log(LOG_ERR,"DTLS Error: Timeout while establishing session with %s.",sock_addr2str(&conn->addr));
return 0;
}