對於這一點,當你第一次收到連接(並執行TLS握手之前),你可以做這樣的事情:
int allow_session_reuse = 1;
long sess_cache_mode;
/* Call some code here to determine whether SSL session caching/reuse
* should be disabled for this connection.
*/
allow_session_reuse = do_session_reuse();
/* Let's assume the answer is "No, we should not allow session reuse
* for this connection."
*/
if (!allow_session_reuse) {
long cache_mode;
/* Disable all session caching on the SSL_CTX object. Note that these
* session caching modes are for the entire SSL_CTX, not for the
* individual SSL objects.
*/
sess_cache_mode = SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_OFF);
} else {
sess_cache_mode = SSL_CTX_get_session_cache_mode(ssl_ctx);
}
/* .... process your TLS handshake here ... */
/* Make sure to restore the previous session cache mode, for the
* next connection.
*/
SSL_CTX_set_session_cache_mode(ssl_ctx, sess_cache_mode);
如果你想緩存的會話數據的更復雜的處理,你會需要考慮使用SSL_CTX_sess_set_get_cb()
來提供會話緩存回調。
希望這有助於!
謝謝!我會研究它。 – moshikipod