Class: Sepa::ApplicationResponse

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Utilities
Defined in:
lib/sepa/application_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#calculate_digest, #canonicalize_exclusively, #canonicalized_node, #cert_is_trusted, #cert_request_valid?, #check_validity_against_schema, #csr_to_binary, #decode, #encode, #extract_cert, #format_cert, #format_cert_request, #hmac, #iso_time, #load_body_template, #process_cert_value, #rsa_key, #x509_certificate, #xml_doc

Constructor Details

#initialize(app_resp) ⇒ ApplicationResponse

Returns a new instance of ApplicationResponse.



11
12
13
# File 'lib/sepa/application_response.rb', line 11

def initialize(app_resp)
  @xml = app_resp
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



6
7
8
# File 'lib/sepa/application_response.rb', line 6

def xml
  @xml
end

Instance Method Details

#certificateObject



50
51
52
# File 'lib/sepa/application_response.rb', line 50

def certificate
  extract_cert(doc, 'X509Certificate', DSIG)
end

#docObject



15
16
17
# File 'lib/sepa/application_response.rb', line 15

def doc
  @doc ||= xml_doc @xml
end

#hashes_match?Boolean

Checks that the hash value reported in the signature matches the actual one.

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sepa/application_response.rb', line 20

def hashes_match?
  are = doc.clone

  digest_value = are.at('xmlns|DigestValue', xmlns: DSIG).content.strip

  are.at('xmlns|Signature', xmlns: DSIG).remove

  actual_digest = calculate_digest(are)

  return true if digest_value == actual_digest

  false
end

#signature_is_valid?Boolean

Checks that the signature is signed with the private key of the certificate’s public key.

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
# File 'lib/sepa/application_response.rb', line 35

def signature_is_valid?
  node = doc.at('xmlns|SignedInfo', 'xmlns' => DSIG)
  node = node.canonicalize

  signature = doc.at('xmlns|SignatureValue', 'xmlns' => DSIG).content
  signature = decode(signature)

  # Return true or false
  certificate.public_key.verify(OpenSSL::Digest::SHA1.new, signature, node)
end

#to_sObject



46
47
48
# File 'lib/sepa/application_response.rb', line 46

def to_s
  @xml
end