Commit graph

8776 commits

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

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.

e0b4c56956
2021-07-18 17:44:50 +09:00
Kazuki Yamaguchi
436aecb520 [ruby/openssl] pkey: remove unused ossl_generate_cb_2() helper function
The previous series of commits re-implemented key generation with the
low level API with the EVP API. The BN_GENCB-based callback function is
no longer used.

81027b7463
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.

1800a8d5eb
2021-07-18 17:44:49 +09:00
Kazuki Yamaguchi
b8dcf9c8fd [ruby/openssl] pkey/rsa: use high level EVP interface to generate parameters and keys
Implement PKey::RSA.new(size, exponent) and PKey::RSA.generate using
OpenSSL::PKey.generate_key instead of the low level RSA functions.

363fd10713
2021-07-18 17:44:48 +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.

c2e9b16f0b
2021-07-18 17:44:47 +09:00
Kazuki Yamaguchi
595644e4f6 [ruby/openssl] pkey: fix interrupt handling in OpenSSL::PKey.generate_key
rb_thread_call_without_gvl() can be interrupted, but it may be able to
resume the operation. Call rb_thread_check_ints() to see if it raises
an exception or not.

88b90fb856
2021-07-18 17:44:46 +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().

faf85d7c1d
2021-07-18 17:44:46 +09:00
Kazuki Yamaguchi
e2014d0354 [ruby/openssl] pkey: prepare pkey_ctx_apply_options() for usage by other operations
The routine to apply Hash to EVP_PKEY_CTX_ctrl_str() is currently used
by key generation, but it is useful for other operations too. Let's
change it to a slightly more generic name.

b2b77527fd
2021-07-18 17:44:45 +09:00
Kazuki Yamaguchi
1706302be5 [ruby/openssl] pkey: fix potential memory leak in PKey#sign
Fix potential leak of EVP_MD_CTX object in an error path. This path is
normally unreachable, since the size of a signature generated by any
supported algorithms would not be larger than LONG_MAX.

99e8630518
2021-07-18 17:44:44 +09:00
Kazuki Yamaguchi
b7a908af34 [ruby/openssl] ossl.c: do not set locking callbacks on LibreSSL
Similarly to OpenSSL >= 1.1.0, LibreSSL 2.9.0 ensures thread safety
without requiring applications to set locking callbacks and made
related functions no-op.

7276233e1a
2021-07-18 17:44:43 +09:00
Kazuki Yamaguchi
88d64418dd [ruby/openssl] ssl: use TLS_method() instead of SSLv23_method() for LibreSSL
LibreSSL 2.2.2 introduced TLS_method(), but with different semantics
from OpenSSL: TLS_method() enabled TLS >= 1.0 while SSLv23_method()
enabled all available versions, which included SSL 3.0 in addition.

However, LibreSSL 2.3.0 removed SSL 3.0 support completely and now
TLS_method() and SSLv23_method() are equivalent.

3b7d7045b8
2021-07-18 17:44:43 +09:00
Kazuki Yamaguchi
50332c4071 [ruby/openssl] ssl: call SSL_CTX_set_ecdh_auto() on OpenSSL 1.0.2 only
SSL_CTX_set_ecdh_auto() exists in OpenSSL 1.1.0 and LibreSSL 2.6.1, but
it is made no-op and the automatic curve selection cannot be disabled.
Wrap it with ifdef to make it clear that it is safe to remove it
completely when we drop support for OpenSSL 1.0.2.

2ae8f21234
2021-07-18 17:44:42 +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.

c055938f4b
2021-07-18 17:44:41 +09:00
Kazuki Yamaguchi
decce40da7 [ruby/openssl] bn: update documentation of OpenSSL::BN#initialize and #to_s
Clarify that BN.new(str, 2) and bn.to_s(2) handles binary string in
big-endian, and the sign of the bignum is ignored.

Reference: https://github.com/ruby/openssl/issues/431

6fae2bd612
2021-07-18 17:44:40 +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

0321b1e945
2021-07-18 17:44:39 +09:00
Kenta Murata
67897762cf
[ruby/fiddle] Add Fiddle::Handle#file_name (https://github.com/ruby/fiddle/pull/88)
4ee1c6fc4b
2021-07-14 18:56:00 +09:00
Nobuyoshi Nakada
169529a0c0
[ruby/fiddle] Check HAVE_RUBY_MEMORY_VIEW_H rather than API version (https://github.com/ruby/fiddle/pull/86)
c5abcc3a7e
2021-07-14 18:55:59 +09:00
Kenta Murata
818c74b7f4 [ruby/fiddle] Return the module handle value in Fiddle::Handle#to_i and add FIddle::Handle#to_ptr (https://github.com/ruby/fiddle/pull/87)
170111a0cb
2021-07-14 18:43:32 +09:00
Nobuyoshi Nakada
cb955dc9ac
[ruby/fiddle] update dependencies 2021-07-13 21:34:28 +09:00
Nobuyoshi Nakada
40d45ab093
[ruby/fiddle] Check HAVE_RUBY_MEMORY_VIEW_H rather than API version
93f9564446
2021-07-13 20:36:45 +09:00
Nobuyoshi Nakada
472d8c5555
[ruby/fiddle] Update required_ruby_version (https://github.com/ruby/fiddle/pull/85)
Drop supports for old versions, keeping 2.5 as CI supports it for
now.

90634e7c55
2021-07-13 19:37:46 +09:00
Sutou Kouhei
bb868f4814
[ruby/fiddle] Use have_header and have_type to detect memory view availability
Fix https://github.com/ruby/fiddle/pull/84

It may detect ruby/memory_view.h for system Ruby that is installed in
/usr.

We can use RUBY_API_VERSION_MAJOR to detect memory view availability
because memory view is available since Ruby 3.0.

Reported by Jun Aruga. Thanks!!!

3292929830
2021-07-13 19:37:46 +09:00
Aaron Patterson
5c0d8c6369
[ruby/fiddle] Add "offsetof" to Struct classes (https://github.com/ruby/fiddle/pull/83)
* Add "offsetof" to Struct classes

I need to get the offset of a member inside a struct without allocating
the struct.  This patch adds an "offsetof" class method to structs that
are generated.

The usage is like this:

```ruby
MyStruct = struct [
  "int64_t i",
  "char c",
]

MyStruct.offsetof("i") # => 0
MyStruct.offsetof("c") # => 8
```

* Update test/fiddle/test_c_struct_builder.rb

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>

4e3b60c5b6

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
2021-07-13 19:37:46 +09:00
Sutou Kouhei
a2c9e1b58a
[ruby/fiddle] Bump version
049138b4b8
2021-07-13 19:37:46 +09:00
Sutou Kouhei
70b0318646
[ruby/fiddle] MemoryView: ensure reset rb_memory_view_t::obj on error
0ed39345fe
2021-07-13 19:37:46 +09:00
Sutou Kouhei
9f86e50e1e
[ruby/fiddle] StringValuePtr may change the val
bddca7c895
2021-07-13 19:37:45 +09:00
Sutou Kouhei
10e26cfa76
[ruby/fiddle] Add MemoryView.export and MemoryView#release (https://github.com/ruby/fiddle/pull/80)
fix https://github.com/ruby/fiddle/pull/79

Users can release memory views explicitly before process exit.

Reported by xtkoba. Thanks!!!

1de64b7e76
2021-07-13 19:37:45 +09:00
Sutou Kouhei
9988f6ac4e
[ruby/fiddle] Add Fiddle::MemoryView#to_s (https://github.com/ruby/fiddle/pull/78)
Fix https://github.com/ruby/fiddle/pull/74

Reported by dsisnero. Thanks!!!
2021-07-13 19:37:45 +09:00
Sutou Kouhei
d1eeb9fec9
[ruby/fiddle] windows: use GetLastError() for win32_last_error
Ruby: [Bug #11579]

Patch by cremno phobia. Thanks!!!

760a8f9b14
2021-07-13 19:37:45 +09:00
Sutou Kouhei
c0f9191ab6
[ruby/fiddle] Bump version
3784cfeec4
2021-07-13 19:37:44 +09:00
Samuel Williams
028441d22f Avoid calling fstat on things we already know are valid sockets. 2021-07-12 19:16:22 +12:00
Nobuyoshi Nakada
c2ed5ab08b [ruby/date] Fixed markups for bold [ci skip]
404f9d2096
2021-07-11 20:28:23 +09:00
Jeremy Evans
8065670cfb [ruby/date] Fix comparison with Float::INFINITY
Fixes [Bug #17945]

953d907238
2021-07-11 20:28:21 +09:00
Nobuyoshi Nakada
fbe9b691bd
Added missing declarations in readline.h bundled with macOS 10.13 2021-07-09 08:52:35 +09:00
Nobuyoshi Nakada
771f6dd75d
[ruby/stringio] Suppress a sign-compare warning
a88c070e0b
2021-07-08 16:43:22 +09:00
Nobuyoshi Nakada
eecc4570cd
Found library is not usable if the header is not found 2021-07-06 01:17:38 +09:00
Nobuyoshi Nakada
1dfe75b0be
Fixed 'maybe_unused' attribute
```
../../../src/ext/bigdecimal/bigdecimal.c:303:5: error: 'maybe_unused' attribute cannot be applied to types
    ENTER(1);
    ^
```
2021-07-06 01:13:54 +09:00
Nobuyoshi Nakada
6d8422659a
Fix linking bundled zlib
* Prefix "./" to the import library name to expanded when static
  linking exts.

* Copy zlib shared library to the top build directory.
2021-07-03 12:52:46 +09:00
Samuel Williams
5e75280c8e Add basic test for updated IO wait functions. 2021-06-29 23:54:41 +12:00
Nobuyoshi Nakada
391abc543c
Scan the coderange in the given encoding 2021-06-26 16:05:15 +09:00
Nobuyoshi Nakada
fd7023a87e
Convert ssize_t properly 2021-06-23 10:09:25 +09:00
Samuel Williams
45e65f302b Deprecate and rework old (fd) centric functions. 2021-06-22 22:48:57 +12:00
Samuel Williams
3deb5d7113 Direct io for accept, send, sendmsg, recvfrom, and related methods. 2021-06-22 22:17:53 +12:00
aycabta
6a48f62c51 [ruby/readline-ext] Version 0.1.2
8541aaccb5
2021-06-22 11:06:00 +09:00
Nobuyoshi Nakada
626427c2e0
Removed no longer used variables 2021-06-14 14:11:38 +09:00
Samuel Williams
2792acc8f2
Add scheduler hook Addrinfo.getaddrinfo. (#4375)
Co-authored-by: Bruno Sutic <code@brunosutic.com>
2021-06-14 16:21:08 +12:00
Nobuyoshi Nakada
32b18fe9d0
Suppress array-parameter warnings by gcc 11 2021-06-13 15:12:45 +09:00
Nobuyoshi Nakada
122ce52e8f
Check if alternative malloc header can work in C++
jemalloc (5.2.1 at least) cannot compile in C++ on macOS SDK, due
to conflicts on exception specification.
2021-06-13 15:12:45 +09:00
Hiroshi SHIBATA
85b94144f2
[ruby/psych] Bump version to 4.0.1
4049939006
2021-06-07 19:15:14 +09:00