Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL errors that don't involve ERR_get_error #14374

Open
HertzDevil opened this issue Mar 19, 2024 · 0 comments
Open

OpenSSL errors that don't involve ERR_get_error #14374

HertzDevil opened this issue Mar 19, 2024 · 0 comments

Comments

@HertzDevil
Copy link
Contributor

OpenSSL::Error calls ERR_get_error in its #initialize to obtain the error on the current thread's OpenSSL error queue, but not all functions signal failure this way. For example, EVP_get_digestbyname, which is used by OpenSSL::Digest.new, simply returns a null pointer, and you get a rather confusing exception message:

require "openssl"

OpenSSL::Digest.new("abc") # Unsupported digest algorithm: abc: Unknown or no error (OpenSSL::Digest::UnsupportedError)

This can be suppressed by passing fetched: true when constructing the exception, although this doesn't appear to have been used publicly, other than in OpenSSL::SSL::Error:

module OpenSSL
  class Digest < ::Digest
    private def new_evp_mt_ctx(name)
      md = LibCrypto.evp_get_digestbyname(name)
      unless md
        raise UnsupportedError.new("Unsupported digest algorithm: #{name}", fetched: true)
      end
      # ...
    end
  end
end

OpenSSL::Digest.new("abc") # Unsupported digest algorithm: abc (OpenSSL::Digest::UnsupportedError)

We need to go through the OpenSSL documentation to see which functions actually need ERR_get_error and which ones do not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant