et_fake_acas_server 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eb1576aa905097e07fb02e00eddb2d7d31b3666afcbcbfff7eead3b1e91fc35
4
- data.tar.gz: c2b2924e9ff62ed86f1fb83c380564af1f96fd87a408479b15ba7958385aa50b
3
+ metadata.gz: df1e3d0a4eb74db657cd414d241db42bda898b486d58f90d4d3fb36dcb8e7021
4
+ data.tar.gz: 8dc55a2fbf8a876c264c2b62df697f2a225d00643d3100ccec954e890c0ef312
5
5
  SHA512:
6
- metadata.gz: e020832a9875ea972225cb13b861d13d009a700b975cb05623749ed5c908a9b3fc733336c9e74c777e4ceb2e485c34d5a19db77ed1cf15bb86245370a5afba3e
7
- data.tar.gz: e60a41b5b7ff70f5a351a8826c4d85bc4205e187e744fc9ce68840dfd5fc6423309ad33424c2a57eff047ead3e81982e69fdb152a427ae31779dcb38e2fce8e4
6
+ metadata.gz: 750f165ebf45b7b8cdae1eb8e6ff61cce2a641f728c3b1fdd16be88498721808a2e2750dd85b2cd2f763a892c29cd12b00267e666055083866ccaf9a29087a89
7
+ data.tar.gz: 48c1d190c4391b001b66db4d2d4725bdf4846a973f057994dc7793fa8bbafa88a83f977123ffe1addd2c8b138dd1793c9b6b6cc3f718932b33f0f58278e42614
data/Gemfile.lock CHANGED
@@ -1,57 +1,53 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- et_fake_acas_server (0.2.3)
5
- activesupport (~> 6.1)
4
+ et_fake_acas_server (1.0.0)
5
+ activesupport (>= 6.1)
6
6
  iodine (~> 0.7)
7
7
  nokogiri (~> 1.8, >= 1.8.2)
8
- ruby-mcrypt (~> 0.2)
9
8
  sinatra (~> 2.0, >= 2.0.3)
10
9
  sinatra-contrib (~> 2.0)
11
10
 
12
11
  GEM
13
12
  remote: https://rubygems.org/
14
13
  specs:
15
- activesupport (6.1.6)
14
+ activesupport (7.0.3.1)
16
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
16
  i18n (>= 1.6, < 2)
18
17
  minitest (>= 5.1)
19
18
  tzinfo (~> 2.0)
20
- zeitwerk (~> 2.3)
21
19
  concurrent-ruby (1.1.10)
22
- i18n (1.10.0)
20
+ i18n (1.12.0)
23
21
  concurrent-ruby (~> 1.0)
24
- iodine (0.7.47)
22
+ iodine (0.7.48)
25
23
  mini_portile2 (2.8.0)
26
- minitest (5.16.1)
24
+ minitest (5.16.3)
27
25
  multi_json (1.15.0)
28
- mustermann (1.1.1)
26
+ mustermann (2.0.2)
29
27
  ruby2_keywords (~> 0.0.1)
30
- nokogiri (1.13.6)
28
+ nokogiri (1.13.8)
31
29
  mini_portile2 (~> 2.8.0)
32
30
  racc (~> 1.4)
33
31
  racc (1.6.0)
34
- rack (2.2.3.1)
35
- rack-protection (2.2.0)
32
+ rack (2.2.4)
33
+ rack-protection (2.2.2)
36
34
  rack
37
35
  rake (13.0.1)
38
- ruby-mcrypt (0.2.0)
39
36
  ruby2_keywords (0.0.5)
40
- sinatra (2.2.0)
41
- mustermann (~> 1.0)
37
+ sinatra (2.2.2)
38
+ mustermann (~> 2.0)
42
39
  rack (~> 2.2)
43
- rack-protection (= 2.2.0)
40
+ rack-protection (= 2.2.2)
44
41
  tilt (~> 2.0)
45
- sinatra-contrib (2.2.0)
42
+ sinatra-contrib (2.2.2)
46
43
  multi_json
47
- mustermann (~> 1.0)
48
- rack-protection (= 2.2.0)
49
- sinatra (= 2.2.0)
44
+ mustermann (~> 2.0)
45
+ rack-protection (= 2.2.2)
46
+ sinatra (= 2.2.2)
50
47
  tilt (~> 2.0)
51
- tilt (2.0.10)
52
- tzinfo (2.0.4)
48
+ tilt (2.0.11)
49
+ tzinfo (2.0.5)
53
50
  concurrent-ruby (~> 1.0)
54
- zeitwerk (2.6.0)
55
51
 
56
52
  PLATFORMS
57
53
  ruby
@@ -27,6 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'sinatra-contrib', '~> 2.0'
28
28
  spec.add_dependency 'sinatra', '~> 2.0', '>= 2.0.3'
29
29
  spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
30
- spec.add_dependency 'activesupport', '~> 6.1'
31
- spec.add_dependency 'ruby-mcrypt', '~> 0.2'
30
+ spec.add_dependency 'activesupport', '>= 6.1'
32
31
  end
@@ -33,9 +33,8 @@ module EtFakeAcasServer
33
33
  when /\A(R|NE|MU)000200/ then
34
34
  json_builder_for_no_match(certificate_number)
35
35
  when /\A(R|NE|MU)000500/ then
36
- json_builder_for_internal_error
36
+ halt 500, JSON.pretty_generate(json_builder_for_internal_error)
37
37
  else
38
- status 500
39
38
  json_builder_for_found(certificate_number)
40
39
  end
41
40
  end
@@ -1,12 +1,10 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/custom_logger'
3
3
  require 'logger'
4
- require 'et_fake_acas_server/soap_server'
5
4
  require 'et_fake_acas_server/json_server'
6
5
 
7
6
  module EtFakeAcasServer
8
7
  class Server < Sinatra::Base
9
- post(/\/Lookup\/.*/) { SoapServer.call(env) }
10
8
  post(/\/ECCLJson/) { JsonServer.call(env) }
11
9
  end
12
10
  end
@@ -1,3 +1,3 @@
1
1
  module EtFakeAcasServer
2
- VERSION = "0.2.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: et_fake_acas_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-21 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,30 +110,16 @@ dependencies:
110
110
  name: activesupport
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '6.1'
116
116
  type: :runtime
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '6.1'
123
- - !ruby/object:Gem::Dependency
124
- name: ruby-mcrypt
125
- requirement: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '0.2'
130
- type: :runtime
131
- prerelease: false
132
- version_requirements: !ruby/object:Gem::Requirement
133
- requirements:
134
- - - "~>"
135
- - !ruby/object:Gem::Version
136
- version: '0.2'
137
123
  description: Standalone fake acas server for use during dev and test of the employment
138
124
  tribunal system
139
125
  email:
@@ -158,16 +144,10 @@ files:
158
144
  - exe/et_fake_acas_server
159
145
  - lib/config.ru
160
146
  - lib/et_fake_acas_server.rb
161
- - lib/et_fake_acas_server/forms/certificate_lookup_form.rb
162
147
  - lib/et_fake_acas_server/forms/certificates_lookup_form.rb
163
148
  - lib/et_fake_acas_server/json_server.rb
164
149
  - lib/et_fake_acas_server/server.rb
165
- - lib/et_fake_acas_server/soap_server.rb
166
150
  - lib/et_fake_acas_server/version.rb
167
- - lib/et_fake_acas_server/xml_builders/found_xml_builder.rb
168
- - lib/et_fake_acas_server/xml_builders/internal_error_xml_builder.rb
169
- - lib/et_fake_acas_server/xml_builders/invalid_certificate_format_xml_builder.rb
170
- - lib/et_fake_acas_server/xml_builders/no_match_xml_builder.rb
171
151
  - lib/pdfs/76 EC (C) Certificate R000080.pdf
172
152
  - public/.keep
173
153
  - temp_x509/acas/privatekey.pem
@@ -1,68 +0,0 @@
1
- require 'nokogiri'
2
- require 'base64'
3
- require 'active_support'
4
- require 'active_support/core_ext/string'
5
- module EtFakeAcasServer
6
- class CertificateLookupForm
7
- def initialize(xml, private_key_file: )
8
- self.xml = xml
9
- self.private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file))
10
- end
11
-
12
- def validate
13
- validate_digest
14
- validate_signature
15
- end
16
-
17
- def certificate_number
18
- parsed_values[:ec_certificate_number]
19
- end
20
-
21
- private
22
-
23
- def parsed_values
24
- @parsed_values ||= begin
25
- doc = Nokogiri::XML(xml)
26
- doc.xpath('//env:Envelope/env:Body/tns:GetECCertificate/tns:request').children.inject({}) do |acc, child|
27
- decoded = Base64.decode64(child.text)
28
- decrypted = private_key.private_decrypt(decoded, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
29
- acc[child.name.underscore.to_sym] = decrypted
30
- acc
31
- end
32
- end
33
- end
34
-
35
- def validate_digest
36
- doc = Nokogiri::XML(xml)
37
- node = doc.xpath('//env:Envelope/env:Header/wsse:Security/wsu:Timestamp', doc.collect_namespaces).first
38
- digest_value = Base64.encode64(OpenSSL::Digest::SHA1.digest(node.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0))).strip
39
-
40
- ns = doc.collect_namespaces
41
- ns['xmlns:ds'] = ns.delete('xmlns')
42
- provided_digest_value = doc.at_xpath('//env:Envelope/env:Header/wsse:Security/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue', ns).text
43
- if digest_value != provided_digest_value
44
- raise 'Wrong digest value'
45
- end
46
-
47
- end
48
-
49
- def validate_signature
50
- doc = Nokogiri::XML(xml)
51
- ns = doc.collect_namespaces
52
- ns['xmlns:ds'] = ns.delete('xmlns')
53
- signed_info_node = doc.at_xpath('//env:Envelope/env:Header/wsse:Security/ds:Signature/ds:SignedInfo', ns)
54
- signature_value_node = doc.at_xpath('//env:Envelope/env:Header/wsse:Security/ds:Signature/ds:SignatureValue', ns)
55
- signature_value = Base64.decode64(signature_value_node.text)
56
- security_token_url = doc.at_xpath('//env:Envelope/env:Header/wsse:Security/ds:Signature/ds:KeyInfo/wsse:SecurityTokenReference/wsse:Reference', ns)['URI'][1..-1]
57
- certificate_value = doc.at_xpath("//env:Envelope/env:Header/wsse:Security/wsse:BinarySecurityToken[@wsu:Id='#{security_token_url}']", ns).text.strip
58
- our_certificate = OpenSSL::X509::Certificate.new Base64.decode64(certificate_value)
59
- document = signed_info_node.canonicalize(Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0)
60
- unless our_certificate.public_key.verify(OpenSSL::Digest::SHA1.new, signature_value, document)
61
- raise 'Invalid signature'
62
- end
63
-
64
- end
65
-
66
- attr_accessor :xml, :private_key
67
- end
68
- end
@@ -1,72 +0,0 @@
1
- require 'sinatra/base'
2
- require 'sinatra/custom_logger'
3
- require 'logger'
4
- require 'et_fake_acas_server/forms/certificate_lookup_form'
5
- require 'et_fake_acas_server/xml_builders/found_xml_builder'
6
- require 'et_fake_acas_server/xml_builders/no_match_xml_builder'
7
- require 'et_fake_acas_server/xml_builders/internal_error_xml_builder'
8
- require 'et_fake_acas_server/xml_builders/invalid_certificate_format_xml_builder'
9
- require 'active_support'
10
- require 'active_support/core_ext/numeric/time'
11
-
12
-
13
- module EtFakeAcasServer
14
- class SoapServer < Sinatra::Base
15
- def initialize(*)
16
- super
17
- self.private_key_file = ENV.fetch('ACAS_PRIVATE_KEY_FILE', File.absolute_path(File.join('..', '..', 'temp_x509', 'acas', 'privatekey.pem'), __dir__))
18
- self.et_public_key_file = ENV.fetch('ET_PUBLIC_KEY_FILE', File.absolute_path(File.join('..', '..', 'temp_x509', 'et', 'publickey.cer'), __dir__))
19
- end
20
-
21
- configure :development, :production do
22
- logger = Logger.new(STDOUT)
23
- logger.level = Logger::DEBUG
24
- set :logger, logger
25
- end
26
-
27
- post '/Lookup/ECService.svc' do
28
- form = CertificateLookupForm.new(request.body.read, private_key_file: private_key_file)
29
- request.body.rewind
30
- form.validate
31
- case form.certificate_number
32
- when /\A(R|NE|MU)000200/ then
33
- xml_builder_for_no_match(form).to_xml
34
- when /\A(R|NE|MU)000201/ then
35
- xml_builder_for_invalid_certificate_format(form).to_xml
36
- when /\A(R|NE|MU)000500/ then
37
- xml_builder_for_internal_error(form).to_xml
38
- else
39
- xml_builder_for_found(form).to_xml
40
- end
41
- end
42
-
43
- private
44
-
45
- attr_accessor :private_key_file, :et_public_key_file
46
-
47
- def xml_builder_for_found(form)
48
- data = OpenStruct.new claimant_name: 'Claimant’s Name',
49
- respondent_name: 'Respondent’s Name',
50
- date_of_issue: Time.parse('1 December 2017 12:00:00'),
51
- date_of_receipt: Time.parse('1 January 2017 12:00:00'),
52
- certificate_number: form.certificate_number,
53
- message: 'CertificateFound',
54
- method_of_issue: 'Email',
55
- certificate_file: File.absolute_path(File.join('..', 'pdfs', '76 EC (C) Certificate R000080.pdf'), __dir__)
56
- FoundXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder(data)
57
- end
58
-
59
- def xml_builder_for_no_match(form)
60
- NoMatchXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
61
- end
62
-
63
- def xml_builder_for_internal_error(form)
64
- InternalErrorXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
65
- end
66
-
67
- def xml_builder_for_invalid_certificate_format(form)
68
- InvalidCertificateFormatXmlBuilder.new(form, rsa_et_certificate_path: et_public_key_file).builder
69
- end
70
- end
71
- end
72
-
@@ -1,77 +0,0 @@
1
- require 'base64'
2
- require 'openssl'
3
- require 'mcrypt'
4
-
5
- module EtFakeAcasServer
6
- class FoundXmlBuilder
7
- def initialize(form, rsa_et_certificate_path:)
8
- self.form = form
9
- self.rsa_et_certificate = OpenSSL::X509::Certificate.new File.read(rsa_et_certificate_path)
10
- end
11
-
12
- def key
13
- @key ||= '12345678901234567890123456789012'
14
- end
15
-
16
- def iv
17
- @iv ||= '12345678901234567890123456789012'
18
- end
19
-
20
- def builder(data)
21
- Nokogiri::XML::Builder.new do |xml|
22
- namespaces = {
23
- 'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope',
24
- 'xmlns:u' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
25
- }
26
- xml['s'].Envelope(namespaces) do
27
- xml['s'].Header do
28
- xml.ActivityId("e67a4d86-e096-4a35-aa3a-2b3a8ffaaa54", 'CorrelationId': '03973d23-3c39-4359-aa69-4d37b922fb60', xmlns: 'http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics')
29
- xml['o'].Security('s:mustUnderstand': '1', 'xmlns:o': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd') do
30
- xml['u'].Timestamp('u:Id': '_0') do
31
- xml['u'].Created '2014-03-03T10:15.01.251Z'
32
- xml['u'].Expires '2014-03-03T10:20:01.251Z'
33
- end
34
- end
35
- end
36
- xml['s'].Body do
37
- xml.GetECCertificateResponse(xmlns: 'https://ec.acas.org.uk/lookup/') do
38
- xml.GetECCertificateResult('xmlns:a': 'http://schemas.datacontract.org/2004/07/Acas.CertificateLookup.EcLookupService', 'xmlns:i': 'http://www.w3.org/2001/XMLSchema-instance') do
39
- xml['a'].Certificate Base64.encode64(aes_encrypt(Base64.encode64(File.read(data.certificate_file))))
40
- xml['a'].ClaimantName Base64.encode64(aes_encrypt(data.claimant_name))
41
- xml['a'].CurrentDateTime Base64.encode64(aes_encrypt(Time.now.strftime('%d/%m/%Y %H:%M:%S')))
42
- xml['a'].DateOfIssue Base64.encode64(aes_encrypt(data.date_of_issue.strftime('%d/%m/%Y %H:%M:%S')))
43
- xml['a'].DateOfReceipt Base64.encode64(aes_encrypt(data.date_of_receipt.strftime('%d/%m/%Y %H:%M:%S')))
44
- xml['a'].ECCertificateNumber Base64.encode64(aes_encrypt(data.certificate_number))
45
- xml['a'].IV Base64.encode64(rsa_encrypt(Base64.encode64(iv)))
46
- xml['a'].Key Base64.encode64(rsa_encrypt(Base64.encode64(key)))
47
- xml['a'].Message Base64.encode64(aes_encrypt(data.message))
48
- xml['a'].MethodOfIssue Base64.encode64(aes_encrypt(data.method_of_issue))
49
- xml['a'].RespondentName Base64.encode64(aes_encrypt(data.respondent_name))
50
- xml['a'].ResponseCode Base64.encode64(aes_encrypt('100'))
51
- xml['a'].ServiceVersion Base64.encode64(aes_encrypt('1.0'))
52
- end
53
- end
54
- end
55
- end
56
- end
57
-
58
- end
59
-
60
- private
61
-
62
- attr_accessor :rsa_et_certificate, :form
63
-
64
- def aes_encrypt(value)
65
- encrypt_cipher = build_encrypt_cipher
66
- encrypt_cipher.encrypt(String.new(value, encoding: 'ascii-8bit'))
67
- end
68
-
69
- def build_encrypt_cipher
70
- Mcrypt.new(:rijndael_256, :cbc, key, iv, :pkcs7)
71
- end
72
-
73
- def rsa_encrypt(value)
74
- rsa_et_certificate.public_key.public_encrypt(value, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
75
- end
76
- end
77
- end
@@ -1,70 +0,0 @@
1
- require 'base64'
2
- require 'openssl'
3
- require 'mcrypt'
4
-
5
- module EtFakeAcasServer
6
- class InternalErrorXmlBuilder
7
- def initialize(form, rsa_et_certificate_path:)
8
- self.form = form
9
- self.rsa_et_certificate = OpenSSL::X509::Certificate.new File.read(rsa_et_certificate_path)
10
- end
11
-
12
- def key
13
- @key ||= '12345678901234567890123456789012'
14
- end
15
-
16
- def iv
17
- @iv ||= '12345678901234567890123456789012'
18
- end
19
-
20
- def builder
21
- Nokogiri::XML::Builder.new do |xml|
22
- namespaces = {
23
- 'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope',
24
- 'xmlns:u' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
25
- }
26
- xml['s'].Envelope(namespaces) do
27
- xml['s'].Header do
28
- xml.ActivityId("e67a4d86-e096-4a35-aa3a-2b3a8ffaaa54", 'CorrelationId': '03973d23-3c39-4359-aa69-4d37b922fb60', xmlns: 'http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics')
29
- xml['o'].Security('s:mustUnderstand': '1', 'xmlns:o': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd') do
30
- xml['u'].Timestamp('u:Id': '_0') do
31
- xml['u'].Created '2014-03-03T10:15.01.251Z'
32
- xml['u'].Expires '2014-03-03T10:20:01.251Z'
33
- end
34
- end
35
- end
36
- xml['s'].Body do
37
- xml.GetECCertificateResponse(xmlns: 'https://ec.acas.org.uk/lookup/') do
38
- xml.GetECCertificateResult('xmlns:a': 'http://schemas.datacontract.org/2004/07/Acas.CertificateLookup.EcLookupService', 'xmlns:i': 'http://www.w3.org/2001/XMLSchema-instance') do
39
- xml['a'].CurrentDateTime Base64.encode64(aes_encrypt(Time.now.strftime('%d/%m/%Y %H:%M:%S')))
40
- xml['a'].IV Base64.encode64(rsa_encrypt(Base64.encode64(iv)))
41
- xml['a'].Key Base64.encode64(rsa_encrypt(Base64.encode64(key)))
42
- xml['a'].Message Base64.encode64(aes_encrypt('An internal error has occured in ACAS'))
43
- xml['a'].ResponseCode Base64.encode64(aes_encrypt('500'))
44
- xml['a'].ServiceVersion Base64.encode64(aes_encrypt('1.0'))
45
- end
46
- end
47
- end
48
- end
49
- end
50
-
51
- end
52
-
53
- private
54
-
55
- attr_accessor :rsa_et_certificate, :form
56
-
57
- def aes_encrypt(value)
58
- encrypt_cipher = build_encrypt_cipher
59
- encrypt_cipher.encrypt(value)
60
- end
61
-
62
- def build_encrypt_cipher
63
- Mcrypt.new(:rijndael_256, :cbc, key, iv, :pkcs7)
64
- end
65
-
66
- def rsa_encrypt(value)
67
- rsa_et_certificate.public_key.public_encrypt(value, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
68
- end
69
- end
70
- end
@@ -1,68 +0,0 @@
1
- require 'base64'
2
- require 'openssl'
3
- module EtFakeAcasServer
4
- class InvalidCertificateFormatXmlBuilder
5
- def initialize(form, rsa_et_certificate_path:)
6
- self.form = form
7
- self.rsa_et_certificate = OpenSSL::X509::Certificate.new File.read(rsa_et_certificate_path)
8
- end
9
-
10
- def key
11
- @key ||= '12345678901234567890123456789012'
12
- end
13
-
14
- def iv
15
- @iv ||= '12345678901234567890123456789012'
16
- end
17
-
18
- def builder
19
- Nokogiri::XML::Builder.new do |xml|
20
- namespaces = {
21
- 'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope',
22
- 'xmlns:u' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
23
- }
24
- xml['s'].Envelope(namespaces) do
25
- xml['s'].Header do
26
- xml.ActivityId("e67a4d86-e096-4a35-aa3a-2b3a8ffaaa54", 'CorrelationId': '03973d23-3c39-4359-aa69-4d37b922fb60', xmlns: 'http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics')
27
- xml['o'].Security('s:mustUnderstand': '1', 'xmlns:o': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd') do
28
- xml['u'].Timestamp('u:Id': '_0') do
29
- xml['u'].Created '2014-03-03T10:15.01.251Z'
30
- xml['u'].Expires '2014-03-03T10:20:01.251Z'
31
- end
32
- end
33
- end
34
- xml['s'].Body do
35
- xml.GetECCertificateResponse(xmlns: 'https://ec.acas.org.uk/lookup/') do
36
- xml.GetECCertificateResult('xmlns:a': 'http://schemas.datacontract.org/2004/07/Acas.CertificateLookup.EcLookupService', 'xmlns:i': 'http://www.w3.org/2001/XMLSchema-instance') do
37
- xml['a'].CurrentDateTime Base64.encode64(aes_encrypt(Time.now.strftime('%d/%m/%Y %H:%M:%S')))
38
- xml['a'].IV Base64.encode64(rsa_encrypt(Base64.encode64(iv)))
39
- xml['a'].Key Base64.encode64(rsa_encrypt(Base64.encode64(key)))
40
- xml['a'].Message Base64.encode64(aes_encrypt('Invalid certificate format'))
41
- xml['a'].ResponseCode Base64.encode64(aes_encrypt('201'))
42
- xml['a'].ServiceVersion Base64.encode64(aes_encrypt('1.0'))
43
- end
44
- end
45
- end
46
- end
47
- end
48
-
49
- end
50
-
51
- private
52
-
53
- attr_accessor :rsa_et_certificate, :form
54
-
55
- def aes_encrypt(value)
56
- encrypt_cipher = build_encrypt_cipher
57
- encrypt_cipher.encrypt(value)
58
- end
59
-
60
- def build_encrypt_cipher
61
- Mcrypt.new(:rijndael_256, :cbc, key, iv, :pkcs7)
62
- end
63
-
64
- def rsa_encrypt(value)
65
- rsa_et_certificate.public_key.public_encrypt(value, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
66
- end
67
- end
68
- end
@@ -1,68 +0,0 @@
1
- require 'base64'
2
- require 'openssl'
3
- module EtFakeAcasServer
4
- class NoMatchXmlBuilder
5
- def initialize(form, rsa_et_certificate_path:)
6
- self.form = form
7
- self.rsa_et_certificate = OpenSSL::X509::Certificate.new File.read(rsa_et_certificate_path)
8
- end
9
-
10
- def key
11
- @key ||= '12345678901234567890123456789012'
12
- end
13
-
14
- def iv
15
- @iv ||= '12345678901234567890123456789012'
16
- end
17
-
18
- def builder
19
- Nokogiri::XML::Builder.new do |xml|
20
- namespaces = {
21
- 'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope',
22
- 'xmlns:u' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
23
- }
24
- xml['s'].Envelope(namespaces) do
25
- xml['s'].Header do
26
- xml.ActivityId("e67a4d86-e096-4a35-aa3a-2b3a8ffaaa54", 'CorrelationId': '03973d23-3c39-4359-aa69-4d37b922fb60', xmlns: 'http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics')
27
- xml['o'].Security('s:mustUnderstand': '1', 'xmlns:o': 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd') do
28
- xml['u'].Timestamp('u:Id': '_0') do
29
- xml['u'].Created '2014-03-03T10:15.01.251Z'
30
- xml['u'].Expires '2014-03-03T10:20:01.251Z'
31
- end
32
- end
33
- end
34
- xml['s'].Body do
35
- xml.GetECCertificateResponse(xmlns: 'https://ec.acas.org.uk/lookup/') do
36
- xml.GetECCertificateResult('xmlns:a': 'http://schemas.datacontract.org/2004/07/Acas.CertificateLookup.EcLookupService', 'xmlns:i': 'http://www.w3.org/2001/XMLSchema-instance') do
37
- xml['a'].CurrentDateTime Base64.encode64(aes_encrypt(Time.now.strftime('%d/%m/%Y %H:%M:%S')))
38
- xml['a'].IV Base64.encode64(rsa_encrypt(Base64.encode64(iv)))
39
- xml['a'].Key Base64.encode64(rsa_encrypt(Base64.encode64(key)))
40
- xml['a'].Message Base64.encode64(aes_encrypt('Certificate not found'))
41
- xml['a'].ResponseCode Base64.encode64(aes_encrypt('200'))
42
- xml['a'].ServiceVersion Base64.encode64(aes_encrypt('1.0'))
43
- end
44
- end
45
- end
46
- end
47
- end
48
-
49
- end
50
-
51
- private
52
-
53
- attr_accessor :rsa_et_certificate, :form
54
-
55
- def aes_encrypt(value)
56
- encrypt_cipher = build_encrypt_cipher
57
- encrypt_cipher.encrypt(value)
58
- end
59
-
60
- def build_encrypt_cipher
61
- Mcrypt.new(:rijndael_256, :cbc, key, iv, :pkcs7)
62
- end
63
-
64
- def rsa_encrypt(value)
65
- rsa_et_certificate.public_key.public_encrypt(value, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
66
- end
67
- end
68
- end