![]() |
![]()
| ![]() |
![]()
NAME
SYNOPSIS
typedef int
int
int
int
DESCRIPTION
When a new session is established between client and server, the server generates a session id. The session id is an arbitrary sequence of bytes. The length of the session id is between 1 and 32 bytes. The session id is not security critical but must be unique for the server. Additionally, the session id is transmitted in the clear when reusing the session so it must not contain sensitive information. Without a callback being set, an OpenSSL server will generate a unique session id from pseudo random numbers of the maximum possible length. Using the callback function, the session id can be changed to contain additional information like, e.g., a host id in order to improve load balancing or external caching techniques. The callback function receives a pointer to the memory location to put id into and a pointer to the maximum allowed length id_len. The buffer at location id is only guaranteed to have the size id_len. The callback is only allowed to generate a shorter id and reduce id_len; the callback must never increase id_len or write to the location id exceeding the given limit. The location id is filled with 0x00 before the callback is called, so the callback may only fill part of the possible length and leave id_len untouched while maintaining reproducibility. Since the sessions must be
distinguished, session ids must be unique. Without the callback a random
number is used, so that the probability of generating the same session id is
extremely small (2^256 for TLSv1). In order to ensure the uniqueness of the
generated session id, the callback must call
The callback must return 0 if it cannot generate a session id for whatever reason and return 1 on success. RETURN VALUES
EXAMPLESThe callback function listed will generate a session id with the server id given, and will fill the rest with pseudo random bytes: const char session_id_prefix = "www-18"; #define MAX_SESSION_ID_ATTEMPTS 10 static int generate_session_id(const SSL *ssl, unsigned char *id, unsigned int *id_len) { unsigned int count = 0; do { RAND_pseudo_bytes(id, *id_len); /* * Prefix the session_id with the required prefix. NB: If * our prefix is too long, clip it – but there will be * worse effects anyway, e.g., the server could only * possibly create one session ID (the prefix!) so all * future session negotiations will fail due to conflicts. */ 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; } SEE ALSOHISTORY
|