From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EA2722045B; Mon, 29 Feb 2016 05:45:14 +0000 (UTC) Date: Mon, 29 Feb 2016 05:45:14 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] ssl: ensure is session_id_context is always set Message-ID: <20160229054514.GA8344@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: When a client attempts to reuse a session, we must have a session_id_context set or else handshakes fail. This problem manifests only with clients which attempt to reuse stored sessions. This is irrespective of any session caching configured (even if explicitly disabled) in the server. The SSL_set_session_id_context(3SSL) manpage states: If the session id context is not set on an SSL/TLS server and client certificates are used, stored sessions will not be reused but a fatal error will be flagged and the handshake will fail. --- lib/yahns/server.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb index d6a03f3..ba2066b 100644 --- a/lib/yahns/server.rb +++ b/lib/yahns/server.rb @@ -386,6 +386,13 @@ def fdmap_init env['HTTPS'] = 'on' # undocumented, but Rack::Request uses this env['rack.url_scheme'] = 'https' + # avoid "session id context uninitialized" errors when a client + # attempts to reuse a cached SSL session. Server admins may + # configure their own cache and session_id_context if desired. + # 32 bytes is SSL_MAX_SSL_SESSION_ID_LENGTH and has been since + # the SSLeay days + ssl_ctx.session_id_context ||= OpenSSL::Random.random_bytes(32) + # call OpenSSL::SSL::SSLContext#setup explicitly here to detect # errors and avoid race conditions. We avoid calling this in the # parent process since -- EW