2014-07-11 22:12:11 +02:00
|
|
|
#include <openssl/err.h>
|
|
|
|
|
2018-03-17 17:29:09 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "dtls_openssl.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-08 14:00:29 +01:00
|
|
|
#include "cw_util.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "timer.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
unsigned int psk_client_cb(SSL * ssl,
|
|
|
|
const char *hint,
|
|
|
|
char *identity,
|
|
|
|
unsigned int max_identity_len,
|
|
|
|
unsigned char *psk, unsigned int max_psk_len)
|
|
|
|
{
|
2018-03-11 11:29:00 +01:00
|
|
|
int l;
|
2015-02-03 00:27:58 +01:00
|
|
|
BIO *b = SSL_get_rbio(ssl);
|
2022-08-09 22:35:47 +02:00
|
|
|
/*struct cw_Conn *conn = b->ptr;*/
|
|
|
|
struct cw_Conn * conn = BIO_get_data(b); /*b->ptr;*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
snprintf(identity, max_identity_len, "CLient_identity");
|
|
|
|
|
2018-04-04 10:59:07 +02:00
|
|
|
l = bstr16_len(conn->dtls_psk) < max_psk_len ? bstr16_len(conn->dtls_psk) : max_psk_len;
|
|
|
|
memcpy(psk, bstr16_data(conn->dtls_psk), l);
|
2014-07-11 22:12:11 +02:00
|
|
|
return l;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-08 00:57:19 +01:00
|
|
|
int
|
2022-08-09 22:35:47 +02:00
|
|
|
dtls_openssl_connect(struct cw_Conn *conn)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-11 11:29:00 +01:00
|
|
|
struct dtls_openssl_data *d;
|
|
|
|
int rc;
|
|
|
|
time_t timer;
|
2022-07-11 08:26:56 +02:00
|
|
|
|
|
|
|
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call");
|
|
|
|
|
|
|
|
BIO_METHOD * biomethod = dtls_openssl_bio_method();
|
|
|
|
if (!biomethod){
|
|
|
|
cw_dbg(DBG_DTLS_BIO, "ERROR: Creating new OpenSSL BIO");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 1");
|
2018-03-11 11:29:00 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!conn->dtls_data)
|
2015-02-03 00:27:58 +01:00
|
|
|
conn->dtls_data =
|
2022-07-18 01:15:17 +02:00
|
|
|
dtls_openssl_data_create(conn, DTLS_client_method(),
|
2022-07-11 08:26:56 +02:00
|
|
|
biomethod);
|
|
|
|
|
|
|
|
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 2");
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-03-11 11:29:00 +01:00
|
|
|
d = (struct dtls_openssl_data *) conn->dtls_data;
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!d)
|
|
|
|
return 0;
|
|
|
|
|
2018-03-11 11:29:00 +01:00
|
|
|
/*
|
2020-03-08 00:57:19 +01:00
|
|
|
if (conn->dtls_psk)
|
|
|
|
SSL_set_psk_client_callback(d->ssl, psk_client_cb);
|
2018-03-11 11:29:00 +01:00
|
|
|
*/
|
2014-08-02 09:43:20 +02:00
|
|
|
|
2022-07-11 08:26:56 +02:00
|
|
|
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 3");
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-08 14:00:29 +01:00
|
|
|
errno =0;
|
2018-03-11 11:29:00 +01:00
|
|
|
timer = cw_timer_start(10);
|
2015-02-08 14:00:29 +01:00
|
|
|
do {
|
|
|
|
rc = SSL_connect(d->ssl);
|
|
|
|
}while(rc!=1 && errno==EAGAIN && !cw_timer_timeout(timer));
|
2020-03-08 00:57:19 +01:00
|
|
|
|
2022-07-18 01:15:17 +02:00
|
|
|
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 4 %d ",rc);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
if (rc == 1) {
|
2015-02-08 14:00:29 +01:00
|
|
|
cw_dbg(DBG_DTLS,"SSL connect successfull!");
|
2015-02-03 00:27:58 +01:00
|
|
|
conn->read = dtls_openssl_read;
|
|
|
|
conn->write = dtls_openssl_write;
|
|
|
|
return 1;
|
|
|
|
}
|
2022-07-11 08:26:56 +02:00
|
|
|
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 5");
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2020-03-08 00:57:19 +01:00
|
|
|
rc = dtls_openssl_log_error(d->ssl, rc, "DTLS connect");
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-03-08 00:57:19 +01:00
|
|
|
|