Class: Saml::Kit::Signature

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Translatable
Defined in:
lib/saml/kit/signature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Signature

Returns a new instance of Signature.



12
13
14
15
# File 'lib/saml/kit/signature.rb', line 12

def initialize(node)
  @name = 'Signature'
  @node = node
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/saml/kit/signature.rb', line 10

def name
  @name
end

Instance Method Details

#canonicalization_methodObject



46
47
48
# File 'lib/saml/kit/signature.rb', line 46

def canonicalization_method
  at_xpath('./ds:SignedInfo/ds:CanonicalizationMethod/@Algorithm').try(:value)
end

#certificateObject

Returns the embedded X509 Certificate



18
19
20
21
22
# File 'lib/saml/kit/signature.rb', line 18

def certificate
  value = at_xpath('./ds:KeyInfo/ds:X509Data/ds:X509Certificate').try(:text)
  return if value.nil?
  ::Xml::Kit::Certificate.new(value, use: :signing)
end

#digest_methodObject



34
35
36
# File 'lib/saml/kit/signature.rb', line 34

def digest_method
  at_xpath('./ds:SignedInfo/ds:Reference/ds:DigestMethod/@Algorithm').try(:value)
end

#digest_valueObject



30
31
32
# File 'lib/saml/kit/signature.rb', line 30

def digest_value
  at_xpath('./ds:SignedInfo/ds:Reference/ds:DigestValue').try(:text)
end

#present?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/saml/kit/signature.rb', line 59

def present?
  node
end

#signature_methodObject



42
43
44
# File 'lib/saml/kit/signature.rb', line 42

def signature_method
  at_xpath('./ds:SignedInfo/ds:SignatureMethod/@Algorithm').try(:value)
end

#signature_valueObject



38
39
40
# File 'lib/saml/kit/signature.rb', line 38

def signature_value
  at_xpath('./ds:SignatureValue').try(:text)
end

#to_hObject

Returns the XML Hash.



55
56
57
# File 'lib/saml/kit/signature.rb', line 55

def to_h
  @xml_hash ||= present? ? Hash.from_xml(to_xml)['Signature'] : {}
end

#to_xmlObject



63
64
65
# File 'lib/saml/kit/signature.rb', line 63

def to_xml
  node.to_s
end

#transformsObject



50
51
52
# File 'lib/saml/kit/signature.rb', line 50

def transforms
  node.search('./ds:SignedInfo/ds:Reference/ds:Transforms/ds:Transform/@Algorithm', Saml::Kit::Document::NAMESPACES).try(:map, &:value)
end

#trusted?(metadata) ⇒ Boolean

Returns true when the fingerprint of the certificate matches one of the certificates registered in the metadata.

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/saml/kit/signature.rb', line 25

def trusted?()
  return false if .nil?
  .matches?(certificate.fingerprint, use: :signing)
end