2016-01-19 33 views
1

我正在運行基本服務器,使用內部緩存(SSL_SESS_CACHE_SERVER緩存模式)。因此,每次客戶端發送有效的會話ID時,OpenSSL都會自動啓動會話重用。我希望有一個選項可以根據一些非常動態的屬性來決定是否需要(或不)重用可用會話。OpenSSL會話重用(服務器端) - 想要選擇要重用的會話

如果我能得到類似於客戶端的「SSL_set_session」的東西,那將是完美的。 OpenSSL會緩存會話,我將決定何時以及如何使用SSL_set_session來使用它們。

不存儲特定的會話不是一個選項。我正在尋找一種方法來使會話查找&重用 - 僅按需求。

謝謝!

回答

0

對於這一點,當你第一次收到連接(並執行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()來提供會話緩存回調。

希望這有助於!

+0

謝謝!我會研究它。 – moshikipod