Skip to content

Commit d8770ea

Browse files
committed
(PUP-11428) Refactor printing an ssl context
Move the logic for printing an SSLContext to the SSLProvider.
1 parent 861921e commit d8770ea

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lib/puppet/ssl/ssl_provider.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ def verify_request(csr, public_key)
173173
csr
174174
end
175175

176+
def print(ssl_context, alg = 'SHA256')
177+
if Puppet::Util::Log.sendlevel?(:debug)
178+
chain = ssl_context.client_chain
179+
# print from root to client
180+
chain.reverse.each_with_index do |cert, i|
181+
digest = Puppet::SSL::Digest.new(alg, cert.to_der)
182+
if i == chain.length - 1
183+
Puppet.debug(_("Verified client certificate '%{subject}' fingerprint %{digest}") % {subject: cert.subject.to_utf8, digest: digest})
184+
else
185+
Puppet.debug(_("Verified CA certificate '%{subject}' fingerprint %{digest}") % {subject: cert.subject.to_utf8, digest: digest})
186+
end
187+
end
188+
end
189+
end
190+
176191
private
177192

178193
def default_flags

lib/puppet/ssl/state_machine.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,7 @@ def ensure_ca_certificates
417417
def ensure_client_certificate
418418
final_state = run_machine(NeedLock.new(self), Done)
419419
ssl_context = final_state.ssl_context
420-
421-
if Puppet::Util::Log.sendlevel?(:debug)
422-
chain = ssl_context.client_chain
423-
# print from root to client
424-
chain.reverse.each_with_index do |cert, i|
425-
digest = Puppet::SSL::Digest.new(@digest, cert.to_der)
426-
if i == chain.length - 1
427-
Puppet.debug(_("Verified client certificate '%{subject}' fingerprint %{digest}") % {subject: cert.subject.to_utf8, digest: digest})
428-
else
429-
Puppet.debug(_("Verified CA certificate '%{subject}' fingerprint %{digest}") % {subject: cert.subject.to_utf8, digest: digest})
430-
end
431-
end
432-
end
433-
420+
@ssl_provider.print(ssl_context, @digest)
434421
ssl_context
435422
end
436423

0 commit comments

Comments
 (0)