Commit graph

14230 commits

Author SHA1 Message Date
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.

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.

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.

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.

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.

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?

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

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.

098bcb68af
2021-03-16 19:16:11 +09:00
Kazuki Yamaguchi
baea36c955 [ruby/openssl] hmac: add a test case for OpenSSL::HMAC singleton methods
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.

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.

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.

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.

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.

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)

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.

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.

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.

b70817faec
2021-03-16 19:16:10 +09:00
Kazuki Yamaguchi
0c66784602 [ruby/openssl] test/openssl/test_config: fix non-deterministic test case
Sort keys of a section before comparing. The ordering is not part of the
API. This can cause a test failure if we use OpenSSL's C implementation.

Fixes: 2ad65b5f673f ("config: support .include directive", 2018-08-16)

259e6fd2dc
2021-03-16 19:16:10 +09:00
Kazuki Yamaguchi
ffc01afc47 [ruby/openssl] test/openssl/test_config: add missing test case for Config.parse_config
9ce2ccf36d
2021-03-16 19:16:10 +09:00
Kazuki Yamaguchi
67f5847c61 [ruby/openssl] config: remove deprecated methods
Remove 4 deprecated methods.

The following two methods have been marked as deprecated since 2003,
by r4531 (ruby.git commit 78ff3833fb).

 - OpenSSL::Config#value
 - OpenSSL::Config#section

Other two methods are removed because the corresponding functions
disappeared in OpenSSL 1.1.0.

 - OpenSSL::Config#add_value
 - OpenSSL::Config#[]=

9783d7f21c
2021-03-16 19:16:10 +09:00
Spencer McIntyre
4d8bce227c [ruby/openssl] Define Cipher #ccm_data_len= for CCM mode ciphers
Allow specifying just length to #update

CCM mode ciphers need to specify the total plaintext or ciphertext
length to EVP_CipherUpdate.

Update the link to the tests file

Define Cipher#ccm_data_len= for CCM mode ciphers

Add a unit test for CCM mode

Also check CCM is authenticated when testing

bb3816953b
2021-03-16 19:16:10 +09:00
aycabta
61a29a41e1 [ruby/rdoc] Allow empty .rdoc_options
0c8cb25b50
2021-03-16 15:47:27 +09:00
aycabta
971a0cd246 [ruby/rdoc] Allow partial default values to be overridden with .rdoc_options
e14800891f
2021-03-16 15:47:27 +09:00
Nobuyoshi Nakada
de8e6218a3 [ruby/rdoc] Fixed CodeFence without blank lines
Currently a fenced code block needs a preceding blank line, it
should not be required, as:
https://github.github.com/gfm/#fenced-code-blocks
> A fenced code block may interrupt a paragraph, and does not
> require a blank line either before or after.

Just recommended:
https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks
> We recommend placing a blank line before and after code blocks
> to make the raw formatting easier to read.

0e1776caf3
2021-03-16 15:47:27 +09:00
Nobuyoshi Nakada
3651f678a7 [ruby/rdoc] Support GFM table
9dc933df16
2021-03-16 15:47:27 +09:00
Nobuyoshi Nakada
82b6f89283 File.dirname optional level
* file.c (rb_file_dirname_n): chomp N level of base names.
  [Feature #12194]
2021-03-15 15:09:05 +09:00
xtkoba (Tee KOBAYASHI)
0846c2da45
Check backref number buffer overrun [Bug #16376] 2021-03-15 10:17:50 +09:00
Jeremy Evans
aaab3b1de9 Fix integer/float remainder with infinity argument of opposite sign
Previously, the result was incorrect:

4.remainder(-Float::INFINITY)
Before: => NaN
After: => 4

4.2.remainder(-Float::INFINITY)
Before: => NaN
After: => 4.2

Fixes [Bug #6120]
2021-03-12 07:35:18 -08:00
Nobuyoshi Nakada
a6b5d70bca
Create the test file under the created temporary directory
Fixes https://github.com/ruby/ruby/pull/4255
2021-03-11 09:21:21 +09:00
Jeremy Evans
d9fea496af Remove cvar overtaken classes at end of test methods
Fixes issues when the same tests are executed more than once,
which some CI machines do.
2021-03-10 12:09:45 -08:00
eileencodes
cbc7c1c061 Add cvar overtaken tests
While working on another project we noticed that there were no tests for
the cvar overtaken exception when using classes. This change adds a test
for cvar overtaken with classes and moves the cvar overtaken test for
modules into the new file.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2021-03-10 09:40:00 -08:00
Yusuke Endoh
d10b535806 test/ruby/test_string.rb: make GitHub syntax-highlight correctly
It looks like GitHub syntax-highlighting does not support an empty
heredoc. This change adds a newline to make GitHub can handle the syntax
appropriately.

https://bugs.ruby-lang.org/issues/17662
2021-03-08 17:04:27 +09:00
Aditya Prakash
7de349bb49 [rubygems/rubygems] Remote test to check require
This test was triggering require of `rubygems/core_ext/tcpsocket_init`
which overrides TCPSocket.initialize globally. Requires don't get
reset between test runs and it was making other test unreliable.

Fixes timeout of test on ruby master

fdfe5c9691
2021-03-08 13:47:35 +09:00
David Rodríguez
53468cc111 Sync latest development version of bundler & rubygems 2021-03-08 13:47:35 +09:00
Nobuyoshi Nakada
32a13591e0
[ruby/stringio] Check if closed in loop
[Bug #17675] https://bugs.ruby-lang.org/issues/17675

1ed61d0cbc
2021-03-08 10:13:29 +09:00
Nobuyoshi Nakada
d0a05fd4b4
Fixed FD leaks 2021-03-08 10:08:40 +09:00
Hiroshi SHIBATA
c3c1800708
Prefer to use omit 2021-03-08 09:34:16 +09:00
Nobuyoshi Nakada
f6d5de8f33 [ruby/io-wait] Declare as Ractor-safe
Fixes https://bugs.ruby-lang.org/issues/17659

ba338b4764
2021-03-07 09:54:35 +09:00
Nobuyoshi Nakada
ef9bde6516 [ruby/io-wait] Refined uncommon device type tests
0c73ebcf5d
2021-03-07 09:54:35 +09:00
Jeremy Evans
68d028578a Undef Enumerator::Chain#{feed,next,next_values,peek,peek_values}
Previously these methods were defined but raised TypeError, which
seems worse.
2021-03-06 13:56:16 -08:00
Jeremy Evans
e1d16a9e56 Make Enumerator#{+,chain} create lazy chain if any included enumerator is lazy
Implements [Feature #17347]
2021-03-06 13:56:16 -08:00
Jeremy Evans
bf40fe9fed Fix calling enumerator methods such as with_index on Enumerator::Chain
This previously raised a TypeError.  Wrap the Enumerator::Chain in
an Enumerator to work around the problem.

Fixes [Bug #17216]
2021-03-06 13:56:16 -08:00
Jeremy Evans
14e1739ff3 [ruby/irb] Make save-history extension safe for concurrent use
This makes the save-history extension check for modifications to
the history file before saving it.  If the history file was modified
after the history was loaded and before it was saved, append only
the new history lines to the history file.

This can result in more lines in the history file than SAVE_HISTORY
allows.  However, that will be fixed the next time irb is run and
the history is saved.

Fixes [Bug #13654]

041ef53845
2021-03-06 00:18:32 +09:00
aycabta
182cde8dfb [ruby/irb] Add a test for not continuing when endless range at eol
1020ac9c65
2021-03-05 22:03:11 +09:00
Aaron Patterson
d45466dc5b
Oops! Add another test and fix to_proc implementation 2021-02-26 10:06:56 -08:00
Aaron Patterson
0590e9b677
Fiddle::Function responds to to_proc
This lets us cast a Fiddle::Function to a block, allowing is to write
things like:

```ruby
f = Fiddle::Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
define_method :strcpy, &f
```
2021-02-26 09:57:13 -08:00
Aaron Patterson
cfc23903df
Revert "Add tests for bug 17652"
This reverts commit a9920e7782.
2021-02-25 16:31:24 -08:00
Peter Zhu
a9920e7782 Add tests for bug 17652 2021-02-25 11:01:50 -08:00
Aaron Patterson
08d5db4064
Reverting PR #4221
It seems this breaks tests on Solaris, so I'm reverting it until we
figure out the right fix.

  20210224T210007Z.fail.html.gz
2021-02-24 13:44:10 -08:00