Commit graph

1056 commits

Author SHA1 Message Date
Samuel Williams
98f500d095
[ruby/openssl] Remove usage of IO internals. 2023-05-29 22:01:58 +09:00
Jun Aruga
b26ddfd72f [ruby/openssl] Fix warnings about the OPENSSL_FIPS macro in OpenSSL 1.1.
The commit <c5b2bc1268> made the warnings below
in the case of OpenSSL 1.1 where the `OPENSSL_FIPS` macro is not defined.

```
$ bundle install --standalone

$ bundle exec rake compile -- \
  --with-openssl-dir=$HOME/.local/openssl-1.1.1t-debug \
  --with-cflags="-Wundef"
mkdir -p tmp/x86_64-linux/openssl/3.2.1
cd tmp/x86_64-linux/openssl/3.2.1
/usr/local/ruby-3.2.1/bin/ruby -I. -r.rake-compiler-siteconf.rb ../../../../ext/openssl/extconf.rb -- --with-openssl-dir=/home/jaruga/.local/openssl-1.1.1t-debug --with-cflags=-Wundef
...
gcc -I. -I/usr/local/ruby-3.2.1/include/ruby-3.2.0/x86_64-linux -I/usr/local/ruby-3.2.1/include/ruby-3.2.0/ruby/backward -I/usr/local/ruby-3.2.1/include/ruby-3.2.0 -I../../../../ext/openssl -DRUBY_EXTCONF_H=\"extconf.h\" -I/home/jaruga/.local/openssl-1.1.1t-debug/include    -fPIC -Wundef  -o ossl.o -c ../../../../ext/openssl/ossl.c
../../../../ext/openssl/ossl.c: In function ‘ossl_fips_mode_get’:
../../../../ext/openssl/ossl.c:425:7: warning: "OPENSSL_FIPS" is not defined, evaluates to 0 [-Wundef]
  425 | #elif OPENSSL_FIPS
      |       ^~~~~~~~~~~~
../../../../ext/openssl/ossl.c: In function ‘ossl_fips_mode_set’:
../../../../ext/openssl/ossl.c:460:7: warning: "OPENSSL_FIPS" is not defined, evaluates to 0 [-Wundef]
  460 | #elif OPENSSL_FIPS
      |       ^~~~~~~~~~~~
../../../../ext/openssl/ossl.c: In function ‘Init_openssl’:
../../../../ext/openssl/ossl.c:1218:7: warning: "OPENSSL_FIPS" is not defined, evaluates to 0 [-Wundef]
 1218 | #elif OPENSSL_FIPS
      |       ^~~~~~~~~~~~
...
cp tmp/x86_64-linux/openssl/3.2.1/openssl.so tmp/x86_64-linux/stage/lib/openssl.so
```

b4228cbcd6
2023-05-19 09:25:11 +09:00
Jun Aruga
678d41bc51 [ruby/openssl] Implement FIPS functions on OpenSSL 3.
This commit is to implement the `OpenSSL::OPENSSL_FIPS`, `ossl_fips_mode_get`
and `ossl_fips_mode_set` to pass the test `test/openssl/test_fips.rb`.

It seems that the `OPENSSL_FIPS` macro is not used on the FIPS mode case any
more, and some FIPS related APIs also were removed in OpenSSL 3.

See the document <https://github.com/openssl/openssl/blob/master/doc/man7/migration_guide.pod#removed-fips_mode-and-fips_mode_set>
the section OPENSSL 3.0 > Main Changes from OpenSSL 1.1.1 >
Other notable deprecations and changes - Removed FIPS_mode() and FIPS_mode_set() .

The `OpenSSL::OPENSSL_FIPS` returns always true in OpenSSL 3 because the used
functions `EVP_default_properties_enable_fips` and `EVP_default_properties_is_fips_enabled`
works with the OpenSSL installed without FIPS option.

The `TEST_RUBY_OPENSSL_FIPS_ENABLED` is set on the FIPS mode case on the CI.
Because I want to test that the `OpenSSL.fips_mode` returns the `true` or
'false' surely in the CI. You can test the FIPS mode case by setting
`TEST_RUBY_OPENSSL_FIPS_ENABLED` on local too. Right now I don't find a better
way to get the status of the FIPS mode enabled or disabled for this purpose. I
am afraid of the possibility that the FIPS test case is unintentionally skipped.

I also replaced the ambiguous "returns" with "should return" in the tests.

c5b2bc1268
2023-05-19 09:25:10 +09:00
Nobuyoshi Nakada
75a2dff0e0 [ruby/openssl] Register global variables before assignment
98099d3796
2023-04-07 12:09:08 +09:00
Matt Valentine-House
5e4b80177e Update the depend files 2023-02-28 09:09:00 -08:00
Matt Valentine-House
f38c6552f9 Remove intern/gc.h from Make deps 2023-02-27 10:11:56 -08:00
Charles Oliver Nutter
b572f2436c
[ruby/openssl] Stub gemspec for JRuby
JRuby has its own implementation of the `openssl` library in
jruby-openssl. The simplest way for us to allow users to set
openssl as a gem dependency is to ship a stub gem that just
depends on jruby-openssl. This patch adds that to the gemspec.
Additional work may be required to fit this stub gem into the test
and release process.

See #20 for more details.

74ccaa5e18
2023-02-21 19:50:49 +09:00
Nobuyoshi Nakada
899ea35035
Extract include/ruby/internal/attr/packed_struct.h
Split `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED` macros into the
macros bellow:
* `RBIMPL_ATTR_PACKED_STRUCT_BEGIN`
* `RBIMPL_ATTR_PACKED_STRUCT_END`
* `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_BEGIN`
* `RBIMPL_ATTR_PACKED_STRUCT_UNALIGNED_END`
2023-02-08 12:34:13 +09:00
Mau Magnaguagno
5b67c15cd8
[ruby/openssl] [DOC] Remove repeated example from Digest
5a36cc3cb2
2023-01-31 13:14:06 +09:00
Hiroshi SHIBATA
cd6c7613f3
Apply the accidental commits again before Ruby 3.2.
Reverts the following commits:

  eb8d4d7b51
  edb83dc3a2
  d40064d184
2022-12-26 12:07:42 +09:00
Hiroshi SHIBATA
edb83dc3a2
Revert the additional change from openssl-3.1.0
Revert "[ruby/openssl] pkey/ec: constify"

  This reverts commit d2cd903c85.
2022-12-23 19:37:24 +09:00
Nobuyoshi Nakada
d2cd903c85 [ruby/openssl] pkey/ec: constify
6fb3499a7b
2022-12-23 11:42:15 +09:00
Kazuki Yamaguchi
2d2baaf2f4 [ruby/openssl] Ruby/OpenSSL 3.1.0
c2f7d775c6
2022-12-23 09:39:15 +09:00
Kazuki Yamaguchi
a778305919 [ruby/openssl] Ruby/OpenSSL 3.0.2
48b79333e0
2022-12-23 09:39:15 +09:00
Kazuki Yamaguchi
046aadb89b [ruby/openssl] Ruby/OpenSSL 2.2.3
04acccd692
2022-12-23 09:39:15 +09:00
Joe Truba
0e11d2c3f8 [ruby/openssl] pkey/ec: check private key validity with OpenSSL 3
The behavior of EVP_PKEY_public_check changed between OpenSSL 1.1.1
and 3.0 so that it no longer validates the private key. Instead, private
keys can be validated through EVP_PKEY_private_check and
EVP_PKEY_pairwise_check.

[ky: simplified condition to use either EVP_PKEY_check() or
EVP_PKEY_public_check().]

e38a63ab3d
2022-12-23 09:39:15 +09:00
Yuta Saito
782777a803 [ruby/openssl] Undefine OpenSSL::SSL for no socket platforms
This fixes a linkage error about `ossl_ssl_type` on platforms which do
not have socket, like WASI.

Even before this patch, some items are disabled under `OPENSSL_NO_SOCK` since
ee22fad45d
However, due to some new use of OpenSSL::SSL::Socket over the past few years,
the build under `OPENSSL_NO_SOCK` had been broken.

This patch guards whole `OpenSSL::SSL` items by `OPENSSL_NO_SOCK`.

[ky: adjusted to apply on top of my previous commit that removed the
OpenSSL::ExtConfig, and added a guard to lib/openssl/ssl.rb.]

b0cfac6a96
2022-12-23 09:39:15 +09:00
Kazuki Yamaguchi
e6ca644329 [ruby/openssl] ssl: remove OpenSSL::ExtConfig
This module was introduced in 2015 for internal use within this library.
Neither of the two constants in it is used anymore. I don't think we
will be adding a new constant in the foreseeable future, either.

OPENSSL_NO_SOCK is unused since commit 998d66712a (r55191).
HAVE_TLSEXT_HOST_NAME is unused since commit 4eb4b3297a.

eed3894bda
2022-12-23 09:39:15 +09:00
Kazuki Yamaguchi
dd6f3276e0 [ruby/openssl] ssl: disable NPN support on LibreSSL
As noted in commit a2ed156cc9 ("test/test_ssl: do not run NPN tests
for LibreSSL >= 2.6.1", 2017-08-13), NPN is known not to work properly
on LibreSSL.

Disable NPN support on LibreSSL, whether OPENSSL_NO_NEXTPROTONEG is
defined or not.

NPN is less relevant today anyway. Let's also silence test suite when
it's not available.

289f6e0e1f
2022-12-23 09:39:15 +09:00
Kazuki Yamaguchi
d6c16dd3e6 [ruby/openssl] ssl: update TLS1_3_VERSION workaround for older LibreSSL versions
The macro is now defined by default in LibreSSL 3.4+. Let's document it
for future readers.

935698e9f9
2022-12-23 09:39:15 +09:00
Nobuyoshi Nakada
6df4d272c3 [ruby/openssl] Suppress deprecation warnings by OpenSSL 3
91657a7924
2022-12-23 09:39:15 +09:00
Nobuyoshi Nakada
d7d1bb3e87 [ruby/openssl] Constify when building with OpenSSL 3
c0023822fe
2022-12-23 09:39:15 +09:00
Nobuyoshi Nakada
2bc7eac822 [ruby/openssl] Check for functions with arguments
b67aaf925d
2022-12-23 09:39:14 +09:00
Joe Truba
ca7a6b1553 [ruby/openssl] pkey/ec: fix ossl_raise() calls using cEC_POINT instead of eEC_POINT
b2e9f5e132
2022-12-23 09:39:14 +09:00
Joe Truba
13137236dc [ruby/openssl] raise when EC_POINT_cmp or EC_GROUP_cmp error instead of returning true
e1e8f3cebe
2022-12-23 09:39:14 +09:00
Nobuyoshi Nakada
99d0a257af [ruby/openssl] [DOC] Remove duplicate doc
RDoc does not consider preprocessor conditionals, but equally uses
both documents of `#if` and `#else` sides.

ea0a112a0c
2022-12-13 19:55:18 +09:00
Hiroshi SHIBATA
3de7ff8eb9
We should apply https://github.com/ruby/openssl/pull/576 instead of them:
6d8f396f37
  c8b3bd45cc
2022-12-13 18:07:41 +09:00
Henrique Bontempo
2be03fb5b0
[ruby/openssl] Fixes OPENSSL_LIBRARY_VERSION description on
documentation
(https://github.com/ruby/openssl/pull/559)

Adds back missing constant description on the documentation.
2022-12-13 18:07:41 +09:00
Theo Buehler
8ab8c2d601
[ruby/openssl] Enable HKDF support for LibreSSL 3.6 and later
LibreSSL 3.6 added support for HKDF in EVP. Enable this in ossl_kdf.c.

9bdd39a7e2
2022-12-13 18:07:41 +09:00
Yusuke Nakamura
d4dce27d89
[ruby/openssl] Allow empty string to OpenSSL::Cipher#update
For some reasons, plaintext may be empty string.

ref https://www.rfc-editor.org/rfc/rfc9001.html#section-5.8

953592a29e
2022-12-13 18:07:41 +09:00
Theo Buehler
d92f4fe4d7
[ruby/openssl] Use EVP_Digest{Sign,Verify} when available
LibreSSL 3.4 added EVP_DigestSign() and EVP_DigestVerify(). Use them
when available to prepare for the addition of Ed25519 support in
LibreSSL 3.7.

475b2bf766
2022-12-13 18:07:41 +09:00
Ben Toews
7db29de008 [ruby/openssl] add document-method for BN#mod_inverse
5befde7519
2022-10-17 23:38:35 +09:00
Ben Toews
149cb049f1 [ruby/openssl] add BN#mod_sqrt
4619ab3e76
2022-10-17 23:38:34 +09:00
Ben Toews
e037731c9f [ruby/openssl] define BIGNUM_2cr macro for BN function that takes context and
returns a BN

4d0971c51c
2022-10-17 23:38:34 +09:00
Bart de Water
6166fa612c [ruby/openssl] Call out insecure PKCS #1 v1.5 default padding for RSA
fd5eaa6dfc
2022-10-17 16:35:35 +09:00
Samuel Williams
aecc470a33 [ruby/openssl] Use default IO#timeout if possible.
471340f612
2022-10-17 16:35:35 +09:00
Christophe De La Fuente
17998ad3bb [ruby/openssl] Add support to SSL_CTX_set_keylog_callback
- This callback is invoked when TLS key material is generated or
  received, in order to allow applications to store this keying material
  for debugging purposes.
- It is invoked with an `SSLSocket` and a string containing the key
  material in the format used by NSS for its SSLKEYLOGFILE debugging
  output.
- This commit adds the Ruby binding `keylog_cb` and the related tests
- It is only compatible with OpenSSL >= 1.1.1. Even if LibreSSL implements
  `SSL_CTX_set_keylog_callback()` from v3.4.2, it does nothing (see
  648d39f0f0)

3b63232cf1
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
e4b1627983 [ruby/openssl] ssl: fix "warning: ‘ctx’ may be used uninitialized"
The code was introduced by 65530b887e ("ssl: enable generating keying
material from SSL sessions", 2022-08-03).

This is harmless, but we should avoid it.

f5b82e814b
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
04bf83d6f7 [ruby/openssl] bump version number to 3.1.0.pre
fceb978a5d
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
cd83f5b961 [ruby/openssl] Ruby/OpenSSL 3.0.1
e5bbd015dc
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
15a966a674 [ruby/openssl] Ruby/OpenSSL 2.2.2
de8a644bc4
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
33d30a8675 [ruby/openssl] Ruby/OpenSSL 2.1.4
5316241e61
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
b69d41e1c4 [ruby/openssl] pkey/ec: check existence of public key component before exporting
i2d_PUBKEY_bio() against an EC_KEY without the public key component
trggers a null dereference.

This is a regression introduced by commit 56f0d34d63 ("pkey:
refactor #export/#to_pem and #to_der", 2017-06-14).

Fixes https://github.com/ruby/openssl/pull/527#issuecomment-1220504524
Fixes https://github.com/ruby/openssl/issues/369#issuecomment-1221554057

f6ee0fa4de
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
0677b2fb87 [ruby/openssl] pkey: restore support for decoding "openssl ecparam -genkey" output
Scan through the input for a private key, then fallback to generic
decoder.

OpenSSL 3.0's OSSL_DECODER supports encoded key parameters. The PEM
header "-----BEGIN EC PARAMETERS-----" is used by one of such encoding
formats. While this is useful for OpenSSL::PKey::PKey, an edge case has
been discovered.

The openssl CLI command line "openssl ecparam -genkey" prints two PEM
blocks in a row, one for EC parameters and another for the private key.
Feeding the whole output into OSSL_DECODER results in only the first PEM
block, the key parameters, being decoded. Previously, ruby/openssl did
not support decoding key parameters and it would decode the private key
PEM block instead.

While the new behavior is technically correct, "openssl ecparam -genkey"
is so widely used that ruby/openssl does not want to break existing
applications.

Fixes https://github.com/ruby/openssl/pull/535

d486c82833
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
4fb2845c7b [ruby/openssl] pkey: clear error queue before each OSSL_DECODER_from_bio() call
Fix potential error queue leak.

3992b6f208
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
10f93a8bd7 [ruby/openssl] pkey/dsa: let PKey::DSA.generate choose appropriate q size
DSA parameters generation via EVP_PKEY_paramgen() will not automatically
adjust the size of q value but uses 224 bits by default unless specified
explicitly. This behavior is different from the now-deprecated
DSA_generate_parameters_ex(), which PKey::DSA.generate used to call.

Fixes https://github.com/ruby/openssl/issues/483

Fixes: 1800a8d5eb ("pkey/dsa: use high level EVP interface to generate parameters and keys", 2020-05-17)

0105975a0b
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
65bba0ef6f [ruby/openssl] hmac: use EVP_PKEY_new_raw_private_key() if available
Current OpenSSL 3.0.x release has a regression with zero-length MAC
keys. While this issue should be fixed in a future release of OpenSSL,
we can use EVP_PKEY_new_raw_private_key() in place of the problematic
EVP_PKEY_new_mac_key() to avoid the issue. OpenSSL 3.0's man page
recommends using it regardless:

> EVP_PKEY_new_mac_key() works in the same way as
> EVP_PKEY_new_raw_private_key().  New applications should use
> EVP_PKEY_new_raw_private_key() instead.

Fixes https://github.com/ruby/openssl/issues/369#issuecomment-1224912710

4293f18b1f
2022-10-17 16:35:35 +09:00
Kazuki Yamaguchi
bee383d9fe [ruby/openssl] x509*: fix error queue leak in #extensions= and #attributes= methods
X509at_delete_attr() in OpenSSL master puts an error queue entry if
there is no attribute left to delete. We must either clear the error
queue, or try not to call it when the list is already empty.

a0c878481f
2022-10-17 16:35:35 +09:00
madblobfish
79543b9a53 [ruby/openssl] ssl: enable generating keying material from SSL sessions
Add OpenSSL::SSL::SSLSocket#export_keying_material to support RFC 5705

65530b887e
2022-10-17 16:35:35 +09:00
Nobuhiro IMAI
a98096349e [ruby/openssl] Check if the option is an Hash in pkey_ctx_apply_options0()
causes SEGV if it is an Array or something like that.

ef23525210
2022-10-17 16:35:35 +09:00