mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/openssl/ossl_pkey.c (ossl_pkey_to_der): removed; it returns
public key only. * ext/openssl/ossl_pkey_dh.c (ossl_dh_to_der): new function for OpenSSL::PKey::DH#to_der. * ext/openssl/ossl_pkey_dsa.c (ossl_dsa_to_der): new function for OpenSSL::PKey::DSA#to_der. * ext/openssl/ossl_pkey_rsa.c (ossl_rsa_to_der): new function for OpenSSL::PKey::RSA#to_der. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0f3e58e707
commit
54d29aaba9
5 changed files with 89 additions and 22 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Thu Jan 8 21:17:43 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||
|
||||
* ext/openssl/ossl_pkey.c (ossl_pkey_to_der): removed; it returns
|
||||
public key only.
|
||||
|
||||
* ext/openssl/ossl_pkey_dh.c (ossl_dh_to_der): new function for
|
||||
OpenSSL::PKey::DH#to_der.
|
||||
|
||||
* ext/openssl/ossl_pkey_dsa.c (ossl_dsa_to_der): new function for
|
||||
OpenSSL::PKey::DSA#to_der.
|
||||
|
||||
* ext/openssl/ossl_pkey_rsa.c (ossl_rsa_to_der): new function for
|
||||
OpenSSL::PKey::RSA#to_der.
|
||||
|
||||
Thu Jan 8 18:25:29 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* dir.c (glob_helper): should not recurse in exceptional status.
|
||||
|
|
|
@ -144,26 +144,6 @@ ossl_pkey_initialize(VALUE self)
|
|||
return self;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_pkey_to_der(VALUE self)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
VALUE str;
|
||||
long len;
|
||||
unsigned char *p;
|
||||
|
||||
GetPKey(self, pkey);
|
||||
if((len = i2d_PUBKEY(pkey, NULL)) <= 0)
|
||||
ossl_raise(ePKeyError, NULL);
|
||||
str = rb_str_new(0, len);
|
||||
p = RSTRING(str)->ptr;
|
||||
if(len = i2d_PUBKEY(pkey, &p) <= 0)
|
||||
ossl_raise(ePKeyError, NULL);
|
||||
ossl_str_adjust(str, p);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
|
||||
{
|
||||
|
@ -226,7 +206,6 @@ Init_ossl_pkey()
|
|||
rb_define_alloc_func(cPKey, ossl_pkey_alloc);
|
||||
rb_define_method(cPKey, "initialize", ossl_pkey_initialize, 0);
|
||||
|
||||
rb_define_method(cPKey, "to_der", ossl_pkey_to_der, 0);
|
||||
rb_define_method(cPKey, "sign", ossl_pkey_sign, 2);
|
||||
rb_define_method(cPKey, "verify", ossl_pkey_verify, 3);
|
||||
|
||||
|
|
|
@ -199,6 +199,26 @@ ossl_dh_export(VALUE self)
|
|||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_dh_to_der(VALUE self)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
unsigned char *p;
|
||||
long len;
|
||||
VALUE str;
|
||||
|
||||
GetPKeyDH(self, pkey);
|
||||
if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
|
||||
ossl_raise(eDHError, NULL);
|
||||
str = rb_str_new(0, len);
|
||||
p = RSTRING(str)->ptr;
|
||||
if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
|
||||
ossl_raise(eDHError, NULL);
|
||||
ossl_str_adjust(str, p);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stores all parameters of key to the hash
|
||||
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
|
||||
|
@ -341,6 +361,7 @@ Init_ossl_dh()
|
|||
rb_define_method(cDH, "export", ossl_dh_export, 0);
|
||||
rb_define_alias(cDH, "to_pem", "export");
|
||||
rb_define_alias(cDH, "to_s", "export");
|
||||
rb_define_method(cDH, "to_der", ossl_dh_to_der, 0);
|
||||
rb_define_method(cDH, "public_key", ossl_dh_to_public_key, 0);
|
||||
|
||||
rb_define_method(cDH, "params_ok?", ossl_dh_check_params, 0);
|
||||
|
|
|
@ -140,7 +140,8 @@ ossl_dsa_initialize(int argc, VALUE *argv, VALUE self)
|
|||
arg = ossl_to_der_if_possible(arg);
|
||||
in = ossl_obj2bio(arg);
|
||||
dsa = PEM_read_bio_DSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
|
||||
if (!dsa) { BIO_reset(in);
|
||||
if (!dsa) {
|
||||
BIO_reset(in);
|
||||
dsa = PEM_read_bio_DSAPublicKey(in, NULL, NULL, NULL);
|
||||
}
|
||||
if (!dsa) {
|
||||
|
@ -227,6 +228,31 @@ ossl_dsa_export(int argc, VALUE *argv, VALUE self)
|
|||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_dsa_to_der(VALUE self)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
int (*i2d_func)_((DSA*, unsigned char**));
|
||||
unsigned char *p;
|
||||
long len;
|
||||
VALUE str;
|
||||
|
||||
GetPKeyDSA(self, pkey);
|
||||
if(DSA_HAS_PRIVATE(pkey->pkey.dsa))
|
||||
i2d_func = (int(*)_((DSA*,unsigned char**)))i2d_DSAPrivateKey;
|
||||
else
|
||||
i2d_func = i2d_DSA_PUBKEY;
|
||||
if((len = i2d_func(pkey->pkey.dsa, NULL)) <= 0)
|
||||
ossl_raise(eDSAError, NULL);
|
||||
str = rb_str_new(0, len);
|
||||
p = RSTRING(str)->ptr;
|
||||
if(i2d_func(pkey->pkey.dsa, &p) < 0)
|
||||
ossl_raise(eDSAError, NULL);
|
||||
ossl_str_adjust(str, p);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stores all parameters of key to the hash
|
||||
* INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
|
||||
|
@ -363,6 +389,7 @@ Init_ossl_dsa()
|
|||
rb_define_method(cDSA, "export", ossl_dsa_export, -1);
|
||||
rb_define_alias(cDSA, "to_pem", "export");
|
||||
rb_define_alias(cDSA, "to_s", "export");
|
||||
rb_define_method(cDSA, "to_der", ossl_dsa_to_der, 0);
|
||||
rb_define_method(cDSA, "public_key", ossl_dsa_to_public_key, 0);
|
||||
rb_define_method(cDSA, "syssign", ossl_dsa_sign, 1);
|
||||
rb_define_method(cDSA, "sysverify", ossl_dsa_verify, 2);
|
||||
|
|
|
@ -222,6 +222,31 @@ ossl_rsa_export(int argc, VALUE *argv, VALUE self)
|
|||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ossl_rsa_to_der(VALUE self)
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
int (*i2d_func)_((const RSA*, unsigned char**));
|
||||
unsigned char *p;
|
||||
long len;
|
||||
VALUE str;
|
||||
|
||||
GetPKeyRSA(self, pkey);
|
||||
if(RSA_HAS_PRIVATE(pkey->pkey.rsa))
|
||||
i2d_func = i2d_RSAPrivateKey;
|
||||
else
|
||||
i2d_func = i2d_RSAPublicKey;
|
||||
if((len = i2d_func(pkey->pkey.rsa, NULL)) <= 0)
|
||||
ossl_raise(eRSAError, NULL);
|
||||
str = rb_str_new(0, len);
|
||||
p = RSTRING(str)->ptr;
|
||||
if(i2d_func(pkey->pkey.rsa, &p) < 0)
|
||||
ossl_raise(eRSAError, NULL);
|
||||
ossl_str_adjust(str, p);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
#define ossl_rsa_buf_size(pkey) (RSA_size((pkey)->pkey.rsa)+16)
|
||||
|
||||
static VALUE
|
||||
|
@ -440,6 +465,7 @@ Init_ossl_rsa()
|
|||
rb_define_method(cRSA, "export", ossl_rsa_export, -1);
|
||||
rb_define_alias(cRSA, "to_pem", "export");
|
||||
rb_define_alias(cRSA, "to_s", "export");
|
||||
rb_define_method(cRSA, "to_der", ossl_rsa_to_der, 0);
|
||||
rb_define_method(cRSA, "public_key", ossl_rsa_to_public_key, 0);
|
||||
rb_define_method(cRSA, "public_encrypt", ossl_rsa_public_encrypt, 1);
|
||||
rb_define_method(cRSA, "public_decrypt", ossl_rsa_public_decrypt, 1);
|
||||
|
|
Loading…
Reference in a new issue