summaryrefslogtreecommitdiff
path: root/test/openssl/test_pair.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-22 18:34:45 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-22 18:34:45 +0000
commit5326593a8b185c41b7947548bdc62abe08f0eb68 (patch)
tree11fc559c2a375a029865ead67e03db71cba2d159 /test/openssl/test_pair.rb
parentbc6e55c0846ba668534ad224f516d3fdda16993c (diff)
* ext/openssl/ossl_ssl.c: add ECDH callback support. [Feature #11356]
* test/openssl/test_pair.rb: test for ECDH callback support git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/openssl/test_pair.rb')
-rw-r--r--test/openssl/test_pair.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/openssl/test_pair.rb b/test/openssl/test_pair.rb
index cfcfa7a74d..6357cdc818 100644
--- a/test/openssl/test_pair.rb
+++ b/test/openssl/test_pair.rb
@@ -283,6 +283,45 @@ module OpenSSL::TestPairM
serv.close if serv && !serv.closed?
end
+ def test_ecdh_callback
+ called = false
+ ctx2 = OpenSSL::SSL::SSLContext.new
+ ctx2.ciphers = "ECDH"
+ ctx2.tmp_ecdh_callback = ->(*args) {
+ called = true
+ OpenSSL::PKey::EC.new "prime256v1"
+ }
+
+ sock1, sock2 = tcp_pair
+
+ s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2)
+ ctx1 = OpenSSL::SSL::SSLContext.new
+ ctx1.ciphers = "ECDH"
+
+ s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1)
+ th = Thread.new do
+ begin
+ rv = s1.connect_nonblock(exception: false)
+ case rv
+ when :wait_writable
+ IO.select(nil, [s1], nil, 5)
+ when :wait_readable
+ IO.select([s1], nil, nil, 5)
+ end
+ end until rv == s1
+ end
+
+ accepted = s2.accept
+
+ assert called, 'ecdh callback should be called'
+ ensure
+ s1.close if s1
+ s2.close if s2
+ sock1.close if sock1
+ sock2.close if sock2
+ accepted.close if accepted.respond_to?(:close)
+ end
+
def test_connect_accept_nonblock_no_exception
ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.ciphers = "ADH"