You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(PUP-8213) Display correct message when certname is mismatched
Previously, if the server's cert did not match the hostname we tried to connect
to, puppet would output a confusing message:
certificate verify failed: [ok for /CN=XXX]
This occurs because ruby 2.4 introduced a new security feature whereby the cert
is automatically verified during the call to `SSLSocket#connect`[1]. In earlier
ruby versions, the application had to call `SSLSocket#post_connection_check`,
but of course, many people forgot to, or didn't know they had to, leading to
MITM vulnerabilities.
However, when a mismatch occurs, ruby 2.4 invokes our `verify_callback` with
`preverify_ok=false`, but `store_context.error=0` which is `OpenSSL::SSL::V_OK`.
Ruby then raises an `SSLError` whose message is 'certificate verify failed',
which matches the first "if" statement in our error handler.
This commit changes the order so that if an SSLError is rescued, we
check to see if there's a host mismatch first. If not, we check if there
were *any* verify errors, or raise the original error.
This change is compatible with ruby versions prior to 2.4, because both
`SSLSocket#post_connection_check` and our error handler use
`OpenSSL::SSL.verify_certificate_identity` to detect the certname mismatch.
[1] ruby/openssl#60
Copy file name to clipboardExpand all lines: spec/unit/network/http/connection_spec.rb
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,7 @@ def verify_errors
113
113
WebMock.enable!
114
114
end
115
115
116
-
it"should provide a useful error message when one is available and certificate validation fails",:unless=>Puppet.features.microsoft_windows?do
116
+
it"should provide a useful error message when one is available and certificate validation fails in ruby 2.4 and up",:unless=>Puppet.features.microsoft_windows?do
it"should provide a helpful error message when hostname was not match with server certificate",:unless=>Puppet.features.microsoft_windows?do
127
+
it"should provide a helpful error message when hostname does not match server certificate before ruby 2.4",:unless=>Puppet.features.microsoft_windows?do
128
128
Puppet[:confdir]=tmpdir('conf')
129
129
130
130
connection=Puppet::Network::HTTP::Connection.new(
131
131
host,port,
132
132
:verify=>ConstantErrorValidator.new(
133
-
:fails_with=>'hostname was not match with server certificate',
133
+
:fails_with=>"hostname 'myserver' does not match the server certificate",
it"should provide a helpful error message when hostname does not match server certificate in ruby 2.4 or greater",:unless=>Puppet.features.microsoft_windows?do
0 commit comments