2016-03-12 22:31:13 +01:00
|
|
|
/*
|
|
|
|
This file is part of actube.
|
|
|
|
|
|
|
|
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 Functions for OpenSSL BIO
|
|
|
|
*/
|
|
|
|
|
2018-03-17 17:29:09 +01:00
|
|
|
|
2014-08-16 10:17:33 +02:00
|
|
|
#include <errno.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include "dtls_openssl.h"
|
2018-04-02 01:39:08 +02:00
|
|
|
#include "dtls_common.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-03-17 17:29:09 +01:00
|
|
|
|
2018-03-26 19:05:14 +02:00
|
|
|
#include <openssl/bio.h>
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#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"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
|
|
|
|
BIO_METHOD *dtls_openssl_bio_method()
|
|
|
|
{
|
2022-07-11 08:26:56 +02:00
|
|
|
int index = BIO_get_new_index() ;
|
2022-07-18 01:15:17 +02:00
|
|
|
/* index = BIO_TYPE_DGRAM;*/
|
2022-07-11 08:26:56 +02:00
|
|
|
cw_dbg(DBG_DTLS_BIO, "Creating new OpenSSL BIO Methods");
|
|
|
|
|
2022-07-10 12:25:14 +02:00
|
|
|
BIO_METHOD * bio_methods;
|
2022-07-11 08:26:56 +02:00
|
|
|
bio_methods = BIO_meth_new(index,"CW Packet");
|
|
|
|
if (!bio_methods){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BIO_meth_set_write(bio_methods,dtls_openssl_bio_write);
|
|
|
|
BIO_meth_set_read(bio_methods,dtls_openssl_bio_read);
|
|
|
|
BIO_meth_set_puts(bio_methods,dtls_openssl_bio_puts);
|
|
|
|
BIO_meth_set_ctrl(bio_methods,dtls_openssl_bio_ctrl);
|
|
|
|
BIO_meth_set_create(bio_methods,dtls_openssl_bio_new);
|
|
|
|
BIO_meth_set_destroy(bio_methods,dtls_openssl_bio_free);
|
|
|
|
|
|
|
|
|
|
|
|
/* bio_methods = BIO_mth_new(BIO_TYPE_DGRAM,"CW Packet");*/
|
2015-02-03 00:27:36 +01:00
|
|
|
|
2022-07-10 12:25:14 +02:00
|
|
|
|
|
|
|
/* bio_methods.type = BIO_TYPE_DGRAM;
|
2015-02-03 00:27:36 +01:00
|
|
|
bio_methods.name = "CW packet";
|
|
|
|
bio_methods.bwrite = dtls_openssl_bio_write;
|
|
|
|
bio_methods.bread = dtls_openssl_bio_read;
|
|
|
|
bio_methods.bputs = dtls_openssl_bio_puts;
|
|
|
|
bio_methods.bgets = 0;
|
|
|
|
bio_methods.ctrl = dtls_openssl_bio_ctrl;
|
|
|
|
bio_methods.create = dtls_openssl_bio_new;
|
|
|
|
bio_methods.destroy = dtls_openssl_bio_free;
|
|
|
|
bio_methods.callback_ctrl = 0;
|
2022-07-10 12:25:14 +02:00
|
|
|
*/
|
2015-02-03 00:27:36 +01:00
|
|
|
|
2022-07-11 08:26:56 +02:00
|
|
|
return bio_methods;
|
2015-02-03 00:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int dtls_openssl_bio_write(BIO * b, const char *data, int len)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2022-08-09 22:35:47 +02:00
|
|
|
/* struct cw_Conn *conn = b->ptr;*/
|
|
|
|
struct cw_Conn *conn = BIO_get_data(b);
|
2016-03-12 22:31:13 +01:00
|
|
|
return dtls_bio_write(conn, data, len);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
int dtls_openssl_bio_read(BIO * b, char *out, int maxlen)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2022-08-09 22:35:47 +02:00
|
|
|
/*struct cw_Conn *conn = b->ptr;*/
|
|
|
|
struct cw_Conn *conn = BIO_get_data(b);
|
2016-03-12 22:31:13 +01:00
|
|
|
return dtls_bio_read(conn, out, maxlen);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
int dtls_openssl_bio_new(BIO * bi)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2022-07-11 08:26:56 +02:00
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
bi->init = 1;
|
|
|
|
bi->num = 0;
|
|
|
|
bi->flags = 0;
|
2015-02-03 00:27:36 +01:00
|
|
|
bi->ptr = NULL;
|
2022-07-11 08:26:56 +02:00
|
|
|
*/
|
|
|
|
BIO_set_init(bi,1);
|
|
|
|
|
2016-03-12 22:31:13 +01:00
|
|
|
cw_dbg(DBG_DTLS_BIO, "Creating new OpenSSL BIO");
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
int dtls_openssl_bio_puts(BIO * b, const char *str)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2015-02-03 00:27:36 +01:00
|
|
|
cw_dbg(DBG_DTLS_BIO, "SSL BIO puts: '%s'", str);
|
2014-07-11 22:12:11 +02:00
|
|
|
return dtls_openssl_bio_write(b, str, strlen(str));
|
|
|
|
}
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
int dtls_openssl_bio_free(BIO * bio)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2015-02-03 00:27:36 +01:00
|
|
|
if (bio == NULL)
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
long dtls_openssl_bio_ctrl(BIO * b, int cmd, long num, void *ptr)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2022-08-09 22:35:47 +02:00
|
|
|
/*struct cw_Conn *conn = b->ptr;*/
|
|
|
|
struct cw_Conn *conn = BIO_get_data(b);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-12 22:31:13 +01:00
|
|
|
long ret = 1;
|
2015-02-03 00:27:36 +01:00
|
|
|
switch (cmd) {
|
2014-07-11 22:12:11 +02:00
|
|
|
case BIO_CTRL_DUP:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_FLUSH:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_DGRAM_QUERY_MTU:
|
|
|
|
case BIO_CTRL_DGRAM_GET_MTU:
|
2016-03-12 22:31:13 +01:00
|
|
|
ret = conn->dtls_mtu;
|
2014-07-11 22:12:11 +02:00
|
|
|
break;
|
2015-02-03 00:27:36 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
case BIO_CTRL_DGRAM_SET_MTU:
|
2016-03-12 22:31:13 +01:00
|
|
|
ret = 1;
|
2014-07-11 22:12:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|