1312 Commits

Author SHA1 Message Date
Nobuyoshi Nakada
7d4461e162
[Misc #22206] Generate dependencies without compiler builds
Replace `tool/update-deps` with a Ruby source scanner so dependency
updates no longer require GNU make, a configured build, or compiler
preprocessor output.

Keep compact source mappings and scanner declarations in dependency
files, and expand complete rules into the build directory.  Avoid the
temporary fixture headers required by the compiler-driven prototype.

Use the generated rules from GNU make, BSD make, and NMake builds.
Support out-of-tree and read-only source trees, and retain expanded
dependencies shipped in release archives when baseruby is unavailable.
2026-07-23 00:04:47 +09:00
Kazuki Yamaguchi
3a23757843 [ruby/openssl] pkey: add OpenSSL::PKey::PKey#get_param
Expose EVP_PKEY_get_params(), added in OpenSSL 3.0, for retrieving
various parameters from an EVP_PKEY object.

https://github.com/ruby/openssl/commit/fbddeb74b0
2026-07-10 11:25:43 +00:00
Kazuki Yamaguchi
3169b4edc7 [ruby/openssl] ssl: sync SSL_OP constants with OpenSSL 4.0
https://github.com/ruby/openssl/commit/8adbb9adbc
2026-07-10 11:24:22 +00:00
Kazuki Yamaguchi
f5d2c075b6 [ruby/openssl] ssl: use uint64_t for SSL options
OpenSSL 3.0 changed the type of SSL options to uint64_t. Since OpenSSL
3.2 began using the 33rd bit, treating it as unsigned long is no longer
sufficient.

https://github.com/ruby/openssl/commit/743daa7ac9
2026-07-10 11:24:22 +00:00
Kazuki Yamaguchi
ccde9900f9 [ruby/openssl] ossl.h: add UINT64T2NUM(x)
https://github.com/ruby/openssl/commit/567be80127
2026-07-10 11:24:22 +00:00
Kazuki Yamaguchi
b32c5de5da [ruby/openssl] ns_spki: allocate OpenSSL objects in #initialize{,_copy}
https://github.com/ruby/openssl/commit/f9026106a3
2026-07-05 17:49:15 +00:00
Kazuki Yamaguchi
9d0a246e0a [ruby/openssl] pkcs7: allocate OpenSSL objects in #initialize{,_copy}
https://github.com/ruby/openssl/commit/6bb2810f59
2026-07-05 17:49:15 +00:00
Kazuki Yamaguchi
7bb18ed2bb [ruby/openssl] ts: allocate OpenSSL objects in #initialize{,_copy}
https://github.com/ruby/openssl/commit/4cbe86fd1e
2026-07-05 17:49:15 +00:00
Kazuki Yamaguchi
594e1e9eff [ruby/openssl] x509*: allocate OpenSSL objects in #initialize{,_copy}
https://github.com/ruby/openssl/commit/c70b060c3d
2026-07-05 17:49:15 +00:00
Kazuki Yamaguchi
24ed3e0ddd [ruby/openssl] pkcs12: allocate OpenSSL objects in #initialize{,_copy}
https://github.com/ruby/openssl/commit/1472feb74e
2026-07-05 17:49:15 +00:00
Kazuki Yamaguchi
62b4b3a9b0 [ruby/openssl] ocsp: allocate OpenSSL objects in #initialize{,_copy}
Allocate the underlying OpenSSL object in #initialize{,_copy} instead
of .allocate. Allocating an empty OpenSSL object in .allocate is
wasteful because #initialize{,_copy} cannot always reuse an existing
object and have to allocate a new one.

Some ruby/openssl classes already follow this approach, such as
OpenSSL::PKey::PKey. Let's standardize on it.

Also expand New*() and Set*() macros, which are only used once or twice
and are not very helpful for readability in my opinion.

https://github.com/ruby/openssl/commit/5f10428793
2026-07-05 17:49:15 +00:00
Kazuki Yamaguchi
d12337ccb4 [ruby/openssl] pkey, ssl, cipher, hpke: use ossl_want_uninitialized()
Simplify the code and raise exceptions with a consistent error message.

This unifies the exception type raised when #initialize is called twice
to TypeError. This should not affect valid usage of these classes.

https://github.com/ruby/openssl/commit/24f72a8350
2026-07-05 17:49:14 +00:00
Kazuki Yamaguchi
72be7924c1 [ruby/openssl] ossl.c: add helper function ossl_want_uninitialized()
https://github.com/ruby/openssl/commit/02872d3c8f
2026-07-05 17:49:14 +00:00
Kazuki Yamaguchi
a1c3f8101b [ruby/openssl] provider: fix potential memory leak in .load
Allocate the wrapper object before attempting to load the provider.

Also, expand macros NewProvider() and SetProvider(), which are only
used once and are unlikely to be reused in the future.

https://github.com/ruby/openssl/commit/f62cc13cfa
2026-07-05 17:49:14 +00:00
Kazuki Yamaguchi
b5ee8653e4 [ruby/openssl] Implement dcompact
We can implement this now that we require Ruby 2.7 or later.

The return value of OpenSSL's *_set_ex_data() functions is not checked
since replacing an existing index should not fail.

https://github.com/ruby/openssl/commit/98acd95e86
2026-07-05 10:40:31 +00:00
Nobuyoshi Nakada
b5c564c85d [ruby/openssl] Fix unused-but-set-global warnings in clang-23
https://github.com/ruby/openssl/commit/44bb2aa070
2026-06-25 09:00:51 +00:00
Kazuki Yamaguchi
b914f83054 [ruby/openssl] x509store: add X509::Store{,Context}#flags and #clear_flags
OpenSSL::X509::Store{,Context}#flags= does not clear existing flags.
Instead, it ORs new flags to the current set. This is contrary to
normal convention and likely unintentional, but changing the behavior
would not be acceptable for compatibility reasons.

Add #flags to get the current flags to allow users to explicitly express
the intention with "store.flags |= OpenSSL::X509::V_...".
Also, add #clear_flags to remove existing flags. The underlying OpenSSL
C APIs appear to have been added in a patch release of OpenSSL 0.9.8.

Warn in #flags= if the argument is not a superset of the existing flags.

https://github.com/ruby/openssl/commit/a245620e2e
2026-06-24 13:51:04 +00:00
Kazuki Yamaguchi
3082e00b61 [ruby/openssl] ssl: let SSLServer accept frozen SSLContext
Do not raise FrozenError in SSLServer.new when
SSLContext#session_id_context cannot be updated. session_id_context is
only necessary for session resumption, so its absence is not critical.

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

https://github.com/ruby/openssl/commit/51de9c303e
2026-06-24 13:35:43 +00:00
Kazuki Yamaguchi
9643b8335a [ruby/openssl] pkey: expand OSSL_3_const macro
OSSL_3_const was useful when supporting OpenSSL 1.0.2-3.x at the same
time. Since support for OpenSSL < 1.1.1 has been dropped, most uses can
simply be replaced with plain const.

https://github.com/ruby/openssl/commit/ce050d7740
2026-06-24 11:06:59 +00:00
Hiroshi SHIBATA
55ec9b91b5 [ruby/openssl] Remove version constraint for jruby-openssl
"~> 0.14" is equivalent to ">= 0.14, < 1". Since the openssl gem is an
empty stub on JRuby, there is no good reason to specify version bounds
on jruby-openssl.

[ky: commit message]

https://github.com/ruby/openssl/commit/3ffbe73aaa

Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
2026-06-22 17:42:39 +00:00
Adrien Rey-Jarthon
d54ab7bdd9 [ruby/openssl] x509crl: add OpenSSL::X509::CRL#by_serial for faster lookup of a single cert
https://github.com/ruby/openssl/commit/83f4a0db32
2026-06-22 17:23:39 +00:00
Bart de Water
c729c842d5 [ruby/openssl] Add EVP_PKEY KEM operations
https://github.com/ruby/openssl/commit/f2ec03dda1
2026-06-22 17:18:23 +00:00
Kazuki Yamaguchi
20e8c63fad Update ext/openssl/depend
Commit be5877d1539e2802743904662f532b2b8237ce1e added new source files.
2026-06-21 21:05:50 +09:00
Ryo Kajiwara
be5877d153 [ruby/openssl] Add Hybrid Public Key Encryption (HPKE) API Support
https://github.com/ruby/openssl/commit/6b80681cde
2026-06-21 11:59:34 +00:00
Nobuyoshi Nakada
a2b9d6ff3b [ruby/openssl] Constify pkey pointers
https://github.com/ruby/openssl/commit/9d74f60dea
2026-06-21 03:05:27 +00:00
Kazuki Yamaguchi
0765e35cba [ruby/openssl] asn1: limit nesting depth in OpenSSL::ASN1.decode
Feeding a deeply nested constructed encoding to OpenSSL::ASN1.decode,
.decode_all, or .traverse can cause unbounded recursion and result in
SystemStackError.

Add an explicit nesting depth limit of 200 levels and raise
OpenSSL::ASN1::ASN1Error if it is exceeded. This limit is arbitrary and
currently not configurable, but should be sufficient for any practical
use cases.

Fixes https://hackerone.com/reports/3662125

https://github.com/ruby/openssl/commit/fc753239cc
2026-05-30 09:03:21 +00:00
Kazuki Yamaguchi
861aed4f42 [ruby/openssl] kdf: document incompatibility with timeout
OpenSSL::KDF.pbkdf2_hmac and .scrypt are currently not interrupted by
Timeout.timeout because they make a single, slow OpenSSL function call
during which Ruby-level interrupts cannot be handled. Add advice against
using parameters from untrusted inputs.

https://github.com/ruby/openssl/commit/58c0b81a59
2026-05-29 13:07:47 +00:00
Kazuki Yamaguchi
f995e2266a [ruby/openssl] pkcs12: add missing error check for d2i_PKCS12_bio()
Also, avoid using the "reuse" behavior of d2i_*{,_bio}() functions.

https://github.com/ruby/openssl/commit/3f1a7a377c
2026-05-29 08:45:38 +00:00
Kazuki Yamaguchi
c3ddba2fc7 [ruby/openssl] ts: do not use the "reuse" behavior of d2i_*{,_bio}() functions
The man page discourages using this behavior because it may leave the
object in an inconsistent state on error paths. This fixes a potential
memory leak reported at <https://github.com/ruby/openssl/issues/1011>.

https://github.com/ruby/openssl/commit/01e5602581
2026-05-29 08:45:38 +00:00
Kazuki Yamaguchi
24df92edba [ruby/openssl] pkcs7: avoid using strcmp() with Ruby strings
We should not rely on the NUL terminator of Ruby strings. Use memcmp().

https://github.com/ruby/openssl/commit/0b35e1a810
2026-05-29 08:38:50 +00:00
Étienne Barrié
31c37abd06 [ruby/openssl] Make OpenSSL::Digest classes Ractor-safe
Use class_eval with a string so the initialize instance method, and the
digest and hexdigest class methods are not defined via define_method
with a Proc (which is not Ractor-safe).

https://github.com/ruby/openssl/commit/502bc6c378
2026-05-29 08:23:23 +00:00
USAMI Kenta
863c8656f1 [ruby/openssl] Document syswrite_nonblock opts and symbol return value
https://github.com/ruby/openssl/commit/6339db4386
2026-05-22 10:38:14 +00:00
Kazuki Yamaguchi
8247840443 [ruby/openssl] Merge branch 'maint-4.0'
* maint-4.0:
  Ruby/OpenSSL 4.0.2
  Ruby/OpenSSL 3.3.3
  Ruby/OpenSSL 3.2.4

https://github.com/ruby/openssl/commit/318be774d7

Kazuki Yamaguchi (6):
      Ruby/OpenSSL 3.2.4
      Merge branch 'maint-3.2' into maint-3.3
      Ruby/OpenSSL 3.3.3
      Merge branch 'maint-3.3' into maint-4.0
      Ruby/OpenSSL 4.0.2
      Merge branch 'maint-4.0'
2026-05-13 15:33:24 +00:00
Kazuki Yamaguchi
f1b2b6ba57 [ruby/openssl] ssl: refactor SSLSocket#{peer_,}finished_message
The variable-sized alloca makes me nervous, even though it turned out
to be safe: the Finished message is 36 bytes long in SSL 3.0 and is
usually smaller in newer protocol versions. However, the alloca is not
actually needed since we can simply write into the String's content.

While at it, update the rdoc comment to clarify the difference of the
two methods.

https://github.com/ruby/openssl/commit/2e74589683
2026-04-29 12:25:33 +00:00
ndossche
686b071ae2 [ruby/openssl] pkcs7: fix error check of PKCS7_SIGNER_INFO_set()
This function returns <=0 on error, not only 0.
This is evident by looking at the implementation where it can return a
negative error here [1]. Use in OpenSSL itself also uses the <=0 check [2].

[1] 087bddcda9/crypto/pkcs7/pk7_lib.c (L378-L381)
[2] 087bddcda9/crypto/pkcs7/pk7_lib.c (L414)

https://github.com/ruby/openssl/commit/ecfc1d04eb
2026-04-29 11:15:51 +00:00
ndossche
a130f137f9 [ruby/openssl] asn1: add error checks for ASN1_STRING_set() calls
Other calls in the project have such checks, add it consistently
everywhere to raise an exception in case of an error.

https://github.com/ruby/openssl/commit/ac48b6c8af
2026-04-29 11:08:56 +00:00
ndossche
e3fe84d222 [ruby/openssl] x509attr: use sk_ASN1_TYPE_new_reserve()
This should avoid reallocations and prevent the main error condition of
the push call.

https://github.com/ruby/openssl/commit/0966d0466e
2026-04-29 09:59:46 +00:00
ndossche
801fc08330 [ruby/openssl] x509attr: check for errors of sk_ASN1_TYPE_push()
This function returns 0 on error.

https://github.com/ruby/openssl/commit/8ca0afb30a
2026-04-29 09:59:45 +00:00
ndossche
a9cbdceb46 [ruby/openssl] cipher: fix error checks for EVP_CIPHER_CTX_ctrl()
The return value behaviour isn't explicitly documented for OpenSSL.
For LibreSSL, it says [1]:

> EVP_CIPHER_CTX_ctrl() returns 1 for success or 0 for failure.
> Some implementations may return negative values for some errors.

So it appears that we need to check for `<= 0` instead of `!0`.
Furthermore, I looked for how OpenSSL does this and found it also does
things inconsistently. I submitted a PR to check for `<= 0` which was
accepted [2].

[1] https://man.openbsd.org/EVP_CIPHER_CTX_ctrl.3
[2] https://github.com/openssl/openssl/pull/30923

https://github.com/ruby/openssl/commit/811f2ca57e
2026-04-29 09:56:18 +00:00
ndossche
1dcb7acbc6 [ruby/openssl] x509store, ssl: check for error of CRYPTO_set_ex_data()
This can technically fail because it internally performs allocations.
Also confirmed by the man page [1].

[1] (among other functions on this page) https://docs.openssl.org/3.5/man3/BIO_get_ex_new_index

https://github.com/ruby/openssl/commit/c0de3f5c83
2026-04-20 10:31:10 +00:00
ndossche
b4c8c8a6f0 [ruby/openssl] pkcs7: fix error check of PKCS7_RECIP_INFO_set()
This function actually returns a value <=0 on error, but it is not
documented as such.
Example from OpenSSL code [1] and implementation [2] indicate as such.

[1] 4b8ddae690/crypto/pkcs7/pk7_lib.c (L578)
[2] 4b8ddae690/crypto/pkcs7/pk7_lib.c (L625)

https://github.com/ruby/openssl/commit/e70a63fabe
2026-04-20 10:04:05 +00:00
ndossche
83b7a4d9a5 [ruby/openssl] x509cert: check for error of X509_set_serialNumber()
This function may return 0 on error [1].

[1] https://manpages.debian.org/stretch/libssl-doc/X509_set_serialNumber.3ssl.en.html

https://github.com/ruby/openssl/commit/c6caa4f1c1
2026-04-20 09:55:38 +00:00
ndossche
359f671f88 [ruby/openssl] x509name: check for error of X509_NAME_cmp()
These functions may return -2 to indicate an error according to the
manual [1]. This can also be confirmed when looking at the code as it
may call into i2d_X509_NAME() which can fail [2].
In such cases, the failure is reinterpreted as a "less than" comparison
and the error is not reported, potentially leading to wrong results in
userland code.

[1] https://manpages.opensuse.org/Tumbleweed/openssl-3-doc/X509_NAME_cmp.33ssl.en.html
[2] f023662d1b/crypto/x509/x509_cmp.c (L269-L271)

https://github.com/ruby/openssl/commit/08e5547b85
2026-04-20 09:44:36 +00:00
Nora Dossche
fb38a1c5dc [ruby/openssl] pkey: fix memory leak when derived key is too large
Unlikely to happen in practice, but mirrors other similar checks that
also free the context.

https://github.com/ruby/openssl/commit/fd28a16519
2026-04-17 16:56:12 +00:00
Kazuki Yamaguchi
7209523ffd [ruby/openssl] kdf: fix wrong OPENSSL_cleanse() calls
Embarrassingly, the previous commits introduced OPENSSL_cleanse() calls
against the temporary struct instead of the buffer content. Thanks to
nagachika for noticing.

https://github.com/ruby/openssl/commit/8eca3efad4
2026-04-08 13:00:08 +00:00
Kazuki Yamaguchi
a5c9e84055 [ruby/openssl] kdf: release GVL in OpenSSL::KDF.scrypt
scrypt is another password hashing algorithm, so releasing the GVL is
useful.

https://github.com/ruby/openssl/commit/dd2f6ba892
2026-04-08 11:08:25 +00:00
Kazuki Yamaguchi
5c7e3c202a [ruby/openssl] kdf: release GVL in OpenSSL::KDF.pbkdf2_hmac
Since PBKDF2 runs single-threaded and is typically configured to take
several hundred milliseconds or longer, it is a perfect candidate to be
run without the GVL.

https://github.com/ruby/openssl/commit/2a24966414
2026-04-08 11:08:25 +00:00
Kazuki Yamaguchi
b41b143018 [ruby/openssl] asn1: use new ASN1_BIT_STRING accessor functions with OpenSSL 4.0
ASN1_STRING has been made opaque in OpenSSL's master branch. Use the
new accessor functions instead of accessing fields directly.

Other uses of ASN1_STRING fields were already updated in
<https://github.com/ruby/openssl/pull/978>. This patch converts the
remaining ones, which require the new functions added in OpenSSL 4.0
and were not available at that time.

https://github.com/ruby/openssl/commit/ebb505f217
2026-03-31 15:14:53 +00:00
Kazuki Yamaguchi
f17a0af910 [ruby/openssl] pkey: remove unnecessary prototype from ossl_pkey.h
ossl_ec_new() was removed in commit https://github.com/ruby/openssl/commit/94aeab2f265d (pkey: simplify
ossl_pkey_new(), 2017-03-16), but it forgot to remove the declaration
while doing so.

https://github.com/ruby/openssl/commit/faad7a0811
2026-03-31 15:14:53 +00:00
Kazuki Yamaguchi
de1d14c0ca [ruby/openssl] Add const qualifiers for OpenSSL 4.0 compatibility
OpenSSL's master branch is changing functions to return const pointers
where the returned objects are not meant to be modified by the caller.

Update ossl_*_new() to take const pointers accordingly. Unfortunately,
*_dup() in older versions of OpenSSL and in LibreSSL/AWS-LC take
non-const pointers, so const casts are required.

https://github.com/ruby/openssl/commit/34c49e6c6c
2026-03-31 15:14:53 +00:00