aboutsummaryrefslogtreecommitdiffstats
path: root/ext
Commit message (Collapse)AuthorAgeFilesLines
* pkey: remove unused ossl_generate_cb_2() helper functionky/pkey-refactor-generateKazuki Yamaguchi2021-04-054-81/+15
| | | | | | 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.
* pkey/dsa: use high level EVP interface to generate parameters and keysKazuki Yamaguchi2021-04-051-115/+25
| | | | | | Implement PKey::DSA.new(size) and PKey::DSA.generate using OpenSSL::PKey.generate_parameters and .generate_key instead of the low level DSA functions.
* pkey/rsa: use high level EVP interface to generate parameters and keysKazuki Yamaguchi2021-04-051-116/+16
| | | | | Implement PKey::RSA.new(size, exponent) and PKey::RSA.generate using OpenSSL::PKey.generate_key instead of the low level RSA functions.
* pkey/dh: use high level EVP interface to generate parameters and keysKazuki Yamaguchi2021-04-051-153/+33
| | | | | | | | | | 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.
* pkey: fix interrupt handling in OpenSSL::PKey.generate_keyKazuki Yamaguchi2021-04-051-5/+13
| | | | | | 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.
* Merge pull request #396 from rhenium/ky/drop-openssl-1.0.1Kazuki Yamaguchi2021-04-048-279/+48
|\ | | | | require OpenSSL >= 1.0.2 and LibreSSL >= 3.1
| * ossl.c: do not set locking callbacks on LibreSSLky/drop-openssl-1.0.1Kazuki Yamaguchi2021-04-042-2/+7
| | | | | | | | | | | | 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.
| * ssl: use TLS_method() instead of SSLv23_method() for LibreSSLKazuki Yamaguchi2021-04-041-1/+1
| | | | | | | | | | | | | | | | | | 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.
| * ssl: call SSL_CTX_set_ecdh_auto() on OpenSSL 1.0.2 onlyKazuki Yamaguchi2021-04-041-5/+6
| | | | | | | | | | | | | | 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.
| * require OpenSSL >= 1.0.2 and LibreSSL >= 3.1Kazuki Yamaguchi2021-04-047-272/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | bn: update documentation of OpenSSL::BN#initialize and #to_sKazuki Yamaguchi2021-04-021-14/+36
| | | | | | | | | | | | | | 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
* | BN.abs and BN uplusRick Mark2021-04-011-1/+30
| | | | | | | | Adds standard math abs fuction and revises uplus to return a duplicated object due to BN mutability
* | Enclose the code that was accidentally a link in "tt"aycabta2021-03-311-1/+1
| | | | | | | | (cherry picked from commit ruby/ruby@66d2fc7989d741bf5a73286233139901cecb4fc2)
* | Use #ifdef consistently for HAVE_RB_EXT_RACTOR_SAFETom Stuart2021-03-252-3/+3
| | | | | | | | | | We previously used a mix of both `#if` and `#ifdef`, but the latter is more reliable because it will still work if the macro is undefined.
* | Fix OpenSSL::Engine build on DebianTom Stuart2021-03-241-14/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | On Debian 9 (“stretch”) the `OPENSSL_NO_STATIC_ENGINE` macro is not defined, which causes all the `#if HAVE_ENGINE_LOAD_…` directives to fail with `error: 'HAVE_ENGINE_LOAD_…' is not defined, evaluates to 0 [-Werror,-Wundef]` while building TruffleRuby. We can accomplish the same thing with `#ifdef`, which (of course) works fine when the `HAVE_ENGINE_LOAD…` macros are also undefined. Upstreamed from oracle/truffleruby#2255, which fixed oracle/truffleruby#2254.
* | pkcs7: keep private key when duplicating PKCS7_SIGNER_INFOky/pkcs7-add-signer-keep-pkey-ptrKazuki Yamaguchi2021-03-241-48/+33
|/ | | | | | | | | | | | | ASN1_dup() will not copy the 'pkey' field of a PKCS7_SIGNER_INFO object by design; it is a temporary field kept until the PKCS7 structure is finalized. Let's bump reference counter of the pkey in the original object and use it in the new object, too. This commit also removes PKCS7#add_signer's routine to add the content-type attribute as a signed attribute automatically. This behavior was not documented or tested. This change should not break any working user code since the method was completely useless without the change above.
* Merge pull request #398 from rhenium/ky/pkey-remove-ec-group-from-raw-methodKazuki Yamaguchi2021-03-161-42/+2
|\ | | | | pkey/ec: remove OpenSSL::PKey::EC::Group.new(ec_method) form
| * pkey/ec: remove OpenSSL::PKey::EC::Group.new(ec_method) formky/pkey-remove-ec-group-from-raw-methodKazuki Yamaguchi2020-08-211-42/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The form created an empty EC_GROUP object with the specified EC_METHOD. However, the feature was unfinished and not useful in any way because OpenSSL::PKey::EC::Group did not implement wrappers for necessary functions to set actual parameters for the group, namely EC_GROUP_set_curve() family. EC_GROUP object creation with EC_METHOD explicitly specified is deprecated in OpenSSL 3.0, as it was apparently not intended for use outside OpenSSL. It is still possible to create EC_GROUP, but without EC_METHOD explicitly specified - OpenSSL chooses the appropriate EC_METHOD for the curve type. The OpenSSL::PKey::EC::Group.new(<:GFp|:GF2m>, p, a, b) form will continue to work.
* | Merge branch 'maint-2.2'Kazuki Yamaguchi2021-02-253-17/+51
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * maint-2.2: .github/workflows: update Ruby and OpenSSL/LibreSSL versions bn: check -1 return from BIGNUM functions .github/workflows: disable pkg-config on Windows tests ssl: retry write on EPROTOTYPE on macOS x509store: fix memory leak in X509::StoreContext.new .github/workflows/test.yml: use GitHub Actions Skip one assertion for OpenSSL::PKey::EC::Point#mul on LibreSSL
| * \ Merge branch 'maint-2.1' into maint-2.2Kazuki Yamaguchi2021-02-253-17/+53
| |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * maint-2.1: .github/workflows: update Ruby and OpenSSL/LibreSSL versions bn: check -1 return from BIGNUM functions .github/workflows: disable pkg-config on Windows tests ssl: retry write on EPROTOTYPE on macOS x509store: fix memory leak in X509::StoreContext.new .github/workflows/test.yml: use GitHub Actions Skip one assertion for OpenSSL::PKey::EC::Point#mul on LibreSSL
| | * | bn: check -1 return from BIGNUM functionsky/bn-check-negative-error-returnsKazuki Yamaguchi2021-02-181-12/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although the manpage says that BIGNUM functions return 0 on error, OpenSSL versions before 1.0.2n and current LibreSSL versions may return -1 instead. Note that the implementation of OpenSSL::BN#mod_inverse is extracted from BIGNUM_2c() macro as it didn't really share the same function signature with others.
| | * | ssl: retry write on EPROTOTYPE on macOSky/ssl-macos-send-eprototypeKazuki Yamaguchi2020-08-121-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Errno::EPROTOTYPE is not supposed to be raised by SSLSocket#write. However, on macOS, send(2) which is called via SSL_write() can occasionally return EPROTOTYPE. Retry SSL_write() so that we get a proper error, just as ext/socket does. Reference: https://bugs.ruby-lang.org/issues/14713 Reference: https://github.com/ruby/openssl/issues/227
| | * | x509store: fix memory leak in X509::StoreContext.newky/x509stctx-new-fix-leakKazuki Yamaguchi2020-08-121-5/+16
| | | | | | | | | | | | | | | | | | | | The certificate passed as the second argument was not properly free'd in the error paths.
* | | | support Ruby 2.x for opensslKoichi Sasada2021-02-142-2/+35
| | | | | | | | | | | | | | | | ruby/ruby@e76b56f58e44cb54497d93526d649950f5bdd1c0
* | | | openssl is ractor-safeKoichi Sasada2021-02-143-10/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ossl_bn_ctx is C's global variable and it should be ractor-local to make it ractor-safe. ruby/ruby@b5588edc0a538de840c79e0bbc9d271ba0c5a711
* | | | Fixed the results of OpenSSL::Timestamp::Response#failure_infoNobuyoshi Nakada2021-02-141-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | | | Use rb_intern_const instead of rb_intern in Init functionsNobuyoshi Nakada2020-12-141-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` find . -name \*.o -exec nm {} + |& sed '/Init_.*\.rbimpl_id/!d;s/^.* b //;s/\.[1-9][0-9]*$//;s/\.rbimpl_id$//' | uniq ``` should be empty.
* | | | Don't redefine #rb_intern over and over againStefan Stüben2020-12-141-32/+30
| | | |
* | | | Enhance TLS 1.3 support on LibreSSL 3.2/3.3Jeremy Evans2020-12-031-0/+6
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This defines TLS1_3_VERSION when using LibreSSL 3.2+. LibreSSL 3.2/3.3 doesn't advertise this by default, even though it will use TLS 1.3 in both client and server modes. Changes between LibreSSL 3.1 and 3.2/3.3 broke a few tests, Defining TLS1_3_VERSION by itself fixes 1 test failure. A few tests now fail on LibreSSL 3.2/3.3 unless TLS 1.2 is set as the maximum version, and this adjusts those tests. The client CA test doesn't work in LibreSSL 3.2+, so I've marked that as pending. For the hostname verification, LibreSSL 3.2.2+ has a new stricter hostname verifier that doesn't like subjectAltName such as c*.example.com and d.*.example.com, so adjust the related tests. With these changes, the tests pass on LibreSSL 3.2/3.3.
* | | Merge pull request #394 from rhenium/ky/ssl-remove-tmp-ecdh-callbackKazuki Yamaguchi2020-08-212-70/+3
|\ \ \ | | | | | | | | ssl: remove SSL::SSLContext#tmp_ecdh_callback
| * | | ssl: remove SSL::SSLContext#tmp_ecdh_callbackky/ssl-remove-tmp-ecdh-callbackKazuki Yamaguchi2020-08-132-70/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The underlying API SSL_CTX_set_tmp_ecdh_callback() was removed by LibreSSL >= 2.6.1 and OpenSSL >= 1.1.0, in other words, it is not supported by any non-EOL versions of OpenSSL. The wrapper was initially implemented in Ruby 2.3 and has been deprecated since Ruby/OpenSSL 2.0 (bundled with Ruby 2.4) with explicit warning with rb_warn().
* | | | x509store: update rdoc for X509::Store and X509::StoreContextKazuki Yamaguchi2020-08-121-13/+113
| | | | | | | | | | | | | | | | | | | | Add more details about each method, and add reference to OpenSSL man pages.
* | | | x509store: avoid ossl_raise() calls with NULL messageKazuki Yamaguchi2020-08-121-19/+14
| | | | | | | | | | | | | | | | | | | | Use the OpenSSL function name that caused the error to generate a better error message.
* | | | x509store: refactor X509::StoreContext#chainKazuki Yamaguchi2020-08-121-18/+5
| | | | | | | | | | | | | | | | | | | | Use ossl_x509_sk2ary() to create an array of OpenSSL::X509::Certificate from STACK_OF(X509).
* | | | x509store: emit warning if arguments are given to X509::Store.newKazuki Yamaguchi2020-08-121-1/+2
| | | | | | | | | | | | | | | | | | | | Anything passed to OpenSSL::X509::Store.new was always ignored. Let's emit an explicit warning to not confuse users.
* | | | x509store: let X509::Store#add_file raise TypeError if nil is givenKazuki Yamaguchi2020-08-121-16/+12
|/ / / | | | | | | | | | | | | | | | | | | | | | 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.
* | | [DOC] Fix RDoc markupNobuhiro IMAI2020-07-291-1/+1
| | |
* | | Fix typo in documentationClaus Lensbøl2020-07-241-3/+3
| | | | | | | | | | | | The socket is called ssl_connection, not connection
* | | Merge pull request #383 from cwjenkins/add_rsa_keys_eqlKazuki Yamaguchi2020-07-161-0/+39
|\ \ \ | | | | | | | | Add wrapper method for EVP_PKEY_cmp to compare same type keys
| * | | Add compare? method to OpenSSL::PKey that wraps EVP_PKEY_cmp.Colton Jenkins2020-07-141-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | 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?
* | | | User lower case cipher names for maximum compatibilityBart de Water2020-07-072-13/+13
|/ / / | | | | | | | | | We ran into some Linux-based systems not accepting the upper case variant
* | | Merge pull request #371 from rhenium/ky/hmac-evpKazuki Yamaguchi2020-06-305-170/+49
|\ \ \ | | | | | | | | hmac: migrate from the low-level HMAC API to the EVP API
| * | | hmac: migrate from the low-level HMAC API to the EVP APIky/hmac-evpKazuki Yamaguchi2020-06-305-170/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use the EVP API instead of the low-level HMAC API. Use of the HMAC API has been discouraged and is being marked as deprecated starting from OpenSSL 3.0.0. The two singleton methods OpenSSL::HMAC, HMAC.digest and HMAC.hexdigest are now in lib/openssl/hmac.rb.
* | | | pkey/ec: deprecate OpenSSL::PKey::EC::Point#mul(ary, ary [, bn])ky/pkey-ec-point-deprecate-mul-aryKazuki Yamaguchi2020-06-291-0/+8
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | digest, hmac, ts, x509: use IO.binread in examples where appropriateKazuki Yamaguchi2020-05-134-18/+18
| | | | | | | | | | | | | | | | | | | | | IO.read may mangle line separator, which will corrupt binary data including DER-encoded X.509 certificates and such. Fixes: https://github.com/ruby/openssl/issues/243
* | | Merge pull request #329 from rhenium/ky/pkey-generic-operationsKazuki Yamaguchi2020-05-133-110/+366
|\ \ \ | | | | | | | | pkey: add more support for 'generic' pkey types
| * | | pkey: reimplement PKey::DH#compute_key and PKey::EC#dh_compute_keyky/pkey-generic-operationsKazuki Yamaguchi2020-05-132-67/+0
| | | | | | | | | | | | | | | | | | | | Use the new OpenSSL::PKey::PKey#derive instead of the raw {EC,}DH_compute_key(), mainly to reduce amount of the C code.
| * | | pkey: add PKey::PKey#deriveKazuki Yamaguchi2020-05-131-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | | pkey: support 'one-shot' signing and verificationKazuki Yamaguchi2020-05-131-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | | pkey: port PKey::PKey#sign and #verify to the EVP_Digest* interfaceKazuki Yamaguchi2020-05-131-39/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.