aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
Commit message (Collapse)AuthorAgeFilesLines
* ssl: add SSLContext#tmp_dh=ky/ssl-set-tmp-dhKazuki Yamaguchi2021-09-262-0/+52
| | | | | | | | | | | | | | | | | | Provide a wrapper of SSL_set0_tmp_dh_pkey()/SSL_CTX_set_tmp_dh(), which sets the DH parameters used for ephemeral DH key exchange. SSLContext#tmp_dh_callback= already exists for this purpose, as a wrapper around SSL_CTX_set_tmp_dh_callback(), but it is considered obsolete and the OpenSSL API is deprecated for future removal. There is no practical use case where an application needs to use different DH parameters nowadays. This was originally introduced to support export grade ciphers. RDoc for #tmp_dh_callback= is updated to recommend the new #tmp_dh=. Note that current versions of OpenSSL support automatic ECDHE curve selection which is enabled by default. SSLContext#tmp_dh= should only be necessary if you must allow ancient clients which don't support ECDHE.
* Merge pull request #456 from ruby/compilation-warningsKazuki Yamaguchi2021-09-129-26/+87
|\ | | | | Suppress compilation warnings
| * Add fallthrough commentsNobuyoshi Nakada2021-09-122-0/+4
| |
| * Suppress cast-function-type warningsNobuyoshi Nakada2021-09-128-26/+83
| |
* | Separate formatting from ossl_make_errorNobuyoshi Nakada2021-09-123-13/+16
| | | | | | | | | | | | Just append OpenSSL error reason to the given message string object, which would be alreadly formatted. Suppress -Wformat-security warning in `ossl_tsfac_create_ts`.
* | Suppress printf format warningsNobuyoshi Nakada2021-09-124-4/+8
|/ | | | | | * Add `printf` format attribute to `ossl_raise`. * Fix a format specifier in `config_load_bio`. * Use `ASSUME` for the unreachable condition.
* Strip trailing spacesKazuki Yamaguchi2021-07-182-2/+2
|
* Deprecate and rework old (fd) centric functionsSamuel Williams2021-07-182-6/+28
| | | | | | [ky: fixed compatibility with older versions of Ruby] (cherry picked from commit ruby/ruby@45e65f302b663b2c6ab69df06d3b6f219c1797b2)
* Use rb_block_call() instead of the deprecated rb_iterate() in OpenSSLBenoit Daloze2021-07-061-2/+3
| | | | | * See https://bugs.ruby-lang.org/issues/18025 and https://github.com/ruby/ruby/pull/4629
* Add example to OpenSSL::KDF.hkdf method (#447)Yusuke Nakamura2021-06-271-0/+8
| | | | The values from RFC 5869 https://datatracker.ietf.org/doc/html/rfc5869#appendix-A.1
* Include peer socket IP address in errorsVinicius Stock2021-06-141-4/+30
|
* Fix -Wundef warnings in core extensionsBenoit Daloze2021-05-251-1/+1
| | | | | | * See [Feature #17752] (cherry picked from commit ruby/ruby@59a92a84c8145c3dffd9f2a0e570dbc61211c86c)
* Merge pull request #417 from mame/add-BN_set_flagsKazuki Yamaguchi2021-05-251-0/+53
|\ | | | | Add OpenSSL::BN#set_flags and #get_flags
| * Add OpenSSL::BN#set_flags and #get_flagsYusuke Endoh2021-05-251-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, OpenSSL::BN::CONSTTIME is added. OpenSSL itself had a feature that was vulnerable against a side-channel attack. The OpenSSL authors determined that it was not a security issue, and they have already fixed the issue by using BN_set_flags. https://github.com/openssl/openssl/pull/13888 If a Ruby OpenSSL user was faced with a similar issue, they couldn't prevent the issue because Ruby OpenSSL lacks a wrapper to BN_set_flags. For the case, this change introduces the wrapper.
* | Merge pull request #382 from rhenium/ky/pkey-encrypt-decryptKazuki Yamaguchi2021-05-254-286/+375
|\ \ | | | | | | pkey: implement PKey#encrypt, #decrypt, #sign_raw, #verify_raw, and #verify_recover
| * | pkey/dsa: refactor DSA#sys{sign,verify} with PKey#{sign,verify}_rawky/pkey-encrypt-decryptKazuki Yamaguchi2021-05-251-88/+0
| | | | | | | | | | | | | | | | | | With the newly added OpenSSL::PKey::PKey#{sign,verify}_raw, OpenSSL::PKey::DSA's low level signing operation methods can be implemented in Ruby. The definitions are now in lib/openssl/pkey.rb.
| * | pkey/ec: refactor EC#dsa_{sign,verify}_asn1 with PKey#{sign,verify}_rawKazuki Yamaguchi2021-05-251-55/+0
| | | | | | | | | | | | | | | | | | With the newly added OpenSSL::PKey::PKey#{sign,verify}_raw, OpenSSL::PKey::EC's low level signing operation methods can be implemented in Ruby. The definitions are now in lib/openssl/pkey.rb.
| * | pkey/rsa: port RSA#{private,public}_{encrypt,decrypt} to the EVP APIKazuki Yamaguchi2021-05-251-141/+0
| | | | | | | | | | | | | | | | | | | | | Implement these methods using the new OpenSSL::PKey::PKey#{encrypt,sign} family. The definitions are now in lib/openssl/pkey.rb. Also, recommend using those generic methods in the documentation.
| * | pkey: implement PKey#sign_raw, #verify_raw, and #verify_recoverKazuki Yamaguchi2021-05-251-0/+232
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a variant of PKey#sign and #verify that do not hash the data automatically. Sometimes the caller has the hashed data only, but not the plaintext to be signed. In that case, users would have to use the low-level API such as RSA#private_encrypt or #public_decrypt directly. OpenSSL 1.0.0 and later supports EVP_PKEY_sign() and EVP_PKEY_verify() which provide the same functionality as part of the EVP API. This patch adds wrappers for them.
| * | pkey: update version reference in #sign and #verify documentationKazuki Yamaguchi2021-05-251-2/+2
| | | | | | | | | | | | The next release is decided to be 3.0 rather than 2.3.
| * | pkey: implement PKey#encrypt and #decryptKazuki Yamaguchi2021-05-251-0/+141
| | | | | | | | | | | | | | | Support public key encryption and decryption operations using the EVP API.
* | | Merge pull request #442 from rhenium/ky/parse-der-then-pemKazuki Yamaguchi2021-05-255-61/+63
|\ \ \ | | | | | | | | x509, ssl, pkcs7: try to parse as DER-encoding first
| * | | x509, ssl, pkcs7: try to parse as DER-encoding firstky/parse-der-then-pemKazuki Yamaguchi2021-05-195-61/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Methods that take both PEM-encoding and DER-encoding have not been consistent in the order in which encoding to attempt to parse. A DER-encoding may contain a valid PEM block ("\n-----BEGIN ..-----" to "-----END ...-----") embedded within it. Also, the PEM-encoding parser allows arbitrary data around the PEM block and silently skips it. As a result, attempting to parse data in DER-encoding as PEM-encoding first can incorrectly finds the embedded PEM block instead. This commit ensures that DER encoding will always be attempted before PEM encoding. OpenSSL::X509::Certificate is one of the updated classes. With this, the following will always be true: # obj is an OpenSSL::X509::Certificate obj == OpenSSL::X509::Certificate.new(obj.to_der) obj == OpenSSL::X509::Certificate.new(obj.to_pem)
* | | | pkey: remove deprecated parameter settersky/pkey-remove-deprecated-settersKazuki Yamaguchi2021-05-251-52/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the following methods, which have been marked as deprecated and produced a warning since version 2.0, commit 7ea72f1f5084 ("adapt OpenSSL::PKey to OpenSSL 1.1.0 opaque structs", 2016-06-05). - OpenSSL::PKey::RSA#n=, #e=, #d=, #p=, #q=, #dmp1=, #dmq1=, #iqmp= - OpenSSL::PKey::DSA#p=, #q=, #g=, #priv_key=, #pub_key= - OpenSSL::PKey::DH#p=, #g=, #priv_key=, #pub_key= These methods could only work with OpenSSL 1.0.2 or older, which is now EOL.
* | | | Implement `Certificate.load` to load certificate chain. (#441)Samuel Williams2021-05-221-0/+153
|/ / / | | | | | | | | | | | | * Add feature for loading the chained certificate into Certificate array. Co-authored-by: Sao I Kuan <saoikuan@gmail.com>
* / / Fix some typos [ci skip]Ryuta Kamizono2021-04-263-4/+4
|/ /
* | pkey/dh, pkey/ec: use EVP_PKEY_check() familyky/pkey-generic-evp-moreKazuki Yamaguchi2021-04-153-8/+45
| | | | | | | | | | | | | | | | | | Use EVP_PKEY_param_check() instead of DH_check() if available. Also, use EVP_PKEY_public_check() instead of EC_KEY_check_key(). EVP_PKEY_*check() is part of the EVP API and is meant to replace those low-level functions. They were added by OpenSSL 1.1.1. It is currently not provided by LibreSSL.
* | pkey: implement {DH,DSA,RSA}#public_key in RubyKazuki Yamaguchi2021-04-153-149/+14
| | | | | | | | | | | | | | | | | | | | | | 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.
* | pkey: implement #to_text using EVP APIKazuki Yamaguchi2021-04-155-116/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #397 from rhenium/ky/pkey-refactor-generateKazuki Yamaguchi2021-04-057-470/+102
|\ \ | | | | | | pkey: use high level EVP interface to generate parameters and keys
| * | 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.
* | | pkey: allow setting algorithm-specific options in #sign and #verifyky/pkey-sign-verify-optionsKazuki Yamaguchi2021-04-041-38/+75
| | | | | | | | | | | | | | | | | | 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().
* | | pkey: prepare pkey_ctx_apply_options() for usage by other operationsKazuki Yamaguchi2021-04-041-8/+14
| | | | | | | | | | | | | | | | | | 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.
* | | pkey: fix potential memory leak in PKey#signKazuki Yamaguchi2021-04-041-2/+6
|/ / | | | | | | | | | | 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.
* | 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