Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/scripts/zephyr-4.x/builds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ native_sim samples/wolfssl_tls_sock
native_sim samples/wolfssl_tls_sock external_libc.conf
native_sim samples/wolfssl_tls_sock tls_cert.conf
native_sim samples/wolfssl_tls_sock ocsp.conf
native_sim samples/wolfssl_tls_sock dtls13.conf
native_sim samples/wolfssl_tls_sock dtls_cid.conf
native_sim samples/wolfssl_tls_sock small_stack.conf
native_sim samples/wolfssl_test
native_sim samples/wolfssl_test external_libc.conf
native_sim samples/wolfssl_benchmark
native_sim samples/wolfssl_benchmark external_libc.conf
native_sim samples/wolfssl_test prj-cert.conf
native_sim samples/wolfssl_test prj-x25519-ed448.conf
native_sim samples/wolfssl_test prj-ed25519-x448.conf
native_sim samples/wolfssl_test sp_stack.conf
native_sim samples/wolfssl_test small_stack.conf
native_sim samples/wolfssl_test rsa_2048.conf
native_sim samples/wolfssl_test rsa_3072.conf
Comment thread
Frauschi marked this conversation as resolved.
Resolved
native_sim samples/wolfssl_test rsa_3072_ecc_custom.conf
native_sim samples/wolfssl_test no_ecc_x25519_psk.conf
# external_libc overlay is native_sim-only in the original Jenkins matrix
frdm_rw612/rw612 samples/wolfssl_tls_sock
frdm_rw612/rw612 samples/wolfssl_test
Expand Down
3 changes: 3 additions & 0 deletions .github/scripts/zephyr-4.x/dtls13.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DTLS 1.3, with ML-KEM from the sample's prj.conf
CONFIG_WOLFSSL_DTLS=y
CONFIG_WOLFSSL_DTLS_VERSION_1_3=y
3 changes: 3 additions & 0 deletions .github/scripts/zephyr-4.x/dtls_cid.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DTLS 1.2 with Connection ID
CONFIG_WOLFSSL_DTLS=y
CONFIG_WOLFSSL_DTLS_CID=y
4 changes: 4 additions & 0 deletions .github/scripts/zephyr-4.x/no_ecc_x25519_psk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TLS without ECC: X25519 is the only key exchange group, with PSK suites
CONFIG_WOLFSSL_ECC=n
CONFIG_WOLFSSL_CURVE25519=y
CONFIG_WOLFSSL_PSK=y
2 changes: 2 additions & 0 deletions .github/scripts/zephyr-4.x/rsa_2048.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Largest RSA key 2048 bits
CONFIG_WOLFSSL_RSA_MAX_BITS_2048=y
2 changes: 2 additions & 0 deletions .github/scripts/zephyr-4.x/rsa_3072.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Largest RSA key 3072 bits
CONFIG_WOLFSSL_RSA_MAX_BITS_3072=y
9 changes: 9 additions & 0 deletions .github/scripts/zephyr-4.x/rsa_3072_ecc_custom.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Custom curves (prj-ecc-custom.conf) with the largest RSA key 3072 bits
CONFIG_WOLFSSL_ECC=y
CONFIG_WOLFSSL_ECC_256=y
CONFIG_WOLFSSL_ECC_384=y
CONFIG_WOLFSSL_ECC_512=y
CONFIG_WOLFSSL_ECC_BRAINPOOL=y
CONFIG_MAIN_STACK_SIZE=65536
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536
CONFIG_WOLFSSL_RSA_MAX_BITS_3072=y
3 changes: 3 additions & 0 deletions .github/scripts/zephyr-4.x/small_stack.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# wolfSSL and wolfCrypt temporaries on the heap, which needs a larger arena
CONFIG_WOLFSSL_SMALL_STACK=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072
2 changes: 2 additions & 0 deletions .github/scripts/zephyr-4.x/sp_stack.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SP math temporaries on the thread stack
CONFIG_WOLFCRYPT_SP_SMALL_STACK=n
4 changes: 2 additions & 2 deletions .github/scripts/zephyr-4.x/zephyr-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# -h, --help Show this help
#
# Examples:
# # Test master against Zephyr 4.1.0 for native_sim
# # Test master against Zephyr 4.3.0 for native_sim
# ./zephyr-test.sh
#
# # Test a specific branch for frdm_rw612 on Zephyr 4.3.0
Expand Down Expand Up @@ -54,7 +54,7 @@ set -euo pipefail
# Defaults
WOLFSSL_REPO="https://github.com/wolfSSL/wolfssl"
WOLFSSL_BRANCH="master"
ZEPHYR_VERSION="v4.1.0"
ZEPHYR_VERSION="v4.3.0"
BOARD_TARGET="native_sim"
SAMPLE_NAME="wolfssl_tls_sock"
SUBDIR="samples"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zephyr-4.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
zephyr-ref: [ v4.1.0, v4.3.0, v4.4.0 ]
zephyr-ref: [ v4.3.0, v4.4.0, v4.5.0 ]
steps:
- name: Checkout test driver
uses: actions/checkout@v5
Expand Down
19 changes: 4 additions & 15 deletions .github/workflows/zephyr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ jobs:
fail-fast: false
matrix:
config:
- zephyr-ref: v3.4.0
zephyr-sdk: 0.16.1
- zephyr-ref: v3.5.0
zephyr-sdk: 0.16.3
- zephyr-ref: v3.7.2
zephyr-sdk: 0.16.8
- zephyr-ref: v2.7.4
zephyr-sdk: 0.16.3
if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }}
Expand Down Expand Up @@ -92,17 +90,8 @@ jobs:
- name: Run wolfssl test
id: wolfssl-test
working-directory: zephyr
# Scope -T to the sample directory (not the whole module) so twister does
# not load zephyr/tests/*/testcase.yaml. The condvar test's modern
# list-form platform_allow is rejected by the 2.7.4 twister schema, and
# this is the only sample step that runs on 2.7.4.
#
# Name the two scenarios rather than running the whole sample: the rest
# need a Zephyr these versions predate - hierarchical board names,
# COMMON_LIBC_MALLOC_ARENA_SIZE, and toolchains beyond the x86_64 one
# installed above. --test drops the others before their platform_allow
# is resolved, so an unrecognized board does not abort the run - but
# the yaml is still parsed, so a modern-only key would.
# 2.7.4's twister rejects the zephyr/tests yaml, so -T stays on the
# sample; the other scenarios need boards or toolchains not set up here.
run: |
./zephyr/scripts/twister -T modules/crypto/wolfssl/zephyr/samples/wolfssl_test \
--test sample.crypto.wolfssl_test \
Expand Down
7 changes: 7 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ CONFIG_WOLFCRYPT_FIPS_V5_2_3
CONFIG_WOLFCRYPT_FIPS_V6
CONFIG_WOLFCRYPT_FIPS_V7
CONFIG_WOLFCRYPT_SP_SMALL
CONFIG_WOLFCRYPT_SP_SMALL_STACK
CONFIG_WOLFSSL
CONFIG_WOLFSSL_AES_BITSLICED
CONFIG_WOLFSSL_AES_TOUCH_LINES
Expand All @@ -212,6 +213,8 @@ CONFIG_WOLFSSL_CRYPTO_CB
CONFIG_WOLFSSL_CURVE25519
CONFIG_WOLFSSL_CURVE448
CONFIG_WOLFSSL_DTLS
CONFIG_WOLFSSL_DTLS_CID
CONFIG_WOLFSSL_DTLS_VERSION_1_3
CONFIG_WOLFSSL_ECC
CONFIG_WOLFSSL_ECC_256
CONFIG_WOLFSSL_ECC_384
Expand Down Expand Up @@ -254,12 +257,16 @@ CONFIG_WOLFSSL_POST_HANDSHAKE_AUTH
CONFIG_WOLFSSL_PSK
CONFIG_WOLFSSL_PUBLIC_ASN
CONFIG_WOLFSSL_RSA
CONFIG_WOLFSSL_RSA_MAX_BITS_2048
CONFIG_WOLFSSL_RSA_MAX_BITS_3072
CONFIG_WOLFSSL_RSA_MAX_BITS_4096
CONFIG_WOLFSSL_RSA_PSS
CONFIG_WOLFSSL_SESSION_CACHE
CONFIG_WOLFSSL_SESSION_EXPORT
CONFIG_WOLFSSL_SESSION_TICKET
CONFIG_WOLFSSL_SETTINGS_FILE
CONFIG_WOLFSSL_SINGLE_THREADED
CONFIG_WOLFSSL_SMALL_STACK
CONFIG_WOLFSSL_SNI
CONFIG_WOLFSSL_SYS_INIT
CONFIG_WOLFSSL_TARGET_HOST
Expand Down
8 changes: 8 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -40048,6 +40048,7 @@ int SendClientKeyExchange(WOLFSSL* ssl)
break;
}
#endif
#ifdef HAVE_ECC
ret = EccSharedSecret(
ssl,
(ecc_key*)ssl->hsKey, ssl->peerEccKey,
Expand All @@ -40065,6 +40066,9 @@ int SendClientKeyExchange(WOLFSSL* ssl)
(void**)&ssl->peerEccKey);
ssl->peerEccKeyPresent = 0;
}
#else
ret = BAD_KEA_TYPE_E;
#endif
break;
}
#endif /* (HAVE_ECC || HAVE_CURVE25519 || HAVE_CURVE448) && !NO_PSK */
Expand Down Expand Up @@ -48373,6 +48377,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
break;
}
#endif
#ifdef HAVE_ECC
/* Generate shared secret */
ret = EccSharedSecret(ssl,
ssl->eccTempKey, ssl->peerEccKey,
Expand All @@ -48390,6 +48395,9 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
(void**)&ssl->peerEccKey);
ssl->peerEccKeyPresent = 0;
}
#else
ret = BAD_KEA_TYPE_E;
#endif
break;
}
#endif /* (HAVE_ECC || CURVE25519 || CURVE448) && !NO_PSK */
Expand Down
7 changes: 7 additions & 0 deletions src/ssl_api_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,13 @@ int wolfSSL_has_pending(const WOLFSSL* ssl)
else if (ssl->buffers.inputBuffer.length > ssl->buffers.inputBuffer.idx) {
ret = 1;
}
#elif defined(WOLFSSL_DTLS)
/* A DTLS read takes a whole datagram, which can hold more records. They
* may carry no application data, so wolfSSL_read() can still WANT_READ. */
else if (ssl->options.dtls &&
ssl->buffers.inputBuffer.length > ssl->buffers.inputBuffer.idx) {
ret = 1;
}
#endif

return ret;
Expand Down
27 changes: 18 additions & 9 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,18 @@ int wolfSSL_GetHmacType(WOLFSSL* ssl)
}


static void TlsHmacInnerWrite(WOLFSSL* ssl, byte* inner, word32 sz,
int content, int verify)
{
XMEMSET(inner, 0, WOLFSSL_TLS_HMAC_INNER_SZ);

WriteSEQ(ssl, verify, inner);
inner[SEQ_SZ] = (byte)content;
inner[SEQ_SZ + ENUM_LEN] = ssl->version.major;
inner[SEQ_SZ + ENUM_LEN + ENUM_LEN] = ssl->version.minor;
c16toa((word16)sz, inner + SEQ_SZ + ENUM_LEN + VERSION_SZ);
}

int wolfSSL_SetTlsHmacInner(WOLFSSL* ssl, byte* inner, word32 sz, int content,
int verify)
{
Expand All @@ -886,20 +898,15 @@ int wolfSSL_SetTlsHmacInner(WOLFSSL* ssl, byte* inner, word32 sz, int content,

if (content == dtls12_cid
#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_DTLS_CID)
|| (ssl->options.dtls && DtlsGetCidTxSize(ssl) > 0)
|| (ssl->options.dtls &&
(verify ? DtlsGetCidRxSize(ssl) : DtlsGetCidTxSize(ssl)) > 0)
#endif
) {
WOLFSSL_MSG("wolfSSL_SetTlsHmacInner doesn't support CID");
return BAD_FUNC_ARG;
}

XMEMSET(inner, 0, WOLFSSL_TLS_HMAC_INNER_SZ);

WriteSEQ(ssl, verify, inner);
inner[SEQ_SZ] = (byte)content;
inner[SEQ_SZ + ENUM_LEN] = ssl->version.major;
inner[SEQ_SZ + ENUM_LEN + ENUM_LEN] = ssl->version.minor;
c16toa((word16)sz, inner + SEQ_SZ + ENUM_LEN + VERSION_SZ);
TlsHmacInnerWrite(ssl, inner, sz, content, verify);

return 0;
}
Expand Down Expand Up @@ -1407,9 +1414,11 @@ static int TLS_hmac_SetInner(WOLFSSL* ssl, byte* inner, word32* innerSz,
return 0;
}
#endif
/* No CID in this direction, even when the other direction uses one */
*innerSz = WOLFSSL_TLS_HMAC_INNER_SZ;
return wolfSSL_SetTlsHmacInner(ssl, inner, sz, content,
TlsHmacInnerWrite(ssl, inner, sz, content,
!ssl->options.dtls ? verify : epochOrder);
return 0;
}

#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_DTLS_CID)
Expand Down
63 changes: 63 additions & 0 deletions tests/api/test_dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,69 @@ int test_dtls12_basic_connection_id(void)
return EXPECT_RESULT();
}

/* Only one side gives the other a CID, so the other side's records carry none */
int test_dtls12_one_sided_connection_id(void)
{
EXPECT_DECLS;
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
defined(WOLFSSL_DTLS_CID) && !defined(WOLFSSL_NO_TLS12) && \
!defined(NO_RSA) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
defined(HAVE_ECC) && ((defined(HAVE_AES_CBC) && \
!defined(WOLFSSL_AEAD_ONLY)) || defined(HAVE_AESGCM))
unsigned char cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
const char* params[] = {
#if defined(HAVE_AES_CBC) && !defined(WOLFSSL_AEAD_ONLY)
"ECDHE-RSA-AES128-SHA256",
#endif
#ifdef HAVE_AESGCM
"ECDHE-RSA-AES128-GCM-SHA256",
#endif
};
unsigned char readBuf[40];
size_t i;
int side;

for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
for (side = 0; side < 2 && EXPECT_SUCCESS(); side++) {
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
struct test_memio_ctx test_ctx;
int len = (int)XSTRLEN(params[i]);

XMEMSET(&test_ctx, 0, sizeof(test_ctx));
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
&ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method),
0);
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), 1);
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), 1);
ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
ExpectIntEQ(wolfSSL_dtls_cid_set(side == 0 ? ssl_c : ssl_s, cid,
sizeof(cid)), 1);

ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
ExpectIntEQ(wolfSSL_dtls_cid_is_enabled(ssl_c), 1);
ExpectIntEQ(wolfSSL_dtls_cid_is_enabled(ssl_s), 1);

ExpectIntEQ(wolfSSL_write(ssl_c, params[i], len), len);
XMEMSET(readBuf, 0, sizeof(readBuf));
ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), len);
ExpectStrEQ(readBuf, params[i]);
ExpectIntEQ(wolfSSL_write(ssl_s, params[i], len), len);
XMEMSET(readBuf, 0, sizeof(readBuf));
ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), len);
ExpectStrEQ(readBuf, params[i]);

wolfSSL_free(ssl_c);
wolfSSL_free(ssl_s);
wolfSSL_CTX_free(ctx_c);
wolfSSL_CTX_free(ctx_s);
}
}
#endif
return EXPECT_RESULT();
}


/** Test DTLS 1.3 behavior when server hits WANT_WRITE during HRR
* The test sets up a DTLS 1.3 connection where the server is forced to
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int test_dtls13_packet_forgeries(void);
int test_dtls13_wire_mangle(void);

int test_dtls12_basic_connection_id(void);
int test_dtls12_one_sided_connection_id(void);
int test_wolfSSL_dtls_cid_parse(void);
int test_wolfSSL_dtls_cid_args(void);
int test_wolfSSL_dtls_set_pending_peer(void);
Expand Down Expand Up @@ -215,6 +216,7 @@ int test_dtls_no_cookie_ch_pause(WOLFSSL* ssl, void* ctx);

#define TEST_DTLS_DECLS \
TEST_DECL_GROUP("dtls", test_dtls12_basic_connection_id), \
TEST_DECL_GROUP("dtls", test_dtls12_one_sided_connection_id), \
TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_cid_parse), \
TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_cid_args), \
TEST_DECL_GROUP("dtls", test_wolfSSL_dtls_set_pending_peer), \
Expand Down
Loading
Loading