 -        ctx.cert = File.open(SERVER_CERT) { |f|
 -          OpenSSL::X509::Certificate.new(f)
 -        }
-+        ctx = Net::TestUtils.create_ssl_ctx
++        ctx = create_ctx
          sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
          sock.sync_close = true
          begin
+diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb
+index 17fabb62d5..fa0e3fa86a 100644
+--- a/test/net/http/test_https.rb
++++ b/test/net/http/test_https.rb
+@@ -4,23 +4,15 @@
+   require 'net/https'
+   require 'stringio'
+   require 'timeout'
+-  require File.expand_path("utils", File.dirname(__FILE__))
++  require File.expand_path("utils", __dir__)
++  require File.expand_path('..\utils_ssl', File.dirname(__FILE__))
+ rescue LoadError
+   # should skip this test
+ end
+ 
+ class TestNetHTTPS < Test::Unit::TestCase
+   include TestNetHTTPUtils
+-
+-  def self.fixture(key)
+-    File.read(File.expand_path("../fixtures/#{key}", __dir__))
+-  end
+-
+-  CA_CERT = OpenSSL::X509::Certificate.new(fixture("cacert.pem"))
+-  SERVER_KEY = OpenSSL::PKey.read(fixture("server.key"))
+-  SERVER_CERT = OpenSSL::X509::Certificate.new(fixture("server.crt"))
+-  DHPARAMS = OpenSSL::PKey::DH.new(fixture("dhparams.pem"))
+-  TEST_STORE = OpenSSL::X509::Store.new.tap {|s| s.add_cert(CA_CERT) }
++  include TestNetUtilsSSL
+ 
+   CONFIG = {
+     'host' => '127.0.0.1',
+@@ -141,6 +133,7 @@ def test_session_reuse
+ 
+     http = Net::HTTP.new("localhost", config("port"))
+     http.use_ssl = true
++    http.max_version = OpenSSL::SSL::TLS1_2_VERSION
+     http.cert_store = TEST_STORE
+ 
+     http.start
 diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb
-index 33b305e116..7a888b3012 100644
+index 33b305e116..d6bc366a84 100644
 --- a/test/net/imap/test_imap.rb
 +++ b/test/net/imap/test_imap.rb
-@@ -2,11 +2,9 @@
+@@ -2,11 +2,10 @@
  
  require "net/imap"
  require "test/unit"
-+require_relative '..\utils'
++require File.expand_path('..\utils_ssl', File.dirname(__FILE__))
  
  class IMAPTest < Test::Unit::TestCase
 -  CA_FILE = File.expand_path("../fixtures/cacert.pem", __dir__)
 -  SERVER_KEY = File.expand_path("../fixtures/server.key", __dir__)
 -  SERVER_CERT = File.expand_path("../fixtures/server.crt", __dir__)
++  include TestNetUtilsSSL
  
    def setup
      @do_not_reverse_lookup = Socket.do_not_reverse_lookup
-@@ -81,7 +79,7 @@ def test_imaps_with_ca_file
-           begin
-             Net::IMAP.new("localhost",
-                           :port => port,
--                          :ssl => { :ca_file => CA_FILE })
-+                          :ssl => { :ca_file => Net::TestUtils::CA_FILE })
-           rescue SystemCallError
-             skip $!
-           end
-@@ -106,7 +104,7 @@ def test_imaps_post_connection_check
-           # so the following code should raise a SSLError.
-           Net::IMAP.new(server_addr,
-                         :port => port,
--                        :ssl => { :ca_file => CA_FILE })
-+                        :ssl => { :ca_file => Net::TestUtils::CA_FILE })
-         end
-       end
-     end
-@@ -117,7 +115,7 @@ def test_starttls
-       imap = nil
-       starttls_test do |port|
-         imap = Net::IMAP.new("localhost", :port => port)
--        imap.starttls(:ca_file => CA_FILE)
-+        imap.starttls(:ca_file => Net::TestUtils::CA_FILE)
-         imap
-       end
-     rescue SystemCallError
-@@ -708,14 +706,7 @@ def test_append_fail
+@@ -708,14 +707,7 @@ def test_append_fail
    def imaps_test
      server = create_tcp_server
      port = server.addr[1]

Patch by MSP-Greg
Add shared util.rb file with create_ssl_ctx method
Removes duplicated code in ftp, imap, & smtp
diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb
index 2504a48d0a..3e0ee6974b 100644
--- a/test/net/ftp/test_ftp.rb
+++ b/test/net/ftp/test_ftp.rb
@@ -6,6 +6,7 @@
 require "stringio"
 require "tempfile"
 require "tmpdir"
+require_relative '..\utils'
 
 class FTPTest < Test::Unit::TestCase
   SERVER_NAME = "localhost"
@@ -15,9 +16,6 @@ class FTPTest < Test::Unit::TestCase
     rescue SocketError
       "127.0.0.1"
     end

-        ctx.cert = File.open(SERVER_CERT) { |f|
-          OpenSSL::X509::Certificate.new(f)
-        }
+        ctx = create_ctx
         sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
         sock.sync_close = true
         sock.accept
diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb
index 90c92e06f8..70f2575d5e 100644
--- a/test/net/smtp/test_smtp.rb
+++ b/test/net/smtp/test_smtp.rb
@@ -2,12 +2,11 @@
 require 'net/smtp'
 require 'stringio'
 require 'test/unit'
+require File.expand_path('..\utils_ssl', File.dirname(__FILE__))
 
 module Net
   class TestSMTP < Test::Unit::TestCase
-    CA_FILE = File.expand_path("../fixtures/cacert.pem", __dir__)
-    SERVER_KEY = File.expand_path("../fixtures/server.key", __dir__)
-    SERVER_CERT = File.expand_path("../fixtures/server.crt", __dir__)
+    include TestNetUtilsSSL
 
     class FakeSocket
       attr_reader :write_io
@@ -105,14 +104,7 @@ def test_crlf_injection
 
     def test_tls_connect
       servers = Socket.tcp_server_sockets("localhost", 0)
