Skip to content

Commit 984dd91

Browse files
Merge pull request #8005 from ColtonWilley/copy_key_option
New option to always copy over key to SSL object
2 parents ee7f02b + 6414cf6 commit 984dd91

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ AC_ARG_WITH([liboqs],
12371237
tryliboqsdir="/usr/local"
12381238
fi
12391239
1240-
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBOQS -DHAVE_TLS_EXTENSIONS -I$tryliboqsdir/include"
1240+
CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIBOQS -DHAVE_TLS_EXTENSIONS -I$tryliboqsdir/include -pthread"
12411241
LDFLAGS="$AM_LDFLAGS $LDFLAGS -L$tryliboqsdir/lib"
12421242
12431243
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <oqs/common.h>]], [[ OQS_init(); ]])], [ liboqs_linked=yes ],[ liboqs_linked=no ])

src/internal.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6829,7 +6829,22 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
68296829
ssl->buffers.certChainCnt = ctx->certChainCnt;
68306830
#endif
68316831
#ifndef WOLFSSL_BLIND_PRIVATE_KEY
6832+
#ifdef WOLFSSL_COPY_KEY
6833+
if (ctx->privateKey != NULL) {
6834+
if (ssl->buffers.key != NULL) {
6835+
FreeDer(&ssl->buffers.key);
6836+
}
6837+
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
6838+
ctx->privateKey->length, ctx->privateKey->type,
6839+
ctx->privateKey->heap);
6840+
ssl->buffers.weOwnKey = 1;
6841+
}
6842+
else {
6843+
ssl->buffers.key = ctx->privateKey;
6844+
}
6845+
#else
68326846
ssl->buffers.key = ctx->privateKey;
6847+
#endif
68336848
#else
68346849
if (ctx->privateKey != NULL) {
68356850
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,

src/ssl.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20410,7 +20410,22 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2041020410
ssl->buffers.certChainCnt = ctx->certChainCnt;
2041120411
#endif
2041220412
#ifndef WOLFSSL_BLIND_PRIVATE_KEY
20413+
#ifdef WOLFSSL_COPY_KEY
20414+
if (ctx->privateKey != NULL) {
20415+
if (ssl->buffers.key != NULL) {
20416+
FreeDer(&ssl->buffers.key);
20417+
}
20418+
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
20419+
ctx->privateKey->length, ctx->privateKey->type,
20420+
ctx->privateKey->heap);
20421+
ssl->buffers.weOwnKey = 1;
20422+
}
20423+
else {
20424+
ssl->buffers.key = ctx->privateKey;
20425+
}
20426+
#else
2041320427
ssl->buffers.key = ctx->privateKey;
20428+
#endif
2041420429
#else
2041520430
if (ctx->privateKey != NULL) {
2041620431
AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,

wolfssl/wolfcrypt/settings.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,11 +3654,22 @@ extern void uITRON4_free(void *p) ;
36543654
#define KEEP_PEER_CERT
36553655
#endif
36563656

3657+
/* Always copy certificate(s) from SSL CTX to each SSL object on creation,
3658+
* if this is not defined then each SSL object shares a pointer to the
3659+
* original certificate buffer owned by the SSL CTX. */
36573660
#if defined(OPENSSL_ALL) && !defined(WOLFSSL_NO_COPY_CERT)
36583661
#undef WOLFSSL_COPY_CERT
36593662
#define WOLFSSL_COPY_CERT
36603663
#endif
36613664

3665+
/* Always copy private key from SSL CTX to each SSL object on creation,
3666+
* if this is not defined then each SSL object shares a pointer to the
3667+
* original key buffer owned by the SSL CTX. */
3668+
#if defined(OPENSSL_ALL) && !defined(WOLFSSL_NO_COPY_KEY)
3669+
#undef WOLFSSL_COPY_KEY
3670+
#define WOLFSSL_COPY_KEY
3671+
#endif
3672+
36623673
/*
36633674
* Keeps the "Finished" messages after a TLS handshake for use as the so-called
36643675
* "tls-unique" channel binding. See comment in internal.h around clientFinished

0 commit comments

Comments
 (0)