pike.git / lib / modules / SSL.pmod / Context.pike

version» Context lines:

pike.git/lib/modules/SSL.pmod/Context.pike:143:   //! Required to select which out of several certificates to use   //! (@rfc{5246:7.4.1.4.1@}).   //! @value Constants.EXTENSION_ec_point_formats   //! Required for elliptic curve key exchange (@rfc{4492:5.1.2@}).   //! @value Constants.EXTENSION_elliptic_curves   //! Required for elliptic curve key exchange (@rfc{4492:5.1.1@}).   //! @value Constants.EXTENSION_server_name   //! Allows the client to select which of several domains hosted on   //! the same server it wants to connect to. Required by many   //! websites (@rfc{6066:3@}). + //! @value Constants.EXTENSION_session_ticket + //! Support session resumption without server-side state + //! (@rfc{4507@} and @rfc{5077@}).   //! @value Constants.EXTENSION_next_protocol_negotiation   //! Not supported by Pike. The server side will just check that   //! the client packets are correctly formatted.   //! @value Constants.EXTENSION_signed_certificate_timestamp   //! Not supported by Pike. The server side will just check that   //! the client packets are correctly formatted.   //! @value Constants.EXTENSION_early_data   //! Needed for TLS 1.3 0-RTT handshake. EXPERIMENTAL.   //! @value Constants.EXTENSION_padding   //! This extension is required to avoid a bug in some f5 SSL
pike.git/lib/modules/SSL.pmod/Context.pike:183:   //! @rfc{6066@}   multiset(int) extensions = (<    EXTENSION_renegotiation_info,    EXTENSION_max_fragment_length,    EXTENSION_ec_point_formats,    EXTENSION_encrypt_then_mac,    EXTENSION_application_layer_protocol_negotiation,    EXTENSION_signature_algorithms,    EXTENSION_elliptic_curves,    EXTENSION_server_name, +  EXTENSION_session_ticket,    EXTENSION_next_protocol_negotiation,    EXTENSION_signed_certificate_timestamp,    EXTENSION_early_data,    EXTENSION_padding,   >);      //   // --- Cryptography   //   
pike.git/lib/modules/SSL.pmod/Context.pike:1093:   //! corresponding session, or zero if it is not found or caching is   //! disabled.   Session lookup_session(string id)   {    if (use_cache)    return session_cache[id];    else    return 0;   }    + //! Decode a session ticket and return the corresponding session + //! if valid or zero if invalid. + //! + //! @note + //! The default implementation just calls @[lookup_session()]. + //! + //! Override this function (and @[encode_ticket()]) to implement + //! server-side state-less session resumption. + //! + //! @seealso + //! @[encode_ticket()], @[lookup_session()] + Session decode_ticket(string(8bit) ticket) + { +  return lookup_session(ticket); + } +  + //! Generate a session ticket for a session. + //! + //! @note + //! The default implementation just generates a random ticket + //! and calls @[record_session()] to store it. + //! + //! Over-ride this function (and @[decode_ticket()]) to implement + //! server-side state-less session resumption. + //! + //! @returns + //! Returns @expr{0@} (zero) on failure (ie cache disabled), and + //! an array on success: + //! @array + //! @elem string(8bit) 0 + //! Non-empty string with the ticket. + //! @elem int + //! Lifetime hint for the ticket. + //! @endarray + //! + //! @seealso + //! @[decode_ticket()], @[record_session()], @rfc{4507:3.3@} + array(string(8bit)|int) encode_ticket(Session session) + { +  if (!use_cache) return 0; +  string(8bit) ticket = session->ticket; +  if (!sizeof(ticket||"")) { +  do { +  ticket = random(32); +  } while(session_cache[ticket]); +  // FIXME: Should we update the fields here? +  // Consider moving this to the caller. +  session->ticket = ticket; +  session->ticket_expiry_time = time(1) + 3600; +  } +  string(8bit) orig_id = session->identity; +  session->identity = ticket; +  record_session(session); +  session->identity = orig_id; +  // FIXME: Calculate the lifetime from the ticket_expiry_time field? +  return ({ ticket, 3600 }); + } +    //! Create a new session.   Session new_session()   {    string(8bit) id = "";    if(use_cache)    do {    id = random(32);    } while( session_cache[id] );       Session s = Session(id);    s->ffdhe_groups = ffdhe_groups;       return s;   }      //! Add a session to the cache (if caching is enabled).   void record_session(Session s)   { -  if (use_cache && s->identity) +  if (use_cache && sizeof(s->identity||""))    {    if( sizeof(session_cache) > max_sessions )    {    forget_old_sessions();    int to_delete = sizeof(session_cache)-max_sessions;    foreach(session_cache; string id;)    {    // Randomly delete sessions to keep within the limit.    if( to_delete-- < 0 ) break;    SSL3_DEBUG_MSG("SSL.Context->record_session: "