Skip to content

Commit

Permalink
Merge branch 'upstream' of github.com:kassane/openssl into zig-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Sep 24, 2023
2 parents 72c801c + 1acc3e8 commit 2f22e83
Show file tree
Hide file tree
Showing 102 changed files with 2,181 additions and 341 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ OpenSSL 3.0
* Fixed a bug where the RC4-MD5 ciphersuite incorrectly used the
AAD data as the MAC key ([CVE-2022-1434])
* Fix a bug in the OPENSSL_LH_flush() function that breaks reuse of the memory
occuppied by the removed hash table entries ([CVE-2022-1473])
occupied by the removed hash table entries ([CVE-2022-1473])

### Major changes between OpenSSL 3.0.1 and OpenSSL 3.0.2 [15 Mar 2022]

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Welcome to the OpenSSL Project (Forked to zig-pkg support)
[![openssl logo]][www.openssl.org]

[![Zig Build](https://github.com/kassane/openssl/actions/workflows/zig.yml/badge.svg)](https://github.com/kassane/openssl/actions/workflows/zig.yml)
[![Zig Embedded](https://github.com/kassane/openssl/actions/workflows/zig-embedded.yml/badge.svg)](https://github.com/kassane/openssl/actions/workflows/zig-embedded.yml)

OpenSSL is a robust, commercial-grade, full-featured Open Source Toolkit
for the Transport Layer Security (TLS) protocol formerly known as the
Expand Down
2 changes: 1 addition & 1 deletion crypto/bio/bio_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int _dopr(char **sbuffer, char **buffer,
#define DP_F_NUM (1 << 3)
/* print leading zeroes */
#define DP_F_ZERO (1 << 4)
/* print HEX in UPPPERcase */
/* print HEX in UPPERcase */
#define DP_F_UP (1 << 5)
/* treat value as unsigned */
#define DP_F_UNSIGNED (1 << 6)
Expand Down
3 changes: 2 additions & 1 deletion crypto/bio/bss_dgram_pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ static int dgram_pair_init(BIO *bio)
if (b == NULL)
return 0;

b->req_buf_len = 17*1024; /* default buffer size */
b->mtu = 1472; /* conservative default MTU */
/* default buffer size */
b->req_buf_len = 9 * (sizeof(struct dgram_hdr) + b->mtu);

b->lock = CRYPTO_THREAD_lock_new();
if (b->lock == NULL) {
Expand Down
14 changes: 14 additions & 0 deletions crypto/bio/bss_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_FLUSH:
ret = 1;
break;
case BIO_CTRL_GET_RPOLL_DESCRIPTOR:
case BIO_CTRL_GET_WPOLL_DESCRIPTOR:
{
BIO_POLL_DESCRIPTOR *pd = ptr;

if (!b->init) {
ret = 0;
break;
}

pd->type = BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD;
pd->value.fd = b->num;
}
break;
# ifndef OPENSSL_NO_KTLS
case BIO_CTRL_SET_KTLS:
crypto_info = (ktls_crypto_info_t *)ptr;
Expand Down
2 changes: 0 additions & 2 deletions crypto/build.info
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ $UTIL_COMMON=\
param_build_set.c der_writer.c threads_lib.c params_dup.c \
time.c params_idx.c

SHARED_SOURCE[../libssl]=sparse_array.c

SOURCE[../libcrypto]=$UTIL_COMMON \
mem.c mem_sec.c \
cversion.c info.c cpt_err.c ebcdic.c uid.c o_time.c o_dir.c \
Expand Down
33 changes: 25 additions & 8 deletions crypto/cmp/cmp_vfy.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ int OSSL_CMP_validate_cert_path(const OSSL_CMP_CTX *ctx,
return valid;
}

static int verify_cb_cert(X509_STORE *ts, X509 *cert, int err)
{
X509_STORE_CTX_verify_cb verify_cb;
X509_STORE_CTX *csc;
int ok = 0;

if (ts == NULL || (verify_cb = X509_STORE_get_verify_cb(ts)) == NULL)
return ok;
if ((csc = X509_STORE_CTX_new()) != NULL
&& X509_STORE_CTX_init(csc, ts, cert, NULL)) {
X509_STORE_CTX_set_error(csc, err);
X509_STORE_CTX_set_current_cert(csc, cert);
ok = (*verify_cb)(0, csc);
}
X509_STORE_CTX_free(csc);
return ok;
}

/* Return 0 if expect_name != NULL and there is no matching actual_name */
static int check_name(const OSSL_CMP_CTX *ctx, int log_success,
const char *actual_desc, const X509_NAME *actual_name,
Expand Down Expand Up @@ -256,9 +274,14 @@ static int cert_acceptable(const OSSL_CMP_CTX *ctx,
time_cmp = X509_cmp_timeframe(vpm, X509_get0_notBefore(cert),
X509_get0_notAfter(cert));
if (time_cmp != 0) {
int err = time_cmp > 0 ? X509_V_ERR_CERT_HAS_EXPIRED
: X509_V_ERR_CERT_NOT_YET_VALID;

ossl_cmp_warn(ctx, time_cmp > 0 ? "cert has expired"
: "cert is not yet valid");
return 0;
if (ctx->log_cb != NULL /* logging not temporarily disabled */
&& verify_cb_cert(ts, cert, err) <= 0)
return 0;
}

if (!check_name(ctx, 1,
Expand Down Expand Up @@ -432,12 +455,6 @@ static int check_msg_all_certs(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg,
return ret;
}

static int no_log_cb(const char *func, const char *file, int line,
OSSL_CMP_severity level, const char *msg)
{
return 1;
}

/*-
* Verify message signature with any acceptable and valid candidate cert.
* On success cache the found cert using ossl_cmp_ctx_set1_validatedSrvCert().
Expand Down Expand Up @@ -465,7 +482,7 @@ static int check_msg_find_cert(OSSL_CMP_CTX *ctx, const OSSL_CMP_MSG *msg)

/* enable clearing irrelevant errors in attempts to validate sender certs */
(void)ERR_set_mark();
ctx->log_cb = no_log_cb; /* temporarily disable logging */
ctx->log_cb = NULL; /* temporarily disable logging */

/*
* try first cached scrt, used successfully earlier in same transaction,
Expand Down
24 changes: 15 additions & 9 deletions crypto/engine/eng_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,34 @@ static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)
return item;
}

void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb)
int engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb)
{
ENGINE_CLEANUP_ITEM *item;

if (!int_cleanup_check(1))
return;
return 0;
item = int_cleanup_item(cb);
if (item != NULL)
if (sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0) <= 0)
OPENSSL_free(item);
if (item != NULL) {
if (sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0))
return 1;
OPENSSL_free(item);
}
return 0;
}

void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
int engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
{
ENGINE_CLEANUP_ITEM *item;

if (!int_cleanup_check(1))
return;
return 0;
item = int_cleanup_item(cb);
if (item != NULL) {
if (sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item) <= 0)
OPENSSL_free(item);
if (sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item) > 0)
return 1;
OPENSSL_free(item);
}
return 0;
}

/* The API function that performs all cleanup */
Expand Down
10 changes: 7 additions & 3 deletions crypto/engine/eng_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ static int engine_list_add(ENGINE *e)
ERR_raise(ERR_LIB_ENGINE, ENGINE_R_INTERNAL_LIST_ERROR);
return 0;
}
engine_list_head = e;
e->prev = NULL;
/*
* The first time the list allocates, we should register the cleanup.
*/
engine_cleanup_add_last(engine_list_cleanup);
if (!engine_cleanup_add_last(engine_list_cleanup)) {
CRYPTO_DOWN_REF(&e->struct_ref, &ref);
ERR_raise(ERR_LIB_ENGINE, ENGINE_R_INTERNAL_LIST_ERROR);
return 0;
}
engine_list_head = e;
e->prev = NULL;
} else {
/* We are adding to the tail of an existing list. */
if ((engine_list_tail == NULL) || (engine_list_tail->next != NULL)) {
Expand Down
4 changes: 2 additions & 2 deletions crypto/engine/eng_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ typedef struct st_engine_cleanup_item {
ENGINE_CLEANUP_CB *cb;
} ENGINE_CLEANUP_ITEM;
DEFINE_STACK_OF(ENGINE_CLEANUP_ITEM)
void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
int engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb);
int engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);

/* We need stacks of ENGINEs for use in eng_table.c */
DEFINE_STACK_OF(ENGINE)
Expand Down
9 changes: 6 additions & 3 deletions crypto/engine/eng_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
added = 1;
if (!int_table_check(table, 1))
goto end;
if (added)
/* The cleanup callback needs to be added */
engine_cleanup_add_first(cleanup);
/* The cleanup callback needs to be added */
if (added && !engine_cleanup_add_first(cleanup)) {
lh_ENGINE_PILE_free(&(*table)->piles);
*table = NULL;
goto end;
}
while (num_nids--) {
tmplate.nid = *nids;
fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);
Expand Down
2 changes: 1 addition & 1 deletion crypto/err/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ void ERR_add_error_vdata(int num, va_list args)
i = es->top;

/*
* If err_data is allocated already, re-use the space.
* If err_data is allocated already, reuse the space.
* Otherwise, allocate a small new buffer.
*/
if ((es->err_data_flags[i] & flags) == flags) {
Expand Down
28 changes: 24 additions & 4 deletions crypto/evp/legacy_blake2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,31 @@
#include "prov/blake2.h" /* diverse BLAKE2 macros */
#include "legacy_meth.h"

#define ossl_blake2b_init ossl_blake2b512_init
#define ossl_blake2s_init ossl_blake2s256_init
/*
* Local hack to adapt the BLAKE2 init functions to what the
* legacy function signatures demand.
*/
static int blake2s_init(BLAKE2S_CTX *C)
{
BLAKE2S_PARAM P;

ossl_blake2s_param_init(&P);
return ossl_blake2s_init(C, &P);
}
static int blake2b_init(BLAKE2B_CTX *C)
{
BLAKE2B_PARAM P;

ossl_blake2b_param_init(&P);
return ossl_blake2b_init(C, &P);
}
#define blake2s_update ossl_blake2s_update
#define blake2b_update ossl_blake2b_update
#define blake2s_final ossl_blake2s_final
#define blake2b_final ossl_blake2b_final

IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2s_int, ossl_blake2s)
IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2b_int, ossl_blake2b)
IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2s_int, blake2s)
IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2b_int, blake2b)

static const EVP_MD blake2b_md = {
NID_blake2b512,
Expand Down
2 changes: 1 addition & 1 deletion crypto/evp/pmeth_gn.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int EVP_PKEY_generate(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
goto legacy;

/*
* Asssigning gentmp to ctx->keygen_info is something our legacy
* Assigning gentmp to ctx->keygen_info is something our legacy
* implementations do. Because the provider implementations aren't
* allowed to reach into our EVP_PKEY_CTX, we need to provide similar
* space for backward compatibility. It's ok that we attach a local
Expand Down
5 changes: 3 additions & 2 deletions crypto/evp/pmeth_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ static EVP_PKEY_CTX *int_ctx_new(OSSL_LIB_CTX *libctx,
*/
if (e != NULL)
pmeth = ENGINE_get_pkey_meth(e, id);
else if (pkey != NULL && pkey->foreign)
else
# endif /* OPENSSL_NO_ENGINE */
if (pkey != NULL && pkey->foreign)
pmeth = EVP_PKEY_meth_find(id);
else
# endif
app_pmeth = pmeth = evp_pkey_meth_find_added_by_application(id);

/* END legacy */
Expand Down
2 changes: 2 additions & 0 deletions crypto/ex_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ int ossl_crypto_get_ex_new_index_ex(OSSL_LIB_CTX *ctx, int class_index,
* "app_data" routines use ex_data index zero. See RT 3710. */
if (ip->meth == NULL
|| !sk_EX_CALLBACK_push(ip->meth, NULL)) {
sk_EX_CALLBACK_free(ip->meth);
ip->meth = NULL;
ERR_raise(ERR_LIB_CRYPTO, ERR_R_CRYPTO_LIB);
goto err;
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/lhash/lhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ static void contract(OPENSSL_LHASH *lh)
if (n == NULL) {
/* fputs("realloc error in lhash", stderr); */
lh->error++;
return;
} else {
lh->b = n;
}
lh->num_alloc_nodes /= 2;
lh->pmax /= 2;
lh->p = lh->pmax - 1;
lh->b = n;
} else
lh->p--;

Expand Down
8 changes: 4 additions & 4 deletions crypto/o_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep)


/*
* Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its
* hex representation @@@ (Contents of buffer are always kept in ASCII, also
* on EBCDIC machines)
* Given a buffer of length 'buflen' return a OPENSSL_malloc'ed string with
* its hex representation @@@ (Contents of buffer are always kept in ASCII,
* also on EBCDIC machines)
*/
char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen)
{
return ossl_buf2hexstr_sep(buf, buflen, ':');
return ossl_buf2hexstr_sep(buf, buflen, DEFAULT_SEPARATOR);
}

int openssl_strerror_r(int errnum, char *buf, size_t buflen)
Expand Down
Loading

0 comments on commit 2f22e83

Please sign in to comment.