2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
2015-04-19 23:55:09 -04:00
|
|
|
* This program is licensed under the same licence as Ruby.
|
2003-07-23 12:12:24 -04:00
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#include "ossl.h"
|
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
#if !defined(OPENSSL_NO_RSA)
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
#define GetPKeyRSA(obj, pkey) do { \
|
2011-03-07 10:03:18 -05:00
|
|
|
GetPKey((obj), (pkey)); \
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_RSA) { /* PARANOIA? */ \
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eRuntimeError, "THIS IS NOT A RSA!") ; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
#define GetRSA(obj, rsa) do { \
|
|
|
|
EVP_PKEY *_pkey; \
|
|
|
|
GetPKeyRSA((obj), _pkey); \
|
|
|
|
(rsa) = EVP_PKEY_get0_RSA(_pkey); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
RSA_HAS_PRIVATE(RSA *rsa)
|
|
|
|
{
|
2016-06-19 01:31:28 -04:00
|
|
|
const BIGNUM *p, *q;
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
|
|
|
|
RSA_get0_factors(rsa, &p, &q);
|
|
|
|
return p && q; /* d? why? */
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
static inline int
|
|
|
|
RSA_PRIVATE(VALUE obj, RSA *rsa)
|
|
|
|
{
|
|
|
|
return RSA_HAS_PRIVATE(rsa) || OSSL_PKEY_IS_PRIVATE(obj);
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cRSA;
|
|
|
|
VALUE eRSAError;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rsa_instance(VALUE klass, RSA *rsa)
|
|
|
|
{
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
VALUE obj;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!rsa) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKey(klass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(pkey = EVP_PKEY_new())) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
|
|
|
|
EVP_PKEY_free(pkey);
|
|
|
|
return Qfalse;
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKey(obj, pkey);
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
ossl_rsa_new(EVP_PKEY *pkey)
|
|
|
|
{
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
if (!pkey) {
|
|
|
|
obj = rsa_instance(cRSA, RSA_new());
|
|
|
|
}
|
|
|
|
else {
|
2015-05-29 01:55:02 -04:00
|
|
|
obj = NewPKey(cRSA);
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_RSA) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(rb_eTypeError, "Not a RSA key!");
|
|
|
|
}
|
2015-05-29 01:55:02 -04:00
|
|
|
SetPKey(obj, pkey);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
if (obj == Qfalse) {
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private
|
|
|
|
*/
|
2011-09-01 03:42:29 -04:00
|
|
|
struct rsa_blocking_gen_arg {
|
|
|
|
RSA *rsa;
|
|
|
|
BIGNUM *e;
|
|
|
|
int size;
|
|
|
|
BN_GENCB *cb;
|
|
|
|
int result;
|
|
|
|
};
|
|
|
|
|
2012-07-10 09:57:11 -04:00
|
|
|
static void *
|
2011-09-01 03:42:29 -04:00
|
|
|
rsa_blocking_gen(void *arg)
|
|
|
|
{
|
|
|
|
struct rsa_blocking_gen_arg *gen = (struct rsa_blocking_gen_arg *)arg;
|
|
|
|
gen->result = RSA_generate_key_ex(gen->rsa, gen->size, gen->e, gen->cb);
|
2012-07-10 09:57:11 -04:00
|
|
|
return 0;
|
2011-09-01 03:42:29 -04:00
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static RSA *
|
2012-03-22 22:33:05 -04:00
|
|
|
rsa_generate(int size, unsigned long exp)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
2011-09-01 03:42:29 -04:00
|
|
|
int i;
|
2016-06-05 11:35:12 -04:00
|
|
|
struct ossl_generate_cb_arg cb_arg = { 0 };
|
2011-09-01 03:42:29 -04:00
|
|
|
struct rsa_blocking_gen_arg gen_arg;
|
|
|
|
RSA *rsa = RSA_new();
|
|
|
|
BIGNUM *e = BN_new();
|
2016-06-05 11:35:12 -04:00
|
|
|
BN_GENCB *cb = BN_GENCB_new();
|
2011-09-01 03:42:29 -04:00
|
|
|
|
2016-06-05 11:35:12 -04:00
|
|
|
if (!rsa || !e || !cb) {
|
|
|
|
RSA_free(rsa);
|
|
|
|
BN_free(e);
|
|
|
|
BN_GENCB_free(cb);
|
|
|
|
return NULL;
|
2011-09-01 03:42:29 -04:00
|
|
|
}
|
2011-11-04 01:12:31 -04:00
|
|
|
for (i = 0; i < (int)sizeof(exp) * 8; ++i) {
|
2012-03-22 22:33:05 -04:00
|
|
|
if (exp & (1UL << i)) {
|
2011-09-01 03:42:29 -04:00
|
|
|
if (BN_set_bit(e, i) == 0) {
|
|
|
|
BN_free(e);
|
|
|
|
RSA_free(rsa);
|
2016-06-05 11:35:12 -04:00
|
|
|
BN_GENCB_free(cb);
|
|
|
|
return NULL;
|
2011-09-01 03:42:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rb_block_given_p())
|
|
|
|
cb_arg.yield = 1;
|
2016-06-05 11:35:12 -04:00
|
|
|
BN_GENCB_set(cb, ossl_generate_cb_2, &cb_arg);
|
2011-09-01 03:42:29 -04:00
|
|
|
gen_arg.rsa = rsa;
|
|
|
|
gen_arg.e = e;
|
|
|
|
gen_arg.size = size;
|
2016-06-05 11:35:12 -04:00
|
|
|
gen_arg.cb = cb;
|
2011-09-01 03:42:29 -04:00
|
|
|
if (cb_arg.yield == 1) {
|
|
|
|
/* we cannot release GVL when callback proc is supplied */
|
|
|
|
rsa_blocking_gen(&gen_arg);
|
|
|
|
} else {
|
|
|
|
/* there's a chance to unblock */
|
2012-07-10 09:57:11 -04:00
|
|
|
rb_thread_call_without_gvl(rsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
|
2011-09-01 03:42:29 -04:00
|
|
|
}
|
2016-06-05 11:35:12 -04:00
|
|
|
|
|
|
|
BN_GENCB_free(cb);
|
|
|
|
BN_free(e);
|
2011-09-01 03:42:29 -04:00
|
|
|
if (!gen_arg.result) {
|
|
|
|
RSA_free(rsa);
|
2016-05-18 00:07:47 -04:00
|
|
|
if (cb_arg.state) {
|
|
|
|
/* must clear OpenSSL error stack */
|
|
|
|
ossl_clear_error();
|
|
|
|
rb_jump_tag(cb_arg.state);
|
|
|
|
}
|
2016-06-05 11:35:12 -04:00
|
|
|
return NULL;
|
2011-09-01 03:42:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rsa;
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* RSA.generate(size) => RSA instance
|
|
|
|
* RSA.generate(size, exponent) => RSA instance
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Generates an RSA keypair. +size+ is an integer representing the desired key
|
|
|
|
* size. Keys smaller than 1024 should be considered insecure. +exponent+ is
|
|
|
|
* an odd number normally 3, 17, or 65537.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
2007-03-29 13:29:03 -04:00
|
|
|
/* why does this method exist? why can't initialize take an optional exponent? */
|
2003-07-23 12:12:24 -04:00
|
|
|
RSA *rsa;
|
|
|
|
VALUE size, exp;
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &size, &exp);
|
|
|
|
|
2012-03-22 22:33:05 -04:00
|
|
|
rsa = rsa_generate(NUM2INT(size), NIL_P(exp) ? RSA_F4 : NUM2ULONG(exp)); /* err handled by rsa_instance */
|
2003-07-23 12:12:24 -04:00
|
|
|
obj = rsa_instance(klass, rsa);
|
|
|
|
|
|
|
|
if (obj == Qfalse) {
|
|
|
|
RSA_free(rsa);
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* RSA.new(key_size) => RSA instance
|
|
|
|
* RSA.new(encoded_key) => RSA instance
|
|
|
|
* RSA.new(encoded_key, pass_phrase) => RSA instance
|
|
|
|
*
|
|
|
|
* Generates or loads an RSA keypair. If an integer +key_size+ is given it
|
|
|
|
* represents the desired key size. Keys less than 1024 bits should be
|
|
|
|
* considered insecure.
|
|
|
|
*
|
|
|
|
* A key can instead be loaded from an +encoded_key+ which must be PEM or DER
|
|
|
|
* encoded. A +pass_phrase+ can be used to decrypt the key. If none is given
|
|
|
|
* OpenSSL will prompt for the pass phrase.
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* = Examples
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* OpenSSL::PKey::RSA.new 2048
|
|
|
|
* OpenSSL::PKey::RSA.new File.read 'rsa.pem'
|
|
|
|
* OpenSSL::PKey::RSA.new File.read('rsa.pem'), 'my pass phrase'
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
RSA *rsa;
|
|
|
|
BIO *in;
|
2003-09-17 05:05:02 -04:00
|
|
|
VALUE arg, pass;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetPKey(self, pkey);
|
* ext/openssl/ossl_pkey_dh.c (ossl_dh_initialize): should create
empty pkey object if no argument is passed. [ruby-talk:103328]
* ext/openssl/ossl_pkey_dsa.c (ossl_dsa_initialize): ditto.
* ext/openssl/ossl_pkey_rsa.c (ossl_rsa_initialize): ditto.
* ext/openssl/ossl_pkey_dh.c: add new methods: OpenSSL::PKey::DH#p,
OpenSSL::PKey::DH#p=, OpenSSL::PKey::DH#g, OpenSSL::PKey::DH#g=,
OpenSSL::PKey::DH#pub_key, OpenSSL::PKey::DH#pub_key=,
OpenSSL::PKey::DH#priv_key and OpenSSL::PKey::DH#priv_key=.
* ext/openssl/ossl_pkey_dsa.c: add new methods: OpenSSL::PKey::DSA#p,
OpenSSL::PKey::DSA#p=, OpenSSL::PKey::DSA#q, OpenSSL::PKey::DSA#q=,
OpenSSL::PKey::DSA#g, OpenSSL::PKey::DSA#g=,
OpenSSL::PKey::DSA#pub_key, OpenSSL::PKey::DSA#pub_key=,
OpenSSL::PKey::DSA#priv_key and OpenSSL::PKey::DSA#priv_key=.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-06-21 12:36:19 -04:00
|
|
|
if(rb_scan_args(argc, argv, "02", &arg, &pass) == 0) {
|
|
|
|
rsa = RSA_new();
|
|
|
|
}
|
2016-08-29 01:47:09 -04:00
|
|
|
else if (RB_INTEGER_TYPE_P(arg)) {
|
|
|
|
rsa = rsa_generate(NUM2INT(arg), NIL_P(pass) ? RSA_F4 : NUM2ULONG(pass));
|
2003-09-17 05:05:02 -04:00
|
|
|
if (!rsa) ossl_raise(eRSAError, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-05-20 11:05:25 -04:00
|
|
|
pass = ossl_pem_passwd_value(pass);
|
2003-09-17 05:05:02 -04:00
|
|
|
arg = ossl_to_der_if_possible(arg);
|
|
|
|
in = ossl_obj2bio(arg);
|
2016-05-20 11:05:25 -04:00
|
|
|
rsa = PEM_read_bio_RSAPrivateKey(in, NULL, ossl_pem_passwd_cb, (void *)pass);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!rsa) {
|
2011-06-22 04:41:08 -04:00
|
|
|
OSSL_BIO_reset(in);
|
2011-05-11 17:51:52 -04:00
|
|
|
rsa = PEM_read_bio_RSA_PUBKEY(in, NULL, NULL, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
if (!rsa) {
|
2011-06-22 04:41:08 -04:00
|
|
|
OSSL_BIO_reset(in);
|
2011-05-11 17:51:52 -04:00
|
|
|
rsa = d2i_RSAPrivateKey_bio(in, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
if (!rsa) {
|
2011-06-22 04:41:08 -04:00
|
|
|
OSSL_BIO_reset(in);
|
2011-05-11 17:51:52 -04:00
|
|
|
rsa = d2i_RSA_PUBKEY_bio(in, NULL);
|
2003-09-17 05:05:02 -04:00
|
|
|
}
|
|
|
|
if (!rsa) {
|
2011-06-22 04:41:08 -04:00
|
|
|
OSSL_BIO_reset(in);
|
2011-05-11 17:51:52 -04:00
|
|
|
rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
if (!rsa) {
|
2011-06-22 04:41:08 -04:00
|
|
|
OSSL_BIO_reset(in);
|
2011-05-11 17:51:52 -04:00
|
|
|
rsa = d2i_RSAPublicKey_bio(in, NULL);
|
2003-09-17 05:05:02 -04:00
|
|
|
}
|
|
|
|
BIO_free(in);
|
2011-04-05 22:44:46 -04:00
|
|
|
if (!rsa) {
|
2011-11-23 18:15:09 -05:00
|
|
|
ossl_raise(eRSAError, "Neither PUB key nor PRIV key");
|
2011-04-05 22:44:46 -04:00
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
|
|
|
|
RSA_free(rsa);
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-06-19 05:29:59 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_initialize_copy(VALUE self, VALUE other)
|
|
|
|
{
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
RSA *rsa, *rsa_new;
|
|
|
|
|
|
|
|
GetPKey(self, pkey);
|
|
|
|
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE)
|
|
|
|
ossl_raise(eRSAError, "RSA already initialized");
|
|
|
|
GetRSA(other, rsa);
|
|
|
|
|
|
|
|
rsa_new = ASN1_dup((i2d_of_void *)i2d_RSAPrivateKey, (d2i_of_void *)d2i_RSAPrivateKey, (char *)rsa);
|
|
|
|
if (!rsa_new)
|
|
|
|
ossl_raise(eRSAError, "ASN1_dup");
|
|
|
|
|
|
|
|
EVP_PKEY_assign_RSA(pkey, rsa_new);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.public? => true
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* The return value is always true since every private key is also a public
|
|
|
|
* key.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_is_public(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
2007-03-29 13:29:03 -04:00
|
|
|
* This method should check for n and e. BUG.
|
2003-07-23 12:12:24 -04:00
|
|
|
*/
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
(void)rsa;
|
2003-07-23 12:12:24 -04:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.private? => true | false
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Does this keypair contain a private key?
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_is_private(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2010-04-22 04:21:01 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
return RSA_PRIVATE(self, rsa) ? Qtrue : Qfalse;
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
2013-04-15 22:24:09 -04:00
|
|
|
* rsa.export([cipher, pass_phrase]) => PEM-format String
|
|
|
|
* rsa.to_pem([cipher, pass_phrase]) => PEM-format String
|
|
|
|
* rsa.to_s([cipher, pass_phrase]) => PEM-format String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Outputs this keypair in PEM encoding. If +cipher+ and +pass_phrase+ are
|
|
|
|
* given they will be used to encrypt the key. +cipher+ must be an
|
2016-08-29 01:47:09 -04:00
|
|
|
* OpenSSL::Cipher instance.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_export(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO *out;
|
|
|
|
const EVP_CIPHER *ciph = NULL;
|
|
|
|
VALUE cipher, pass, str;
|
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "02", &cipher, &pass);
|
|
|
|
|
|
|
|
if (!NIL_P(cipher)) {
|
|
|
|
ciph = GetCipherPtr(cipher);
|
2016-05-20 11:05:25 -04:00
|
|
|
pass = ossl_pem_passwd_value(pass);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (RSA_HAS_PRIVATE(rsa)) {
|
|
|
|
if (!PEM_write_bio_RSAPrivateKey(out, rsa, ciph, NULL, 0,
|
|
|
|
ossl_pem_passwd_cb, (void *)pass)) {
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
} else {
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (!PEM_write_bio_RSA_PUBKEY(out, rsa)) {
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
str = ossl_membio2str(out);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.to_der => DER-format String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Outputs this keypair in DER encoding.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2004-01-08 07:24:22 -05:00
|
|
|
static VALUE
|
|
|
|
ossl_rsa_to_der(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2016-08-29 01:47:09 -04:00
|
|
|
int (*i2d_func)(const RSA *, unsigned char **);
|
2004-01-08 07:24:22 -05:00
|
|
|
unsigned char *p;
|
|
|
|
long len;
|
|
|
|
VALUE str;
|
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
if (RSA_HAS_PRIVATE(rsa))
|
2004-01-08 07:24:22 -05:00
|
|
|
i2d_func = i2d_RSAPrivateKey;
|
|
|
|
else
|
2016-08-29 01:47:09 -04:00
|
|
|
i2d_func = (int (*)(const RSA *, unsigned char **))i2d_RSA_PUBKEY;
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if((len = i2d_func(rsa, NULL)) <= 0)
|
2004-01-08 07:24:22 -05:00
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
str = rb_str_new(0, len);
|
2008-07-22 11:34:23 -04:00
|
|
|
p = (unsigned char *)RSTRING_PTR(str);
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if(i2d_func(rsa, &p) < 0)
|
2004-01-08 07:24:22 -05:00
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
ossl_str_adjust(str, p);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.public_encrypt(string) => String
|
|
|
|
* rsa.public_encrypt(string, padding) => String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Encrypt +string+ with the public key. +padding+ defaults to PKCS1_PADDING.
|
|
|
|
* The encrypted string output can be decrypted using #private_decrypt.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
2004-12-05 11:36:26 -05:00
|
|
|
ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2016-06-19 01:31:28 -04:00
|
|
|
const BIGNUM *rsa_n;
|
2004-12-05 11:36:26 -05:00
|
|
|
int buf_len, pad;
|
|
|
|
VALUE str, buffer, padding;
|
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
RSA_get0_key(rsa, &rsa_n, NULL, NULL);
|
|
|
|
if (!rsa_n)
|
2016-05-26 01:24:58 -04:00
|
|
|
ossl_raise(eRSAError, "incomplete RSA");
|
2004-12-05 11:36:26 -05:00
|
|
|
rb_scan_args(argc, argv, "11", &buffer, &padding);
|
|
|
|
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
|
2003-07-23 12:12:24 -04:00
|
|
|
StringValue(buffer);
|
2016-11-30 09:41:46 -05:00
|
|
|
str = rb_str_new(0, RSA_size(rsa));
|
2011-03-24 03:29:21 -04:00
|
|
|
buf_len = RSA_public_encrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
(unsigned char *)RSTRING_PTR(str), rsa, pad);
|
2003-09-17 05:05:02 -04:00
|
|
|
if (buf_len < 0) ossl_raise(eRSAError, NULL);
|
2006-08-31 06:30:33 -04:00
|
|
|
rb_str_set_len(str, buf_len);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.public_decrypt(string) => String
|
|
|
|
* rsa.public_decrypt(string, padding) => String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Decrypt +string+, which has been encrypted with the private key, with the
|
|
|
|
* public key. +padding+ defaults to PKCS1_PADDING.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
2004-12-05 11:36:26 -05:00
|
|
|
ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2016-06-19 01:31:28 -04:00
|
|
|
const BIGNUM *rsa_n;
|
2004-12-05 11:36:26 -05:00
|
|
|
int buf_len, pad;
|
|
|
|
VALUE str, buffer, padding;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
RSA_get0_key(rsa, &rsa_n, NULL, NULL);
|
|
|
|
if (!rsa_n)
|
2016-05-26 01:24:58 -04:00
|
|
|
ossl_raise(eRSAError, "incomplete RSA");
|
2004-12-05 11:36:26 -05:00
|
|
|
rb_scan_args(argc, argv, "11", &buffer, &padding);
|
|
|
|
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
|
2003-07-23 12:12:24 -04:00
|
|
|
StringValue(buffer);
|
2016-11-30 09:41:46 -05:00
|
|
|
str = rb_str_new(0, RSA_size(rsa));
|
2011-03-24 03:29:21 -04:00
|
|
|
buf_len = RSA_public_decrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
(unsigned char *)RSTRING_PTR(str), rsa, pad);
|
2004-12-05 11:36:26 -05:00
|
|
|
if (buf_len < 0) ossl_raise(eRSAError, NULL);
|
2006-08-31 06:30:33 -04:00
|
|
|
rb_str_set_len(str, buf_len);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.private_encrypt(string) => String
|
|
|
|
* rsa.private_encrypt(string, padding) => String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Encrypt +string+ with the private key. +padding+ defaults to PKCS1_PADDING.
|
|
|
|
* The encrypted string output can be decrypted using #public_decrypt.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
2004-12-05 11:36:26 -05:00
|
|
|
ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2016-06-19 01:31:28 -04:00
|
|
|
const BIGNUM *rsa_n;
|
2004-12-05 11:36:26 -05:00
|
|
|
int buf_len, pad;
|
|
|
|
VALUE str, buffer, padding;
|
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
RSA_get0_key(rsa, &rsa_n, NULL, NULL);
|
|
|
|
if (!rsa_n)
|
2016-05-26 01:24:58 -04:00
|
|
|
ossl_raise(eRSAError, "incomplete RSA");
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (!RSA_PRIVATE(self, rsa))
|
|
|
|
ossl_raise(eRSAError, "private key needed.");
|
2004-12-05 11:36:26 -05:00
|
|
|
rb_scan_args(argc, argv, "11", &buffer, &padding);
|
|
|
|
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
|
2003-07-23 12:12:24 -04:00
|
|
|
StringValue(buffer);
|
2016-11-30 09:41:46 -05:00
|
|
|
str = rb_str_new(0, RSA_size(rsa));
|
2011-03-24 03:29:21 -04:00
|
|
|
buf_len = RSA_private_encrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
(unsigned char *)RSTRING_PTR(str), rsa, pad);
|
2003-09-17 05:05:02 -04:00
|
|
|
if (buf_len < 0) ossl_raise(eRSAError, NULL);
|
2006-08-31 06:30:33 -04:00
|
|
|
rb_str_set_len(str, buf_len);
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:29:03 -04:00
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.private_decrypt(string) => String
|
|
|
|
* rsa.private_decrypt(string, padding) => String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Decrypt +string+, which has been encrypted with the public key, with the
|
|
|
|
* private key. +padding+ defaults to PKCS1_PADDING.
|
2007-03-29 13:29:03 -04:00
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
2004-12-05 11:36:26 -05:00
|
|
|
ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2016-06-19 01:31:28 -04:00
|
|
|
const BIGNUM *rsa_n;
|
2004-12-05 11:36:26 -05:00
|
|
|
int buf_len, pad;
|
|
|
|
VALUE str, buffer, padding;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
RSA_get0_key(rsa, &rsa_n, NULL, NULL);
|
|
|
|
if (!rsa_n)
|
2016-05-26 01:24:58 -04:00
|
|
|
ossl_raise(eRSAError, "incomplete RSA");
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (!RSA_PRIVATE(self, rsa))
|
|
|
|
ossl_raise(eRSAError, "private key needed.");
|
2004-12-05 11:36:26 -05:00
|
|
|
rb_scan_args(argc, argv, "11", &buffer, &padding);
|
|
|
|
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
|
2003-07-23 12:12:24 -04:00
|
|
|
StringValue(buffer);
|
2016-11-30 09:41:46 -05:00
|
|
|
str = rb_str_new(0, RSA_size(rsa));
|
2011-03-24 03:29:21 -04:00
|
|
|
buf_len = RSA_private_decrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
(unsigned char *)RSTRING_PTR(str), rsa, pad);
|
2003-09-17 05:05:02 -04:00
|
|
|
if (buf_len < 0) ossl_raise(eRSAError, NULL);
|
2006-08-31 06:30:33 -04:00
|
|
|
rb_str_set_len(str, buf_len);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.params => hash
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
|
|
|
|
*
|
|
|
|
* Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd',
|
|
|
|
* 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.
|
|
|
|
*
|
|
|
|
* Don't use :-)) (It's up to you)
|
2003-07-23 12:12:24 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_rsa_get_params(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2003-07-23 12:12:24 -04:00
|
|
|
VALUE hash;
|
2016-06-19 01:31:28 -04:00
|
|
|
const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
RSA_get0_key(rsa, &n, &e, &d);
|
|
|
|
RSA_get0_factors(rsa, &p, &q);
|
|
|
|
RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
hash = rb_hash_new();
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
rb_hash_aset(hash, rb_str_new2("n"), ossl_bn_new(n));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("e"), ossl_bn_new(e));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("d"), ossl_bn_new(d));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("p"), ossl_bn_new(p));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("q"), ossl_bn_new(q));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("dmp1"), ossl_bn_new(dmp1));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("dmq1"), ossl_bn_new(dmq1));
|
|
|
|
rb_hash_aset(hash, rb_str_new2("iqmp"), ossl_bn_new(iqmp));
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.to_text => String
|
|
|
|
*
|
|
|
|
* THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
|
|
|
|
*
|
|
|
|
* Dumps all parameters of a keypair to a String
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2003-09-17 05:05:02 -04:00
|
|
|
* Don't use :-)) (It's up to you)
|
2003-07-23 12:12:24 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_rsa_to_text(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO *out;
|
|
|
|
VALUE str;
|
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (!RSA_print(out, rsa, 0)) { /* offset = 0 */
|
2003-07-23 12:12:24 -04:00
|
|
|
BIO_free(out);
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
2003-09-17 05:05:02 -04:00
|
|
|
str = ossl_membio2str(out);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-12-10 18:13:47 -05:00
|
|
|
* call-seq:
|
|
|
|
* rsa.public_key -> RSA
|
2007-03-29 13:29:03 -04:00
|
|
|
*
|
2010-12-10 18:13:47 -05:00
|
|
|
* Makes new RSA instance containing the public key from the private key.
|
2003-07-23 12:12:24 -04:00
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_rsa_to_public_key(VALUE self)
|
|
|
|
{
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
RSA *rsa;
|
|
|
|
VALUE obj;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
GetPKeyRSA(self, pkey);
|
|
|
|
/* err check performed by rsa_instance */
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
rsa = RSAPublicKey_dup(EVP_PKEY_get0_RSA(pkey));
|
2016-11-30 09:41:46 -05:00
|
|
|
obj = rsa_instance(rb_obj_class(self), rsa);
|
2003-07-23 12:12:24 -04:00
|
|
|
if (obj == Qfalse) {
|
|
|
|
RSA_free(rsa);
|
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: Test me
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_rsa_blinding_on(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
if (RSA_blinding_on(rsa, ossl_bn_ctx) != 1) {
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(eRSAError, NULL);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_rsa_blinding_off(VALUE self)
|
|
|
|
{
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
RSA *rsa;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
GetRSA(self, rsa);
|
|
|
|
RSA_blinding_off(rsa);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* Document-method: OpenSSL::PKey::RSA#set_key
|
|
|
|
* call-seq:
|
|
|
|
* rsa.set_key(n, e, d) -> self
|
|
|
|
*
|
|
|
|
* Sets +n+, +e+, +d+ for the RSA instance.
|
|
|
|
*/
|
2016-06-28 05:42:29 -04:00
|
|
|
OSSL_PKEY_BN_DEF3(rsa, RSA, key, n, e, d)
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* Document-method: OpenSSL::PKey::RSA#set_factors
|
|
|
|
* call-seq:
|
|
|
|
* rsa.set_factors(p, q) -> self
|
|
|
|
*
|
|
|
|
* Sets +p+, +q+ for the RSA instance.
|
|
|
|
*/
|
2016-06-28 05:42:29 -04:00
|
|
|
OSSL_PKEY_BN_DEF2(rsa, RSA, factors, p, q)
|
2016-08-29 01:47:09 -04:00
|
|
|
/*
|
|
|
|
* Document-method: OpenSSL::PKey::RSA#set_crt_params
|
|
|
|
* call-seq:
|
|
|
|
* rsa.set_crt_params(dmp1, dmq1, iqmp) -> self
|
|
|
|
*
|
|
|
|
* Sets +dmp1+, +dmq1+, +iqmp+ for the RSA instance. They are calculated by
|
|
|
|
* <tt>d mod (p - 1)</tt>, <tt>d mod (q - 1)</tt> and <tt>q^(-1) mod p</tt>
|
|
|
|
* respectively.
|
|
|
|
*/
|
2016-06-28 05:42:29 -04:00
|
|
|
OSSL_PKEY_BN_DEF3(rsa, RSA, crt_params, dmp1, dmq1, iqmp)
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
2016-08-29 01:47:09 -04:00
|
|
|
#define DefRSAConst(x) rb_define_const(cRSA, #x, INT2NUM(RSA_##x))
|
2004-12-05 11:36:26 -05:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
void
|
2014-09-30 01:25:32 -04:00
|
|
|
Init_ossl_rsa(void)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
2010-12-05 19:54:44 -05:00
|
|
|
#if 0
|
2007-03-11 22:01:19 -04:00
|
|
|
mPKey = rb_define_module_under(mOSSL, "PKey");
|
2016-08-29 01:47:09 -04:00
|
|
|
cPKey = rb_define_class_under(mPKey, "PKey", rb_cObject);
|
|
|
|
ePKeyError = rb_define_class_under(mPKey, "PKeyError", eOSSLError);
|
2007-03-11 22:01:19 -04:00
|
|
|
#endif
|
|
|
|
|
2011-05-30 17:47:37 -04:00
|
|
|
/* Document-class: OpenSSL::PKey::RSAError
|
|
|
|
*
|
|
|
|
* Generic exception that is raised if an operation on an RSA PKey
|
|
|
|
* fails unexpectedly or in case an instantiation of an instance of RSA
|
|
|
|
* fails due to non-conformant input data.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
eRSAError = rb_define_class_under(mPKey, "RSAError", ePKeyError);
|
|
|
|
|
2011-05-30 17:47:37 -04:00
|
|
|
/* Document-class: OpenSSL::PKey::RSA
|
|
|
|
*
|
|
|
|
* RSA is an asymmetric public key algorithm that has been formalized in
|
|
|
|
* RFC 3447. It is in widespread use in public key infrastuctures (PKI)
|
|
|
|
* where certificates (cf. OpenSSL::X509::Certificate) often are issued
|
|
|
|
* on the basis of a public/private RSA key pair. RSA is used in a wide
|
|
|
|
* field of applications such as secure (symmetric) key exchange, e.g.
|
|
|
|
* when establishing a secure TLS/SSL connection. It is also used in
|
|
|
|
* various digital signature schemes.
|
|
|
|
*/
|
2003-07-23 12:12:24 -04:00
|
|
|
cRSA = rb_define_class_under(mPKey, "RSA", cPKey);
|
|
|
|
|
|
|
|
rb_define_singleton_method(cRSA, "generate", ossl_rsa_s_generate, -1);
|
|
|
|
rb_define_method(cRSA, "initialize", ossl_rsa_initialize, -1);
|
2016-06-19 05:29:59 -04:00
|
|
|
rb_define_copy_func(cRSA, ossl_rsa_initialize_copy);
|
2010-04-22 04:21:01 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cRSA, "public?", ossl_rsa_is_public, 0);
|
|
|
|
rb_define_method(cRSA, "private?", ossl_rsa_is_private, 0);
|
|
|
|
rb_define_method(cRSA, "to_text", ossl_rsa_to_text, 0);
|
|
|
|
rb_define_method(cRSA, "export", ossl_rsa_export, -1);
|
|
|
|
rb_define_alias(cRSA, "to_pem", "export");
|
|
|
|
rb_define_alias(cRSA, "to_s", "export");
|
2004-01-08 07:24:22 -05:00
|
|
|
rb_define_method(cRSA, "to_der", ossl_rsa_to_der, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_define_method(cRSA, "public_key", ossl_rsa_to_public_key, 0);
|
2004-12-05 11:36:26 -05:00
|
|
|
rb_define_method(cRSA, "public_encrypt", ossl_rsa_public_encrypt, -1);
|
|
|
|
rb_define_method(cRSA, "public_decrypt", ossl_rsa_public_decrypt, -1);
|
|
|
|
rb_define_method(cRSA, "private_encrypt", ossl_rsa_private_encrypt, -1);
|
|
|
|
rb_define_method(cRSA, "private_decrypt", ossl_rsa_private_decrypt, -1);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, n);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, e);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, d);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, p);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, q);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, dmp1);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, dmq1);
|
|
|
|
DEF_OSSL_PKEY_BN(cRSA, rsa, iqmp);
|
openssl: adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs
* ext/openssl/openssl_missing.[ch]: Implement EVP_PKEY_get0_*() and
{RSA,DSA,EC_KEY,DH}_get0_*() functions.
OpenSSL 1.1.0 makes EVP_PKEY/RSA/DSA/DH opaque. We used to provide
setter methods for each parameter of each PKey type, for example
PKey::RSA#e=, but this is no longer possible because the new API
RSA_set0_key() requires the 'n' at the same time. This commit adds
deprecation warning to them and adds PKey::*#set_* methods as direct
wrapper for those new APIs. For example, 'rsa.e = 3' now needs to be
rewritten as 'rsa.set_key(rsa.n, 3, rsa.d)'.
[ruby-core:75225] [Feature #12324]
* ext/openssl/ossl_pkey*.[ch]: Use the new accessor functions. Implement
RSA#set_{key,factors,crt_params}, DSA#set_{key,pqg}, DH#set_{key,pqg}.
Emit a warning with rb_warning() when old setter methods are used.
* test/drb/ut_array_drbssl.rb, test/drb/ut_drb_drbssl.rb,
test/rubygems/test_gem_remote_fetcher.rb: Don't set a priv_key for DH
object that are used in tmp_dh_callback. Generating a new key pair
every time should be fine - actually the private exponent is ignored
in OpenSSL >= 1.0.2f/1.0.1r even if we explicitly set.
https://www.openssl.org/news/secadv/20160128.txt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-05 11:00:47 -04:00
|
|
|
rb_define_method(cRSA, "set_key", ossl_rsa_set_key, 3);
|
|
|
|
rb_define_method(cRSA, "set_factors", ossl_rsa_set_factors, 2);
|
|
|
|
rb_define_method(cRSA, "set_crt_params", ossl_rsa_set_crt_params, 3);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
rb_define_method(cRSA, "params", ossl_rsa_get_params, 0);
|
|
|
|
|
2004-12-05 11:36:26 -05:00
|
|
|
DefRSAConst(PKCS1_PADDING);
|
|
|
|
DefRSAConst(SSLV23_PADDING);
|
|
|
|
DefRSAConst(NO_PADDING);
|
|
|
|
DefRSAConst(PKCS1_OAEP_PADDING);
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* TODO: Test it
|
|
|
|
rb_define_method(cRSA, "blinding_on!", ossl_rsa_blinding_on, 0);
|
|
|
|
rb_define_method(cRSA, "blinding_off!", ossl_rsa_blinding_off, 0);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* defined NO_RSA */
|
|
|
|
void
|
2014-09-30 01:25:32 -04:00
|
|
|
Init_ossl_rsa(void)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* NO_RSA */
|