 -      ctx.cert = File.open(SERVER_CERT) { |f|
 -        OpenSSL::X509::Certificate.new(f)
 -      }
-+      ctx = Net::TestUtils.create_ssl_ctx
++      ctx = create_ctx
        begin
          sock = nil
          Thread.start do
+diff --git a/test/net/utils_ssl.rb b/test/net/utils_ssl.rb
+new file mode 100644
+index 0000000000..81e7f082e7
+--- /dev/null
++++ b/test/net/utils_ssl.rb
+@@ -0,0 +1,23 @@
++# frozen_string_literal: true
++
++module TestNetUtilsSSL
++
++  def self.fixture(fn)
++    File.read File.expand_path("fixtures/#{fn}", __dir__)
++  end
++
++  CA_FILE = File.expand_path("fixtures/cacert.pem", __dir__)
++  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) }
++
++  def create_ctx
++    ctx = OpenSSL::SSL::SSLContext.new
++    ctx.ca_file = CA_FILE
++    ctx.key  = SERVER_KEY
++    ctx.cert = SERVER_CERT
++    ctx
++  end
++end

-        ctx.cert = File.open(SERVER_CERT) { |f|
-          OpenSSL::X509::Certificate.new(f)
-        }
+        ctx = Net::TestUtils.create_ssl_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..cc440dda2b 100644
--- a/test/net/smtp/test_smtp.rb
+++ b/test/net/smtp/test_smtp.rb
@@ -2,12 +2,10 @@
 require 'net/smtp'
 require 'stringio'
 require 'test/unit'
+require_relative '..\utils'
 
 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__)
 
     class FakeSocket
       attr_reader :write_io
@@ -105,14 +103,7 @@ def test_crlf_injection
 
     def test_tls_connect
       servers = Socket.tcp_server_sockets("localhost", 0)

 
   def setup
     @thread = nil
@@ -1862,14 +1862,7 @@ def test_active_private_data_connection
           sock.print("220 (test_ftp).\r\n")
           commands.push(sock.gets)
           sock.print("234 AUTH success.\r\n")
-          ctx = OpenSSL::SSL::SSLContext.new
-          ctx.ca_file = CA_FILE
-          ctx.key = File.open(SERVER_KEY) { |f|
-            OpenSSL::PKey::RSA.new(f)
-          }
-          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
           begin
@@ -1946,14 +1939,7 @@ def test_passive_private_data_connection
           sock.print("220 (test_ftp).\r\n")
           commands.push(sock.gets)
           sock.print("234 AUTH success.\r\n")
-          ctx = OpenSSL::SSL::SSLContext.new
-          ctx.ca_file = CA_FILE
-          ctx.key = File.open(SERVER_KEY) { |f|
-            OpenSSL::PKey::RSA.new(f)
-          }
-          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
           begin
@@ -2028,14 +2014,7 @@ def test_active_clear_data_connection
           sock.print("220 (test_ftp).\r\n")
           commands.push(sock.gets)
           sock.print("234 AUTH success.\r\n")
-          ctx = OpenSSL::SSL::SSLContext.new
-          ctx.ca_file = CA_FILE
-          ctx.key = File.open(SERVER_KEY) { |f|
-            OpenSSL::PKey::RSA.new(f)
-          }
-          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
           begin
@@ -2097,14 +2076,7 @@ def test_passive_clear_data_connection
           sock.print("220 (test_ftp).\r\n")
           commands.push(sock.gets)
           sock.print("234 AUTH success.\r\n")
-          ctx = OpenSSL::SSL::SSLContext.new
-          ctx.ca_file = CA_FILE
-          ctx.key = File.open(SERVER_KEY) { |f|
-            OpenSSL::PKey::RSA.new(f)
-          }
-          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
           begin
@@ -2189,14 +2161,7 @@ def test_abort_tls
       sock.print("220 (test_ftp).\r\n")
       commands.push(sock.gets)
       sock.print("234 AUTH success.\r\n")
