SSL_CTX_SET_GENERATE_SESSION_ID(3ssl) OpenSSL SSL_CTX_set_generate_session_id, SSL_set_generate_session_id, SSL_has_matching_session_id, GEN_SESSION_CB - SSL ( ) #include typedef int (*GEN_SESSION_CB)(SSL *ssl, unsigned char *id, unsigned int *id_len); int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb); int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB, cb); int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, unsigned int id_len); SSL_CTX_set_generate_session_id() SSL/TLS ctx cb. SSL_set_generate_session_id() SSL/TLS ssl cb. SSL_has_matching_session_id() id ( id_len) ssl. . . 1 32 . . . OpenSSL . . id id_len. id id_len. id_len id_len id . id 0x00 id_len . . (2^256 SSLv3/TLSv1). SSL_has_matching_session_id() . . ( ). id_len . SSL_has_matching_session_id() . . . SSL_has_matching_session_id() . 0 1 . SSL_CTX_set_generate_session_id() SSL_set_generate_session_id() 1 0 . SSL_has_matching_session_id() 1 0 . : const char session_id_prefix = "www-18"; #define MAX_SESSION_ID_ATTEMPTS 10 static int generate_session_id(SSL *ssl, unsigned char *id, unsigned int *id_len) { unsigned int count = 0; do { RAND_pseudo_bytes(id, *id_len); /* * . : * - * * ( !) * . */ memcpy(id, session_id_prefix, strlen(session_id_prefix) < *id_len ? strlen(session_id_prefix) : *id_len); } while (SSL_has_matching_session_id(ssl, id, *id_len) && ++count < MAX_SESSION_ID_ATTEMPTS); if (count >= MAX_SESSION_ID_ATTEMPTS) return 0; return 1; } ssl(7), SSL_get_version(3) 2001-2020 OpenSSL. . Apache 2.0 ( ""). . LICENSE . 3 . . : . 3.6.2 7 2026 SSL_CTX_SET_GENERATE_SESSION_ID(3ssl)