Skip to content

Commit 63d8336

Browse files
committed
Document TLS 1.3 PSK callback default suite and tighten its test
Document in the four TLS 1.3 PSK callback setters that the callback may leave the cipher name NULL, in which case WOLFSSL_DEF_PSK_CIPHER is used, and that a key length of 0 means no PSK. On the server, a non-zero key with no name is accepted and the non-TLS 1.3 server callback is skipped. In test_tls13_psk_cb_no_cipher_name, compare the negotiated suite with WOLFSSL_DEF_PSK_CIPHER and drop the cipher list restriction so the test follows an overridden default. Pin the zero length key case to PSK_KEY_ERROR, or to WOLFSSL_ERROR_WANT_READ when OPENSSL_EXTRA or WOLFSSL_PSK_ONE_ID lets the ClientHello go out.
1 parent 03ed77c commit 63d8336

4 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎doc/dox_comments/header_files-ja/ssl.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13053,7 +13053,7 @@ int wolfSSL_inject(WOLFSSL* ssl, const void* data, int sz);
1305313053
/*!
1305413054
\ingroup Setup
1305513055

13056-
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)クライアント側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。この関数はWOLFSSL_CTX構造体のclient_psk_tls13_cbメンバーを設定します。
13056+
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)クライアント側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。コールバックが暗号名を設定しない(NULLのままの)場合、デフォルトのPSK暗号スイートTLS13-AES128-GCM-SHA256(WOLFSSL_DEF_PSK_CIPHER)が使用されます。鍵長0を返すことはPSKが無いことを示します。この関数はWOLFSSL_CTX構造体のclient_psk_tls13_cbメンバーを設定します。
1305713057

1305813058
\param [in,out] ctx wolfSSL_CTX_new()で作成されたWOLFSSL_CTX構造体へのポインタ。
1305913059
\param [in] cb TLS 1.3クライアント用の事前共有鍵(PSK)コールバック。
@@ -13075,7 +13075,7 @@ void wolfSSL_CTX_set_psk_client_tls13_callback(WOLFSSL_CTX* ctx,
1307513075
/*!
1307613076
\ingroup Setup
1307713077

13078-
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)クライアント側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。この関数はWOLFSSL構造体のoptionsフィールドのclient_psk_tls13_cbメンバーを設定します。
13078+
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)クライアント側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。コールバックが暗号名を設定しない(NULLのままの)場合、デフォルトのPSK暗号スイートTLS13-AES128-GCM-SHA256(WOLFSSL_DEF_PSK_CIPHER)が使用されます。鍵長0を返すことはPSKが無いことを示します。この関数はWOLFSSL構造体のoptionsフィールドのclient_psk_tls13_cbメンバーを設定します。
1307913079

1308013080
\param [in,out] ssl wolfSSL_new()を使用して作成されたWOLFSSL構造体へのポインタ。
1308113081
\param [in] cb TLS 1.3クライアント用の事前共有鍵(PSK)コールバック。
@@ -13097,7 +13097,7 @@ void wolfSSL_set_psk_client_tls13_callback(WOLFSSL* ssl,
1309713097
/*!
1309813098
\ingroup Setup
1309913099

13100-
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)サーバー側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。この関数はWOLFSSL_CTX構造体のserver_psk_tls13_cbメンバーを設定します。
13100+
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)サーバー側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。コールバックが0以外の鍵長を返し暗号名を設定しない(NULLのままの)場合、デフォルトのPSK暗号スイートTLS13-AES128-GCM-SHA256(WOLFSSL_DEF_PSK_CIPHER)でPSKが受け入れられ、TLS 1.3以外のサーバーPSKコールバックは呼び出されません。鍵長0を返すことはアイデンティティが不明であることを示します。この関数はWOLFSSL_CTX構造体のserver_psk_tls13_cbメンバーを設定します。
1310113101

1310213102
\param [in,out] ctx wolfSSL_CTX_new()で作成されたWOLFSSL_CTX構造体へのポインタ。
1310313103
\param [in] cb TLS 1.3サーバー用の事前共有鍵(PSK)コールバック。
@@ -13119,7 +13119,7 @@ void wolfSSL_CTX_set_psk_server_tls13_callback(WOLFSSL_CTX* ctx,
1311913119
/*!
1312013120
\ingroup Setup
1312113121

13122-
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)サーバー側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。この関数はWOLFSSL構造体のoptionsフィールドのserver_psk_tls13_cbメンバーを設定します。
13122+
\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)サーバー側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。コールバックが0以外の鍵長を返し暗号名を設定しない(NULLのままの)場合、デフォルトのPSK暗号スイートTLS13-AES128-GCM-SHA256(WOLFSSL_DEF_PSK_CIPHER)でPSKが受け入れられ、TLS 1.3以外のサーバーPSKコールバックは呼び出されません。鍵長0を返すことはアイデンティティが不明であることを示します。この関数はWOLFSSL構造体のoptionsフィールドのserver_psk_tls13_cbメンバーを設定します。
1312313123

1312413124
\param [in,out] ssl wolfSSL_new()を使用して作成されたWOLFSSL構造体へのポインタ。
1312513125
\param [in] cb TLS 1.3サーバー用の事前共有鍵(PSK)コールバック。

‎doc/dox_comments/header_files/ssl.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17472,6 +17472,10 @@ int wolfSSL_inject(WOLFSSL* ssl, const void* data, int sz);
1747217472
for TLS v1.3 connections.
1747317473
The callback is used to find a PSK identity and return its key and
1747417474
the name of the cipher to use for the handshake.
17475+
The callback may leave the cipher name unset (NULL), in which case the
17476+
default PSK cipher suite TLS13-AES128-GCM-SHA256
17477+
(WOLFSSL_DEF_PSK_CIPHER) is used. Returning a key length of 0 means no
17478+
PSK is available.
1747517479
The function sets the client_psk_tls13_cb member of the
1747617480
WOLFSSL_CTX structure.
1747717481

@@ -17500,6 +17504,10 @@ void wolfSSL_CTX_set_psk_client_tls13_callback(WOLFSSL_CTX* ctx,
1750017504
for TLS v1.3 connections.
1750117505
The callback is used to find a PSK identity and return its key and
1750217506
the name of the cipher to use for the handshake.
17507+
The callback may leave the cipher name unset (NULL), in which case the
17508+
default PSK cipher suite TLS13-AES128-GCM-SHA256
17509+
(WOLFSSL_DEF_PSK_CIPHER) is used. Returning a key length of 0 means no
17510+
PSK is available.
1750317511
The function sets the client_psk_tls13_cb member of the options field in
1750417512
WOLFSSL structure.
1750517513

@@ -17527,6 +17535,11 @@ void wolfSSL_set_psk_client_tls13_callback(WOLFSSL* ssl,
1752717535
for TLS v1.3 connections.
1752817536
The callback is used to find a PSK identity and return its key and
1752917537
the name of the cipher to use for the handshake.
17538+
If the callback returns a non-zero key length and leaves the cipher
17539+
name unset (NULL), the PSK is accepted with the default PSK cipher suite
17540+
TLS13-AES128-GCM-SHA256 (WOLFSSL_DEF_PSK_CIPHER) and the non-TLS 1.3
17541+
server PSK callback is not called. Returning a key length of 0 means the
17542+
identity is not known.
1753017543
The function sets the server_psk_tls13_cb member of the
1753117544
WOLFSSL_CTX structure.
1753217545

@@ -17555,6 +17568,11 @@ void wolfSSL_CTX_set_psk_server_tls13_callback(WOLFSSL_CTX* ctx,
1755517568
for TLS v1.3 connections.
1755617569
The callback is used to find a PSK identity and return its key and
1755717570
the name of the cipher to use for the handshake.
17571+
If the callback returns a non-zero key length and leaves the cipher
17572+
name unset (NULL), the PSK is accepted with the default PSK cipher suite
17573+
TLS13-AES128-GCM-SHA256 (WOLFSSL_DEF_PSK_CIPHER) and the non-TLS 1.3
17574+
server PSK callback is not called. Returning a key length of 0 means the
17575+
identity is not known.
1755817576
The function sets the server_psk_tls13_cb member of the options field in
1755917577
WOLFSSL structure.
1756017578

‎src/tls.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17055,9 +17055,10 @@ int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isServer)
1705517055
MAX_PSK_ID_LEN, ssl->arrays->psk_key, MAX_PSK_KEY_LEN);
1705617056
}
1705717057
if (
17058-
#ifdef OPENSSL_EXTRA
17058+
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_PSK_ONE_ID)
1705917059
/* OpenSSL treats a PSK key length of 0
17060-
* to indicate no PSK available.
17060+
* to indicate no PSK available. With one PSK ID this is
17061+
* the only check before the key is offered.
1706117062
*/
1706217063
ssl->arrays->psk_keySz == 0 ||
1706317064
#endif

‎tests/api/test_tls13.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19357,10 +19357,6 @@ int test_tls13_psk_cb_no_cipher_name(void)
1935719357
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
1935819358
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
1935919359
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
19360-
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES128-GCM-SHA256"),
19361-
WOLFSSL_SUCCESS);
19362-
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "TLS13-AES128-GCM-SHA256"),
19363-
WOLFSSL_SUCCESS);
1936419360
wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, NULL);
1936519361
wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, NULL);
1936619362
wolfSSL_set_psk_client_tls13_callback(ssl_c,
@@ -19369,7 +19365,7 @@ int test_tls13_psk_cb_no_cipher_name(void)
1936919365
test_tls13_psk_no_name_server_cb);
1937019366
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
1937119367
ExpectIntEQ(wolfSSL_get_current_cipher_suite(ssl_c),
19372-
(TLS13_BYTE << 8) | TLS_AES_128_GCM_SHA256);
19368+
(TLS13_BYTE << 8) | WOLFSSL_DEF_PSK_CIPHER);
1937319369
ExpectIntEQ(ssl_s->options.pskNegotiated, 1);
1937419370

1937519371
wolfSSL_free(ssl_c);
@@ -19387,7 +19383,16 @@ int test_tls13_psk_cb_no_cipher_name(void)
1938719383
wolfTLSv1_3_client_method, NULL), 0);
1938819384
wolfSSL_set_psk_client_tls13_callback(ssl_c,
1938919385
test_tls13_psk_none_client_cb);
19390-
ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
19386+
ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
19387+
#ifdef OPENSSL_EXTRA
19388+
/* A zero length key means no PSK, so the ClientHello is sent without
19389+
* one and the client waits for the server. */
19390+
ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
19391+
WOLFSSL_ERROR_WANT_READ);
19392+
#else
19393+
ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
19394+
WC_NO_ERR_TRACE(PSK_KEY_ERROR));
19395+
#endif
1939119396

1939219397
wolfSSL_free(ssl_c);
1939319398
wolfSSL_CTX_free(ctx_c);

0 commit comments

Comments
 (0)