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
8 changes: 4 additions & 4 deletions doc/dox_comments/header_files-ja/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13053,7 +13053,7 @@ int wolfSSL_inject(WOLFSSL* ssl, const void* data, int sz);
/*!
\ingroup Setup

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

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

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

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

\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)サーバー側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。この関数はWOLFSSL_CTX構造体のserver_psk_tls13_cbメンバーを設定します。
\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メンバーを設定します。

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

\brief この関数はTLS v1.3接続のための事前共有鍵(PSK)サーバー側コールバックを設定します。コールバックはPSKアイデンティティを検索し、その鍵とハンドシェイクで使用する暗号の名前を返すために使用されます。この関数はWOLFSSL構造体のoptionsフィールドのserver_psk_tls13_cbメンバーを設定します。
\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メンバーを設定します。

\param [in,out] ssl wolfSSL_new()を使用して作成されたWOLFSSL構造体へのポインタ。
\param [in] cb TLS 1.3サーバー用の事前共有鍵(PSK)コールバック。
Expand Down
18 changes: 18 additions & 0 deletions doc/dox_comments/header_files/ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17472,6 +17472,10 @@ int wolfSSL_inject(WOLFSSL* ssl, const void* data, int sz);
for TLS v1.3 connections.
The callback is used to find a PSK identity and return its key and
the name of the cipher to use for the handshake.
The callback may leave the cipher name unset (NULL), in which case the
default PSK cipher suite TLS13-AES128-GCM-SHA256
(WOLFSSL_DEF_PSK_CIPHER) is used. Returning a key length of 0 means no
PSK is available.
Comment thread
embhorn marked this conversation as resolved.
Resolved
The function sets the client_psk_tls13_cb member of the
WOLFSSL_CTX structure.

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

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

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

Expand Down
3 changes: 3 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34335,6 +34335,9 @@ int GetCipherSuiteFromName(const char* name, byte* cipherSuite0,
(void)major;
(void)minor;

if (name == NULL)
return ret;

/* Support trailing : */
nameDelim = XSTRSTR(name, ":");
if (nameDelim)
Expand Down
9 changes: 6 additions & 3 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -17042,7 +17042,9 @@ int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isServer)
ssl, ssl->arrays->server_hint,
ssl->arrays->client_identity, MAX_PSK_ID_LEN,
ssl->arrays->psk_key, MAX_PSK_KEY_LEN, &cipherName);
if (GetCipherSuiteFromName(cipherName, &cipherSuite0,
/* No name from the callback keeps the default suite. */
if (cipherName != NULL &&
GetCipherSuiteFromName(cipherName, &cipherSuite0,
&cipherSuite, NULL, NULL, &cipherSuiteFlags) != 0) {
return PSK_KEY_ERROR;
}
Expand All @@ -17053,9 +17055,10 @@ int TLSX_PopulateExtensions(WOLFSSL* ssl, byte isServer)
MAX_PSK_ID_LEN, ssl->arrays->psk_key, MAX_PSK_KEY_LEN);
}
if (
#ifdef OPENSSL_EXTRA
#if defined(OPENSSL_EXTRA) || defined(WOLFSSL_PSK_ONE_ID)
/* OpenSSL treats a PSK key length of 0
* to indicate no PSK available.
* to indicate no PSK available. With one PSK ID this is
* the only check before the key is offered.
*/
ssl->arrays->psk_keySz == 0 ||
#endif
Expand Down
12 changes: 8 additions & 4 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -4752,15 +4752,17 @@ static int SetupPskKey(WOLFSSL* ssl, PreSharedKey* psk, int clientHello)
}
}
else if (ssl->options.client_psk_tls13_cb != NULL) {
byte cipherSuite0;
byte cipherSuite;
byte cipherSuite0 = TLS13_BYTE;
byte cipherSuite = WOLFSSL_DEF_PSK_CIPHER;
int cipherSuiteFlags = WOLFSSL_CIPHER_SUITE_FLAG_NONE;

ssl->arrays->psk_keySz = ssl->options.client_psk_tls13_cb(ssl,
ssl->arrays->server_hint, ssl->arrays->client_identity,
MAX_PSK_ID_LEN, ssl->arrays->psk_key, MAX_PSK_KEY_LEN,
&cipherName);
if (GetCipherSuiteFromName(cipherName, &cipherSuite0,
/* No name from the callback keeps the default suite. */
if (cipherName != NULL &&
GetCipherSuiteFromName(cipherName, &cipherSuite0,
&cipherSuite, NULL, NULL, &cipherSuiteFlags) != 0) {
WOLFSSL_ERROR_VERBOSE(PSK_KEY_ERROR);
return PSK_KEY_ERROR;
Expand Down Expand Up @@ -6899,7 +6901,9 @@ int FindPskSuite(const WOLFSSL* ssl, PreSharedKey* psk, byte* psk_key,
(char*)psk->identity, psk_key, MAX_PSK_KEY_LEN, &cipherName);
if (*psk_keySz != 0) {
int cipherSuiteFlags = WOLFSSL_CIPHER_SUITE_FLAG_NONE;
*found = (GetCipherSuiteFromName(cipherName, &cipherSuite0,
/* No name from the callback keeps the default suite. */
*found = (cipherName == NULL) ||
(GetCipherSuiteFromName(cipherName, &cipherSuite0,
&cipherSuite, NULL, NULL, &cipherSuiteFlags) == 0);
(void)cipherSuiteFlags;
}
Expand Down
118 changes: 118 additions & 0 deletions tests/api/test_tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -19391,3 +19391,121 @@ int test_tls13_new_session_ticket_max_fragment(void)
#endif
return EXPECT_RESULT();
}

#if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && !defined(NO_SHA256) && \
!defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
static const unsigned char test_tls13_psk_no_name_key[32] = {
0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A
};

/* Supplies a key but leaves the cipher suite name unset. */
static unsigned int test_tls13_psk_no_name_client_cb(WOLFSSL* ssl,
const char* hint, char* identity, unsigned int id_max_len,
unsigned char* key, unsigned int key_max_len, const char** ciphersuite)
{
(void)ssl;
(void)hint;
(void)ciphersuite;
if (id_max_len == 0 || key_max_len < sizeof(test_tls13_psk_no_name_key))
return 0;
XSTRNCPY(identity, "no_name_client", id_max_len);
XMEMCPY(key, test_tls13_psk_no_name_key,
sizeof(test_tls13_psk_no_name_key));
return (unsigned int)sizeof(test_tls13_psk_no_name_key);
}

/* Declines to supply a PSK and leaves the cipher suite name unset. */
static unsigned int test_tls13_psk_none_client_cb(WOLFSSL* ssl,
const char* hint, char* identity, unsigned int id_max_len,
unsigned char* key, unsigned int key_max_len, const char** ciphersuite)
{
(void)ssl;
(void)hint;
(void)identity;
(void)id_max_len;
(void)key;
(void)key_max_len;
(void)ciphersuite;
return 0;
}

static unsigned int test_tls13_psk_no_name_server_cb(WOLFSSL* ssl,
const char* id, unsigned char* key, unsigned int key_max_len,
const char** ciphersuite)
{
(void)ssl;
(void)ciphersuite;
if (key_max_len < sizeof(test_tls13_psk_no_name_key) || id == NULL)
return 0;
if (XSTRCMP(id, "no_name_client") != 0)
return 0;
XMEMCPY(key, test_tls13_psk_no_name_key,
sizeof(test_tls13_psk_no_name_key));
return (unsigned int)sizeof(test_tls13_psk_no_name_key);
}
#endif

int test_tls13_psk_cb_no_cipher_name(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && !defined(NO_SHA256) && \
!defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
WOLFSSL_CTX *ctx_c = NULL;
WOLFSSL_CTX *ctx_s = NULL;
WOLFSSL *ssl_c = NULL;
WOLFSSL *ssl_s = NULL;
struct test_memio_ctx test_ctx;

/* Both callbacks omit the suite name, so the default suite is used. */
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, NULL);
wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, NULL);
wolfSSL_set_psk_client_tls13_callback(ssl_c,
test_tls13_psk_no_name_client_cb);
wolfSSL_set_psk_server_tls13_callback(ssl_s,
test_tls13_psk_no_name_server_cb);
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
ExpectIntEQ(wolfSSL_get_current_cipher_suite(ssl_c),
(TLS13_BYTE << 8) | WOLFSSL_DEF_PSK_CIPHER);
ExpectIntEQ(ssl_s->options.pskNegotiated, 1);

wolfSSL_free(ssl_c);
ssl_c = NULL;
wolfSSL_CTX_free(ctx_c);
ctx_c = NULL;
wolfSSL_free(ssl_s);
ssl_s = NULL;
wolfSSL_CTX_free(ctx_s);
ctx_s = NULL;

/* A client callback returning 0 must not fault on the unset name. */
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
wolfTLSv1_3_client_method, NULL), 0);
wolfSSL_set_psk_client_tls13_callback(ssl_c,
test_tls13_psk_none_client_cb);
ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
#ifdef OPENSSL_EXTRA
/* A zero length key means no PSK, so the ClientHello is sent without
* one and the client waits for the server. */
ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
WOLFSSL_ERROR_WANT_READ);
#else
ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
WC_NO_ERR_TRACE(PSK_KEY_ERROR));
#endif

wolfSSL_free(ssl_c);
wolfSSL_CTX_free(ctx_c);
#endif
return EXPECT_RESULT();
}
4 changes: 3 additions & 1 deletion tests/api/test_tls13.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ int test_tls13_psk_mode_mismatch_falls_back(void);
int test_tls13_ticket_psk_modes_uses_policy(void);
int test_tls13_ecdsa_scheme_curve_binding(void);
int test_tls13_new_session_ticket_max_fragment(void);
int test_tls13_psk_cb_no_cipher_name(void);
int test_tls13_send_session_ticket_psk_modes(void);
int test_tls13_new_session_ticket_ext_framing(void);
int test_tls13_new_session_ticket_keeps_ems(void);
Expand Down Expand Up @@ -420,6 +421,7 @@ int test_tls13_exporter_suite_decision_coverage(void);
TEST_DECL_GROUP("tls13", test_tls13_AEAD_limit_KeyUpdate_want_write), \
TEST_DECL_GROUP("tls13", test_tls13_exporter_suite_decision_coverage), \
TEST_DECL_GROUP("tls13", test_tls13_ecdsa_scheme_curve_binding), \
TEST_DECL_GROUP("tls13", test_tls13_new_session_ticket_max_fragment)
TEST_DECL_GROUP("tls13", test_tls13_new_session_ticket_max_fragment), \
TEST_DECL_GROUP("tls13", test_tls13_psk_cb_no_cipher_name)

#endif /* WOLFCRYPT_TEST_TLS13_H */
Loading