mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/openssl/ossl_pkey_dh.c (ossl_dh_initialize):
pop pushed error after each try of reading. fixes #4550 * ext/openssl/ossl_pkey_dsa.c (ossl_dsa_initialize): ditto. * ext/openssl/ossl_pkey_ec.c (ossl_ec_initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6fc7c377bc
commit
d5b1fde5c7
5 changed files with 33 additions and 2 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Wed Apr 6 15:12:40 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/openssl/ossl_pkey_dh.c (ossl_dh_initialize):
|
||||||
|
pop pushed error after each try of reading. fixes #4550
|
||||||
|
|
||||||
|
* ext/openssl/ossl_pkey_dsa.c (ossl_dsa_initialize): ditto.
|
||||||
|
|
||||||
|
* ext/openssl/ossl_pkey_ec.c (ossl_ec_initialize): ditto.
|
||||||
|
|
||||||
Wed Apr 6 11:36:44 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
Wed Apr 6 11:36:44 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ext/openssl/ossl_pkey_rsa.c (ossl_rsa_initialize):
|
* ext/openssl/ossl_pkey_rsa.c (ossl_rsa_initialize):
|
||||||
|
|
|
@ -170,10 +170,14 @@ ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
|
dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
|
||||||
if (!dh){
|
if (!dh){
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
dh = d2i_DHparams_bio(in, NULL);
|
dh = d2i_DHparams_bio(in, NULL);
|
||||||
}
|
}
|
||||||
BIO_free(in);
|
BIO_free(in);
|
||||||
if (!dh) ossl_raise(eDHError, NULL);
|
if (!dh) {
|
||||||
|
(void)ERR_get_error();
|
||||||
|
ossl_raise(eDHError, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!EVP_PKEY_assign_DH(pkey, dh)) {
|
if (!EVP_PKEY_assign_DH(pkey, dh)) {
|
||||||
DH_free(dh);
|
DH_free(dh);
|
||||||
|
|
|
@ -162,22 +162,29 @@ ossl_dsa_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
dsa = PEM_read_bio_DSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
|
dsa = PEM_read_bio_DSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
|
||||||
if (!dsa) {
|
if (!dsa) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
dsa = PEM_read_bio_DSAPublicKey(in, NULL, NULL, NULL);
|
dsa = PEM_read_bio_DSAPublicKey(in, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
if (!dsa) {
|
if (!dsa) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
dsa = PEM_read_bio_DSA_PUBKEY(in, NULL, NULL, NULL);
|
dsa = PEM_read_bio_DSA_PUBKEY(in, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
if (!dsa) {
|
if (!dsa) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
dsa = d2i_DSAPrivateKey_bio(in, NULL);
|
dsa = d2i_DSAPrivateKey_bio(in, NULL);
|
||||||
}
|
}
|
||||||
if (!dsa) {
|
if (!dsa) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
dsa = d2i_DSA_PUBKEY_bio(in, NULL);
|
dsa = d2i_DSA_PUBKEY_bio(in, NULL);
|
||||||
}
|
}
|
||||||
BIO_free(in);
|
BIO_free(in);
|
||||||
if (!dsa) ossl_raise(eDSAError, "Neither PUB key nor PRIV key:");
|
if (!dsa) {
|
||||||
|
(void)ERR_get_error();
|
||||||
|
ossl_raise(eDSAError, "Neither PUB key nor PRIV key:");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!EVP_PKEY_assign_DSA(pkey, dsa)) {
|
if (!EVP_PKEY_assign_DSA(pkey, dsa)) {
|
||||||
DSA_free(dsa);
|
DSA_free(dsa);
|
||||||
|
|
|
@ -187,14 +187,17 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
ec = PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL);
|
ec = PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL);
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
ec = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, NULL);
|
ec = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
ec = d2i_ECPrivateKey_bio(in, NULL);
|
ec = d2i_ECPrivateKey_bio(in, NULL);
|
||||||
}
|
}
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
(void)BIO_reset(in);
|
(void)BIO_reset(in);
|
||||||
|
(void)ERR_get_error();
|
||||||
ec = d2i_EC_PUBKEY_bio(in, NULL);
|
ec = d2i_EC_PUBKEY_bio(in, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +207,7 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
|
||||||
const char *name = StringValueCStr(arg);
|
const char *name = StringValueCStr(arg);
|
||||||
int nid = OBJ_sn2nid(name);
|
int nid = OBJ_sn2nid(name);
|
||||||
|
|
||||||
|
(void)ERR_get_error();
|
||||||
if (nid == NID_undef)
|
if (nid == NID_undef)
|
||||||
ossl_raise(eECError, "unknown curve name (%s)\n", name);
|
ossl_raise(eECError, "unknown curve name (%s)\n", name);
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,13 @@ class OpenSSL::TestPKeyRSA < Test::Unit::TestCase
|
||||||
key4 = OpenSSL::PKey::RSA.new(key3.to_der)
|
key4 = OpenSSL::PKey::RSA.new(key3.to_der)
|
||||||
assert(!key4.private?)
|
assert(!key4.private?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_new
|
||||||
|
key = OpenSSL::PKey::RSA.new 512
|
||||||
|
pem = key.public_key.to_pem
|
||||||
|
OpenSSL::PKey::RSA.new pem
|
||||||
|
assert_equal([], OpenSSL.errors)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue