aboutsummaryrefslogtreecommitdiffstats
path: root/test/openssl
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-19 09:29:59 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-19 09:29:59 +0000
commit42f437b1e8f42b602cc2fcda5296e2f0169f9e28 (patch)
tree8d216d4f7bcfcbe7b29871745c642914c65ae124 /test/openssl
parentc9ebf6bb217ecc50f2f6061f460ca28aeaef5e52 (diff)
downloadruby-42f437b1e8f42b602cc2fcda5296e2f0169f9e28.tar.gz
openssl: implement initialize_copy method for PKey classes
* ext/openssl/ossl_pkey_dh.c, ext/openssl/ossl_pkey_dsa.c, ext/openssl/ossl_pkey_ec.c, ext/openssl/ossl_pkey_rsa.c: Implement initialize_copy method for OpenSSL::PKey::*. [ruby-core:75504] [Bug #12381] * test/openssl/test_pkey_dh.rb, test/openssl/test_pkey_dsa.rb, test/openssl/test_pkey_ec.rb, test/openssl/test_pkey_rsa.rb: Test they actually copy the OpenSSL objects, and modifications to cloned object don't affect the original object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/openssl')
-rw-r--r--test/openssl/test_pkey_dh.rb10
-rw-r--r--test/openssl/test_pkey_dsa.rb8
-rw-r--r--test/openssl/test_pkey_ec.rb23
-rw-r--r--test/openssl/test_pkey_rsa.rb8
4 files changed, 49 insertions, 0 deletions
diff --git a/test/openssl/test_pkey_dh.rb b/test/openssl/test_pkey_dh.rb
index afd7a3187c..4d84f7ad49 100644
--- a/test/openssl/test_pkey_dh.rb
+++ b/test/openssl/test_pkey_dh.rb
@@ -83,6 +83,16 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3
assert_equal(dh.compute_key(dh2.pub_key), dh2.compute_key(dh.pub_key))
end
+ def test_dup
+ dh = OpenSSL::PKey::DH.new(NEW_KEYLEN)
+ dh2 = dh.dup
+ assert_equal dh.to_der, dh2.to_der # params
+ assert_equal_params dh, dh2 # keys
+ dh2.set_pqg(dh2.p + 1, nil, dh2.g)
+ assert_not_equal dh2.p, dh.p
+ assert_equal dh2.g, dh.g
+ end
+
private
def assert_equal_params(dh1, dh2)
diff --git a/test/openssl/test_pkey_dsa.rb b/test/openssl/test_pkey_dsa.rb
index 211c034236..9c29c034d0 100644
--- a/test/openssl/test_pkey_dsa.rb
+++ b/test/openssl/test_pkey_dsa.rb
@@ -230,6 +230,14 @@ YNMbNw==
assert(key3.private?)
end
+ def test_dup
+ key = OpenSSL::PKey::DSA.new(256)
+ key2 = key.dup
+ assert_equal key.params, key2.params
+ key2.set_pqg(key2.p + 1, key2.q, key2.g)
+ assert_not_equal key.params, key2.params
+ end
+
private
def check_sign_verify(digest)
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
index e15d875295..4498b2b8b3 100644
--- a/test/openssl/test_pkey_ec.rb
+++ b/test/openssl/test_pkey_ec.rb
@@ -25,6 +25,29 @@ class OpenSSL::TestEC < OpenSSL::TestCase
end
end
+ def test_dup
+ key = OpenSSL::PKey::EC.new("prime256v1")
+ key.generate_key!
+ key2 = key.dup
+ assert_equal key.to_der, key2.to_der
+ key_tmp = OpenSSL::PKey::EC.new("prime256v1").generate_key!
+ key2.private_key = key_tmp.private_key
+ key2.public_key = key_tmp.public_key
+ assert_not_equal key.to_der, key2.to_der
+
+ group = key.group
+ group2 = group.dup
+ assert_equal group.to_der, group2.to_der
+ group2.asn1_flag ^= OpenSSL::PKey::EC::NAMED_CURVE
+ assert_not_equal group.to_der, group2.to_der
+
+ point = key.public_key
+ point2 = point.dup
+ assert_equal point.to_bn, point2.to_bn
+ point2.invert!
+ assert_not_equal point.to_bn, point2.to_bn
+ end
+
def compare_keys(k1, k2)
assert_equal(k1.to_pem, k2.to_pem)
end
diff --git a/test/openssl/test_pkey_rsa.rb b/test/openssl/test_pkey_rsa.rb
index c3532f637f..49e8ceacd9 100644
--- a/test/openssl/test_pkey_rsa.rb
+++ b/test/openssl/test_pkey_rsa.rb
@@ -294,6 +294,14 @@ AwEAAQ==
assert(key3.private?)
end
+ def test_dup
+ key = OpenSSL::PKey::RSA.generate(256, 17)
+ key2 = key.dup
+ assert_equal key.params, key2.params
+ key2.set_key(key2.n, 3, key2.d)
+ assert_not_equal key.params, key2.params
+ end
+
private
def check_PUBKEY(asn1, key)