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.



14
15
16
17
# File 'lib/saml/kit/signature.rb', line 14

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#canonicalization_methodObject



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

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

#certificateObject

Returns the embedded X509 Certificate



20
21
22
23
24
# File 'lib/saml/kit/signature.rb', line 20

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



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

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

#digest_valueObject



32
33
34
# File 'lib/saml/kit/signature.rb', line 32

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

#expected_digest_valueObject



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

def expected_digest_value
  digests = dsignature.references.map do |x|
    Base64.encode64(x.calculate_digest_value).chomp
  end
  digests.count > 1 ? digests : digests[0]
end

#present?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/saml/kit/signature.rb', line 68

def present?
  node
end

#signature_methodObject



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

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

#signature_valueObject



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

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

#to_hObject

Returns the XML Hash.



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

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

#to_xml(pretty: false) ⇒ Object



72
73
74
# File 'lib/saml/kit/signature.rb', line 72

def to_xml(pretty: false)
  pretty ? node.to_xml(indent: 2) : node.to_s
end

#transformsObject



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

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)


27
28
29
30
# File 'lib/saml/kit/signature.rb', line 27

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