mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
e29819df6e
ext/openssl/ossl.c: Expose OpenSSL::OPENSSL_FIPS constant to indicate whether OpenSSL runs in FIPS mode. test/openssl/test_pkey_dh.rb: Generate 256 bit keys for non-FIPS installations to improve test performance (e.g. for rubyci). test/openssl/utils.rb: Replace DSS1 as certificate signature digest with SHA1 for FIPS installations when using DSA by introducing TestUtils::DSA_SIGNATURE_DIGEST. test/openssl/test_x509cert.rb: test/openssl/test_x509crl.rb: test/openssl/test_x509req.rb: Use DSA_SIGNATURE_DIGEST NEWS: Introduce OpenSSL::OPENSSL_FIPS These changes allow running the OpenSSL tests in FIPS mode while keeping a high performance for non-FIPS installations. Introduction of OpenSSL::OPENSSL_FIPS allows for applications to react to special requirements when using OpenSSL in FIPS mode. [Feature #6946] [ruby-core:47345] - Diese und die folgenden Zeilen werden ignoriert -- M ext/openssl/extconf.rb M ext/openssl/ossl.c M NEWS M ChangeLog M test/openssl/utils.rb M test/openssl/test_x509crl.rb M test/openssl/test_x509req.rb M test/openssl/test_x509cert.rb M test/openssl/test_pkey_dh.rb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
83 lines
1.9 KiB
Ruby
83 lines
1.9 KiB
Ruby
require_relative 'utils'
|
|
|
|
if defined?(OpenSSL)
|
|
|
|
class OpenSSL::TestPKeyDH < Test::Unit::TestCase
|
|
|
|
# improve test performance for non-FIPS installations
|
|
NEW_KEYLEN = OpenSSL::OPENSSL_FIPS ? 1024 : 256
|
|
|
|
def test_new
|
|
dh = OpenSSL::PKey::DH.new(NEW_KEYLEN)
|
|
assert_key(dh)
|
|
end
|
|
|
|
def test_new_break
|
|
assert_nil(OpenSSL::PKey::DH.new(NEW_KEYLEN) { break })
|
|
assert_raises(RuntimeError) do
|
|
OpenSSL::PKey::DH.new(NEW_KEYLEN) { raise }
|
|
end
|
|
end
|
|
|
|
def test_to_der
|
|
dh = OpenSSL::TestUtils::TEST_KEY_DH1024
|
|
der = dh.to_der
|
|
dh2 = OpenSSL::PKey::DH.new(der)
|
|
assert_equal_params(dh, dh2)
|
|
assert_no_key(dh2)
|
|
end
|
|
|
|
def test_to_pem
|
|
dh = OpenSSL::TestUtils::TEST_KEY_DH1024
|
|
pem = dh.to_pem
|
|
dh2 = OpenSSL::PKey::DH.new(pem)
|
|
assert_equal_params(dh, dh2)
|
|
assert_no_key(dh2)
|
|
end
|
|
|
|
def test_public_key
|
|
dh = OpenSSL::TestUtils::TEST_KEY_DH1024
|
|
public_key = dh.public_key
|
|
assert_no_key(public_key) #implies public_key.public? is false!
|
|
assert_equal(dh.to_der, public_key.to_der)
|
|
assert_equal(dh.to_pem, public_key.to_pem)
|
|
end
|
|
|
|
def test_generate_key
|
|
dh = OpenSSL::TestUtils::TEST_KEY_DH512_PUB.public_key # creates a copy
|
|
assert_no_key(dh)
|
|
dh.generate_key!
|
|
assert_key(dh)
|
|
end
|
|
|
|
def test_key_exchange
|
|
dh = OpenSSL::TestUtils::TEST_KEY_DH512_PUB
|
|
dh2 = dh.public_key
|
|
dh.generate_key!
|
|
dh2.generate_key!
|
|
assert_equal(dh.compute_key(dh2.pub_key), dh2.compute_key(dh.pub_key))
|
|
end
|
|
|
|
private
|
|
|
|
def assert_equal_params(dh1, dh2)
|
|
assert_equal(dh1.g, dh2.g)
|
|
assert_equal(dh1.p, dh2.p)
|
|
end
|
|
|
|
def assert_no_key(dh)
|
|
assert_equal(false, dh.public?)
|
|
assert_equal(false, dh.private?)
|
|
assert_equal(nil, dh.pub_key)
|
|
assert_equal(nil, dh.priv_key)
|
|
end
|
|
|
|
def assert_key(dh)
|
|
assert(dh.public?)
|
|
assert(dh.private?)
|
|
assert(dh.pub_key)
|
|
assert(dh.priv_key)
|
|
end
|
|
end
|
|
|
|
end
|