File tree Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Expand file tree Collapse file tree 2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,10 @@ class SSLContext
6666 AES256-SHA256
6767 AES128-SHA
6868 AES256-SHA
69- } . join ( ":" ) ,
69+ } . join ( ":" ) . freeze ,
7070 )
7171 end
72+ DEFAULT_PARAMS . freeze
7273
7374 DEFAULT_CERT_STORE = OpenSSL ::X509 ::Store . new # :nodoc:
7475 DEFAULT_CERT_STORE . set_default_paths
@@ -114,7 +115,14 @@ def set_params(params={})
114115 params . each { |name , value | self . __send__ ( "#{ name } =" , value ) }
115116 if self . verify_mode != OpenSSL ::SSL ::VERIFY_NONE
116117 unless self . ca_file or self . ca_path or self . cert_store
117- self . cert_store = DEFAULT_CERT_STORE
118+ if not defined? ( Ractor ) or Ractor . current == Ractor . main
119+ self . cert_store = DEFAULT_CERT_STORE
120+ else
121+ self . cert_store = Ractor . current [ :__openssl_default_store__ ] ||=
122+ OpenSSL ::X509 ::Store . new . tap { |store |
123+ store . set_default_paths
124+ }
125+ end
118126 end
119127 end
120128 return params
Original file line number Diff line number Diff line change @@ -2317,6 +2317,50 @@ def test_export_keying_material
23172317 end
23182318 end
23192319
2320+ # OpenSSL::Buffering requires $/ accessible from non-main Ractors (Ruby 3.5)
2321+ # https://bugs.ruby-lang.org/issues/21109
2322+ #
2323+ # Hangs on Windows
2324+ # https://bugs.ruby-lang.org/issues/21537
2325+ if respond_to? ( :ractor ) && RUBY_VERSION >= "3.5" && RUBY_PLATFORM !~ /mswin|mingw/
2326+ ractor
2327+ def test_ractor_client
2328+ start_server { |port |
2329+ s = Ractor . new ( port , @ca_cert ) { |port , ca_cert |
2330+ sock = TCPSocket . new ( "127.0.0.1" , port )
2331+ ctx = OpenSSL ::SSL ::SSLContext . new
2332+ ctx . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
2333+ ctx . cert_store = OpenSSL ::X509 ::Store . new . tap { |store |
2334+ store . add_cert ( ca_cert )
2335+ }
2336+ begin
2337+ ssl = OpenSSL ::SSL ::SSLSocket . new ( sock , ctx )
2338+ ssl . connect
2339+ ssl . puts ( "abc" )
2340+ ssl . gets
2341+ ensure
2342+ ssl . close
2343+ sock . close
2344+ end
2345+ } . value
2346+ assert_equal ( "abc\n " , s )
2347+ }
2348+ end
2349+
2350+ ractor
2351+ def test_ractor_set_params
2352+ # We cannot actually test default stores in the test suite as it depends
2353+ # on the environment, but at least check that it does not raise an
2354+ # exception
2355+ ok = Ractor . new {
2356+ ctx = OpenSSL ::SSL ::SSLContext . new
2357+ ctx . set_params
2358+ ctx . cert_store . kind_of? ( OpenSSL ::X509 ::Store )
2359+ } . value
2360+ assert ( ok , "ctx.cert_store is an instance of OpenSSL::X509::Store" )
2361+ end
2362+ end
2363+
23202364 private
23212365
23222366 def server_connect ( port , ctx = nil )
You can’t perform that action at this time.
0 commit comments