Class: Ronin::DB::CLI::Commands::Certs Private

Inherits:
ModelCommand show all
Includes:
CommandKit::Printing::Fields, CommandKit::Printing::Indent, CommandKit::Printing::Lists
Defined in:
lib/ronin/db/cli/commands/certs.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Queries or imports SSL/TLS certificates.

Usage

ronin-db asn [options]

Options

    --db NAME                    The database to connect to (Default: default)
    --db-uri URI                 The database URI to connect to
    --db-file PATH               The sqlite3 database file to use
-v, --verbose                    Enables verbose output
-A, --active                     Searches for all Certs that are active
-E, --expired                    Searches for all Certs that are expired
    --issuer-common-name NAME    Searches for all Certs with the Issuer Common Name (CN)
    --issuer-organization NAME   Searches for all Certs with the Issuer Organization (O)
    --issuer-organizational-unit NAME
                                 Searches for all Certs with the Issuer Organizational Unit (OU)
    --issuer-locality LOCALITY   Searches for all Certs with the Issuer Locality (L)
    --issuer-state STATE         Searches for all Certs with the Issuer State (ST)
    --issuer-country COUNTRY     Searches for all Certs with the Issuer Country (C)
    --common-name HOST           Searches for all Certs with the Subject Common Name (CN)
    --subject-alt-name HOST      Searches for all Certs with the Subject Alternative Name (SAN)
    --organization NAME          Searches for all Certs with the Subject Organization (O)
    --organizational-unit NAME   Searches for all Certs with the Subject Organizational Unit (OU)
    --locality LOCALITY          Searches for all Certs with the Subject Locality (L)
    --state STATE                Searches for all Certs with the Subject State (ST)
    --country COUNTRY            Searches for all Certs with the Subject Country (C)
    --import FILE                Imports a Cert from a file
-h, --help                       Print help information

Since:

  • 0.2.0

Constant Summary

Constants included from URIMethods

URIMethods::ADAPTER_ALIASES

Instance Attribute Summary

Attributes inherited from ModelCommand

#query_method_calls

Instance Method Summary collapse

Methods inherited from ModelCommand

#db_connect, #initialize, #list, #load_model, #model, model_file, model_name, #query

Methods included from DatabaseOptions

#db_config, #db_connect, included

Methods included from URIMethods

#normalize_adapter, #normalize_sqlite3_path, #parse_uri

Constructor Details

This class inherits a constructor from Ronin::DB::CLI::ModelCommand

Instance Method Details

#import_cert(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Imports a certificate from a file.

Parameters:

  • path (String)

    The path to the certificate file.

Since:

  • 0.2.0



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ronin/db/cli/commands/certs.rb', line 217

def import_cert(path)
  unless File.file?(path)
    print_error "no such file or directory: #{path}"
    exit(-1)
  end

  cert = begin
           Ronin::Support::Crypto::Cert.load_file(path)
         rescue OpenSSL::X509::CertificateError
           print_error "cannot parse the certificate file: #{path}"
           exit(-1)
         end

  model.find_or_import(cert)
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prints a certificate Subject or Issuer.

Parameters:

  • cert_org (Ronin::DB::CertSubject, Ronin::DB::CertIssuer)

    The Subject or Issuer to print.

Since:

  • 0.2.0



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/ronin/db/cli/commands/certs.rb', line 284

def print_cert_org(cert_org)
  fields = {}

  if cert_org.common_name
    fields['Common Name (CN)'] = cert_org.common_name
  end

  if cert_org.email_address
    fields['Email address'] = cert_org.email_address
  end

  if cert_org.organization
    fields['Organization (O)'] = cert_org.organization
  end

  if cert_org.organizational_unit
    fields['Organization Unit (OU)'] = cert_org.organizational_unit
  end

  if cert_org.locality
    fields['Locality (L)'] = cert_org.locality
  end

  if cert_org.state
    fields['State (ST)'] = cert_org.state
  end

  if cert_org.country
    fields['Country (C)'] = cert_org.country
  end

  print_fields(fields)
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prints a certificate record.

Parameters:

  • cert (Ronin::DB::Cert)

    The certificate record to print.

Since:

  • 0.2.0



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/ronin/db/cli/commands/certs.rb', line 239

def print_record(cert)
  puts "[ #{cert.subject.common_name} ]"
  puts

  indent do
    print_fields(
      "Serial"     => cert.serial,
      "Not Before" => cert.not_before,
      "Not After"  => cert.not_after
    )
    puts

    puts "Subject:"
    indent { print_cert_org(cert.subject) }
    puts

    unless cert.subject_alt_names.empty?
      puts "Subject Alt Names:"
      indent { print_list(cert.subject_alt_names) }
      puts
    end

    if cert.issuer
      puts "Issuer:"
      indent { print_cert_org(cert.issuer) }
      puts
    end

    print_fields(
      'Public Key Algorithm' => cert.public_key_algorithm.upcase,
      'Public Key Size'      => cert.public_key_size,
      'Signing Algorithm'    => cert.signing_algorithm,
      'SHA1 Fingerprint'     => cert.sha1_fingerprint,
      'SHA256 Fingerprint'   => cert.sha256_fingerprint
    )
  end
  puts
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin-db certs command.

Since:

  • 0.2.0



201
202
203
204
205
206
207
208
209
# File 'lib/ronin/db/cli/commands/certs.rb', line 201

def run
  db_connect

  if options[:import]
    import_cert(options[:import])
  else
    list
  end
end