aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_pkey_dsa.rb
diff options
context:
space:
mode:
authorrhe <rhe@ruby-lang.org>2016-05-20 15:05:25 +0000
committerKazuki Yamaguchi <k@rhe.jp>2016-05-31 11:31:27 +0900
commitf38501249f33bff7ca9d208670b8cde695ea8b7b (patch)
tree0a8426c286a7b535afc69b5220f6cd9f40de2a30 /test/test_pkey_dsa.rb
parent012635971c01cefbfab15dc51edf1fe29661fc72 (diff)
downloadruby-openssl-f38501249f33bff7ca9d208670b8cde695ea8b7b.tar.gz
openssl: improve handling of password for encrypted PEM
* ext/openssl/ossl.c (ossl_pem_passwd_value): Added. Convert the argument to String with StringValue() and validate the length is in 4..PEM_BUFSIZE. PEM_BUFSIZE is a macro defined in OpenSSL headers. (ossl_pem_passwd_cb): When reading/writing encrypted PEM format, we used to pass the password to PEM_def_callback() directly but it was problematic. It is not NUL character safe. And surprisingly, it silently truncates the password to 1024 bytes. [GH ruby/openssl#51] * ext/openssl/ossl.h: Add function prototype declaration of newly added ossl_pem_passwd_value(). * ext/openssl/ossl_pkey.c (ossl_pkey_new_from_data): Use ossl_pem_passwd_value() to validate the password String. * ext/openssl/ossl_pkey_dsa.c (ossl_dsa_initialize, ossl_dsa_export): ditto. * ext/openssl/ossl_pkey_ec.c (ossl_ec_key_initialize, ossl_ec_key_to_string): ditto. * ext/openssl/ossl_pkey_rsa.c (ossl_rsa_initialize, ossl_rsa_export): ditto. * test/openssl/test_pkey_{dsa,ec,rsa}.rb: test this. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_pkey_dsa.rb')
-rw-r--r--test/test_pkey_dsa.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/test_pkey_dsa.rb b/test/test_pkey_dsa.rb
index 2c0e1fc2..680a1239 100644
--- a/test/test_pkey_dsa.rb
+++ b/test/test_pkey_dsa.rb
@@ -218,6 +218,18 @@ YNMbNw==
assert(pem)
end
+ def test_export_password_funny
+ key = OpenSSL::TestUtils::TEST_KEY_DSA256
+ pem = key.export(OpenSSL::Cipher.new('AES-128-CBC'), "pass\0wd")
+ assert_raise(ArgumentError) do
+ OpenSSL::PKey.read(pem, "pass")
+ end
+ key2 = OpenSSL::PKey.read(pem, "pass\0wd")
+ assert(key2.private?)
+ key3 = OpenSSL::PKey::DSA.new(pem, "pass\0wd")
+ assert(key3.private?)
+ end
+
private
def check_sign_verify(digest)