2014-07-11 22:12:11 +02:00
|
|
|
#include <openssl/err.h>
|
|
|
|
|
|
|
|
#include "dtls_openssl.h"
|
|
|
|
#include "cw_log.h"
|
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
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,
|
|
|
|
};
|
2015-02-03 00:27:58 +01:00
|
|
|
*/
|
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)
|
|
|
|
{
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
BIO *b = SSL_get_rbio(ssl);
|
|
|
|
struct conn *conn = b->ptr;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
// printf("KEYY: %s\n",conn->dtls_psk);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
snprintf(identity, max_identity_len, "CLient_identity");
|
|
|
|
|
|
|
|
int l = conn->dtls_psk_len < max_psk_len ? conn->dtls_psk_len : max_psk_len;
|
2015-02-03 00:27:58 +01:00
|
|
|
memcpy(psk, conn->dtls_psk, l);
|
2014-07-11 22:12:11 +02:00
|
|
|
return l;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
int dtls_openssl_connect(struct conn *conn)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
|
|
|
if (!conn->dtls_data)
|
2015-02-03 00:27:58 +01:00
|
|
|
conn->dtls_data =
|
|
|
|
dtls_openssl_data_create(conn, DTLSv1_client_method(),
|
|
|
|
dtls_openssl_bio_method());
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +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-03 00:27:58 +01:00
|
|
|
// if (conn->dtls_psk)
|
|
|
|
// SSL_set_psk_client_callback(d->ssl, psk_client_cb);
|
2014-08-02 09:43:20 +02:00
|
|
|
|
2014-08-02 14:21:29 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
// dtls_openssl_set_certs(conn,d);
|
2014-08-02 14:21:29 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
if (conn->dtls_cert_file && conn->dtls_key_file) {
|
2014-08-02 09:43:20 +02:00
|
|
|
}
|
2015-02-03 00:27:58 +01:00
|
|
|
// char errstr[256];
|
|
|
|
int rc;
|
|
|
|
// do{
|
|
|
|
|
|
|
|
printf("Calling SSL connect\n");
|
|
|
|
rc = SSL_connect(d->ssl);
|
|
|
|
printf("Back from SSL connect\n");
|
|
|
|
exit(0);
|
2015-02-01 16:55:45 +01:00
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-01 16:55:45 +01:00
|
|
|
if (rc <= 0){
|
2014-07-11 22:12:11 +02:00
|
|
|
int e;
|
|
|
|
e = SSL_get_error(d->ssl,rc);
|
|
|
|
printf("Get Err %i\n",e);
|
|
|
|
|
|
|
|
|
|
|
|
printf("SSL Connect rc = %i\n",rc);
|
|
|
|
e = ERR_get_error();
|
|
|
|
ERR_error_string(e,errstr);
|
|
|
|
cw_log(LOG_ERR,"SSL_connect %s",errstr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
if (rc == 1) {
|
|
|
|
conn->read = dtls_openssl_read;
|
|
|
|
conn->write = dtls_openssl_write;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
// rc = dtls_openssl_log_error(d->ssl,rc,"DTLS connect");
|
|
|
|
rc = dtls_openssl_log_error(0, rc, "DTLS connect");
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
// } while (rc == 0 );
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
// printf("DTLS connect RC: %i\n",rc);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-03 00:27:58 +01:00
|
|
|
// int e = ERR_get_error();
|
|
|
|
// ERR_error_string(e,errstr);
|
|
|
|
// cw_log(LOG_ERR,"SSL_accept %s",errstr);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|