2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2011-06-21 23:40:08 -04:00
|
|
|
require_relative "utils"
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
if defined?(OpenSSL)
|
2011-06-21 23:40:08 -04:00
|
|
|
|
|
|
|
class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
|
2011-06-21 23:43:38 -04:00
|
|
|
def test_session
|
2017-09-03 08:35:27 -04:00
|
|
|
pend "TLS 1.2 is not supported" unless tls12_supported?
|
|
|
|
|
|
|
|
ctx_proc = proc { |ctx| ctx.ssl_version = :TLSv1_2 }
|
|
|
|
start_server(ctx_proc: ctx_proc) do |port|
|
|
|
|
server_connect_with_session(port, nil, nil) { |ssl|
|
2014-08-12 22:03:47 -04:00
|
|
|
session = ssl.session
|
|
|
|
assert(session == OpenSSL::SSL::Session.new(session.to_pem))
|
|
|
|
assert(session == OpenSSL::SSL::Session.new(ssl))
|
|
|
|
session.timeout = 5
|
|
|
|
assert_equal(5, session.timeout)
|
|
|
|
assert_not_nil(session.time)
|
|
|
|
# SSL_SESSION_time keeps long value so we can't keep nsec fragment.
|
|
|
|
session.time = t1 = Time.now.to_i
|
|
|
|
assert_equal(Time.at(t1), session.time)
|
2016-05-25 04:50:03 -04:00
|
|
|
assert_not_nil(session.id)
|
2014-08-12 22:03:47 -04:00
|
|
|
pem = session.to_pem
|
|
|
|
assert_match(/\A-----BEGIN SSL SESSION PARAMETERS-----/, pem)
|
|
|
|
assert_match(/-----END SSL SESSION PARAMETERS-----\Z/, pem)
|
|
|
|
pem.gsub!(/-----(BEGIN|END) SSL SESSION PARAMETERS-----/, '').gsub!(/[\r\n]+/m, '')
|
|
|
|
assert_equal(session.to_der, pem.unpack('m*')[0])
|
|
|
|
assert_not_nil(session.to_text)
|
2017-09-03 08:35:27 -04:00
|
|
|
}
|
2014-08-11 14:47:31 -04:00
|
|
|
end
|
2011-06-21 23:43:38 -04:00
|
|
|
end
|
|
|
|
|
2011-06-23 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EZFglydWJ5
|
|
|
|
LWxhbmcxEjAQBgNVBAMMCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
|
|
|
|
gYkCgYEAy8LEsNRApz7U/j5DoB4XBgO9Z8Atv5y/OVQRp0ag8Tqo1YewsWijxEWB
|
|
|
|
7JOATwpBN267U4T1nPZIxxEEO7n/WNa2ws9JWsjah8ssEBFSxZqdXKSLf0N4Hi7/
|
|
|
|
GQ/aYoaMCiQ8jA4jegK2FJmXM71uPe+jFN/peeBOpRfyXxRFOYcCAwEAAaMSMBAw
|
|
|
|
DgYDVR0PAQH/BAQDAgWgMA0GCSqGSIb3DQEBBQUAA4IBAQA3TRzABRG3kz8jEEYr
|
|
|
|
tDQqXgsxwTsLhTT5d1yF0D8uFw+y15hJAJnh6GJHjqhWBrF4zNoTApFo+4iIL6g3
|
|
|
|
q9C3mUsxIVAHx41DwZBh/FI7J4FqlAoGOguu7892CNVY3ZZjc3AXMTdKjcNoWPzz
|
|
|
|
FCdj5fNT24JMMe+ZdGZK97ChahJsdn/6B3j6ze9NK9mfYEbiJhejGTPLOFVHJCGR
|
|
|
|
KYYZ3ZcKhLDr9ql4d7cCo1gBtemrmFQGPui7GttNEqmXqUKvV8mYoa8farf5i7T4
|
|
|
|
L6a/gp2cVZTaDIS1HjbJsA/Ag7AajZqiN6LfqShNUVsrMZ+5CoV8EkBDTZPJ9MSr
|
|
|
|
a3EqpAIEAKUDAgET
|
|
|
|
-----END SSL SESSION PARAMETERS-----
|
|
|
|
__EOS__
|
|
|
|
|
|
|
|
|
2011-06-23 06:36:09 -04:00
|
|
|
def test_session_time
|
2011-07-16 19:02:42 -04:00
|
|
|
sess = OpenSSL::SSL::Session.new(DUMMY_SESSION_NO_EXT)
|
2011-06-23 06:36:09 -04:00
|
|
|
sess.time = (now = Time.now)
|
|
|
|
assert_equal(now.to_i, sess.time.to_i)
|
|
|
|
sess.time = 1
|
|
|
|
assert_equal(1, sess.time.to_i)
|
|
|
|
sess.time = 1.2345
|
|
|
|
assert_equal(1, sess.time.to_i)
|
|
|
|
# Can OpenSSL handle t>2038y correctly? Version?
|
2011-06-23 09:03:02 -04:00
|
|
|
sess.time = 2**31 - 1
|
|
|
|
assert_equal(2**31 - 1, sess.time.to_i)
|
2011-06-23 06:36:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_session_timeout
|
2011-07-16 19:02:42 -04:00
|
|
|
sess = OpenSSL::SSL::Session.new(DUMMY_SESSION_NO_EXT)
|
2011-06-23 06:36:09 -04:00
|
|
|
assert_raise(TypeError) do
|
2012-09-03 18:54:12 -04:00
|
|
|
sess.timeout = Time.now
|
2011-06-23 06:36:09 -04:00
|
|
|
end
|
|
|
|
sess.timeout = 1
|
|
|
|
assert_equal(1, sess.timeout.to_i)
|
|
|
|
sess.timeout = 1.2345
|
|
|
|
assert_equal(1, sess.timeout.to_i)
|
2011-06-23 09:03:02 -04:00
|
|
|
sess.timeout = 2**31 - 1
|
|
|
|
assert_equal(2**31 - 1, sess.timeout.to_i)
|
2011-06-23 06:36:09 -04:00
|
|
|
end
|
|
|
|
|
2011-07-16 19:02:42 -04:00
|
|
|
def test_session_exts_read
|
|
|
|
assert(OpenSSL::SSL::Session.new(DUMMY_SESSION))
|
2017-09-03 08:35:27 -04:00
|
|
|
end
|
2011-06-21 23:40:08 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
def test_resumption
|
|
|
|
non_resumable = nil
|
|
|
|
start_server { |port|
|
|
|
|
server_connect_with_session(port, nil, nil) { |ssl|
|
|
|
|
non_resumable = ssl.session
|
|
|
|
}
|
|
|
|
}
|
2011-06-21 23:40:08 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
ctx_proc = proc { |ctx|
|
|
|
|
ctx.options &= ~OpenSSL::SSL::OP_NO_TICKET
|
|
|
|
# Disable server-side session cache which is enabled by default
|
|
|
|
ctx.session_cache_mode = OpenSSL::SSL::SSLContext::SESSION_CACHE_OFF
|
|
|
|
}
|
|
|
|
start_server(ctx_proc: ctx_proc) do |port|
|
|
|
|
sess1 = server_connect_with_session(port, nil, nil) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
ssl.session
|
|
|
|
}
|
2011-06-21 23:40:08 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
server_connect_with_session(port, nil, non_resumable) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
}
|
|
|
|
|
|
|
|
server_connect_with_session(port, nil, sess1) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
assert_equal true, ssl.session_reused?
|
|
|
|
}
|
2011-06-21 23:40:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
def test_server_session_cache
|
|
|
|
pend "TLS 1.2 is not supported" unless tls12_supported?
|
2011-06-21 23:40:08 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
ctx_proc = Proc.new do |ctx|
|
|
|
|
ctx.ssl_version = :TLSv1_2
|
|
|
|
ctx.options |= OpenSSL::SSL::OP_NO_TICKET
|
2011-06-21 23:40:08 -04:00
|
|
|
end
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
connections = nil
|
|
|
|
saved_session = nil
|
2011-06-21 23:40:08 -04:00
|
|
|
server_proc = Proc.new do |ctx, ssl|
|
|
|
|
stats = ctx.session_cache_stats
|
|
|
|
|
|
|
|
case connections
|
|
|
|
when 0
|
2017-09-03 08:35:27 -04:00
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
assert_equal 1, stats[:cache_num]
|
|
|
|
assert_equal 0, stats[:cache_hits]
|
|
|
|
assert_equal 0, stats[:cache_misses]
|
2011-06-21 23:40:08 -04:00
|
|
|
when 1
|
2017-09-03 08:35:27 -04:00
|
|
|
assert_equal true, ssl.session_reused?
|
|
|
|
assert_equal 1, stats[:cache_num]
|
|
|
|
assert_equal 1, stats[:cache_hits]
|
|
|
|
assert_equal 0, stats[:cache_misses]
|
|
|
|
|
|
|
|
saved_session = ssl.session
|
|
|
|
assert_equal true, ctx.session_remove(ssl.session)
|
2011-06-21 23:40:08 -04:00
|
|
|
when 2
|
2017-09-03 08:35:27 -04:00
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
assert_equal 1, stats[:cache_num]
|
|
|
|
assert_equal 1, stats[:cache_hits]
|
|
|
|
assert_equal 1, stats[:cache_misses]
|
|
|
|
|
|
|
|
assert_equal true, ctx.session_add(saved_session.dup)
|
2011-06-21 23:40:08 -04:00
|
|
|
when 3
|
2017-09-03 08:35:27 -04:00
|
|
|
assert_equal true, ssl.session_reused?
|
|
|
|
assert_equal 2, stats[:cache_num]
|
|
|
|
assert_equal 2, stats[:cache_hits]
|
|
|
|
assert_equal 1, stats[:cache_misses]
|
|
|
|
|
2016-06-07 08:20:46 -04:00
|
|
|
ctx.flush_sessions(Time.now + 10000)
|
2011-06-21 23:40:08 -04:00
|
|
|
when 4
|
2017-09-03 08:35:27 -04:00
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
assert_equal 1, stats[:cache_num]
|
|
|
|
assert_equal 2, stats[:cache_hits]
|
|
|
|
assert_equal 2, stats[:cache_misses]
|
|
|
|
|
|
|
|
assert_equal true, ctx.session_add(saved_session.dup)
|
2011-06-21 23:40:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
readwrite_loop(ctx, ssl)
|
|
|
|
end
|
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
start_server(ctx_proc: ctx_proc, server_proc: server_proc) do |port|
|
|
|
|
first_session = nil
|
2011-06-21 23:40:08 -04:00
|
|
|
10.times do |i|
|
2017-09-03 08:35:27 -04:00
|
|
|
connections = i
|
|
|
|
server_connect_with_session(port, nil, first_session) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
first_session ||= ssl.session
|
|
|
|
|
|
|
|
case connections
|
|
|
|
when 0;
|
|
|
|
when 1; assert_equal true, ssl.session_reused?
|
|
|
|
when 2; assert_equal false, ssl.session_reused?
|
|
|
|
when 3; assert_equal true, ssl.session_reused?
|
|
|
|
when 4; assert_equal false, ssl.session_reused?
|
|
|
|
when 5..9; assert_equal true, ssl.session_reused?
|
2011-06-21 23:40:08 -04:00
|
|
|
end
|
2017-09-03 08:35:27 -04:00
|
|
|
}
|
2011-06-21 23:40:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-06-22 05:24:31 -04:00
|
|
|
|
|
|
|
def test_ctx_client_session_cb
|
2017-09-03 08:35:27 -04:00
|
|
|
pend "TLS 1.2 is not supported" unless tls12_supported?
|
2011-06-22 09:39:56 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
ctx_proc = proc { |ctx| ctx.ssl_version = :TLSv1_2 }
|
|
|
|
start_server(ctx_proc: ctx_proc) do |port|
|
|
|
|
called = {}
|
|
|
|
ctx = OpenSSL::SSL::SSLContext.new
|
|
|
|
ctx.session_cache_mode = OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT
|
|
|
|
ctx.session_new_cb = lambda { |ary|
|
|
|
|
sock, sess = ary
|
|
|
|
called[:new] = [sock, sess]
|
|
|
|
}
|
|
|
|
ctx.session_remove_cb = lambda { |ary|
|
|
|
|
ctx, sess = ary
|
|
|
|
called[:remove] = [ctx, sess]
|
|
|
|
# any resulting value is OK (ignored)
|
|
|
|
}
|
2011-06-22 09:39:56 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
server_connect_with_session(port, ctx, nil) { |ssl|
|
2014-11-01 09:10:37 -04:00
|
|
|
assert_equal(1, ctx.session_cache_stats[:cache_num])
|
|
|
|
assert_equal(1, ctx.session_cache_stats[:connect_good])
|
|
|
|
assert_equal([ssl, ssl.session], called[:new])
|
|
|
|
assert(ctx.session_remove(ssl.session))
|
|
|
|
assert(!ctx.session_remove(ssl.session))
|
|
|
|
assert_equal([ctx, ssl.session], called[:remove])
|
2017-09-03 08:35:27 -04:00
|
|
|
}
|
2011-06-22 05:24:31 -04:00
|
|
|
end
|
|
|
|
end
|
2011-06-22 09:39:56 -04:00
|
|
|
|
|
|
|
def test_ctx_server_session_cb
|
2017-09-03 08:35:27 -04:00
|
|
|
pend "TLS 1.2 is not supported" unless tls12_supported?
|
2011-06-22 09:39:56 -04:00
|
|
|
|
2017-09-03 08:35:27 -04:00
|
|
|
connections = nil
|
|
|
|
called = {}
|
|
|
|
sctx = nil
|
|
|
|
ctx_proc = Proc.new { |ctx|
|
|
|
|
sctx = ctx
|
|
|
|
ctx.ssl_version = :TLSv1_2
|
|
|
|
ctx.options |= OpenSSL::SSL::OP_NO_TICKET
|
2011-06-22 09:39:56 -04:00
|
|
|
|
|
|
|
# get_cb is called whenever a client proposed to resume a session but
|
|
|
|
# the session could not be found in the internal session cache.
|
2017-09-03 08:35:27 -04:00
|
|
|
last_server_session = nil
|
2011-06-22 09:39:56 -04:00
|
|
|
ctx.session_get_cb = lambda { |ary|
|
2017-09-03 08:35:27 -04:00
|
|
|
_sess, data = ary
|
|
|
|
called[:get] = data
|
|
|
|
|
|
|
|
if connections == 2
|
|
|
|
last_server_session.dup
|
2011-06-22 09:39:56 -04:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.session_new_cb = lambda { |ary|
|
2017-09-03 08:35:27 -04:00
|
|
|
_sock, sess = ary
|
|
|
|
called[:new] = sess
|
|
|
|
last_server_session = sess
|
2011-06-22 09:39:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.session_remove_cb = lambda { |ary|
|
2017-09-03 08:35:27 -04:00
|
|
|
_ctx, sess = ary
|
|
|
|
called[:remove] = sess
|
2011-06-22 09:39:56 -04:00
|
|
|
}
|
|
|
|
}
|
2017-09-03 08:35:27 -04:00
|
|
|
start_server(ctx_proc: ctx_proc) do |port|
|
|
|
|
connections = 0
|
|
|
|
sess0 = server_connect_with_session(port, nil, nil) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
ssl.session
|
|
|
|
}
|
|
|
|
assert_nil called[:get]
|
|
|
|
assert_not_nil called[:new]
|
|
|
|
assert_equal sess0.id, called[:new].id
|
|
|
|
assert_nil called[:remove]
|
|
|
|
called.clear
|
|
|
|
|
|
|
|
# Internal cache hit
|
|
|
|
connections = 1
|
|
|
|
server_connect_with_session(port, nil, sess0.dup) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
assert_equal true, ssl.session_reused?
|
|
|
|
ssl.session
|
|
|
|
}
|
|
|
|
assert_nil called[:get]
|
|
|
|
assert_nil called[:new]
|
|
|
|
assert_nil called[:remove]
|
|
|
|
called.clear
|
|
|
|
|
|
|
|
sctx.flush_sessions(Time.now + 10000)
|
|
|
|
assert_not_nil called[:remove]
|
|
|
|
assert_equal sess0.id, called[:remove].id
|
|
|
|
called.clear
|
|
|
|
|
|
|
|
# External cache hit
|
|
|
|
connections = 2
|
|
|
|
sess2 = server_connect_with_session(port, nil, sess0.dup) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
if !ssl.session_reused? && openssl?(1, 1, 0) && !openssl?(1, 1, 0, 7)
|
|
|
|
# OpenSSL >= 1.1.0, < 1.1.0g
|
|
|
|
pend "External session cache is not working; " \
|
|
|
|
"see https://github.com/openssl/openssl/pull/4014"
|
2012-04-09 06:49:46 -04:00
|
|
|
end
|
2017-09-03 08:35:27 -04:00
|
|
|
assert_equal true, ssl.session_reused?
|
|
|
|
ssl.session
|
|
|
|
}
|
|
|
|
assert_equal sess0.id, sess2.id
|
|
|
|
assert_equal sess0.id, called[:get]
|
|
|
|
assert_nil called[:new]
|
|
|
|
assert_nil called[:remove]
|
|
|
|
called.clear
|
|
|
|
|
|
|
|
sctx.flush_sessions(Time.now + 10000)
|
|
|
|
assert_not_nil called[:remove]
|
|
|
|
assert_equal sess0.id, called[:remove].id
|
|
|
|
called.clear
|
|
|
|
|
|
|
|
# Cache miss
|
|
|
|
connections = 3
|
|
|
|
sess3 = server_connect_with_session(port, nil, sess0.dup) { |ssl|
|
|
|
|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
|
|
|
|
assert_equal false, ssl.session_reused?
|
|
|
|
ssl.session
|
|
|
|
}
|
|
|
|
assert_not_equal sess0.id, sess3.id
|
|
|
|
assert_equal sess0.id, called[:get]
|
|
|
|
assert_not_nil called[:new]
|
|
|
|
assert_equal sess3.id, called[:new].id
|
|
|
|
assert_nil called[:remove]
|
2011-06-22 09:39:56 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-29 01:47:09 -04:00
|
|
|
|
|
|
|
def test_dup
|
|
|
|
sess_orig = OpenSSL::SSL::Session.new(DUMMY_SESSION)
|
|
|
|
sess_dup = sess_orig.dup
|
|
|
|
assert_equal(sess_orig.to_der, sess_dup.to_der)
|
|
|
|
end
|
2017-09-03 08:35:27 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def server_connect_with_session(port, ctx = nil, sess = nil)
|
|
|
|
sock = TCPSocket.new("127.0.0.1", port)
|
|
|
|
ctx ||= OpenSSL::SSL::SSLContext.new
|
|
|
|
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
|
|
|
ssl.session = sess if sess
|
|
|
|
ssl.sync_close = true
|
|
|
|
ssl.connect
|
|
|
|
yield ssl if block_given?
|
|
|
|
ensure
|
|
|
|
ssl&.close
|
|
|
|
sock&.close
|
|
|
|
end
|
2011-06-21 23:40:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|