@@ -19391,3 +19391,121 @@ int test_tls13_new_session_ticket_max_fragment(void)
1939119391#endif
1939219392 return EXPECT_RESULT();
1939319393}
19394+
19395+ #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
19396+ defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
19397+ defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && !defined(NO_SHA256) && \
19398+ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
19399+ static const unsigned char test_tls13_psk_no_name_key[32] = {
19400+ 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
19401+ 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
19402+ 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A,
19403+ 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A
19404+ };
19405+
19406+ /* Supplies a key but leaves the cipher suite name unset. */
19407+ static unsigned int test_tls13_psk_no_name_client_cb(WOLFSSL* ssl,
19408+ const char* hint, char* identity, unsigned int id_max_len,
19409+ unsigned char* key, unsigned int key_max_len, const char** ciphersuite)
19410+ {
19411+ (void)ssl;
19412+ (void)hint;
19413+ (void)ciphersuite;
19414+ if (id_max_len == 0 || key_max_len < sizeof(test_tls13_psk_no_name_key))
19415+ return 0;
19416+ XSTRNCPY(identity, "no_name_client", id_max_len);
19417+ XMEMCPY(key, test_tls13_psk_no_name_key,
19418+ sizeof(test_tls13_psk_no_name_key));
19419+ return (unsigned int)sizeof(test_tls13_psk_no_name_key);
19420+ }
19421+
19422+ /* Declines to supply a PSK and leaves the cipher suite name unset. */
19423+ static unsigned int test_tls13_psk_none_client_cb(WOLFSSL* ssl,
19424+ const char* hint, char* identity, unsigned int id_max_len,
19425+ unsigned char* key, unsigned int key_max_len, const char** ciphersuite)
19426+ {
19427+ (void)ssl;
19428+ (void)hint;
19429+ (void)identity;
19430+ (void)id_max_len;
19431+ (void)key;
19432+ (void)key_max_len;
19433+ (void)ciphersuite;
19434+ return 0;
19435+ }
19436+
19437+ static unsigned int test_tls13_psk_no_name_server_cb(WOLFSSL* ssl,
19438+ const char* id, unsigned char* key, unsigned int key_max_len,
19439+ const char** ciphersuite)
19440+ {
19441+ (void)ssl;
19442+ (void)ciphersuite;
19443+ if (key_max_len < sizeof(test_tls13_psk_no_name_key) || id == NULL)
19444+ return 0;
19445+ if (XSTRCMP(id, "no_name_client") != 0)
19446+ return 0;
19447+ XMEMCPY(key, test_tls13_psk_no_name_key,
19448+ sizeof(test_tls13_psk_no_name_key));
19449+ return (unsigned int)sizeof(test_tls13_psk_no_name_key);
19450+ }
19451+ #endif
19452+
19453+ int test_tls13_psk_cb_no_cipher_name(void)
19454+ {
19455+ EXPECT_DECLS;
19456+ #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
19457+ defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
19458+ defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && !defined(NO_SHA256) && \
19459+ !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
19460+ WOLFSSL_CTX *ctx_c = NULL;
19461+ WOLFSSL_CTX *ctx_s = NULL;
19462+ WOLFSSL *ssl_c = NULL;
19463+ WOLFSSL *ssl_s = NULL;
19464+ struct test_memio_ctx test_ctx;
19465+
19466+ /* Both callbacks omit the suite name, so the default suite is used. */
19467+ XMEMSET(&test_ctx, 0, sizeof(test_ctx));
19468+ ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
19469+ wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
19470+ wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, NULL);
19471+ wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, NULL);
19472+ wolfSSL_set_psk_client_tls13_callback(ssl_c,
19473+ test_tls13_psk_no_name_client_cb);
19474+ wolfSSL_set_psk_server_tls13_callback(ssl_s,
19475+ test_tls13_psk_no_name_server_cb);
19476+ ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
19477+ ExpectIntEQ(wolfSSL_get_current_cipher_suite(ssl_c),
19478+ (TLS13_BYTE << 8) | WOLFSSL_DEF_PSK_CIPHER);
19479+ ExpectIntEQ(ssl_s->options.pskNegotiated, 1);
19480+
19481+ wolfSSL_free(ssl_c);
19482+ ssl_c = NULL;
19483+ wolfSSL_CTX_free(ctx_c);
19484+ ctx_c = NULL;
19485+ wolfSSL_free(ssl_s);
19486+ ssl_s = NULL;
19487+ wolfSSL_CTX_free(ctx_s);
19488+ ctx_s = NULL;
19489+
19490+ /* A client callback returning 0 must not fault on the unset name. */
19491+ XMEMSET(&test_ctx, 0, sizeof(test_ctx));
19492+ ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
19493+ wolfTLSv1_3_client_method, NULL), 0);
19494+ wolfSSL_set_psk_client_tls13_callback(ssl_c,
19495+ test_tls13_psk_none_client_cb);
19496+ ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
19497+ #ifdef OPENSSL_EXTRA
19498+ /* A zero length key means no PSK, so the ClientHello is sent without
19499+ * one and the client waits for the server. */
19500+ ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
19501+ WOLFSSL_ERROR_WANT_READ);
19502+ #else
19503+ ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
19504+ WC_NO_ERR_TRACE(PSK_KEY_ERROR));
19505+ #endif
19506+
19507+ wolfSSL_free(ssl_c);
19508+ wolfSSL_CTX_free(ctx_c);
19509+ #endif
19510+ return EXPECT_RESULT();
19511+ }
0 commit comments