Skip to content

Commit

Permalink
DRY up CLI::Commands::CertDump#process_value.
Browse files Browse the repository at this point in the history
* Added a `grab_cert` method.
* Use the new `Ronin::Support::Network::SSL.get_cert` method.
  • Loading branch information
postmodern committed Dec 28, 2023
1 parent ab37652 commit a7836ea
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/ronin/cli/commands/cert_dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require 'ronin/cli/value_processor_command'
require 'ronin/cli/host_and_port'
require 'ronin/support/crypto/cert'
require 'ronin/support/network/ssl/mixin'
require 'ronin/support/network/ssl'

require 'command_kit/printing/indent'
require 'command_kit/printing/fields'
Expand Down Expand Up @@ -59,7 +59,6 @@ module Commands
#
class CertDump < ValueProcessorCommand

include Support::Network::SSL::Mixin
include CommandKit::Printing::Indent
include CommandKit::Printing::Fields
include CommandKit::Printing::Lists
Expand Down Expand Up @@ -104,11 +103,11 @@ def process_value(value)
when /\A[^:]+:\d+\z/
host, port = host_and_port(value)

print_cert(ssl_cert(host,port))
grab_cert(host,port)
when /\Ahttps:/
host, port = host_and_port_from_url(value)

print_cert(ssl_cert(host,port))
grab_cert(host,port)
else
unless File.file?(value)
print_error "no such file or directory: #{value}"
Expand All @@ -121,6 +120,21 @@ def process_value(value)
end
end

#
# Gets the certs from the host and port, and then print it.
#
# @param [String] host
#
# @param [Integer] port
#
# @since 2.1.0
#
def grab_cert(host,port)
cert = Support::Network::SSL.get_cert(host,port)

print_cert(cert)
end

#
# Prints the certificate.
#
Expand Down

0 comments on commit a7836ea

Please sign in to comment.