Sha256: 5b30e06c4023534ca9e3b78f553a90fb449acde0fdd0e2938b32e62193efb050

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Mihari
  module Clients
    class Crtsh < Base
      #
      # @param [String] base_url
      # @param [Hash] headers
      #
      def initialize(base_url = "https://crt.sh", headers: {})
        super(base_url, headers: headers)
      end

      #
      # Search crt.sh by a given identity
      #
      # @param [String] identity
      # @param [String, nil] match "=", "ILIKE", "LIKE", "single", "any" or nil
      # @param [String, nil] exclude "expired" or nil
      #
      # @return [Array<Mihari::Artifact>]
      #
      def search(identity, match: nil, exclude: nil)
        params = { identity: identity, match: match, exclude: exclude, output: "json" }.compact

        res = get("/", params: params)
        parsed = JSON.parse(res.body.to_s)

        parsed.map do |result|
          values = result["name_value"].to_s.lines.map(&:chomp)
          values.map do |value|
            Artifact.new(data: value, metadata: result)
          end
        end.flatten
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mihari-5.4.3 lib/mihari/clients/crtsh.rb