Skip to content

Commit c4c71ee

Browse files
authored
Merge pull request #10085 from Frauschi/rfc8773bis-cert-with-extern-psk
Add RFC8773(bis) cert_with_extern_psk support
2 parents 423b471 + 0de3925 commit c4c71ee

File tree

19 files changed

+1381
-60
lines changed

19 files changed

+1381
-60
lines changed

.github/workflows/cmake.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
-DWOLFSSL_X963KDF:BOOL=yes -DWOLFSSL_DILITHIUM:BOOL=yes -DWOLFSSL_PKCS11:BOOL=yes \
7373
-DWOLFSSL_ECCSI:BOOL=yes -DWOLFSSL_SAKKE:BOOL=yes -DWOLFSSL_SIPHASH:BOOL=yes \
7474
-DWOLFSSL_WC_RSA_DIRECT:BOOL=yes -DWOLFSSL_PUBLIC_MP:BOOL=yes \
75+
-DWOLFSSL_CERT_WITH_EXTERN_PSK:BOOL=yes \
7576
-DWOLFSSL_EXTRA_PQC_HYBRIDS:BOOL=yes -DWOLFSSL_TLS_NO_MLKEM_STANDALONE:BOOL=no \
7677
..
7778
cmake --build .

.github/workflows/psk.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
matrix:
1919
config: [
2020
# Add new configs here
21+
'--enable-psk --enable-cert-with-extern-psk --disable-mlkem',
2122
'--enable-psk --disable-mlkem C_EXTRA_FLAGS="-DWOLFSSL_STATIC_PSK -DWOLFSSL_OLDTLS_SHA2_CIPHERSUITES"',
2223
'--enable-psk --disable-mlkem C_EXTRA_FLAGS=-DWOLFSSL_STATIC_PSK --disable-rsa --disable-ecc --disable-dh',
2324
'--disable-oldtls --disable-tls13 --enable-psk -disable-rsa --disable-dh -disable-ecc --disable-asn C_EXTRA_FLAGS=-DWOLFSSL_STATIC_PSK --enable-lowresource --enable-singlethreaded --disable-asm --disable-errorstrings --disable-pkcs12 --disable-sha3 --disable-sha224 --disable-sha384 --disable-sha512 --disable-sha --disable-md5 -disable-aescbc --disable-chacha --disable-poly1305 --disable-coding --disable-sp-math-all --disable-mlkem',

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,24 @@ if(WOLFSSL_POSTAUTH)
376376
endif()
377377
endif()
378378

379+
# Certificate Authentication with External PSK (RFC 8773bis)
380+
add_option("WOLFSSL_CERT_WITH_EXTERN_PSK"
381+
"Enable Certificate Authentication with External PSKs for TLS 1.3 (default: disabled)"
382+
"no" "yes;no")
383+
384+
if(WOLFSSL_CERT_WITH_EXTERN_PSK)
385+
if(NOT WOLFSSL_TLS13)
386+
message(WARNING "TLS 1.3 is disabled - disabling cert-with-extern-psk")
387+
override_cache(WOLFSSL_CERT_WITH_EXTERN_PSK "no")
388+
elseif(NOT WOLFSSL_PSK)
389+
message(WARNING "PSK is disabled - disabling cert-with-extern-psk")
390+
override_cache(WOLFSSL_CERT_WITH_EXTERN_PSK "no")
391+
else()
392+
list(APPEND WOLFSSL_DEFINITIONS
393+
"-DWOLFSSL_CERT_WITH_EXTERN_PSK")
394+
endif()
395+
endif()
396+
379397
# Hello Retry Request Cookie
380398
add_option("WOLFSSL_HRR_COOKIE"
381399
"Enable the server to send Cookie Extension in HRR with state (default: disabled)"

cmake/options.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ extern "C" {
308308
#cmakedefine WOLFSSL_DTLS13
309309
#undef WOLFSSL_DTLS_CH_FRAG
310310
#cmakedefine WOLFSSL_DTLS_CH_FRAG
311+
#undef WOLFSSL_CERT_WITH_EXTERN_PSK
312+
#cmakedefine WOLFSSL_CERT_WITH_EXTERN_PSK
311313
#undef WOLFSSL_EITHER_SIDE
312314
#cmakedefine WOLFSSL_EITHER_SIDE
313315
#undef WOLFSSL_ENCRYPTED_KEYS
@@ -427,4 +429,3 @@ extern "C" {
427429

428430

429431
#endif /* WOLFSSL_OPTIONS_H */
430-

configure.ac

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,6 +5146,27 @@ then
51465146
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PSK_ONE_ID"
51475147
fi
51485148

5149+
# Certificate Authentication with External PSK (RFC 8773bis)
5150+
AC_ARG_ENABLE([cert-with-extern-psk],
5151+
[AS_HELP_STRING([--enable-cert-with-extern-psk],[Enable Certificate Authentication with External PSKs for TLS 1.3 (default: disabled)])],
5152+
[ ENABLED_CERT_WITH_EXTERN_PSK=$enableval ],
5153+
[ ENABLED_CERT_WITH_EXTERN_PSK=no ]
5154+
)
5155+
if test "$ENABLED_CERT_WITH_EXTERN_PSK" = "yes"
5156+
then
5157+
if test "$ENABLED_TLS13" = "no"
5158+
then
5159+
AC_MSG_NOTICE([TLS 1.3 is disabled - disabling cert-with-extern-psk])
5160+
ENABLED_CERT_WITH_EXTERN_PSK="no"
5161+
elif test "$ENABLED_PSK" = "no"
5162+
then
5163+
AC_MSG_NOTICE([PSK is disabled - disabling cert-with-extern-psk])
5164+
ENABLED_CERT_WITH_EXTERN_PSK="no"
5165+
else
5166+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_CERT_WITH_EXTERN_PSK"
5167+
fi
5168+
fi
5169+
51495170
# ERROR STRINGS
51505171
AC_ARG_ENABLE([errorstrings],
51515172
[AS_HELP_STRING([--enable-errorstrings],[Enable error strings table (default: enabled)])],

doc/dox_comments/header_files/ssl.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14721,6 +14721,75 @@ void wolfSSL_CTX_set_psk_server_tls13_callback(WOLFSSL_CTX* ctx,
1472114721
void wolfSSL_set_psk_server_tls13_callback(WOLFSSL* ssl,
1472214722
wc_psk_server_tls13_callback cb);
1472314723

14724+
/*!
14725+
\ingroup Setup
14726+
14727+
\brief Enable or disable TLS 1.3 certificate authentication with external
14728+
PSK (RFC8773bis) on a context.
14729+
14730+
When enabled, wolfSSL advertises and accepts the
14731+
`tls_cert_with_extern_psk` extension for TLS 1.3 handshakes using external
14732+
PSKs. Any non-zero \p state value enables the feature and zero disables it.
14733+
14734+
Availability:
14735+
- Built with `--enable-tls13 --enable-psk --enable-cert-with-extern-psk`
14736+
- Or with `WOLFSSL_TLS13` and `WOLFSSL_CERT_WITH_EXTERN_PSK` defined
14737+
14738+
\param [in,out] ctx a pointer to a WOLFSSL_CTX structure, created with
14739+
wolfSSL_CTX_new().
14740+
\param [in] state 0 to disable, non-zero to enable.
14741+
14742+
\return WOLFSSL_SUCCESS on success.
14743+
\return WOLFSSL_FAILURE when \p ctx is NULL.
14744+
14745+
_Example_
14746+
\code
14747+
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
14748+
if (wolfSSL_CTX_set_cert_with_extern_psk(ctx, 1) != WOLFSSL_SUCCESS) {
14749+
/* handle error */
14750+
}
14751+
\endcode
14752+
14753+
\sa wolfSSL_set_cert_with_extern_psk
14754+
\sa wolfSSL_CTX_set_psk_client_tls13_callback
14755+
\sa wolfSSL_CTX_set_psk_server_tls13_callback
14756+
*/
14757+
int wolfSSL_CTX_set_cert_with_extern_psk(WOLFSSL_CTX* ctx, int state);
14758+
14759+
/*!
14760+
\ingroup Setup
14761+
14762+
\brief Enable or disable TLS 1.3 certificate authentication with external
14763+
PSK (RFC8773bis) on a connection.
14764+
14765+
This call applies to a single WOLFSSL object. Any non-zero \p state value
14766+
enables the feature and zero disables it.
14767+
14768+
Availability:
14769+
- Built with `--enable-tls13 --enable-psk --enable-cert-with-extern-psk`
14770+
- Or with `WOLFSSL_TLS13` and `WOLFSSL_CERT_WITH_EXTERN_PSK` defined
14771+
14772+
\param [in,out] ssl a pointer to a WOLFSSL structure, created using
14773+
wolfSSL_new().
14774+
\param [in] state 0 to disable, non-zero to enable.
14775+
14776+
\return WOLFSSL_SUCCESS on success.
14777+
\return WOLFSSL_FAILURE when \p ssl is NULL.
14778+
14779+
_Example_
14780+
\code
14781+
WOLFSSL* ssl = wolfSSL_new(ctx);
14782+
if (wolfSSL_set_cert_with_extern_psk(ssl, 1) != WOLFSSL_SUCCESS) {
14783+
/* handle error */
14784+
}
14785+
\endcode
14786+
14787+
\sa wolfSSL_CTX_set_cert_with_extern_psk
14788+
\sa wolfSSL_set_psk_client_tls13_callback
14789+
\sa wolfSSL_set_psk_server_tls13_callback
14790+
*/
14791+
int wolfSSL_set_cert_with_extern_psk(WOLFSSL* ssl, int state);
14792+
1472414793
/*!
1472514794
\ingroup Setup
1472614795

examples/client/client.c

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ static int ClientWriteRead(WOLFSSL* ssl, const char* msg, int msgSz,
12061206
/* 4. add the same message into Japanese section */
12071207
/* (will be translated later) */
12081208
/* 5. add printf() into suitable position of Usage() */
1209-
static const char* client_usage_msg[][80] = {
1209+
static const char* client_usage_msg[][81] = {
12101210
/* English */
12111211
{
12121212
" NOTE: All files relative to wolfSSL home dir\n", /* 0 */
@@ -1451,24 +1451,28 @@ static const char* client_usage_msg[][80] = {
14511451
#ifndef NO_PSK
14521452
"--openssl-psk Use TLS 1.3 PSK callback compatible with OpenSSL\n", /* 73 */
14531453
#endif
1454+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_CERT_WITH_EXTERN_PSK) && \
1455+
!defined(NO_PSK)
1456+
"--psk-with-certs Use TLS 1.3 PSK with certificates\n", /* 74 */
1457+
#endif
14541458
#ifdef HAVE_RPK
1455-
"--rpk Use RPK for the defined certificates\n", /* 74 */
1459+
"--rpk Use RPK for the defined certificates\n", /* 75 */
14561460
#endif
1457-
"--files-are-der Specified files are in DER, not PEM format\n", /* 75 */
1461+
"--files-are-der Specified files are in DER, not PEM format\n", /* 76 */
14581462
#ifdef WOLFSSL_SYS_CRYPTO_POLICY
1459-
"--crypto-policy <path to crypto policy file>\n", /* 76 */
1463+
"--crypto-policy <path to crypto policy file>\n", /* 77 */
14601464
#endif
14611465
#ifdef HAVE_ECC_BRAINPOOL
1462-
"--bpKs Use Brainpool ECC group for key share\n", /* 77 */
1466+
"--bpKs Use Brainpool ECC group for key share\n", /* 78 */
14631467
#endif
14641468
#if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
14651469
"--ech <base64> Use Encrypted Client Hello with base64 encoded "
14661470
"ECH configs\n",
1467-
/* 78 */
1471+
/* 79 */
14681472
#endif
14691473
"\n"
14701474
"For simpler wolfSSL TLS client examples, visit\n"
1471-
"https://github.com/wolfSSL/wolfssl-examples/tree/master/tls\n", /* 79 */
1475+
"https://github.com/wolfSSL/wolfssl-examples/tree/master/tls\n", /* 80 */
14721476
NULL,
14731477
},
14741478
#ifndef NO_MULTIBYTE_PRINT
@@ -1717,20 +1721,24 @@ static const char* client_usage_msg[][80] = {
17171721
#ifndef NO_PSK
17181722
"--openssl-psk Use TLS 1.3 PSK callback compatible with OpenSSL\n", /* 73 */
17191723
#endif
1724+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_CERT_WITH_EXTERN_PSK) && \
1725+
!defined(NO_PSK)
1726+
"--psk-with-certs Use TLS 1.3 PSK with certificates\n", /* 74 */
1727+
#endif
17201728
#ifdef HAVE_RPK
1721-
"--rpk Use RPK for the defined certificates\n", /* 74 */
1729+
"--rpk Use RPK for the defined certificates\n", /* 75 */
17221730
#endif
1723-
"--files-are-der Specified files are in DER, not PEM format\n", /* 75 */
1731+
"--files-are-der Specified files are in DER, not PEM format\n", /* 76 */
17241732
#ifdef WOLFSSL_SYS_CRYPTO_POLICY
1725-
"--crypto-policy <path to crypto policy file>\n", /* 76 */
1733+
"--crypto-policy <path to crypto policy file>\n", /* 77 */
17261734
#endif
17271735
#ifdef HAVE_ECC_BRAINPOOL
1728-
"--bpKs Use Brainpool ECC group for key share\n", /* 77 */
1736+
"--bpKs Use Brainpool ECC group for key share\n", /* 78 */
17291737
#endif
17301738
"\n"
17311739
"より簡単なwolfSSL TLS クライアントの例については"
17321740
"下記にアクセスしてください\n"
1733-
"https://github.com/wolfSSL/wolfssl-examples/tree/master/tls\n", /* 78 */
1741+
"https://github.com/wolfSSL/wolfssl-examples/tree/master/tls\n", /* 79 */
17341742
NULL,
17351743
},
17361744
#endif
@@ -1966,6 +1974,10 @@ static void Usage(void)
19661974
#ifndef NO_PSK
19671975
printf("%s", msg[++msgid]); /* --openssl-psk */
19681976
#endif
1977+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_CERT_WITH_EXTERN_PSK) && \
1978+
!defined(NO_PSK)
1979+
printf("%s", msg[++msgid]); /* --psk-with-certs */
1980+
#endif
19691981
#ifdef HAVE_RPK
19701982
printf("%s", msg[++msgid]); /* --rpk */
19711983
#endif
@@ -2165,6 +2177,10 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
21652177
#endif
21662178
#if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
21672179
{ "ech", 1, 271 },
2180+
#endif
2181+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_CERT_WITH_EXTERN_PSK) && \
2182+
!defined(NO_PSK)
2183+
{ "psk-with-certs", 0, 272 },
21682184
#endif
21692185
{ 0, 0, 0 }
21702186
};
@@ -2173,6 +2189,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
21732189
int minVersion = CLIENT_INVALID_VERSION;
21742190
int usePsk = 0;
21752191
int opensslPsk = 0;
2192+
int usePskWithCerts = 0;
21762193
int useAnon = 0;
21772194
int sendGET = 0;
21782195
int benchmark = 0;
@@ -2412,6 +2429,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
24122429
(void)pqcAlg;
24132430
(void)opensslPsk;
24142431
(void)fileFormat;
2432+
(void)usePskWithCerts;
24152433
StackTrap();
24162434

24172435
/* Reinitialize the global myVerifyAction. */
@@ -3067,6 +3085,12 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
30673085
echConfigs64 = myoptarg;
30683086
break;
30693087
#endif
3088+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_CERT_WITH_EXTERN_PSK) && \
3089+
!defined(NO_PSK)
3090+
case 272:
3091+
usePskWithCerts = 1;
3092+
break;
3093+
#endif
30703094

30713095
default:
30723096
Usage();
@@ -3077,6 +3101,18 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
30773101
myoptind = 0; /* reset for test cases */
30783102
#endif /* !WOLFSSL_VXWORKS */
30793103

3104+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_CERT_WITH_EXTERN_PSK) && \
3105+
!defined(NO_PSK)
3106+
if (usePskWithCerts) {
3107+
usePsk = 1;
3108+
if (noPskDheKe) {
3109+
LOG_ERROR("--psk-with-certs requires PSK key exchange with (EC)DHE");
3110+
Usage();
3111+
XEXIT_T(MY_EX_USAGE);
3112+
}
3113+
}
3114+
#endif
3115+
30803116
if (externalTest) {
30813117
/* detect build cases that wouldn't allow test against wolfssl.com */
30823118
int done = 0;
@@ -3483,6 +3519,14 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
34833519
wolfSSL_CTX_set_psk_client_tls13_callback(ctx,
34843520
my_psk_client_tls13_cb);
34853521
}
3522+
#if defined(WOLFSSL_CERT_WITH_EXTERN_PSK)
3523+
if (usePskWithCerts) {
3524+
if (wolfSSL_CTX_set_cert_with_extern_psk(ctx, 1) != WOLFSSL_SUCCESS) {
3525+
wolfSSL_CTX_free(ctx); ctx = NULL;
3526+
err_sys("client can't enable cert_with_extern_psk");
3527+
}
3528+
}
3529+
#endif
34863530
#endif
34873531
if (defaultCipherList == NULL) {
34883532
#if defined(HAVE_AESGCM) && !defined(NO_DH)
@@ -3634,7 +3678,8 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
36343678
#endif
36353679
}
36363680

3637-
if (!usePsk && !useAnon && !useVerifyCb && myVerifyAction != VERIFY_FORCE_FAIL) {
3681+
if ((!usePsk || usePskWithCerts) && !useAnon && !useVerifyCb &&
3682+
myVerifyAction != VERIFY_FORCE_FAIL) {
36383683
#if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
36393684
(defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
36403685
!defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
@@ -3718,10 +3763,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
37183763
myVerifyAction == VERIFY_USE_PREVERIFY) {
37193764
wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
37203765
}
3721-
else if (!usePsk && !useAnon && doPeerCheck == 0) {
3766+
else if ((!usePsk || usePskWithCerts) && !useAnon && doPeerCheck == 0) {
37223767
wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
37233768
}
3724-
else if (!usePsk && !useAnon && myVerifyAction == VERIFY_OVERRIDE_DATE_ERR) {
3769+
else if ((!usePsk || usePskWithCerts) && !useAnon &&
3770+
myVerifyAction == VERIFY_OVERRIDE_DATE_ERR) {
37253771
wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
37263772
}
37273773
#endif /* !NO_CERTS */

0 commit comments

Comments
 (0)