Skip to content

Commit 1d93086

Browse files
committed
Revert "Merge pull request puppetlabs#7401 from joshcooper/certmismatch_8213"
This reverts commit aab7b62, reversing changes made to 2c3f51b.
1 parent c77417e commit 1d93086

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

lib/puppet/network/http/connection.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ def with_connection(site, &block)
328328
# can be nil
329329
peer_cert = @verify.peer_certs.last
330330

331-
if peer_cert && !OpenSSL::SSL.verify_certificate_identity(peer_cert.content, site.host)
331+
if error.message.include? "certificate verify failed"
332+
msg = error.message
333+
msg << ": [" + @verify.verify_errors.join('; ') + "]"
334+
raise Puppet::Error, msg, error.backtrace
335+
elsif peer_cert && !OpenSSL::SSL.verify_certificate_identity(peer_cert.content, site.host)
332336
valid_certnames = [peer_cert.name, *peer_cert.subject_alt_names].uniq
333337
if valid_certnames.size > 1
334338
expected_certnames = _("expected one of %{certnames}") % { certnames: valid_certnames.join(', ') }
@@ -338,10 +342,6 @@ def with_connection(site, &block)
338342

339343
msg = _("Server hostname '%{host}' did not match server certificate; %{expected_certnames}") % { host: site.host, expected_certnames: expected_certnames }
340344
raise Puppet::Error, msg, error.backtrace
341-
elsif !@verify.verify_errors.empty?
342-
msg = error.message
343-
msg << ": [" + @verify.verify_errors.join('; ') + "]"
344-
raise Puppet::Error, msg, error.backtrace
345345
else
346346
raise
347347
end

spec/unit/network/http/connection_spec.rb

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def verify_errors
113113
WebMock.enable!
114114
end
115115

116-
it "should provide a useful error message when one is available and certificate validation fails in ruby 2.4 and up" do
116+
it "should provide a useful error message when one is available and certificate validation fails", :unless => Puppet.features.microsoft_windows? do
117117
connection = Puppet::Network::HTTP::Connection.new(
118118
host, port,
119119
:verify => ConstantErrorValidator.new(:fails_with => 'certificate verify failed',
@@ -124,13 +124,13 @@ def verify_errors
124124
end.to raise_error(Puppet::Error, /certificate verify failed: \[shady looking signature\]/)
125125
end
126126

127-
it "should provide a helpful error message when hostname does not match server certificate before ruby 2.4" do
127+
it "should provide a helpful error message when hostname was not match with server certificate", :unless => Puppet.features.microsoft_windows? do
128128
Puppet[:confdir] = tmpdir('conf')
129129

130130
connection = Puppet::Network::HTTP::Connection.new(
131131
host, port,
132132
:verify => ConstantErrorValidator.new(
133-
:fails_with => "hostname 'myserver' does not match the server certificate",
133+
:fails_with => 'hostname was not match with server certificate',
134134
:peer_certs => [Puppet::SSL::CertificateAuthority.new.generate(
135135
'not_my_server', :dns_alt_names => 'foo,bar,baz')]))
136136

@@ -142,24 +142,6 @@ def verify_errors
142142
end
143143
end
144144

145-
it "should provide a helpful error message when hostname does not match server certificate in ruby 2.4 or greater" do
146-
Puppet[:confdir] = tmpdir('conf')
147-
148-
connection = Puppet::Network::HTTP::Connection.new(
149-
host, port,
150-
:verify => ConstantErrorValidator.new(
151-
:fails_with => "certificate verify failed",
152-
:peer_certs => [Puppet::SSL::CertificateAuthority.new.generate(
153-
'not_my_server', :dns_alt_names => 'foo,bar,baz')]))
154-
155-
expect do
156-
connection.get('request')
157-
end.to raise_error(Puppet::Error) do |error|
158-
error.message =~ /\AServer hostname 'my_server' did not match server certificate; expected one of (.+)/
159-
expect($1.split(', ')).to match_array(%w[DNS:foo DNS:bar DNS:baz DNS:not_my_server not_my_server])
160-
end
161-
end
162-
163145
it "should pass along the error message otherwise" do
164146
connection = Puppet::Network::HTTP::Connection.new(
165147
host, port,
@@ -170,7 +152,7 @@ def verify_errors
170152
end.to raise_error(/some other message/)
171153
end
172154

173-
it "should check all peer certificates for upcoming expiration" do
155+
it "should check all peer certificates for upcoming expiration", :unless => Puppet.features.microsoft_windows? do
174156
Puppet[:confdir] = tmpdir('conf')
175157
cert = Puppet::SSL::CertificateAuthority.new.generate(
176158
'server', :dns_alt_names => 'foo,bar,baz')

0 commit comments

Comments
 (0)