Class: Sepa::ApplicationResponse
- Inherits:
-
Object
- Object
- Sepa::ApplicationResponse
- Includes:
- ActiveModel::Validations, Utilities
- Defined in:
- lib/sepa/application_response.rb
Overview
Use functionality from this class more when validating response
Contains functionality for the application response embedded in Response
Instance Attribute Summary collapse
-
#xml ⇒ String
readonly
The raw xml of the application response.
Instance Method Summary collapse
-
#certificate ⇒ OpenSSL::X509::Certificate?
The certificate which private key has been used to sign the application response.
-
#certificate_is_trusted? ⇒ true, false
Checks whether the embedded certificate has been signed by the private key of the bank's root certificate.
-
#doc ⇒ Nokogiri::XML::Document
The application response as a nokogiri xml document.
-
#hashes_match? ⇒ true, false
Checks that the hash value reported in the signature matches the one that is calculated locally.
-
#initialize(app_resp, bank) ⇒ ApplicationResponse
constructor
Initializes the ApplicationResponse with an application response xml and bank.
-
#response_must_validate_against_schema ⇒ Object
private
Validates that the response is valid against the application response schema.
-
#signature_is_valid? ⇒ true, false
Checks that the signature has been calculated with the private key of the certificate's public key.
-
#to_s ⇒ String
Returns the raw xml of the application response.
Methods included from Utilities
#calculate_digest, #canonicalize_exclusively, #canonicalized_node, #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, #set_node_id, #validate_signature, #verify_certificate_against_root_certificate, #x509_certificate, #xml_doc
Constructor Details
#initialize(app_resp, bank) ⇒ ApplicationResponse
Initializes the Sepa::ApplicationResponse with an application response xml and bank
20 21 22 23 |
# File 'lib/sepa/application_response.rb', line 20 def initialize(app_resp, bank) @xml = app_resp @bank = bank end |
Instance Attribute Details
#xml ⇒ String (readonly)
The raw xml of the application response
12 13 14 |
# File 'lib/sepa/application_response.rb', line 12 def xml @xml end |
Instance Method Details
#certificate ⇒ OpenSSL::X509::Certificate?
The certificate which private key has been used to sign the application response
72 73 74 |
# File 'lib/sepa/application_response.rb', line 72 def certificate extract_cert(doc, 'X509Certificate', DSIG) end |
#certificate_is_trusted? ⇒ true, false
Checks whether the embedded certificate has been signed by the private key of the bank's root certificate. The root certificate used varies by bank.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sepa/application_response.rb', line 81 def certificate_is_trusted? root_certificate = case @bank when :nordea NORDEA_ROOT_CERTIFICATE when :danske DANSKE_ROOT_CERTIFICATE end verify_certificate_against_root_certificate(certificate, root_certificate) end |
#doc ⇒ Nokogiri::XML::Document
The application response as a nokogiri xml document
28 29 30 |
# File 'lib/sepa/application_response.rb', line 28 def doc @doc ||= xml_doc @xml end |
#hashes_match? ⇒ true, false
Checks that the hash value reported in the signature matches the one that is calculated locally
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sepa/application_response.rb', line 37 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 |
#response_must_validate_against_schema ⇒ Object (private)
Validates that the response is valid against the application response schema
96 97 98 |
# File 'lib/sepa/application_response.rb', line 96 def response_must_validate_against_schema check_validity_against_schema(doc, 'application_response.xsd') end |
#signature_is_valid? ⇒ true, false
Checks that the signature has been calculated with the private key of the certificate's public key.
56 57 58 |
# File 'lib/sepa/application_response.rb', line 56 def signature_is_valid? validate_signature(doc, certificate, :normal) end |
#to_s ⇒ String
Returns the raw xml of the application response
63 64 65 |
# File 'lib/sepa/application_response.rb', line 63 def to_s @xml end |