Class: Sepa::Response
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Validations, Utilities
- Defined in:
- lib/sepa/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(hash = {}) ⇒ Response
Returns a new instance of Response.
13
14
15
16
17
18
|
# File 'lib/sepa/response.rb', line 13
def initialize(hash = {})
@soap = hash[:response]
@command = hash[:command]
@error = hash[:error]
@encryption_private_key = hash[:encryption_private_key]
end
|
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
6
7
8
|
# File 'lib/sepa/response.rb', line 6
def command
@command
end
|
#error ⇒ Object
Returns the value of attribute error.
6
7
8
|
# File 'lib/sepa/response.rb', line 6
def error
@error
end
|
#soap ⇒ Object
Returns the value of attribute soap.
6
7
8
|
# File 'lib/sepa/response.rb', line 6
def soap
@soap
end
|
Instance Method Details
#application_response ⇒ Object
Gets the application response from the response as an xml document
65
66
67
|
# File 'lib/sepa/response.rb', line 65
def application_response
@application_response ||= (BXD)
end
|
#bank_encryption_certificate ⇒ Object
112
|
# File 'lib/sepa/response.rb', line 112
def bank_encryption_certificate; end
|
#bank_root_certificate ⇒ Object
116
|
# File 'lib/sepa/response.rb', line 116
def bank_root_certificate; end
|
#bank_signing_certificate ⇒ Object
114
|
# File 'lib/sepa/response.rb', line 114
def bank_signing_certificate; end
|
#ca_certificate ⇒ Object
122
|
# File 'lib/sepa/response.rb', line 122
def ca_certificate; end
|
#certificate ⇒ Object
79
80
81
82
83
|
# File 'lib/sepa/response.rb', line 79
def certificate
@certificate ||= begin
(doc, 'BinarySecurityToken', OASIS_SECEXT)
end
end
|
#content ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/sepa/response.rb', line 85
def content
@content ||= begin
xml = xml_doc(application_response)
case @command
when :download_file
content_node = xml.at('xmlns|Content', xmlns: XML_DATA)
content_node.content if content_node
when :download_file_list
content_node = xml.remove_namespaces!.at('FileDescriptors')
content_node.to_xml if content_node
when :get_user_info
canonicalized_node(xml, XML_DATA, 'UserFileTypes')
when :upload_file
signature_node = xml.at('xmlns|Signature', xmlns: DSIG)
if signature_node
signature_node.remove
xml.canonicalize
end
end
end
end
|
#doc ⇒ Object
20
21
22
|
# File 'lib/sepa/response.rb', line 20
def doc
@doc ||= xml_doc @soap
end
|
#file_references ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/sepa/response.rb', line 69
def file_references
return unless @command == :download_file_list
@file_references ||= begin
xml = xml_doc content
descriptors = xml.css('FileDescriptor')
descriptors.map { |descriptor| descriptor.at('FileReference').content }
end
end
|
#hashes_match?(options = {}) ⇒ Boolean
Verifies that all digest values in the response match the actual ones. Takes an optional verbose parameter to show which digests didn’t match i.e. verbose: true
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/sepa/response.rb', line 27
def hashes_match?(options = {})
digests = find_digest_values
nodes = find_nodes_to_verify(digests)
verified_digests = digests.select do |uri, digest|
uri = uri.sub(/^#/, '')
digest == nodes[uri]
end
return true if digests == verified_digests
unverified_digests = digests.select do |uri, digest|
uri = uri.sub(/^#/, '')
digest != nodes[uri]
end
if options[:verbose]
puts "These digests failed to verify: #{unverified_digests}."
end
false
end
|
#own_encryption_certificate ⇒ Object
118
|
# File 'lib/sepa/response.rb', line 118
def own_encryption_certificate; end
|
#own_signing_certificate ⇒ Object
120
|
# File 'lib/sepa/response.rb', line 120
def own_signing_certificate; end
|
#signature_is_valid? ⇒ Boolean
Verifies the signature by extracting the public key from the certificate embedded in the soap header and verifying the signature value with that.
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sepa/response.rb', line 52
def signature_is_valid?
node = doc.at('xmlns|SignedInfo', xmlns: DSIG)
node = canonicalize_exclusively node
signature = doc.at('xmlns|SignatureValue', xmlns: DSIG).content
signature = decode(signature)
certificate.public_key.verify(OpenSSL::Digest::SHA1.new, signature, node)
end
|
#to_s ⇒ Object
108
109
110
|
# File 'lib/sepa/response.rb', line 108
def to_s
@soap
end
|