OpenSSL会话重用(服务器端)-希望选择要重用的会话

OpenSSL会话重用(服务器端)-希望选择要重用的会话,openssl,Openssl,我正在运行一个基本服务器,使用内部缓存(SSL\u SESS\u cache\u server cache模式)。因此,每次客户端发送有效的会话ID时,OpenSSL都会自动启动会话重用。我希望有一个选项,可以根据一些非常动态的属性来决定是否希望(或不希望)重用可用的会话 如果我能得到类似于客户端的“SSL\u set\u session”的东西,那就太完美了。OpenSSL将缓存会话,我将通过使用SSL\u set\u会话来决定何时以及是否使用它们 不存储特定会话不是一个选项。我正在寻找一种方

我正在运行一个基本服务器,使用内部缓存(SSL\u SESS\u cache\u server cache模式)。因此,每次客户端发送有效的会话ID时,OpenSSL都会自动启动会话重用。我希望有一个选项,可以根据一些非常动态的属性来决定是否希望(或不希望)重用可用的会话

如果我能得到类似于客户端的“SSL\u set\u session”的东西,那就太完美了。OpenSSL将缓存会话,我将通过使用SSL\u set\u会话来决定何时以及是否使用它们

不存储特定会话不是一个选项。我正在寻找一种方法,使会话查找和重用只按需进行


谢谢

为此,当您第一次收到连接时(在执行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\u CTX\u sess\u set\u get\u cb()
提供会话缓存回调


希望这有帮助

为此,当您第一次收到连接时(在执行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\u CTX\u sess\u set\u get\u cb()
提供会话缓存回调


希望这有帮助

谢谢!我会调查的,谢谢!我会调查的。