Class: Sepa::OpResponse

Inherits:
Response show all
Includes:
Utilities
Defined in:
lib/sepa/banks/op/op_response.rb

Overview

Handles OP specific response logic. Mainly certificate specific stuff.

Constant Summary collapse

BYPASS_COMMANDS =
%i(
  get_certificate
  get_service_certificates
)

Constants included from ErrorMessages

ErrorMessages::CONTENT_ERROR_MESSAGE, ErrorMessages::CUSTOMER_ID_ERROR_MESSAGE, ErrorMessages::DECRYPTION_ERROR_MESSAGE, ErrorMessages::ENCRYPTION_CERT_ERROR_MESSAGE, ErrorMessages::ENCRYPTION_CERT_REQUEST_ERROR_MESSAGE, ErrorMessages::ENCRYPTION_PRIVATE_KEY_ERROR_MESSAGE, ErrorMessages::ENVIRONMENT_ERROR_MESSAGE, ErrorMessages::FILE_REFERENCE_ERROR_MESSAGE, ErrorMessages::FILE_TYPE_ERROR_MESSAGE, ErrorMessages::HASH_ERROR_MESSAGE, ErrorMessages::NOT_OK_RESPONSE_CODE_ERROR_MESSAGE, ErrorMessages::PIN_ERROR_MESSAGE, ErrorMessages::SIGNATURE_ERROR_MESSAGE, ErrorMessages::SIGNING_CERT_REQUEST_ERROR_MESSAGE, ErrorMessages::STATUS_ERROR_MESSAGE, ErrorMessages::TARGET_ID_ERROR_MESSAGE

Instance Attribute Summary

Attributes inherited from Response

#command, #environment, #error, #soap

Instance Method Summary collapse

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

Methods inherited from Response

#application_response, #bank_encryption_certificate, #bank_root_certificate, #bank_signing_certificate, #ca_certificate, #certificate, #client_errors, #content, #doc, #document_must_validate_against_schema, #error_doc, #extract_application_response, #file_references, #find_digest_values, #find_node_by_uri, #find_nodes_to_verify, #hashes_match?, #initialize, #own_encryption_certificate, #response_code_is_ok?, #signature_is_valid?, #to_s, #validate_response_code, #verify_certificate

Constructor Details

This class inherits a constructor from Sepa::Response

Instance Method Details

#certificate_is_trusted?true, false

Checks whether the certificate embedded in the response soap has been signed with OP's root certificate. The check is skipped in test environment, because a different root certificate is used. The check is also skipped for certificate requests because they are not signed

Returns:

  • (true)

    if certificate is trusted

  • (false)

    if certificate fails to verify

See Also:



67
68
69
70
71
# File 'lib/sepa/banks/op/op_response.rb', line 67

def certificate_is_trusted?
  return true if environment == :test || BYPASS_COMMANDS.include?(command)

  verify_certificate_against_root_certificate(certificate, OP_ROOT_CERTIFICATE)
end

#own_signing_certificateString?

Extracts own signing certificate from the response.

Returns:

  • (String)

    own signing certificate as string it it is found

  • (nil)

    if the certificate cannot be found



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sepa/banks/op/op_response.rb', line 15

def own_signing_certificate
  application_response = extract_application_response(OP_PKI)
  at                   = 'xmlns|Certificate > xmlns|Certificate'
  node                 = Nokogiri::XML(application_response).at(at, xmlns: OP_XML_DATA)

  return unless node

  cert_value = process_cert_value node.content
  cert       = x509_certificate cert_value
  cert.to_s
end

#response_codeString?

Returns the response code in the response. Overrides Response#response_code if Response#command is :get_certificate, because the namespace is different with that command.

Returns:

  • (String)

    response code if it is found

  • (nil)

    if response code cannot be found

See Also:



33
34
35
36
37
38
39
40
41
# File 'lib/sepa/banks/op/op_response.rb', line 33

def response_code
  return super unless %i(
    get_certificate
    get_service_certificates
  ).include? command

  node = doc.at('xmlns|ResponseCode', xmlns: OP_PKI)
  node.content if node
end

#response_textString?

Returns the response text in the response. Overrides Response#response_text if Response#command is :get_certificate, because the namespace is different with that command.

Returns:

  • (String)

    response text if it is found

  • (nil)

    if response text cannot be found

See Also:



49
50
51
52
53
54
55
56
57
# File 'lib/sepa/banks/op/op_response.rb', line 49

def response_text
  return super unless %i(
    get_certificate
    get_service_certificates
  ).include? command

  node = doc.at('xmlns|ResponseText', xmlns: OP_PKI)
  node.content if node
end

#validate_hashesObject

Some OP's certificate responses aren't signed



74
75
76
# File 'lib/sepa/banks/op/op_response.rb', line 74

def validate_hashes
  super unless BYPASS_COMMANDS.include?(command)
end

#verify_signatureObject

Some OP's certificate responses aren't signed



79
80
81
# File 'lib/sepa/banks/op/op_response.rb', line 79

def verify_signature
  super unless BYPASS_COMMANDS.include?(command)
end