mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-10-24 04:09:07 +03:00
On the client side wolfSSL_get_session() returns a ClientSession locator into the static ClientCache rather than a full WOLFSSL_SESSION, unless NO_SESSION_CACHE_REF is defined. Every session accessor maps that locator to the real cache entry through ClientSessionToSession(), but wolfSSL_SESSION_set1_id() and wolfSSL_SESSION_set1_id_context() wrote the session ID and context straight through it. The writes landed at WOLFSSL_SESSION offsets well past the locator, corrupting neighbouring ClientCache entries and, for the last entries, running past the array. Resolve the pointer first in both functions and fail when it no longer maps to a cache entry. A cache entry is keyed by its session ID, so rewriting it in place would stop the handle from resolving and strand the entry in the row of its old ID. set1_id() on a client handle therefore only accepts the ID the entry already holds, and then writes nothing. Callers that want a new ID can use wolfSSL_get1_session(), which returns the connection's own session. Add a regression test that drives the documented get_session, set1_id_context and set1_id flow on a client handle: the context reaches the cached session, re-keying is refused and the handle keeps resolving, an owned session still takes a new ID, and both setters reject a handle whose entry was evicted. Fixes F-9049.
79 lines
4.0 KiB
C
79 lines
4.0 KiB
C
/* test_session.h
|
|
*
|
|
* Copyright (C) 2006-2026 wolfSSL Inc.
|
|
*
|
|
* This file is part of wolfSSL.
|
|
*
|
|
* wolfSSL is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* wolfSSL is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
|
*/
|
|
|
|
#ifndef WOLFCRYPT_TEST_SESSION_H
|
|
#define WOLFCRYPT_TEST_SESSION_H
|
|
|
|
#include <tests/api/api_decl.h>
|
|
|
|
int test_wolfSSL_CTX_add_session(void);
|
|
int test_wolfSSL_CTX_add_session_ext_tls13(void);
|
|
int test_wolfSSL_CTX_add_session_ext_dtls13(void);
|
|
int test_wolfSSL_CTX_add_session_ext_tls12(void);
|
|
int test_wolfSSL_CTX_add_session_ext_dtls12(void);
|
|
int test_wolfSSL_CTX_add_session_ext_tls11(void);
|
|
int test_wolfSSL_CTX_add_session_ext_dtls1(void);
|
|
int test_wolfSSL_CTX_sess_get_cb_default_copy(void);
|
|
int test_wolfSSL_SESSION(void);
|
|
int test_wolfSSL_SESSION_expire_downgrade(void);
|
|
int test_wolfSSL_CTX_sess_set_remove_cb(void);
|
|
int test_wolfSSL_ticket_keys(void);
|
|
int test_wolfSSL_ticket_keys_threaded(void);
|
|
int test_wolfSSL_SESSION_get_ex_new_index(void);
|
|
int test_wolfSSL_SESSION_dup_peer_fail(void);
|
|
int test_wolfSSL_GetSessionAtIndex(void);
|
|
int test_wolfSSL_session_cache_short_ticket_reuse(void);
|
|
int test_wolfSSL_client_cache_id_prefix(void);
|
|
int test_wolfSSL_client_cache_id_overwrite(void);
|
|
int test_wolfSSL_client_cache_set1_id(void);
|
|
int test_wolfSSL_session_cache_restore(void);
|
|
int test_wolfSSL_session_cache_client_geometry(void);
|
|
int test_wolfSSL_get_session_default_ref(void);
|
|
int test_wolfSSL_SetServerID_resume(void);
|
|
|
|
#define TEST_SESSION_DECLS \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_tls13), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_dtls13), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_tls12), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_dtls12), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_tls11), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_add_session_ext_dtls1), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_sess_get_cb_default_copy), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_SESSION), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_SESSION_expire_downgrade), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_CTX_sess_set_remove_cb), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_ticket_keys), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_ticket_keys_threaded), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_SESSION_get_ex_new_index), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_SESSION_dup_peer_fail), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_GetSessionAtIndex), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_session_cache_short_ticket_reuse), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_client_cache_id_prefix), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_client_cache_id_overwrite), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_client_cache_set1_id), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_session_cache_restore), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_session_cache_client_geometry), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_get_session_default_ref), \
|
|
TEST_DECL_GROUP("session", test_wolfSSL_SetServerID_resume)
|
|
|
|
#endif /* WOLFCRYPT_TEST_SESSION_H */
|