Latest update.
This commit is contained in:
+3
-3
@@ -24,7 +24,7 @@
|
||||
static int wsa_init_done = 0;
|
||||
# endif
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
int BIO_get_host_ip(const char *str, unsigned char *ip)
|
||||
{
|
||||
BIO_ADDRINFO *res = NULL;
|
||||
@@ -103,7 +103,7 @@ int BIO_sock_error(int sock)
|
||||
return j;
|
||||
}
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
struct hostent *BIO_gethostbyname(const char *name)
|
||||
{
|
||||
/*
|
||||
@@ -195,7 +195,7 @@ int BIO_socket_ioctl(int fd, long type, void *arg)
|
||||
return i;
|
||||
}
|
||||
|
||||
# if !OPENSSL_API_1_1_0
|
||||
# ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
||||
int BIO_get_accept_socket(char *host, int bind_mode)
|
||||
{
|
||||
int s = INVALID_SOCKET;
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "bio_local.h"
|
||||
|
||||
static int prefix_write(BIO *b, const char *out, size_t outl,
|
||||
size_t *numwritten);
|
||||
static int prefix_read(BIO *b, char *buf, size_t size, size_t *numread);
|
||||
static int prefix_puts(BIO *b, const char *str);
|
||||
static int prefix_gets(BIO *b, char *str, int size);
|
||||
static long prefix_ctrl(BIO *b, int cmd, long arg1, void *arg2);
|
||||
static int prefix_create(BIO *b);
|
||||
static int prefix_destroy(BIO *b);
|
||||
static long prefix_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp);
|
||||
|
||||
static const BIO_METHOD prefix_meth = {
|
||||
BIO_TYPE_BUFFER,
|
||||
"prefix",
|
||||
prefix_write,
|
||||
NULL,
|
||||
prefix_read,
|
||||
NULL,
|
||||
prefix_puts,
|
||||
prefix_gets,
|
||||
prefix_ctrl,
|
||||
prefix_create,
|
||||
prefix_destroy,
|
||||
prefix_callback_ctrl,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_f_prefix(void)
|
||||
{
|
||||
return &prefix_meth;
|
||||
}
|
||||
|
||||
typedef struct prefix_ctx_st {
|
||||
char *prefix; /* Text prefix, given by user */
|
||||
unsigned int indent; /* Indentation amount, given by user */
|
||||
|
||||
int linestart; /* flag to indicate we're at the line start */
|
||||
} PREFIX_CTX;
|
||||
|
||||
static int prefix_create(BIO *b)
|
||||
{
|
||||
PREFIX_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
ctx->prefix = NULL;
|
||||
ctx->indent = 0;
|
||||
ctx->linestart = 1;
|
||||
BIO_set_data(b, ctx);
|
||||
BIO_set_init(b, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int prefix_destroy(BIO *b)
|
||||
{
|
||||
PREFIX_CTX *ctx = BIO_get_data(b);
|
||||
|
||||
OPENSSL_free(ctx->prefix);
|
||||
OPENSSL_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int prefix_read(BIO *b, char *in, size_t size, size_t *numread)
|
||||
{
|
||||
return BIO_read_ex(BIO_next(b), in, size, numread);
|
||||
}
|
||||
|
||||
static int prefix_write(BIO *b, const char *out, size_t outl,
|
||||
size_t *numwritten)
|
||||
{
|
||||
PREFIX_CTX *ctx = BIO_get_data(b);
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* If no prefix is set or if it's empty, and no indentation amount is set,
|
||||
* we've got nothing to do here
|
||||
*/
|
||||
if ((ctx->prefix == NULL || *ctx->prefix == '\0')
|
||||
&& ctx->indent == 0) {
|
||||
/*
|
||||
* We do note if what comes next will be a new line, though, so we're
|
||||
* prepared to handle prefix and indentation the next time around.
|
||||
*/
|
||||
if (outl > 0)
|
||||
ctx->linestart = (out[outl-1] == '\n');
|
||||
return BIO_write_ex(BIO_next(b), out, outl, numwritten);
|
||||
}
|
||||
|
||||
*numwritten = 0;
|
||||
|
||||
while (outl > 0) {
|
||||
size_t i;
|
||||
char c;
|
||||
|
||||
/*
|
||||
* If we know that we're at the start of the line, output prefix and
|
||||
* indentation.
|
||||
*/
|
||||
if (ctx->linestart) {
|
||||
size_t dontcare;
|
||||
|
||||
if (ctx->prefix != NULL
|
||||
&& !BIO_write_ex(BIO_next(b), ctx->prefix, strlen(ctx->prefix),
|
||||
&dontcare))
|
||||
return 0;
|
||||
BIO_printf(BIO_next(b), "%*s", ctx->indent, "");
|
||||
ctx->linestart = 0;
|
||||
}
|
||||
|
||||
/* Now, go look for the next LF, or the end of the string */
|
||||
for (i = 0, c = '\0'; i < outl && (c = out[i]) != '\n'; i++)
|
||||
continue;
|
||||
if (c == '\n')
|
||||
i++;
|
||||
|
||||
/* Output what we found so far */
|
||||
while (i > 0) {
|
||||
size_t num = 0;
|
||||
|
||||
if (!BIO_write_ex(BIO_next(b), out, i, &num))
|
||||
return 0;
|
||||
out += num;
|
||||
outl -= num;
|
||||
*numwritten += num;
|
||||
i -= num;
|
||||
}
|
||||
|
||||
/* If we found a LF, what follows is a new line, so take note */
|
||||
if (c == '\n')
|
||||
ctx->linestart = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static long prefix_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
{
|
||||
long ret = 0;
|
||||
PREFIX_CTX *ctx = BIO_get_data(b);
|
||||
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_SET_PREFIX:
|
||||
OPENSSL_free(ctx->prefix);
|
||||
if (ptr == NULL) {
|
||||
ctx->prefix = NULL;
|
||||
ret = 1;
|
||||
} else {
|
||||
ctx->prefix = OPENSSL_strdup((const char *)ptr);
|
||||
ret = ctx->prefix != NULL;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_SET_INDENT:
|
||||
if (num >= 0) {
|
||||
ctx->indent = (unsigned int)num;
|
||||
ret = 1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_INDENT:
|
||||
ret = (long)ctx->indent;
|
||||
break;
|
||||
default:
|
||||
/* Commands that we intercept before passing them along */
|
||||
switch (cmd) {
|
||||
case BIO_C_FILE_SEEK:
|
||||
case BIO_CTRL_RESET:
|
||||
ctx->linestart = 1;
|
||||
break;
|
||||
}
|
||||
if (BIO_next(b) != NULL)
|
||||
ret = BIO_ctrl(BIO_next(b), cmd, num, ptr);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long prefix_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
|
||||
{
|
||||
return BIO_callback_ctrl(BIO_next(b), cmd, fp);
|
||||
}
|
||||
|
||||
static int prefix_gets(BIO *b, char *buf, int size)
|
||||
{
|
||||
return BIO_gets(BIO_next(b), buf, size);
|
||||
}
|
||||
|
||||
static int prefix_puts(BIO *b, const char *str)
|
||||
{
|
||||
return BIO_write(b, str, strlen(str));
|
||||
}
|
||||
@@ -432,7 +432,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
b->init = 1;
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_serv);
|
||||
data->param_serv = BUF_strdup(ptr);
|
||||
data->param_serv = OPENSSL_strdup(ptr);
|
||||
b->init = 1;
|
||||
} else if (num == 2) {
|
||||
data->bind_mode |= BIO_SOCK_NONBLOCK;
|
||||
|
||||
@@ -54,6 +54,7 @@ void BIO_CONNECT_free(BIO_CONNECT *a);
|
||||
#define BIO_CONN_S_CONNECT 4
|
||||
#define BIO_CONN_S_OK 5
|
||||
#define BIO_CONN_S_BLOCKED_CONNECT 6
|
||||
#define BIO_CONN_S_CONNECT_ERROR 7
|
||||
|
||||
static const BIO_METHOD methods_connectp = {
|
||||
BIO_TYPE_CONNECT,
|
||||
@@ -172,7 +173,8 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
|
||||
ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(),
|
||||
"calling connect(%s, %s)",
|
||||
c->param_hostname, c->param_service);
|
||||
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR);
|
||||
c->state = BIO_CONN_S_CONNECT_ERROR;
|
||||
break;
|
||||
}
|
||||
goto exit_loop;
|
||||
} else {
|
||||
@@ -194,6 +196,11 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
|
||||
c->state = BIO_CONN_S_OK;
|
||||
break;
|
||||
|
||||
case BIO_CONN_S_CONNECT_ERROR:
|
||||
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR);
|
||||
ret = 0;
|
||||
goto exit_loop;
|
||||
|
||||
case BIO_CONN_S_OK:
|
||||
ret = 1;
|
||||
goto exit_loop;
|
||||
@@ -411,7 +418,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
OPENSSL_free(hold_service);
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_service);
|
||||
data->param_service = BUF_strdup(ptr);
|
||||
data->param_service = OPENSSL_strdup(ptr);
|
||||
} else if (num == 2) {
|
||||
const BIO_ADDR *addr = (const BIO_ADDR *)ptr;
|
||||
if (ret) {
|
||||
|
||||
@@ -1009,7 +1009,6 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
|
||||
int ret = 0, n = 0, i, optval;
|
||||
socklen_t optlen;
|
||||
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr;
|
||||
union sctp_notification *snp;
|
||||
struct msghdr msg;
|
||||
struct iovec iov;
|
||||
struct cmsghdr *cmsg;
|
||||
@@ -1075,8 +1074,10 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
|
||||
}
|
||||
|
||||
if (msg.msg_flags & MSG_NOTIFICATION) {
|
||||
snp = (union sctp_notification *)out;
|
||||
if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
|
||||
union sctp_notification snp;
|
||||
|
||||
memcpy(&snp, out, sizeof(snp));
|
||||
if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
|
||||
# ifdef SCTP_EVENT
|
||||
struct sctp_event event;
|
||||
# else
|
||||
@@ -1116,17 +1117,19 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
|
||||
# endif
|
||||
}
|
||||
# ifdef SCTP_AUTHENTICATION_EVENT
|
||||
if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
|
||||
dgram_sctp_handle_auth_free_key_event(b, snp);
|
||||
if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
|
||||
dgram_sctp_handle_auth_free_key_event(b, &snp);
|
||||
# endif
|
||||
|
||||
if (data->handle_notifications != NULL)
|
||||
data->handle_notifications(b, data->notification_context,
|
||||
(void *)out);
|
||||
|
||||
memset(&snp, 0, sizeof(snp));
|
||||
memset(out, 0, outl);
|
||||
} else
|
||||
} else {
|
||||
ret += n;
|
||||
}
|
||||
}
|
||||
while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR)
|
||||
&& (ret < outl));
|
||||
|
||||
@@ -152,7 +152,11 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
long ret = 1;
|
||||
int *ip;
|
||||
# ifndef OPENSSL_NO_KTLS
|
||||
# ifdef __FreeBSD__
|
||||
struct tls_enable *crypto_info;
|
||||
# else
|
||||
struct tls12_crypto_info_aes_gcm_128 *crypto_info;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
switch (cmd) {
|
||||
@@ -183,7 +187,11 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
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);
|
||||
|
||||
+15
-5
@@ -1,8 +1,18 @@
|
||||
LIBS=../../libcrypto
|
||||
|
||||
# Base library
|
||||
SOURCE[../../libcrypto]=\
|
||||
bio_lib.c bio_cb.c bio_err.c \
|
||||
bss_mem.c bss_null.c bss_fd.c \
|
||||
bss_file.c bss_sock.c bss_conn.c \
|
||||
bf_null.c bf_buff.c b_print.c b_dump.c b_addr.c \
|
||||
b_sock.c b_sock2.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c \
|
||||
bss_dgram.c bio_meth.c bf_lbuf.c
|
||||
b_print.c b_dump.c b_addr.c \
|
||||
b_sock.c b_sock2.c \
|
||||
bio_meth.c
|
||||
|
||||
# Source / sink implementations
|
||||
SOURCE[../../libcrypto]=\
|
||||
bss_null.c bss_mem.c bss_bio.c bss_fd.c bss_file.c \
|
||||
bss_sock.c bss_conn.c bss_acpt.c bss_dgram.c \
|
||||
bss_log.c
|
||||
|
||||
# Filters
|
||||
SOURCE[../../libcrypto]=\
|
||||
bf_null.c bf_buff.c bf_lbuf.c bf_nbio.c bf_prefix.c
|
||||
Reference in New Issue
Block a user