class MDQT::Client::MetadataValidator
Public Class Methods
new(options = {})
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 6 def initialize(options = {}) @certs = options[:certs] || [] end
Public Instance Methods
certificates()
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 45 def certificates @certificates ||= normalize_certs(certs) end
certificates?()
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 41 def certificates? certificates.present? end
valid?(response)
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 21 def valid?(response) begin errors = schema.validate(Nokogiri::XML(response.data) { |config| config.strict } ) return false unless errors.length.zero? true rescue => oops false end end
validation_error(response)
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 31 def validation_error(response) begin errors = schema.validate(Nokogiri::XML(response.data) { |config| config.strict } ) return nil if errors.empty? errors.join("\n") rescue => oops return "Invalid XML! #{oops.to_s}" end end
verified_signature?(response)
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 10 def verified_signature?(response) begin signed_document = Xmldsig::SignedDocument.new(response.data) return true if certificates.any? {|c| signed_document.validate(c)} false rescue => oops STDERR.puts oops false end end
Private Instance Methods
certs()
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 51 def certs @certs end
normalize_cert(cert_object)
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 59 def normalize_cert(cert_object) begin return cert_object if cert_object.kind_of?(OpenSSL::X509::Certificate) return OpenSSL::X509::Certificate.new(cert_object) if cert_object.kind_of?(String) && cert_object.include?("-----BEGIN CERTIFICATE-----") OpenSSL::X509::Certificate.new(File.open(cert_object)) rescue => oops raise end end
normalize_certs(certs)
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 55 def normalize_certs(certs) certs.collect {|c| normalize_cert(c)} end
schema()
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 69 def schema @schema ||= Nokogiri::XML::Schema(schema_data_fh) end
schema_data_fh()
click to toggle source
# File lib/mdqt/client/metadata_validator.rb, line 73 def schema_data_fh File.open(File.join(__dir__, '../schema/saml-schema-metadata-2.0.xsd')) end