Sha256: 30b23cea5cff88db52ae087a05ab749dbda5d04370f7bbf74366dbafc51f6d4e

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require 'uri'

module Saml
  module Kit
    module Cli
      class XmlDigitalSignature < Thor
        desc "verify file", "Verify if the contents of a file has a valid signature."
        method_option :format, default: "short", required: false, enum: ["short", "full"]
        def verify(file)
          format = options[:format]
          uri = URI.parse(file) rescue nil

          if uri.nil?
            path = File.expand_path(file)
            say_status :status, "Attempting to read #{path}...", :yellow
            content = IO.read(path)
          else
            say_status :status, "Downloading from #{uri}...", :yellow
            content = Net::HTTP.get_response(uri).body.chomp
          end
          document = ::Xml::Kit::Document.new(content)
          say document.to_xml(pretty: true)
          if document.valid?
            say_status :success, "#{file} is valid", :green
          else
            document.errors.full_messages.each do |error|
              say_status :error, error, :red
            end

            if "full" == format
              document.send(:invalid_signatures).each_with_index do |invalid_signature, index|
                say "Signature: #{index}"
                say invalid_signature.signature.to_xml(indent: 2), :red
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
saml-kit-cli-0.3.3 lib/saml/kit/cli/xml_digital_signature.rb
saml-kit-cli-0.3.2 lib/saml/kit/cli/xml_digital_signature.rb
saml-kit-cli-0.3.1 lib/saml/kit/cli/xml_digital_signature.rb