Граф коммитов

466 Коммитов

Автор SHA1 Сообщение Дата
Kazuki Yamaguchi cc8ff8b50d [ruby/openssl] require Ruby 2.6 or later
Drop support for Ruby 2.3, 2.4, and 2.5.

As of 2021-10, Ruby 2.6 is the oldest version that still receives
security fixes from the Ruby core team, so it doesn't make much sense
to keep code for those ancient versions.

https://github.com/ruby/openssl/commit/3436bd040d
2021-10-16 19:39:13 +09:00
Kazuki Yamaguchi e36906f9ab [ruby/openssl] test/openssl/test_ssl: use TLS 1.2 for finished_messages on LibreSSL
LibreSSL 2.2.x has a bug in the Finished message handling with TLS 1.3.
This is fixed by LibreSSL 3.3.2.

https://github.com/ruby/openssl/commit/0bea59d245
2021-10-16 18:34:35 +09:00
Nobuhiro IMAI f88401f38e [ruby/openssl] fix segv in Timestamp::{Request,Response,TokenInfo}.new
prevent `ossl_ts_*_free()` from calling when `d2i_TS_*_bio()` failed.

https://github.com/ruby/openssl/commit/b29e215786
2021-10-16 18:34:35 +09:00
Nobuyoshi Nakada ed7ea35d74 [ruby/openssl] Fixed misspellings
[ This is a backport to the 2.1 branch. ]

Fixed misspellings reported at [Bug #16437], for default gems.

(cherry picked from commit ruby/ruby@e68999c82c)

https://github.com/ruby/openssl/commit/0f43789503
2021-10-16 18:25:11 +09:00
Kazuki Yamaguchi 6105ef7629 [ruby/openssl] ssl: add SSLContext#tmp_dh=
Provide a wrapper of SSL_set0_tmp_dh_pkey()/SSL_CTX_set_tmp_dh(), which
sets the DH parameters used for ephemeral DH key exchange.

SSLContext#tmp_dh_callback= already exists for this purpose, as a
wrapper around SSL_CTX_set_tmp_dh_callback(), but it is considered
obsolete and the OpenSSL API is deprecated for future removal. There is
no practical use case where an application needs to use different DH
parameters nowadays. This was originally introduced to support export
grade ciphers.

RDoc for #tmp_dh_callback= is updated to recommend the new #tmp_dh=.

Note that current versions of OpenSSL support automatic ECDHE curve
selection which is enabled by default. SSLContext#tmp_dh= should only be
necessary if you must allow ancient clients which don't support ECDHE.

https://github.com/ruby/openssl/commit/aa43da4f04
2021-10-16 18:19:52 +09:00
Hiroshi SHIBATA ecfbf1df33
Use Test::Unit::PendedError instead of MiniTest::Skip for test-unit migration 2021-09-06 19:33:56 +09:00
Yusuke Endoh ab2bd3ff35 test/openssl/test_x509cert.rb: Prevent "unused variable" warning 2021-07-19 10:57:56 +09:00
Vinicius Stock 4f7c3f631a [ruby/openssl] Include peer socket IP address in errors
https://github.com/ruby/openssl/commit/8a1e3f5085
2021-07-18 17:45:03 +09:00
Yusuke Endoh 3d37e5d11c [ruby/openssl] Add OpenSSL::BN#set_flags and #get_flags
Also, OpenSSL::BN::CONSTTIME is added.

OpenSSL itself had a feature that was vulnerable against a side-channel
attack. The OpenSSL authors determined that it was not a security issue,
and they have already fixed the issue by using BN_set_flags.

https://github.com/openssl/openssl/pull/13888

If a Ruby OpenSSL user was faced with a similar issue, they couldn't
prevent the issue because Ruby OpenSSL lacks a wrapper to BN_set_flags.
For the case, this change introduces the wrapper.

https://github.com/ruby/openssl/commit/1e565eba89
2021-07-18 17:45:02 +09:00
Kazuki Yamaguchi 4ebff35971 [ruby/openssl] pkey: implement PKey#sign_raw, #verify_raw, and #verify_recover
Add a variant of PKey#sign and #verify that do not hash the data
automatically.

Sometimes the caller has the hashed data only, but not the plaintext
to be signed. In that case, users would have to use the low-level API
such as RSA#private_encrypt or #public_decrypt directly.

OpenSSL 1.0.0 and later supports EVP_PKEY_sign() and EVP_PKEY_verify()
which provide the same functionality as part of the EVP API. This patch
adds wrappers for them.

https://github.com/ruby/openssl/commit/16cca4e0c4
2021-07-18 17:44:58 +09:00
Kazuki Yamaguchi 87458ff2ae [ruby/openssl] pkey: implement PKey#encrypt and #decrypt
Support public key encryption and decryption operations using the EVP
API.

https://github.com/ruby/openssl/commit/75326d4bbc
2021-07-18 17:44:57 +09:00
Samuel Williams 1146a94aee [ruby/openssl] Implement `Certificate.load` to load certificate chain. (https://github.com/ruby/openssl/pull/441)
* Add feature for loading the chained certificate into Certificate array.

https://github.com/ruby/openssl/commit/05e1c015d6

Co-authored-by: Sao I Kuan <saoikuan@gmail.com>
2021-07-18 17:44:55 +09:00
Kazuki Yamaguchi a01daab656 [ruby/openssl] x509, ssl, pkcs7: try to parse as DER-encoding first
Methods that take both PEM-encoding and DER-encoding have not been
consistent in the order in which encoding to attempt to parse.

A DER-encoding may contain a valid PEM block ("\n-----BEGIN ..-----" to
"-----END ...-----") embedded within it. Also, the PEM-encoding parser
allows arbitrary data around the PEM block and silently skips it. As a
result, attempting to parse data in DER-encoding as PEM-encoding first
can incorrectly finds the embedded PEM block instead.

This commit ensures that DER encoding will always be attempted before
PEM encoding. OpenSSL::X509::Certificate is one of the updated classes.
With this, the following will always be true:

    # obj is an OpenSSL::X509::Certificate
    obj == OpenSSL::X509::Certificate.new(obj.to_der)
    obj == OpenSSL::X509::Certificate.new(obj.to_pem)

https://github.com/ruby/openssl/commit/b280eb1fd0
2021-07-18 17:44:54 +09:00
Aaron Patterson 593164c2be [ruby/openssl] Add SSLSocket#getbyte
Normal sockets respond to `getbyte`, so we should make SSLSocket respond
to `getbyte` as well.  This way we can substitute SSLSockets for regular
sockets.

https://github.com/ruby/openssl/commit/ac1490b7c9
2021-07-18 17:44:53 +09:00
Kazuki Yamaguchi 6d71918d94 [ruby/openssl] pkey/dh, pkey/ec: use EVP_PKEY_check() family
Use EVP_PKEY_param_check() instead of DH_check() if available. Also,
use EVP_PKEY_public_check() instead of EC_KEY_check_key().

EVP_PKEY_*check() is part of the EVP API and is meant to replace those
low-level functions. They were added by OpenSSL 1.1.1. It is currently
not provided by LibreSSL.

https://github.com/ruby/openssl/commit/797e9f8e08
2021-07-18 17:44:52 +09:00
Kazuki Yamaguchi 3fe8387950 [ruby/openssl] pkey: implement {DH,DSA,RSA}#public_key in Ruby
The low-level API that is used to implement #public_key is deprecated
in OpenSSL 3.0. It is actually very simple to implement in another way,
using existing methods only, in much shorter code. Let's do it.

While we are at it, the documentation is updated to recommend against
using #public_key. Now that OpenSSL::PKey::PKey implements public_to_der
method, there is no real use case for #public_key in newly written Ruby
programs.

https://github.com/ruby/openssl/commit/48a6c391ef
2021-07-18 17:44:51 +09:00
Kazuki Yamaguchi 5d1693aac5 [ruby/openssl] pkey: implement #to_text using EVP API
Use EVP_PKEY_print_private() instead of the low-level API *_print()
functions, such as RSA_print().

EVP_PKEY_print_*() family was added in OpenSSL 1.0.0.

Note that it falls back to EVP_PKEY_print_public() and
EVP_PKEY_print_params() as necessary. This is required for EVP_PKEY_DH
type for which _private() fails if the private component is not set in
the pkey object.

Since the new API works in the same way for all key types, we now
implement #to_text in the base class OpenSSL::PKey::PKey rather than in
each subclass.

https://github.com/ruby/openssl/commit/e0b4c56956
2021-07-18 17:44:50 +09:00
Kazuki Yamaguchi 38436d1f5c [ruby/openssl] pkey/dsa: use high level EVP interface to generate parameters and keys
Implement PKey::DSA.new(size) and PKey::DSA.generate using
OpenSSL::PKey.generate_parameters and .generate_key instead of the low
level DSA functions.

https://github.com/ruby/openssl/commit/1800a8d5eb
2021-07-18 17:44:49 +09:00
Kazuki Yamaguchi 098985a5e6 [ruby/openssl] pkey/dh: use high level EVP interface to generate parameters and keys
Implement PKey::DH.new(size, gen), PKey::DH.generate(size, gen), and
PKey::DH#generate_key! using PKey.generate_parameters and .generate_key
instead of the low level DH functions.

Note that the EVP interface can enforce additional restrictions - for
example, DH key shorter than 2048 bits is no longer accepted by default
in OpenSSL 3.0. The test code is updated accordingly.

https://github.com/ruby/openssl/commit/c2e9b16f0b
2021-07-18 17:44:47 +09:00
Kazuki Yamaguchi 8cfe92b8a2 [ruby/openssl] pkey: allow setting algorithm-specific options in #sign and #verify
Similarly to OpenSSL::PKey.generate_key and .generate_parameters, let
OpenSSL::PKey::PKey#sign and #verify take an optional parameter for
specifying control strings for EVP_PKEY_CTX_ctrl_str().

https://github.com/ruby/openssl/commit/faf85d7c1d
2021-07-18 17:44:46 +09:00
Kazuki Yamaguchi cd002305f0 [ruby/openssl] require OpenSSL >= 1.0.2 and LibreSSL >= 3.1
Clean up old version guards in preparation for the upcoming OpenSSL 3.0
support.

OpenSSL 1.0.1 reached its EOL on 2016-12-31. At that time, we decided
to keep 1.0.1 support because many major Linux distributions were still
shipped with 1.0.1. Now, nearly 4 years later, most Linux distributions
are reaching their EOL and it should be safe to assume nobody uses them
anymore. Major ones that were using 1.0.1:

 - Ubuntu 14.04 is EOL since 2019-04-30
 - RHEL 6 will reach EOL on 2020-11-30

LibreSSL 3.0 and older versions are no longer supported by the LibreSSL
team as of October 2020.

Note that OpenSSL 1.0.2 also reached EOL on 2019-12-31 and 1.1.0 also
did on 2018-08-31.

https://github.com/ruby/openssl/commit/c055938f4b
2021-07-18 17:44:41 +09:00
Rick Mark 01fcb8f45b [ruby/openssl] BN.abs and BN uplus
Adds standard math abs fuction and revises uplus to return a duplicated object due to BN mutability

https://github.com/ruby/openssl/commit/0321b1e945
2021-07-18 17:44:39 +09:00
Hiroshi SHIBATA b8dcad8d32 Defer to require prime for OpenSSL::TestBN 2021-05-27 14:42:11 +09:00
Kazuki Yamaguchi e2bf3659e1 [ruby/openssl] pkcs7: keep private key when duplicating PKCS7_SIGNER_INFO
ASN1_dup() will not copy the 'pkey' field of a PKCS7_SIGNER_INFO object
by design; it is a temporary field kept until the PKCS7 structure is
finalized. Let's bump reference counter of the pkey in the original
object and use it in the new object, too.

This commit also removes PKCS7#add_signer's routine to add the
content-type attribute as a signed attribute automatically. This
behavior was not documented or tested. This change should not break any
working user code since the method was completely useless without the
change above.

https://github.com/ruby/openssl/commit/20ca7a27a8
2021-03-31 18:05:07 +09:00
Kazuki Yamaguchi e61e9bcfb2 test/openssl/test_config: skip tests for .include on older OpenSSL
The .include directive was initially added by OpenSSL 1.1.1, but the
syntax was later modified in 1.1.1b to improve compatibility with the
parser in <= 1.1.0. The test case expects 1.1.1b's parser.

95f59d398c

The test case is failing on Ubuntu 18.04 because it still uses the
initial 1.1.1 release:

http://rubyci.s3.amazonaws.com/graviton2/ruby-master/log/20210316T120003Z.fail.html.gz
2021-03-16 22:30:33 +09:00
Kazuki Yamaguchi 44d67128a8 test/openssl/test_cipher: skip AES-CCM tests on OpenSSL <= 1.1.1b
AES CCM mode in OpenSSL <= 1.1.1b was overly strict in the parameters
assignment order. This has been relaxed by OpenSSL 1.1.1c.

b48e3be947

The test case is failing on Ubuntu 18.04 because it still uses the
initial 1.1.1 release and has the issue:

http://rubyci.s3.amazonaws.com/graviton2/ruby-master/log/20210316T120003Z.fail.html.gz
2021-03-16 22:30:18 +09:00
Kazuki Yamaguchi a3f97007bb [ruby/openssl] test: adjust test cases for LibreSSL 3.2.4
LibreSSL 3.2.4 made the certificate verification logic back closer to
pre-3.2.2 one, which is more compatible with OpenSSL.

Part of the fixes added by commit a0e98d48c91f ("Enhance TLS 1.3 support
on LibreSSL 3.2/3.3", 2020-12-03) is required for 3.2.2 and 3.2.3 only
(and ~3.3.1, however 3.3 does not have a stable release yet). Since both
releases are security fix, it should be safe to remove those special
treatment from our test suite.

While we are at it, TestSSL#test_ecdh_curves is split into TLS 1.2 and
TLS 1.3 variants for clarity.

https://github.com/ruby/openssl/commit/a9954bac22
2021-03-16 19:37:06 +09:00
Nobuyoshi Nakada 1ad2224773 [ruby/openssl] Fixed the results of OpenSSL::Timestamp::Response#failure_info
Made stored values `Symbol`s instead of `ID`s.

Fixes https://bugs.ruby-lang.org/issues/17625

Co-Authored-By: xtkoba (Tee KOBAYASHI) <xtkoba+ruby@gmail.com>

https://github.com/ruby/openssl/commit/f2d004679a
2021-03-16 19:37:06 +09:00
Jeremy Evans e2ce383044 [ruby/openssl] Enhance TLS 1.3 support on LibreSSL 3.2/3.3
This defines TLS1_3_VERSION when using LibreSSL 3.2+.  LibreSSL 3.2/3.3
doesn't advertise this by default, even though it will use TLS 1.3
in both client and server modes.

Changes between LibreSSL 3.1 and 3.2/3.3 broke a few tests, Defining
TLS1_3_VERSION by itself fixes 1 test failure.  A few tests now
fail on LibreSSL 3.2/3.3 unless TLS 1.2 is set as the maximum version,
and this adjusts those tests.  The client CA test doesn't work in
LibreSSL 3.2+, so I've marked that as pending.

For the hostname verification, LibreSSL 3.2.2+ has a new stricter
hostname verifier that doesn't like subjectAltName such as
c*.example.com and d.*.example.com, so adjust the related tests.

With these changes, the tests pass on LibreSSL 3.2/3.3.

https://github.com/ruby/openssl/commit/a0e98d48c9
2021-03-16 19:37:06 +09:00
Kazuki Yamaguchi d47210b113 [ruby/openssl] ssl: remove SSL::SSLContext#tmp_ecdh_callback
The underlying API SSL_CTX_set_tmp_ecdh_callback() was removed by
LibreSSL >= 2.6.1 and OpenSSL >= 1.1.0, in other words, it is not
supported by any non-EOL versions of OpenSSL.

The wrapper was initially implemented in Ruby 2.3 and has been
deprecated since Ruby/OpenSSL 2.0 (bundled with Ruby 2.4) with explicit
warning with rb_warn().

https://github.com/ruby/openssl/commit/ee037e1460
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 0b1bb1bc32 [ruby/openssl] test/openssl/test_x509store: tidy up tests for X509::Store#add_cert
Rename the test case to test_add_cert_duplicate to clarify what it is
actually testing.

https://github.com/ruby/openssl/commit/4cc3c4110f
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi d4ad1e71ca [ruby/openssl] test/openssl/test_x509store: break up test_verify
The test case is huge and too complex. Break it up into separate test
cases for better documentation.

https://github.com/ruby/openssl/commit/61012df03b
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 08c99a4208 [ruby/openssl] x509store: emit warning if arguments are given to X509::Store.new
Anything passed to OpenSSL::X509::Store.new was always ignored. Let's
emit an explicit warning to not confuse users.

https://github.com/ruby/openssl/commit/d173700eeb
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 88b8b3ac15 [ruby/openssl] x509store: let X509::Store#add_file raise TypeError if nil is given
Undo special treatment of nil and simply pass the value to
StringValueCStr().

nil was never a valid argument for the method; OpenSSL::X509::StoreError
with an unhelpful error message "system lib" was raised in that case.

https://github.com/ruby/openssl/commit/fb2fcbb137
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 81325db5f8 [ruby/openssl] ssl: initialize verify_mode and verify_hostname with default values
SSLContext's verify_mode expects an SSL_VERIFY_* constant (an integer)
and verify_hostname expects either true or false. However, they are set
to nil after calling OpenSSL::SSL::SSLContext.new, which is surprising.

Set a proper value to them by default: verify_mode is set to
OpenSSL::SSL::VERIFY_NONE and verify_hostname is set to false by
default.

Note that this does not change the default behavior. The certificate
verification was never performed unless verify_mode is set to
OpenSSL::SSL::VERIFY_PEER by a user. The same applies to
verify_hostname.

https://github.com/ruby/openssl/commit/87d869352c
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 3b43e3fa10 [ruby/openssl] test/openssl/test_ssl: revise verify_mode test cases
Add explicit test cases for the behaviors with different verify_mode.
If we made a bug in verify_mode, we would notice it by failures of other
test cases, but there were no dedicated test cases for verify_mode.

https://github.com/ruby/openssl/commit/1ccdc05662
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 57a57e6e56 [ruby/openssl] test/openssl/test_ssl: revise a test case for client_cert_cb
The current test_client_auth_public_key test case checks that supplying
a PKey containing only public components through client_cert_cb will
cause handshake to fail. While this is a correct behavior as a whole,
the assertions are misleading in the sense that giving a public key is
causing the failure. Actually, the handshake fails because a client
certificate is not supplied at all, as a result of ArgumentError that is
silently ignored.

Rename the test case to test_client_cert_cb_ignore_error and simplify it
to clarify what it is testing.

https://github.com/ruby/openssl/commit/785b5569fc
2021-03-16 19:16:11 +09:00
Colton Jenkins c71afc9db7 [ruby/openssl] Add compare? method to OpenSSL::PKey that wraps EVP_PKEY_cmp.
Explicitly check for type given some conflicting statements within openssl's
documentation around EVP_PKEY_cmp and EVP_PKEY_ASN1_METHOD(3).
Add documentation with an example for compare?

https://github.com/ruby/openssl/commit/0bf51da6e2
2021-03-16 19:16:11 +09:00
Bart de Water da6341b709 [ruby/openssl] User lower case cipher names for maximum compatibility
We ran into some Linux-based systems not accepting the upper case variant

https://github.com/ruby/openssl/commit/7bc49121d5
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 13198d4968 [ruby/openssl] hmac: implement base64digest methods
OpenSSL::HMAC implements the similar interface as ::Digest. Let's add
base64digest methods to OpenSSL::HMAC, too, for feature parity.

https://github.com/ruby/openssl/commit/098bcb68af
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi baea36c955 [ruby/openssl] hmac: add a test case for OpenSSL::HMAC singleton methods
https://github.com/ruby/openssl/commit/8253d7c9ce
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi fde9f806cb [ruby/openssl] pkey/ec: deprecate OpenSSL::PKey::EC::Point#mul(ary, ary [, bn])
Deprecate it for future removal. However, I do not expect any
application is affected by this.

The other form of calling it, PKey::EC::Point#mul(bn [, bn]) remains
untouched.

PKey::EC::Point#mul calls EC_POINTs_mul(3) when multiple BNs
are given as an array. LibreSSL 2.8.0 released on 2018-08 removed the
feature and OpenSSL 3.0 which is planned to be released in 2020 will
also deprecate the function as there is no real use-case.

https://github.com/ruby/openssl/commit/812de4253d
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi fbadb01d6e [ruby/openssl] pkey: add PKey::PKey#derive
Add OpenSSL::PKey::PKey#derive as the wrapper for EVP_PKEY_CTX_derive().
This is useful for pkey types that we don't have dedicated classes, such
as X25519.

https://github.com/ruby/openssl/commit/28f0059bea
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi b2dc4880f5 [ruby/openssl] pkey: support 'one-shot' signing and verification
OpenSSL 1.1.1 added EVP_DigestSign() and EVP_DigestVerify() functions
to the interface. Some EVP_PKEY methods such as PureEdDSA algorithms
do not support the streaming mechanism and require us to use them.

https://github.com/ruby/openssl/commit/ae19454592
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 5cae289682 [ruby/openssl] pkey: port PKey::PKey#sign and #verify to the EVP_Digest* interface
Use EVP_DigestSign*() and EVP_DigestVerify*() interface instead of the
old EVP_Sign*() and EVP_Verify*() functions. They were added in OpenSSL
1.0.0.

Also, allow the digest to be specified as nil, as certain EVP_PKEY types
don't expect a digest algorithm.

https://github.com/ruby/openssl/commit/9ff6e5143b
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi 1e3590fe22 [ruby/openssl] pkey: add PKey.generate_parameters and .generate_key
Add two methods to create a PKey using the generic EVP interface. This
is useful for the PKey types we don't have a dedicated class.

https://github.com/ruby/openssl/commit/d8e8e57de9
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi d60ab95398 [ruby/openssl] test/openssl/test_ssl: fix flaky test case
Fix test_socket_open_with_local_address_port_context.

Often with MinGW, it seems EACCES is returned on bind when the port
number is unavailable. Ignore it just as we do for EADDRINUSE and
continue searching free port number.

Fixes: 98f8787b4687 ("test/openssl/test_ssl: fix random failure in
SSLSocket.open test", 2020-02-17)

https://github.com/ruby/openssl/commit/413b15526e
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi efad0166c6 [ruby/openssl] pkey: have PKey.read parse PEM-encoded DHParameter
Try PEM_read_bio_Parameters(). Only PEM format is supported at the
moment since corresponding d2i_* functions are not provided by OpenSSL.

https://github.com/ruby/openssl/commit/867e5c021b
2021-03-16 19:16:10 +09:00
Kazuki Yamaguchi 22aeb6373e [ruby/openssl] config: revert to C implementation of OpenSSL::Config
Revert OpenSSL::Config to using the OpenSSL API and remove our own
parser implementation for the config file syntax.

OpenSSL::Config now wraps a CONF object. Accessor methods deal with the
object directly rather than Ruby-level internal state.

This work is based on the old C code we used before 2010.

https://github.com/ruby/openssl/commit/c891e0ea89
2021-03-16 19:16:10 +09:00
Kazuki Yamaguchi 7c13d2b3cc [ruby/openssl] test/openssl/test_config: skip test_get_value_ENV on LibreSSL
LibreSSL has removed the feature to map environment variables onto the
"ENV" section.

https://github.com/ruby/openssl/commit/b70817faec
2021-03-16 19:16:10 +09:00