aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* pkey: deprecate PKey#set_* methodsky/pkey-deprecate-modifyKazuki Yamaguchi2021-12-206-68/+149
| | | | | | | | | | | | | | | | | | | | | OpenSSL 3.0 made EVP_PKEY immutable. This means we can only have a const pointer of the low level struct and the following methods can no longer be provided when linked against OpenSSL 3.0: - OpenSSL::PKey::RSA#set_key - OpenSSL::PKey::RSA#set_factors - OpenSSL::PKey::RSA#set_crt_params - OpenSSL::PKey::DSA#set_pqg - OpenSSL::PKey::DSA#set_key - OpenSSL::PKey::DH#set_pqg - OpenSSL::PKey::DH#set_key - OpenSSL::PKey::EC#group= - OpenSSL::PKey::EC#private_key= - OpenSSL::PKey::EC#public_key= There is no direct replacement for this functionality at the moment. I plan to introduce a wrapper around EVP_PKEY_fromdata(), which takes all key components at once to construct an EVP_PKEY.
* pkey/ec: deprecate OpenSSL::PKey::EC#generate_key!Kazuki Yamaguchi2021-12-202-8/+17
| | | | | | OpenSSL::PKey::EC#generate_key! will not work on OpenSSL 3.0 because keys are made immutable. Users should use OpenSSL::PKey.generate_key instead.
* pkey/dh: deprecate OpenSSL::PKey::DH#generate_key!Kazuki Yamaguchi2021-12-203-16/+34
| | | | | | OpenSSL::PKey::DH#generate_key! will not work on OpenSSL 3.0 because keys are made immutable. Users should use OpenSSL::PKey.generate_key instead.
* pkey/ec: avoid using EC#public_key= in EC#dh_compute_keyKazuki Yamaguchi2021-12-171-3/+8
| | | | | | Similarly to DH#compute_key, work around it by constructing a SubjectPublicKeyInfo. This should be considered as a temporary implementation.
* pkey/dh: avoid using DH#set_key in DH#compute_keyKazuki Yamaguchi2021-12-171-3/+13
| | | | | | | | | | DH#set_key will not work on OpenSSL 3.0 because keys are immutable. For now, let's reimplement DH#compute_key by manually constructing a DER-encoded SubjectPublicKeyInfo structure and feeding it to OpenSSL::PKey.read. Eventually, we should implement a new method around EVP_PKEY_fromdata() and use it instead.
* Merge pull request #472 from ruby/typoKazuki Yamaguchi2021-11-033-3/+3
|\ | | | | Fix typos [ci skip]
| * Fix typos [ci skip]Nobuyoshi Nakada2021-11-033-3/+3
|/
* Merge pull request #469 from rhenium/ky/ssl-unstarted-ioKazuki Yamaguchi2021-11-012-190/+104
|\ | | | | ssl: disallow reading/writing to unstarted SSL socket
| * ssl: disallow reading/writing to unstarted SSL socketky/ssl-unstarted-ioKazuki Yamaguchi2021-10-252-190/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | OpenSSL::SSL::SSLSocket allowed #read and #write to be called before an SSL/TLS handshake is completed. They passed unencrypted data to the underlying socket. This behavior is very odd to have in this library. A verbose mode warning "SSL session is not started yet" was emitted whenever this happened. It also didn't behave well with OpenSSL::Buffering. Let's just get rid of it. Fixes: https://github.com/ruby/openssl/issues/9
* | x509name: improve docs for X509::NameKazuki Yamaguchi2021-11-012-2/+27
| | | | | | | | | | | | | | | | | | | | Add docs for X509::Name.parse_openssl and X509::Name.parse_rfc2253, which are currently undocumented despite being widely used. Small changes are also made to #to_s and the class description to recommend using RFC 2253-based methods. Fixes: https://github.com/ruby/openssl/issues/470
* | Merge pull request #468 from rhenium/ky/openssl-3.0.0-part1Kazuki Yamaguchi2021-10-2512-150/+168
|\ \ | |/ |/| Miscellaneous changes for OpenSSL 3.0 support
| * bn: expand BIGNUM_RAND and BIGNUM_RAND_RANGE macrosky/openssl-3.0.0-part1Kazuki Yamaguchi2021-10-241-50/+50
| | | | | | | | | | Now that BN.pseudo_rand{,_range} are alias, those macros are only used once. Let's expand the macros for better readability.
| * bn: make BN.pseudo_rand{,_range} an alias of BN.rand{,_range}Kazuki Yamaguchi2021-10-242-16/+6
| | | | | | | | | | | | BN_pseudo_rand() and BN_pseudo_rand_range() are deprecated in OpenSSL 3.0. Since they are identical to their non-'pseudo' version anyway, let's make them alias.
| * pkey, ssl: use EVP_PKEY_eq() instead of EVP_PKEY_cmp()Kazuki Yamaguchi2021-10-244-3/+8
| | | | | | | | | | OpenSSL 3.0 renamed EVP_PKEY_cmp() to EVP_PKEY_eq() because that was a confusing name.
| * pkey/ec: use EC_GROUP_free() instead of EC_GROUP_clear_free()Kazuki Yamaguchi2021-10-241-1/+1
| | | | | | | | | | | | | | EC_GROUP_clear_free() is deprecated in OpenSSL 3.0. EC_GROUP does not include any sensitive data, so we can safely use EC_GROUP_free() instead.
| * pkey/ec: deprecate PKey::EC::Point#make_affine! and make it a no-opKazuki Yamaguchi2021-10-241-0/+5
| | | | | | | | | | | | | | | | | | It converts the internal representation of the point object to the affine coordinate system. However, it had no real use case because the difference in the internal representation has not been visible from Ruby/OpenSSL at all. EC_POINT_make_affine() is marked as deprecated in OpenSSL 3.0.
| * hmac: use EVP_MD_CTX_get_pkey_ctx() instead of EVP_MD_CTX_pkey_ctx()Kazuki Yamaguchi2021-10-243-5/+14
| | | | | | | | | | | | OpenSSL 3.0 renamed EVP_MD_CTX_pkey_ctx() to include "get" in the function name. Adjust compatibility macro so that we can use the new function name for all OpenSSL 1.0.2-3.0.
| * digest: use EVP_MD_CTX_get0_md() instead of EVP_MD_CTX_md() if existsKazuki Yamaguchi2021-10-244-4/+9
| | | | | | | | | | | | | | | | | | | | The function was renamed in OpenSSL 3.0 due to the change of the lifetime of EVP_MD objects. They are no longer necessarily statically allocated and can be reference-counted -- when an EVP_MD_CTX is free'd, the associated EVP_MD can also become inaccessible. Currently Ruby/OpenSSL only handles builtin algorithms, so no special handling is needed except for adapting to the rename.
| * bn: use BN_check_prime() in OpenSSL::BN#prime{,_fasttest}?Kazuki Yamaguchi2021-10-242-49/+22
| | | | | | | | | | In OpenSSL 3.0, BN_is_prime_ex() and BN_is_prime_fasttest_ex() are deprecated in favor of BN_check_prime().
| * ssl: use SSL_get_rbio() to check if SSL is started or notKazuki Yamaguchi2021-10-241-2/+2
| | | | | | | | | | | | | | | | Use SSL_get_rbio() instead of SSL_get_fd(). SSL_get_fd() internally calls SSL_get_rbio() and it's enough for our purpose. In OpenSSL 3.0, SSL_get_fd() leaves an entry in the OpenSSL error queue if BIO has not been set up yet, and we would have to clean it up.
| * ssl: use SSL_CTX_load_verify_{file,dir}() if availableKazuki Yamaguchi2021-10-242-0/+8
| | | | | | | | | | SSL_CTX_load_verify_locations() is deprecated in OpenSSL 3.0 and replaced with those two separate functions. Use them if they exist.
| * ts: use TS_VERIFY_CTX_set_certs instead of TS_VERIFY_CTS_set_certsKazuki Yamaguchi2021-10-243-2/+8
| | | | | | | | | | OpenSSL 3.0 fixed the typo in the function name and replaced the current 'CTS' version with a macro.
| * ossl.c: use ERR_get_error_all() if availableKazuki Yamaguchi2021-10-242-19/+24
| | | | | | | | | | OpenSSL 3.0 deprecated ERR_get_error_line_data() in favor of ERR_get_error_all(), as part of the error queue structure changes.
| * ext/openssl/ossl.h: add helper macros for OpenSSL/LibreSSL versionsKazuki Yamaguchi2021-10-241-0/+12
|/ | | | | | | | Add following convenient macros: - OSSL_IS_LIBRESSL - OSSL_OPENSSL_PREREQ(maj, min, pat) - OSSL_LIBRESSL_PREREQ(maj, min, pat)
* test/openssl/test_ssl: use assert_raise in test_bad_socketKazuki Yamaguchi2021-10-231-1/+1
| | | | The Ruby tree disallows assert_raises.
* Merge pull request #467 from ruby/reject-bad-paramsKazuki Yamaguchi2021-10-232-0/+12
|\ | | | | Raise an exception if the IO object passed to SSLSocket isn't a file
| * Raise an exception if the IO object passed to SSLSocket isn't a fileAaron Patterson2021-10-222-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SSLSocket#connect eventually calls `GetOpenFile` in order to get the underlying file descriptor for the IO object passed in on initialization. `GetOpenFile` assumes that the Ruby object passed in is a T_FILE object and just casts it to a T_FILE without any checks. If you pass an object that *isn't* a T_FILE to that function, the program will segv. Since we assume the IO object is a file in the `connect` method, this commit adds a `CheckType` in the initialize method to ensure that the IO object is actually a T_FILE. If the object *isn't* a T_FILE, this class will segv on `connect`, so I think this is a backwards compatible change.
* | Merge branch 'ky/ssl-test-assume-ec-support'Kazuki Yamaguchi2021-10-2211-299/+250
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | * ky/ssl-test-assume-ec-support: test/openssl/test_pkey_rsa: disable test_no_private_exp on OpenSSL 3.0 test/openssl/test_pkey: use EC keys for PKey.generate_parameters tests test/openssl/test_ssl: fix illegal SAN extension test/openssl/test_pkcs12: fix test failures with OpenSSL 3.0 test/openssl/test_ssl: relax regex to match OpenSSL's error message test/openssl/test_digest: do not test constants for legacy algorithms test/openssl/test_ssl: assume ECC support test/openssl/test_ssl: assume TLS 1.2 support test/openssl/utils: remove dup_public helper method
| * test/openssl/test_pkey_rsa: disable test_no_private_exp on OpenSSL 3.0ky/ssl-test-assume-ec-supportKazuki Yamaguchi2021-10-221-1/+1
| | | | | | | | | | OpenSSL::PKey::RSA#set_key does not exist when built with OpenSSL 3.0, so it is not possible to create an RSA object with incomplete state.
| * test/openssl/test_pkey: use EC keys for PKey.generate_parameters testsKazuki Yamaguchi2021-10-221-16/+11
| | | | | | | | | | | | OpenSSL 3.0 refuses to generate DSA parameters shorter than 2048 bits, but generating 2048 bits parameters takes very long time. Let's use EC in these test cases instead.
| * test/openssl/test_ssl: fix illegal SAN extensionKazuki Yamaguchi2021-10-221-2/+1
| | | | | | | | | | | | A certificate can only have one SubjectAltName extension. OpenSSL 3.0 performs a stricter validation and certificates containing multiple SANs will be rejected.
| * test/openssl/test_pkcs12: fix test failures with OpenSSL 3.0Kazuki Yamaguchi2021-10-221-148/+149
| | | | | | | | | | | | | | | | | | OpenSSL's PKCS12_create() by default uses pbewithSHAAnd40BitRC2-CBC for encryption of the certificates. However, in OpenSSL 3.0, the algorithm is part of the legacy provider and is not enabled by default. Specify another algorithm that is still in the default provider for these test cases.
| * test/openssl/test_ssl: relax regex to match OpenSSL's error messageKazuki Yamaguchi2021-10-221-1/+3
| | | | | | | | | | | | OpenSSL 3.0 slightly changed the error message for a certificate verification failure when an untrusted self-signed certificate is found in the chain.
| * test/openssl/test_digest: do not test constants for legacy algorithmsKazuki Yamaguchi2021-10-221-1/+1
| | | | | | | | | | | | Remove availability test for MD4 and RIPEMD160 as they are considered legacy and may be missing depending on the compile-time options of OpenSSL. OpenSSL 3.0 by default disables them.
| * test/openssl/test_ssl: assume ECC supportKazuki Yamaguchi2021-10-224-24/+14
| | | | | | | | | | | | | | | | Disabling ECC support of OpenSSL is impractical nowadays. We still try to have the C extension compile on no-ec builds (as well as no-dh or no-engine, etc.) as long as we can, but keeping test cases for such an extreme scenario is not worth the effort.
| * test/openssl/test_ssl: assume TLS 1.2 supportKazuki Yamaguchi2021-10-193-55/+26
| | | | | | | | | | Current versions of OpenSSL and LibreSSL all support TLS 1.2, so there is no need for checking the availability.
| * test/openssl/utils: remove dup_public helper methodKazuki Yamaguchi2021-10-195-51/+44
|/ | | | | | It uses deprecated PKey::{RSA,DSA,DH}#set_* methods, which will not work with OpenSSL 3.0. The same can easily be achieved using PKey#public_to_der regardless of the key kind.
* Merge pull request #466 from rhenium/ky/require-ruby-2.6Kazuki Yamaguchi2021-10-168-53/+9
|\ | | | | require Ruby 2.6 or later
| * require Ruby 2.6 or laterky/require-ruby-2.6Kazuki Yamaguchi2021-10-167-51/+7
| | | | | | | | | | | | | | | | 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.
| * bump version number to 3.0.0.preKazuki Yamaguchi2021-10-162-2/+2
|/
* Use Test::Unit::PendedError instead of MiniTest::Skip for test-unit migrationHiroshi SHIBATA2021-10-161-2/+1
| | | | (cherry picked from commit ruby/ruby@ecfbf1df33a1e90008baa131369c80cfa6282692)
* Merge branch 'maint-2.2'Kazuki Yamaguchi2021-10-1611-47/+168
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * maint-2.2: (43 commits) Ruby/OpenSSL 2.2.1 openssl is ractor-safe Fixed the results of OpenSSL::Timestamp::Response#failure_info Don't redefine #rb_intern over and over again Use rb_intern_const instead of rb_intern in Init functions Remove trailing spaces [ci skip] test/openssl/test_ssl: use TLS 1.2 for finished_messages on LibreSSL Ruby/OpenSSL 2.1.3 ssl: avoid directly storing String object in NPN callback x509store: explicitly call rb_gc_mark() against Store/StoreContext ssl: explicitly call rb_gc_mark() against SSLContext/SSLSocket objects digest: load digest library using Kernel#require pkey: use RSTRING_LENINT() instead of casting to int fix segv in Timestamp::{Request,Response,TokenInfo}.new ts: libressl build fix warning ext/openssl/extconf.rb: require OpenSSL version >= 1.0.1, < 3 .github/workflows: update OpenSSL/LibreSSL versions test: adjust test cases for LibreSSL 3.2.4 ssl: temporary lock string buffer while reading ssl: create a temporary frozen string buffer when writing ...
| * Ruby/OpenSSL 2.2.1v2.2.1ky/release-2.2.1Kazuki Yamaguchi2021-10-163-2/+19
| |
| * openssl is ractor-safeKoichi Sasada2021-10-163-12/+72
| | | | | | | | | | | | | | | | | | | | | | | | [ This is a backport to the 2.2 branch. ] ossl_bn_ctx is C's global variable and it should be ractor-local to make it ractor-safe. ruby/ruby@b5588edc0a538de840c79e0bbc9d271ba0c5a711 (cherry picked from commit 9e7cf9e930cb986a04e312cb576814254dff13be and commit f2db943e8f19d4fa7bf871b9914dd9b92a5fbe6f)
| * Fixed the results of OpenSSL::Timestamp::Response#failure_infoNobuyoshi Nakada2021-10-162-11/+16
| | | | | | | | | | | | | | | | | | | | | | [ This is a backport to the 2.2 branch. ] 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> (cherry picked from commit f2d004679a62408a89d7304b229c24e789b94776)
| * Don't redefine #rb_intern over and over againStefan Stùˆben2021-10-161-34/+32
| | | | | | | | | | | | [ This is a backport to the 2.2 branch. ] (cherry picked from commit 03304838c931d9600617241909974df5ef58d06b)
| * Use rb_intern_const instead of rb_intern in Init functionsNobuyoshi Nakada2021-10-161-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | [ This is a backport to the 2.2 branch. ] ``` find . -name \*.o -exec nm {} + |& sed '/Init_.*\.rbimpl_id/!d;s/^.* b //;s/\.[1-9][0-9]*$//;s/\.rbimpl_id$//' | uniq ``` should be empty. (cherry picked from commit 9e4d4704e65bccd3cedeb9a07c9101f3c2eb02e9)
| * Remove trailing spaces [ci skip]Nobuyoshi Nakada2021-10-162-2/+2
| | | | | | | | | | | | [ This is a backport to the 2.2 branch. ] (cherry picked from commit 942bb13afaff7d4ec19b4337c6972476c373c988)
| * test/openssl/test_ssl: use TLS 1.2 for finished_messages on LibreSSLKazuki Yamaguchi2021-10-161-0/+1
| | | | | | | | | | LibreSSL 2.2.x has a bug in the Finished message handling with TLS 1.3. This is fixed by LibreSSL 3.3.2.
| * Merge branch 'maint-2.1' into maint-2.2Kazuki Yamaguchi2021-10-1610-73/+195
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * maint-2.1: Ruby/OpenSSL 2.1.3 ssl: avoid directly storing String object in NPN callback x509store: explicitly call rb_gc_mark() against Store/StoreContext ssl: explicitly call rb_gc_mark() against SSLContext/SSLSocket objects digest: load digest library using Kernel#require pkey: use RSTRING_LENINT() instead of casting to int ext/openssl/extconf.rb: require OpenSSL version >= 1.0.1, < 3 .github/workflows: update OpenSSL/LibreSSL versions test: adjust test cases for LibreSSL 3.2.4 ssl: temporary lock string buffer while reading ssl: create a temporary frozen string buffer when writing Use rb_block_call() instead of the deprecated rb_iterate() in OpenSSL