  
    def setup
      @thread = nil
-@@ -1820,7 +1818,7 @@ def test_tls_with_ca_file
-           begin
-             Net::FTP.new(SERVER_NAME,
-                          :port => port,
--                         :ssl => { :ca_file => CA_FILE })
-+                         :ssl => { :ca_file => Net::TestUtils::CA_FILE })
-           rescue SystemCallError
-             skip $!
-           end
-@@ -1845,7 +1843,7 @@ def test_tls_post_connection_check
-           # so the following code should raise a SSLError.
-           Net::FTP.new(SERVER_ADDR,
-                        :port => port,
--                       :ssl => { :ca_file => CA_FILE })
-+                       :ssl => { :ca_file => Net::TestUtils::CA_FILE })
-         end
-       end
-     end
-@@ -1862,14 +1860,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 = Net::TestUtils.create_ssl_ctx
-           sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
-           sock.sync_close = true
-           begin
-@@ -1908,7 +1899,7 @@ def test_active_private_data_connection
-       end
-       ftp = Net::FTP.new(SERVER_NAME,
-                          port: port,
--                         ssl: { ca_file: CA_FILE },
-+                         ssl: { ca_file: Net::TestUtils::CA_FILE },
-                          passive: false)
-       begin
-         assert_equal("AUTH TLS\r\n", commands.shift)
-@@ -1946,14 +1937,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 = Net::TestUtils.create_ssl_ctx
-           sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
-           sock.sync_close = true
-           begin
-@@ -1992,7 +1976,7 @@ def test_passive_private_data_connection
-       end
-       ftp = Net::FTP.new(SERVER_NAME,
-                          port: port,
--                         ssl: { ca_file: CA_FILE },
-+                         ssl: { ca_file: Net::TestUtils::CA_FILE },
-                          passive: true)
-       begin
-         assert_equal("AUTH TLS\r\n", commands.shift)
-@@ -2028,14 +2012,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 = Net::TestUtils.create_ssl_ctx
-           sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
-           sock.sync_close = true
-           begin
-@@ -2066,7 +2043,7 @@ def test_active_clear_data_connection
-       end
-       ftp = Net::FTP.new(SERVER_NAME,
-                          port: port,
--                         ssl: { ca_file: CA_FILE },
-+                         ssl: { ca_file: Net::TestUtils::CA_FILE },
-                          private_data_connection: false,
-                          passive: false)
-       begin
-@@ -2097,14 +2074,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 = Net::TestUtils.create_ssl_ctx
-           sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
-           sock.sync_close = true
-           begin
-@@ -2135,7 +2105,7 @@ def test_passive_clear_data_connection
-       end
-       ftp = Net::FTP.new(SERVER_NAME,
-                          port: port,
--                         ssl: { ca_file: CA_FILE },
-+                         ssl: { ca_file: Net::TestUtils::CA_FILE },
-                          private_data_connection: false,
-                          passive: true)
-       begin
-@@ -2170,7 +2140,7 @@ def test_tls_connect_timeout
-         assert_raise(Net::OpenTimeout) do
-           Net::FTP.new(SERVER_NAME,
-                        port: port,
--                       ssl: { ca_file: CA_FILE },
-+                       ssl: { ca_file: Net::TestUtils::CA_FILE },
-                        ssl_handshake_timeout: 0.1)
-         end
-         @thread.join
-@@ -2189,14 +2159,7 @@ def test_abort_tls
+@@ -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")

-        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)

-    ctx.cert = File.open(SERVER_CERT) { |f|
-      OpenSSL::X509::Certificate.new(f)
-    }
+    ctx = create_ctx
     ssl_server = OpenSSL::SSL::SSLServer.new(server, ctx)
     started = false
     ths = Thread.start do
@@ -757,14 +749,7 @@ def starttls_test
         sock.print("* OK test server\r\n")
         sock.gets
         sock.print("RUBY0001 OK completed\r\n")
