Class: Samlr::Signature

Inherits:
Object show all
Defined in:
lib/samlr/signature.rb

Overview

A SAML specific implementation en.wikipedia.org/wiki/XML_Signature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original, prefix, options) ⇒ Signature

Is initialized with the source document and a path to the element embedding the signature



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/samlr/signature.rb', line 12

def initialize(original, prefix, options)
  # Signature validations require document alterations
  @original = original
  @document = original.dup
  @prefix   = prefix
  @options  = options

  if @signature = document.at("#{prefix}/ds:Signature", NS_MAP)
    @signature.remove # enveloped signatures only
  end

  @fingerprint = if options[:fingerprint]
    Fingerprint.from_string(options[:fingerprint])
  elsif options[:certificate]
    Certificate.new(options[:certificate]).fingerprint
  end
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



9
10
11
# File 'lib/samlr/signature.rb', line 9

def document
  @document
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



9
10
11
# File 'lib/samlr/signature.rb', line 9

def fingerprint
  @fingerprint
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/samlr/signature.rb', line 9

def options
  @options
end

#originalObject (readonly)

Returns the value of attribute original.



9
10
11
# File 'lib/samlr/signature.rb', line 9

def original
  @original
end

#prefixObject (readonly)

Returns the value of attribute prefix.



9
10
11
# File 'lib/samlr/signature.rb', line 9

def prefix
  @prefix
end

#signatureObject (readonly)

Returns the value of attribute signature.



9
10
11
# File 'lib/samlr/signature.rb', line 9

def signature
  @signature
end

Instance Method Details

#missing?Boolean

Returns:

  • (Boolean)


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

def missing?
  signature.nil? || certificate.nil?
end

#present?Boolean

Returns:

  • (Boolean)


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

def present?
  !missing?
end

#referencesObject



48
49
50
51
52
53
54
# File 'lib/samlr/signature.rb', line 48

def references
  @references ||= [].tap do |refs|
    original.xpath("#{prefix}/ds:Signature/ds:SignedInfo/ds:Reference[@URI]", NS_MAP).each do |ref|
      refs << Samlr::Reference.new(ref)
    end
  end
end

#verify!Object

Raises:



38
39
40
41
42
43
44
45
46
# File 'lib/samlr/signature.rb', line 38

def verify!
  raise SignatureError.new("No signature at #{prefix}/ds:Signature") unless present?

  verify_fingerprint! unless options[:skip_fingerprint]
  verify_digests!
  verify_signature!

  true
end