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
19 20 21 22 |
# File 'lib/sepa/application_response.rb', line 19 def initialize(app_resp, bank) @xml = app_resp @bank = bank end |
Instance Attribute Details
#xml ⇒ String (readonly)
The raw xml of the application response
11 12 13 |
# File 'lib/sepa/application_response.rb', line 11 def xml @xml end |
Instance Method Details
#certificate ⇒ OpenSSL::X509::Certificate?
The certificate which private key has been used to sign the application response
71 72 73 |
# File 'lib/sepa/application_response.rb', line 71 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.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sepa/application_response.rb', line 80 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
27 28 29 |
# File 'lib/sepa/application_response.rb', line 27 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
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sepa/application_response.rb', line 36 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
95 96 97 |
# File 'lib/sepa/application_response.rb', line 95 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.
55 56 57 |
# File 'lib/sepa/application_response.rb', line 55 def signature_is_valid? validate_signature(doc, certificate, :normal) end |
#to_s ⇒ String
Returns the raw xml of the application response
62 63 64 |
# File 'lib/sepa/application_response.rb', line 62 def to_s @xml end |