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

ssl: show reason of 'certificate verify error' in exception message #99

Merged
merged 2 commits into from
Jan 26, 2017

Conversation

rhenium
Copy link
Member

@rhenium rhenium commented Jan 20, 2017

The 'certificate verify error' is one of the most common errors that can
be raised by OpenSSL::SSL::SSLSocket#connect. The certificate
verification may fail due to many different issues such as misconfigured
trusted certificate store or inaccurate system clock.

Unfortunately, since the detail is not put to the queue and is only
accessible through OpenSSL::SSL::SSLSocket#verify_result, it is
sometimes hard to figure out the real reason. Let's include a human
readable reason message in the exception message. Like this:

require "socket"
require "openssl"

ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(cert_store: OpenSSL::X509::Store.new)
ssl = OpenSSL::SSL::SSLSocket.new(Socket.tcp("ruby-lang.org", 443), ctx)
ssl.connect

-:7:in `connect': SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
	from -:7:in `<main>'

@rhenium rhenium force-pushed the topic/ssl-certificate-verify-error-desc branch from e2193f1 to 3334ebe Compare January 20, 2017 14:33
@@ -1521,6 +1521,9 @@ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
int ret, ret2;
VALUE cb_state;
int nonblock = opts != Qfalse;
#if defined(SSL_R_CERTIFICATE_VERIFY_FAILED)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This #if may be unnecessary, but I'm not sure if these error codes are meant to be part of the public API.

@rhenium rhenium force-pushed the topic/ssl-certificate-verify-error-desc branch from 3334ebe to 7afa6f8 Compare January 20, 2017 14:41
As the current behavior is useless. If OpenSSL.debug is set to true,
errors put to the error queue will be printed to stderr anyway.
The 'certificate verify error' is one of the most common errors that can
be raised by OpenSSL::SSL::SSLSocket#connect. The certificate
verification may fail due to many different issues such as misconfigured
trusted certificate store or inaccurate system clock.

Unfortunately, since the detail is not put to the queue and is only
accessible through OpenSSL::SSL::SSLSocket#verify_result, it is
sometimes hard to figure out the real reason. Let's include a human
readable reason message in the exception message. Like this:

  require "socket"
  require "openssl"

  ctx = OpenSSL::SSL::SSLContext.new
  ctx.set_params(cert_store: OpenSSL::X509::Store.new)
  ssl = OpenSSL::SSL::SSLSocket.new(Socket.tcp("www.ruby-lang.org", 443), ctx)
  ssl.connect

  #=>
  -:7:in `connect': SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate) (OpenSSL::SSL::SSLError)
  	from -:7:in `<main>'
@rhenium rhenium force-pushed the topic/ssl-certificate-verify-error-desc branch from 7afa6f8 to 654e024 Compare January 24, 2017 04:32
@rhenium rhenium merged commit 654e024 into ruby:master Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant