From: "Evan M. Webb" Date: 2005-04-05T08:31:13+09:00 Subject: [PATCH] openssl session id support --=-JAYGe8FA8S2BE+mCbb3S Content-Type: text/plain Content-Transfer-Encoding: 7bit The following patch adds support for setting the session id within an SSL::Context object. Setting the context is necessary for any client using peer certificates that wish to reuse session ids from previous connections. Without this patch, any client that connects again and attempts to reuse the session id will recieve 'session id context uninitialized' as an SSL Error and the connection is terminated immediately. -- Evan M. Webb --=-JAYGe8FA8S2BE+mCbb3S Content-Disposition: attachment; filename=ruby-ssl-session.diff Content-Type: text/x-patch; name=ruby-ssl-session.diff; charset=us-ascii Content-Transfer-Encoding: 7bit --- ruby-1.8.2/ext/openssl/ossl_ssl.c.orig 2005-04-04 12:07:26.000000000 -0700 +++ ruby-1.8.2/ext/openssl/ossl_ssl.c 2005-04-04 12:13:33.000000000 -0700 @@ -349,6 +349,30 @@ return Qnil; } +VALUE +ossl_sslctx_set_session_id(VALUE self, VALUE sid) { + SSL_CTX *ctx; + int i; + VALUE str; + + rb_check_frozen(self); + str = sid; + StringValue(str); + + Data_Get_Struct(self, SSL_CTX, ctx); + + if(!ctx) { + ossl_raise(eSSLError, "SSL_CTX is not initialized."); + return Qnil; + } + if(!SSL_CTX_set_session_id_context(ctx,RSTRING(str)->ptr, + RSTRING(str)->len)) { + ossl_raise(eSSLError, "SSL_CTX_set_session_id_context"); + } + + return Qnil; +} + /* * SSLSocket class */ @@ -728,6 +752,7 @@ rb_define_method(cSSLContext, "initialize", ossl_sslctx_initialize, -1); rb_define_method(cSSLContext, "ciphers", ossl_sslctx_get_ciphers, 0); rb_define_method(cSSLContext, "ciphers=", ossl_sslctx_set_ciphers, 1); + rb_define_method(cSSLContext, "session_id=", ossl_sslctx_set_session_id, 1); /* class SSLSocket */ cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject); --- ruby-1.8.2/ext/openssl/lib/openssl/ssl.rb.orig 2005-04-04 13:03:18.000000000 -0700 +++ ruby-1.8.2/ext/openssl/lib/openssl/ssl.rb 2005-04-04 12:33:41.000000000 -0700 @@ -58,9 +58,19 @@ include SocketForwarder attr_accessor :start_immediately - def initialize(svr, ctx) + def initialize(svr, ctx, session_id=nil) @svr = svr @ctx = ctx + if session_id + @session_id = session_id + else + @session_id = ('a' .. 'z').to_a.sort_by { rand } [0,24].join("") + end + + if @ctx.respond_to? :session_id= + @ctx.session_id = @session_id + end + @start_immediately = true end --=-JAYGe8FA8S2BE+mCbb3S--