mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
486e6e02c2
commit
b380c987e1
6 changed files with 77 additions and 89 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
||||||
|
Sun Jul 26 08:33:03 2015 Aaron Patterson <tenderlove@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Sun Jul 26 08:14:59 2015 Aaron Patterson <tenderlove@ruby-lang.org>
|
Sun Jul 26 08:14:59 2015 Aaron Patterson <tenderlove@ruby-lang.org>
|
||||||
|
|
||||||
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): support
|
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): support
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
require 'openssl.so'
|
require 'openssl.so'
|
||||||
|
|
||||||
require 'openssl/bn'
|
require 'openssl/bn'
|
||||||
|
require 'openssl/pkey'
|
||||||
require 'openssl/cipher'
|
require 'openssl/cipher'
|
||||||
require 'openssl/config'
|
require 'openssl/config'
|
||||||
require 'openssl/digest'
|
require 'openssl/digest'
|
||||||
|
|
36
ext/openssl/lib/openssl/pkey.rb
Normal file
36
ext/openssl/lib/openssl/pkey.rb
Normal file
|
@ -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
|
|
@ -74,20 +74,6 @@ module OpenSSL
|
||||||
DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
|
DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
|
||||||
end
|
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",
|
INIT_VARS = ["cert", "key", "client_ca", "ca_file", "ca_path",
|
||||||
"timeout", "verify_mode", "verify_depth", "renegotiation_cb",
|
"timeout", "verify_mode", "verify_depth", "renegotiation_cb",
|
||||||
"verify_callback", "options", "cert_store", "extra_chain_cert",
|
"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
|
# You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS
|
||||||
def initialize(version = nil)
|
def initialize(version = nil)
|
||||||
INIT_VARS.each { |v| instance_variable_set v, 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
|
return unless version
|
||||||
self.ssl_version = version
|
self.ssl_version = version
|
||||||
end
|
end
|
||||||
|
@ -130,7 +116,7 @@ module OpenSSL
|
||||||
end
|
end
|
||||||
|
|
||||||
def tmp_dh_callback=(value)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -523,67 +523,6 @@ OSSL_PKEY_BN(dh, g)
|
||||||
OSSL_PKEY_BN(dh, pub_key)
|
OSSL_PKEY_BN(dh, pub_key)
|
||||||
OSSL_PKEY_BN(dh, priv_key)
|
OSSL_PKEY_BN(dh, priv_key)
|
||||||
|
|
||||||
/*
|
|
||||||
* -----BEGIN DH PARAMETERS-----
|
|
||||||
* MEYCQQD0zXHljRg/mJ9PYLACLv58Cd8VxBxxY7oEuCeURMiTqEhMym16rhhKgZG2
|
|
||||||
* zk2O9uUIBIxSj+NKMURHGaFKyIvLAgEC
|
|
||||||
* -----END DH PARAMETERS-----
|
|
||||||
*/
|
|
||||||
static unsigned char DEFAULT_DH_512_PRIM[] = {
|
|
||||||
0xf4, 0xcd, 0x71, 0xe5, 0x8d, 0x18, 0x3f, 0x98,
|
|
||||||
0x9f, 0x4f, 0x60, 0xb0, 0x02, 0x2e, 0xfe, 0x7c,
|
|
||||||
0x09, 0xdf, 0x15, 0xc4, 0x1c, 0x71, 0x63, 0xba,
|
|
||||||
0x04, 0xb8, 0x27, 0x94, 0x44, 0xc8, 0x93, 0xa8,
|
|
||||||
0x48, 0x4c, 0xca, 0x6d, 0x7a, 0xae, 0x18, 0x4a,
|
|
||||||
0x81, 0x91, 0xb6, 0xce, 0x4d, 0x8e, 0xf6, 0xe5,
|
|
||||||
0x08, 0x04, 0x8c, 0x52, 0x8f, 0xe3, 0x4a, 0x31,
|
|
||||||
0x44, 0x47, 0x19, 0xa1, 0x4a, 0xc8, 0x8b, 0xcb,
|
|
||||||
};
|
|
||||||
static unsigned char DEFAULT_DH_512_GEN[] = { 0x02 };
|
|
||||||
|
|
||||||
/*
|
|
||||||
* -----BEGIN DH PARAMETERS-----
|
|
||||||
* MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ
|
|
||||||
* AV/ZD2AWPbrTqV76mGRgJg4EddgT1zG0jq3rnFdMj2XzkBYx3BVvfR0Arnby0RHR
|
|
||||||
* T4h7KZ/2zmjvV+eF8kBUHBJAojUlzxKj4QeO2x20FP9X5xmNUXeDAgEC
|
|
||||||
* -----END DH PARAMETERS-----
|
|
||||||
*/
|
|
||||||
static unsigned char DEFAULT_DH_1024_PRIM[] = {
|
|
||||||
0x9d, 0x25, 0x39, 0x5c, 0xb4, 0x54, 0x8a, 0xff,
|
|
||||||
0x25, 0xe6, 0xd6, 0x9f, 0x4c, 0xc3, 0xc1, 0x8d,
|
|
||||||
0xa1, 0xfa, 0xba, 0x88, 0x4c, 0x53, 0xa9, 0x74,
|
|
||||||
0xda, 0xfa, 0xba, 0x0b, 0x20, 0xbe, 0x40, 0xd7,
|
|
||||||
0xba, 0xe7, 0x1d, 0x70, 0x28, 0x61, 0x60, 0x4c,
|
|
||||||
0x49, 0x01, 0x5f, 0xd9, 0x0f, 0x60, 0x16, 0x3d,
|
|
||||||
0xba, 0xd3, 0xa9, 0x5e, 0xfa, 0x98, 0x64, 0x60,
|
|
||||||
0x26, 0x0e, 0x04, 0x75, 0xd8, 0x13, 0xd7, 0x31,
|
|
||||||
0xb4, 0x8e, 0xad, 0xeb, 0x9c, 0x57, 0x4c, 0x8f,
|
|
||||||
0x65, 0xf3, 0x90, 0x16, 0x31, 0xdc, 0x15, 0x6f,
|
|
||||||
0x7d, 0x1d, 0x00, 0xae, 0x76, 0xf2, 0xd1, 0x11,
|
|
||||||
0xd1, 0x4f, 0x88, 0x7b, 0x29, 0x9f, 0xf6, 0xce,
|
|
||||||
0x68, 0xef, 0x57, 0xe7, 0x85, 0xf2, 0x40, 0x54,
|
|
||||||
0x1c, 0x12, 0x40, 0xa2, 0x35, 0x25, 0xcf, 0x12,
|
|
||||||
0xa3, 0xe1, 0x07, 0x8e, 0xdb, 0x1d, 0xb4, 0x14,
|
|
||||||
0xff, 0x57, 0xe7, 0x19, 0x8d, 0x51, 0x77, 0x83
|
|
||||||
};
|
|
||||||
static unsigned char DEFAULT_DH_1024_GEN[] = { 0x02 };
|
|
||||||
|
|
||||||
static DH*
|
|
||||||
ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
|
|
||||||
{
|
|
||||||
DH *dh;
|
|
||||||
|
|
||||||
if ((dh = DH_new()) == NULL) ossl_raise(eDHError, NULL);
|
|
||||||
dh->p = BN_bin2bn(p, rb_long2int(plen), NULL);
|
|
||||||
dh->g = BN_bin2bn(g, rb_long2int(glen), NULL);
|
|
||||||
if (dh->p == NULL || dh->g == NULL){
|
|
||||||
DH_free(dh);
|
|
||||||
ossl_raise(eDHError, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dh;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* INIT
|
* INIT
|
||||||
*/
|
*/
|
||||||
|
@ -594,8 +533,6 @@ Init_ossl_dh(void)
|
||||||
mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL and mPKey */
|
mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL and mPKey */
|
||||||
mPKey = rb_define_module_under(mOSSL, "PKey");
|
mPKey = rb_define_module_under(mOSSL, "PKey");
|
||||||
#endif
|
#endif
|
||||||
DH *OSSL_DEFAULT_DH_512;
|
|
||||||
DH *OSSL_DEFAULT_DH_1024;
|
|
||||||
|
|
||||||
/* Document-class: OpenSSL::PKey::DHError
|
/* Document-class: OpenSSL::PKey::DHError
|
||||||
*
|
*
|
||||||
|
@ -651,16 +588,6 @@ Init_ossl_dh(void)
|
||||||
DEF_OSSL_PKEY_BN(cDH, dh, pub_key);
|
DEF_OSSL_PKEY_BN(cDH, dh, pub_key);
|
||||||
DEF_OSSL_PKEY_BN(cDH, dh, priv_key);
|
DEF_OSSL_PKEY_BN(cDH, dh, priv_key);
|
||||||
rb_define_method(cDH, "params", ossl_dh_get_params, 0);
|
rb_define_method(cDH, "params", ossl_dh_get_params, 0);
|
||||||
|
|
||||||
OSSL_DEFAULT_DH_512 = ossl_create_dh(
|
|
||||||
DEFAULT_DH_512_PRIM, sizeof(DEFAULT_DH_512_PRIM),
|
|
||||||
DEFAULT_DH_512_GEN, sizeof(DEFAULT_DH_512_GEN));
|
|
||||||
OSSL_DEFAULT_DH_1024 = ossl_create_dh(
|
|
||||||
DEFAULT_DH_1024_PRIM, sizeof(DEFAULT_DH_1024_PRIM),
|
|
||||||
DEFAULT_DH_1024_GEN, sizeof(DEFAULT_DH_1024_GEN));
|
|
||||||
|
|
||||||
rb_define_const(cDH, "DEFAULT_512", dh_instance(cDH, OSSL_DEFAULT_DH_512));
|
|
||||||
rb_define_const(cDH, "DEFAULT_1024", dh_instance(cDH, OSSL_DEFAULT_DH_1024));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* defined NO_DH */
|
#else /* defined NO_DH */
|
||||||
|
|
|
@ -6,6 +6,27 @@ class OpenSSL::TestPKeyDH < Test::Unit::TestCase
|
||||||
|
|
||||||
NEW_KEYLEN = 256
|
NEW_KEYLEN = 256
|
||||||
|
|
||||||
|
def test_DEFAULT_512
|
||||||
|
params = <<-eop
|
||||||
|
-----BEGIN DH PARAMETERS-----
|
||||||
|
MEYCQQD0zXHljRg/mJ9PYLACLv58Cd8VxBxxY7oEuCeURMiTqEhMym16rhhKgZG2
|
||||||
|
zk2O9uUIBIxSj+NKMURHGaFKyIvLAgEC
|
||||||
|
-----END DH PARAMETERS-----
|
||||||
|
eop
|
||||||
|
assert_equal params, OpenSSL::PKey::DH::DEFAULT_512.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_DEFAULT_1024
|
||||||
|
params = <<-eop
|
||||||
|
-----BEGIN DH PARAMETERS-----
|
||||||
|
MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ
|
||||||
|
AV/ZD2AWPbrTqV76mGRgJg4EddgT1zG0jq3rnFdMj2XzkBYx3BVvfR0Arnby0RHR
|
||||||
|
T4h7KZ/2zmjvV+eF8kBUHBJAojUlzxKj4QeO2x20FP9X5xmNUXeDAgEC
|
||||||
|
-----END DH PARAMETERS-----
|
||||||
|
eop
|
||||||
|
assert_equal params, OpenSSL::PKey::DH::DEFAULT_1024.to_s
|
||||||
|
end
|
||||||
|
|
||||||
def test_new
|
def test_new
|
||||||
dh = OpenSSL::PKey::DH.new(NEW_KEYLEN)
|
dh = OpenSSL::PKey::DH.new(NEW_KEYLEN)
|
||||||
assert_key(dh)
|
assert_key(dh)
|
||||||
|
|
Loading…
Reference in a new issue