class Metasploit::Credential::Pkcs12

A private Pkcs12 file.

Public Instance Methods

openssl_pkcs12() click to toggle source

Converts the private pkcs12 data in {#data} to an ‘OpenSSL::PKCS12` instance.

@return [OpenSSL::PKCS12] @raise [ArgumentError] if {#data} cannot be loaded

# File app/models/metasploit/credential/pkcs12.rb, line 41
def openssl_pkcs12
  if data
    begin
      password = ''
      OpenSSL::PKCS12.new(Base64.strict_decode64(data), password)
    rescue OpenSSL::PKCS12::PKCS12Error => error
      raise ArgumentError.new(error)
    end
  end
end
to_s() click to toggle source

The {#data key data}‘s fingerprint, suitable for displaying to the user.

@return [String]

# File app/models/metasploit/credential/pkcs12.rb, line 56
def to_s
  return '' unless data

  cert = openssl_pkcs12.certificate
  result = []
  result << "subject:#{cert.subject.to_s}"
  result << "issuer:#{cert.issuer.to_s}"
  result.join(',')
end

Private Instance Methods

readable() click to toggle source

Validates that {#data} can be read by OpenSSL and a ‘OpenSSL::PKCS12` can be created from {#data}. Any exception raised will be reported as a validation error.

@return [void]

# File app/models/metasploit/credential/pkcs12.rb, line 73
def readable
  if data
    begin
      openssl_pkcs12
    rescue => error
      errors.add(:data, "#{error.class} #{error}")
    end
  end
end