diff options
author | tenderlove <tenderlove@ruby-lang.org> | 2015-07-25 23:35:49 +0000 |
---|---|---|
committer | tenderlove <tenderlove@ruby-lang.org> | 2015-07-25 23:35:49 +0000 |
commit | 954789b1174616ea46700e32c4ce662b29977d1a (patch) | |
tree | 8e93ce73454157440486e4d3d3d761da33068638 /lib/openssl | |
parent | 8c55d4c39a5e654a1082282ccce888a35522cb18 (diff) | |
download | ruby-openssl-history-954789b1174616ea46700e32c4ce662b29977d1a.tar.gz |
* ext/openssl/lib/openssl/pkey.rb: implement DEFAULT_512 and
DEFAULT_1024 constants in Ruby.
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): Ask PKey for the
default DH callback since it aleady must check whether openssl has
been compiled with DH support.
* ext/openssl/ossl_pkey_dh.c (OSSL_PKEY_BN): Remove C definitions of
DEFAULT_512 and DEFAULT_1024
* ext/openssl/ossl_pkey_dh.c (Init_ossl_dh): ditto
* test/openssl/test_pkey_dh.rb (class OpenSSL): add test to ensure the
Ruby definitions are the same as the C definitions were.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51382 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/openssl')
-rw-r--r-- | lib/openssl/pkey.rb | 36 | ||||
-rw-r--r-- | lib/openssl/ssl.rb | 18 |
2 files changed, 38 insertions, 16 deletions
diff --git a/lib/openssl/pkey.rb b/lib/openssl/pkey.rb new file mode 100644 index 0000000..007934f --- /dev/null +++ b/lib/openssl/pkey.rb @@ -0,0 +1,36 @@ +module OpenSSL + module PKey + if defined?(OpenSSL::PKey::DH) + + class DH + DEFAULT_512 = new <<-_end_of_pem_ +-----BEGIN DH PARAMETERS----- +MEYCQQD0zXHljRg/mJ9PYLACLv58Cd8VxBxxY7oEuCeURMiTqEhMym16rhhKgZG2 +zk2O9uUIBIxSj+NKMURHGaFKyIvLAgEC +-----END DH PARAMETERS----- + _end_of_pem_ + + DEFAULT_1024 = new <<-_end_of_pem_ +-----BEGIN DH PARAMETERS----- +MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ +AV/ZD2AWPbrTqV76mGRgJg4EddgT1zG0jq3rnFdMj2XzkBYx3BVvfR0Arnby0RHR +T4h7KZ/2zmjvV+eF8kBUHBJAojUlzxKj4QeO2x20FP9X5xmNUXeDAgEC +-----END DH PARAMETERS----- + _end_of_pem_ + end + + DEFAULT_TMP_DH_CALLBACK = lambda { |ctx, is_export, keylen| + warn "using default DH parameters." if $VERBOSE + case keylen + when 512 then OpenSSL::PKey::DH::DEFAULT_512 + when 1024 then OpenSSL::PKey::DH::DEFAULT_1024 + else + nil + end + } + + else + DEFAULT_TMP_DH_CALLBACK = nil + end + end +end diff --git a/lib/openssl/ssl.rb b/lib/openssl/ssl.rb index 1c0cc2f..e1b557c 100644 --- a/lib/openssl/ssl.rb +++ b/lib/openssl/ssl.rb @@ -74,20 +74,6 @@ module OpenSSL DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL end - if defined?(OpenSSL::PKey::DH) - DEFAULT_TMP_DH_CALLBACK = lambda { |ctx, is_export, keylen| - warn "using default DH parameters." if $VERBOSE - case keylen - when 512 then OpenSSL::PKey::DH::DEFAULT_512 - when 1024 then OpenSSL::PKey::DH::DEFAULT_1024 - else - nil - end - } - else - DEFAULT_TMP_DH_CALLBACK = nil - end - INIT_VARS = ["cert", "key", "client_ca", "ca_file", "ca_path", "timeout", "verify_mode", "verify_depth", "renegotiation_cb", "verify_callback", "options", "cert_store", "extra_chain_cert", @@ -105,7 +91,7 @@ module OpenSSL # You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS def initialize(version = nil) INIT_VARS.each { |v| instance_variable_set v, nil } - @tmp_dh_callback = DEFAULT_TMP_DH_CALLBACK + @tmp_dh_callback = OpenSSL::PKey::DEFAULT_TMP_DH_CALLBACK return unless version self.ssl_version = version end @@ -130,7 +116,7 @@ module OpenSSL end def tmp_dh_callback=(value) - @tmp_dh_callback = value || DEFAULT_TMP_DH_CALLBACK + @tmp_dh_callback = value || OpenSSL::PKey::DEFAULT_TMP_DH_CALLBACK end end |