Sha256: d8bce65f22dc756a616bde1c85e838d2b52e3355e12a4c696bd09cc7588a2ce9

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Mihari
  module Clients
    #
    # crt.sh API client
    #
    class Crtsh < Base
      #
      # @param [String] base_url
      # @param [Hash] headers
      # @param [Integer, nil] timeout
      #
      def initialize(base_url = "https://crt.sh", headers: {}, timeout: nil)
        super(base_url, headers: headers, timeout: timeout)
      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::Models::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 { |value| Models::Artifact.new(data: value, metadata: result) }
        end.flatten
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mihari-5.7.1 lib/mihari/clients/crtsh.rb
mihari-5.7.0 lib/mihari/clients/crtsh.rb