Latest update.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "bio_local.h"
|
||||
#include "internal/ktls.h"
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
@@ -51,6 +52,17 @@ int BIO_socket(int domain, int socktype, int protocol, int options)
|
||||
BIOerr(BIO_F_BIO_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
{
|
||||
/*
|
||||
* The new socket is created successfully regardless of ktls_enable.
|
||||
* ktls_enable doesn't change any functionality of the socket, except
|
||||
* changing the setsockopt to enable the processing of ktls_start.
|
||||
* Thus, it is not a problem to call it for non-TLS sockets.
|
||||
*/
|
||||
ktls_enable(sock);
|
||||
}
|
||||
# endif
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
@@ -750,7 +750,7 @@ int BIO_set_ex_data(BIO *bio, int idx, void *data)
|
||||
return CRYPTO_set_ex_data(&(bio->ex_data), idx, data);
|
||||
}
|
||||
|
||||
void *BIO_get_ex_data(BIO *bio, int idx)
|
||||
void *BIO_get_ex_data(const BIO *bio, int idx)
|
||||
{
|
||||
return CRYPTO_get_ex_data(&(bio->ex_data), idx);
|
||||
}
|
||||
|
||||
@@ -222,19 +222,20 @@ static int acpt_state(BIO *b, BIO_ACCEPT *c)
|
||||
break;
|
||||
|
||||
case ACPT_S_CREATE_SOCKET:
|
||||
ret = BIO_socket(BIO_ADDRINFO_family(c->addr_iter),
|
||||
BIO_ADDRINFO_socktype(c->addr_iter),
|
||||
BIO_ADDRINFO_protocol(c->addr_iter), 0);
|
||||
if (ret == (int)INVALID_SOCKET) {
|
||||
s = BIO_socket(BIO_ADDRINFO_family(c->addr_iter),
|
||||
BIO_ADDRINFO_socktype(c->addr_iter),
|
||||
BIO_ADDRINFO_protocol(c->addr_iter), 0);
|
||||
if (s == (int)INVALID_SOCKET) {
|
||||
ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
|
||||
"calling socket(%s, %s)",
|
||||
c->param_addr, c->param_serv);
|
||||
BIOerr(BIO_F_ACPT_STATE, BIO_R_UNABLE_TO_CREATE_SOCKET);
|
||||
goto exit_loop;
|
||||
}
|
||||
c->accept_sock = ret;
|
||||
b->num = ret;
|
||||
c->accept_sock = s;
|
||||
b->num = s;
|
||||
c->state = ACPT_S_LISTEN;
|
||||
s = -1;
|
||||
break;
|
||||
|
||||
case ACPT_S_LISTEN:
|
||||
|
||||
+52
-2
@@ -11,6 +11,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "bio_local.h"
|
||||
#include "internal/ktls.h"
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
|
||||
@@ -20,6 +21,9 @@ typedef struct bio_connect_st {
|
||||
char *param_hostname;
|
||||
char *param_service;
|
||||
int connect_mode;
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
unsigned char record_type;
|
||||
# endif
|
||||
|
||||
BIO_ADDRINFO *addr_first;
|
||||
const BIO_ADDRINFO *addr_iter;
|
||||
@@ -308,7 +312,12 @@ static int conn_read(BIO *b, char *out, int outl)
|
||||
|
||||
if (out != NULL) {
|
||||
clear_socket_error();
|
||||
ret = readsocket(b->num, out, outl);
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
if (BIO_get_ktls_recv(b))
|
||||
ret = ktls_read_record(b->num, out, outl);
|
||||
else
|
||||
# endif
|
||||
ret = readsocket(b->num, out, outl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (BIO_sock_should_retry(ret))
|
||||
@@ -333,7 +342,16 @@ static int conn_write(BIO *b, const char *in, int inl)
|
||||
}
|
||||
|
||||
clear_socket_error();
|
||||
ret = writesocket(b->num, in, inl);
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
if (BIO_should_ktls_ctrl_msg_flag(b)) {
|
||||
ret = ktls_send_ctrl_message(b->num, data->record_type, in, inl);
|
||||
if (ret >= 0) {
|
||||
ret = inl;
|
||||
BIO_clear_ktls_ctrl_msg_flag(b);
|
||||
}
|
||||
} else
|
||||
# endif
|
||||
ret = writesocket(b->num, in, inl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (BIO_sock_should_retry(ret))
|
||||
@@ -349,6 +367,13 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
const char **pptr = NULL;
|
||||
long ret = 1;
|
||||
BIO_CONNECT *data;
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
# ifdef __FreeBSD__
|
||||
struct tls_enable *crypto_info;
|
||||
# else
|
||||
struct tls12_crypto_info_aes_gcm_128 *crypto_info;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
data = (BIO_CONNECT *)b->ptr;
|
||||
|
||||
@@ -497,6 +522,31 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
case BIO_CTRL_EOF:
|
||||
ret = (b->flags & BIO_FLAGS_IN_EOF) != 0 ? 1 : 0;
|
||||
break;
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
case BIO_CTRL_SET_KTLS:
|
||||
# ifdef __FreeBSD__
|
||||
crypto_info = (struct tls_enable *)ptr;
|
||||
# else
|
||||
crypto_info = (struct tls12_crypto_info_aes_gcm_128 *)ptr;
|
||||
# endif
|
||||
ret = ktls_start(b->num, crypto_info, sizeof(*crypto_info), num);
|
||||
if (ret)
|
||||
BIO_set_ktls_flag(b, num);
|
||||
break;
|
||||
case BIO_CTRL_GET_KTLS_SEND:
|
||||
return BIO_should_ktls_flag(b, 1);
|
||||
case BIO_CTRL_GET_KTLS_RECV:
|
||||
return BIO_should_ktls_flag(b, 0);
|
||||
case BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG:
|
||||
BIO_set_ktls_ctrl_msg_flag(b);
|
||||
data->record_type = num;
|
||||
ret = 0;
|
||||
break;
|
||||
case BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG:
|
||||
BIO_clear_ktls_ctrl_msg_flag(b);
|
||||
ret = 0;
|
||||
break;
|
||||
# endif
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user