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"
|
2015-02-07 03:02:05 +01:00
|
|
|
#include "dtls.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()
|
|
|
|
{
|
|
|
|
static BIO_METHOD bio_methods;
|
|
|
|
|
|
|
|
bio_methods.type = BIO_TYPE_DGRAM;
|
|
|
|
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;
|
|
|
|
|
|
|
|
return &bio_methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dtls_openssl_bio_write(BIO * b, const char *data, int len)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
struct conn *conn = b->ptr;
|
2015-02-07 03:02:05 +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
|
|
|
{
|
2015-02-03 00:27:36 +01:00
|
|
|
|
|
|
|
struct conn *conn = b->ptr;
|
2015-02-07 03:02:05 +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
|
|
|
{
|
|
|
|
bi->init = 1;
|
|
|
|
bi->num = 0;
|
|
|
|
bi->flags = 0;
|
2015-02-03 00:27:36 +01:00
|
|
|
bi->ptr = NULL;
|
|
|
|
cw_dbg(DBG_DTLS_BIO, "SSL BIO new");
|
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
|
|
|
{
|
|
|
|
long ret = 1;
|
2015-02-03 00:27:36 +01:00
|
|
|
// long sockopt_val = 0;
|
|
|
|
// unsigned int sockopt_len = 0;
|
|
|
|
// BIO_memory_data* pData = (BIO_memory_data*)b->ptr;
|
2014-07-11 22:12:11 +02:00
|
|
|
//
|
2015-02-03 00:27:36 +01:00
|
|
|
// printf("BIO CONTROL cmd=%d,num=%d\n",cmd,num);
|
|
|
|
// exit(1);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
switch (cmd) {
|
2014-07-11 22:12:11 +02:00
|
|
|
case BIO_CTRL_RESET:
|
|
|
|
case BIO_CTRL_EOF:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_INFO:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_GET_CLOSE:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_SET_CLOSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_WPENDING:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2015-02-03 00:27:36 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
case BIO_CTRL_PENDING:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_DUP:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_FLUSH:
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_PUSH:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIO_CTRL_POP:
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
case BIO_CTRL_DGRAM_QUERY_MTU:
|
2015-02-03 00:27:36 +01:00
|
|
|
{
|
2015-03-12 23:21:57 +01:00
|
|
|
ret = 1300;
|
2015-02-03 00:27:36 +01:00
|
|
|
break;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
/* sockopt_len = sizeof(sockopt_val);
|
|
|
|
if ((ret = getsockopt(pData->sock, IPPROTO_IP, IP_MTU, (void *)&sockopt_val, &sockopt_len)) < 0 || sockopt_val < 0)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pData->nMtu = sockopt_val;
|
|
|
|
ret = sockopt_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-02-03 00:27:36 +01:00
|
|
|
*/ }
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
case BIO_CTRL_DGRAM_GET_MTU:
|
2014-08-16 10:17:33 +02:00
|
|
|
ret = 1500;
|
2015-02-03 00:27:36 +01:00
|
|
|
// ret = pData->nMtu;
|
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:
|
2015-02-03 00:27:36 +01:00
|
|
|
// pData->nMtu = num;
|
|
|
|
// ret = num;
|
2014-07-11 22:12:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|