xmlenc 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +7 -8
- data/CHANGELOG.md +5 -0
- data/README.md +4 -1
- data/Rakefile +3 -3
- data/lib/xmlenc.rb +1 -0
- data/lib/xmlenc/algorithms/aes_gcm.rb +59 -0
- data/lib/xmlenc/builder/base.rb +1 -1
- data/lib/xmlenc/builder/encrypted_data.rb +4 -1
- data/lib/xmlenc/encrypted_data.rb +4 -1
- data/lib/xmlenc/version.rb +1 -1
- data/spec/lib/xmlenc/algorithms/aes_gcm_spec.rb +65 -0
- data/spec/lib/xmlenc/builder/base_spec.rb +1 -1
- data/xmlenc.gemspec +17 -25
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 189069caca22405d127c3d7814b26a34203962b33537d39684d7bcf54bec40cd
|
4
|
+
data.tar.gz: b3d3b202f281123001ded9d4a01e210fdfa4d70408a693e73d1d6017f7164df2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e2f5fed7fe6be20f00b009d8346f76dddfdf72ed042adc328bd0b5dfbd81b77651eecc82e4201086b18f0c5c96db73df75855bac4ed7ddc2aeb8345bea90c2
|
7
|
+
data.tar.gz: 533f7b9c88eba4686ea805b7aadfa1f2a02a745e0dd1926e9d6e5459f8163bacb6ed5b3ae56f1372bbb041ecc00b21bc74a4807403abeddf42e23f64ef91ed7d
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.
|
1
|
+
[![Build Status](https://app.travis-ci.com/digidentity/xmlenc.svg?branch=master)](https://app.travis-ci.com/digidentity/xmlenc)
|
2
2
|
[![Coverage Status](https://coveralls.io/repos/digidentity/xmlenc/badge.svg?branch=master&service=github)](https://coveralls.io/github/digidentity/xmlenc?branch=master)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/digidentity/xmlenc/badges/gpa.svg)](https://codeclimate.com/github/digidentity/xmlenc)
|
4
4
|
|
@@ -39,6 +39,9 @@ Data algorithms
|
|
39
39
|
* http://www.w3.org/2001/04/xmlenc#tripledes-cbc
|
40
40
|
* http://www.w3.org/2001/04/xmlenc#aes128-cbc
|
41
41
|
* http://www.w3.org/2001/04/xmlenc#aes256-cbc
|
42
|
+
* http://www.w3.org/2009/xmlenc11#aes128-gcm
|
43
|
+
* http://www.w3.org/2009/xmlenc11#aes192-gcm
|
44
|
+
* http://www.w3.org/2009/xmlenc11#aes256-gcm
|
42
45
|
|
43
46
|
Key algorithms
|
44
47
|
|
data/Rakefile
CHANGED
@@ -25,8 +25,8 @@ require "rake/testtask"
|
|
25
25
|
|
26
26
|
require "rspec/core/rake_task"
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
RSpec::Core::RakeTask.new(:core) do |spec|
|
29
|
+
spec.rspec_opts = ['--backtrace']
|
30
|
+
end
|
31
31
|
|
32
32
|
task :default => [:core]
|
data/lib/xmlenc.rb
CHANGED
@@ -38,6 +38,7 @@ module Xmlenc
|
|
38
38
|
autoload :RsaOaepMgf1p, 'xmlenc/algorithms/rsa_oaep_mgf1p'
|
39
39
|
autoload :DES3CBC, 'xmlenc/algorithms/des3_cbc'
|
40
40
|
autoload :AESCBC, 'xmlenc/algorithms/aes_cbc'
|
41
|
+
autoload :AESGCM, 'xmlenc/algorithms/aes_gcm'
|
41
42
|
end
|
42
43
|
|
43
44
|
autoload :EncryptedDocument, 'xmlenc/encrypted_document'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Xmlenc
|
2
|
+
module Algorithms
|
3
|
+
class AESGCM
|
4
|
+
AUTH_TAG_LEN = 16
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def [](size)
|
8
|
+
new(size)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(size)
|
13
|
+
@size = size
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup(key = nil)
|
17
|
+
@cipher= nil
|
18
|
+
@iv = nil
|
19
|
+
@key = key || cipher.random_key
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def decrypt(cipher_value, options = {})
|
24
|
+
cipher.decrypt
|
25
|
+
cipher.padding = 0
|
26
|
+
cipher.key = @key
|
27
|
+
cipher.iv = cipher_value[0...iv_len]
|
28
|
+
cipher.auth_tag = cipher_value[-AUTH_TAG_LEN..-1]
|
29
|
+
cipher.update(cipher_value[iv_len..-(AUTH_TAG_LEN + 1)]) << cipher.final
|
30
|
+
end
|
31
|
+
|
32
|
+
def encrypt(data, options = {})
|
33
|
+
cipher.encrypt
|
34
|
+
cipher.key = @key
|
35
|
+
cipher.iv = iv
|
36
|
+
cipher.auth_data = ''
|
37
|
+
iv << (cipher.update(data) << cipher.final) << cipher.auth_tag
|
38
|
+
end
|
39
|
+
|
40
|
+
def key
|
41
|
+
@key
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def iv
|
47
|
+
@iv ||= cipher.random_iv
|
48
|
+
end
|
49
|
+
|
50
|
+
def iv_len
|
51
|
+
cipher.iv_len
|
52
|
+
end
|
53
|
+
|
54
|
+
def cipher
|
55
|
+
@cipher ||= OpenSSL::Cipher.new("aes-#{@size}-gcm")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/xmlenc/builder/base.rb
CHANGED
@@ -31,7 +31,7 @@ module Xmlenc
|
|
31
31
|
|
32
32
|
module XmlMapperClassMethods
|
33
33
|
def parse(xml, options = {})
|
34
|
-
raise Xmlenc::UnparseableMessage("Unable to parse nil document") if xml.nil?
|
34
|
+
raise Xmlenc::UnparseableMessage.new("Unable to parse nil document") if xml.nil?
|
35
35
|
|
36
36
|
object = super
|
37
37
|
if object.is_a?(Array)
|
@@ -6,7 +6,10 @@ module Xmlenc
|
|
6
6
|
ALGORITHMS = {
|
7
7
|
'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' => Algorithms::DES3CBC,
|
8
8
|
'http://www.w3.org/2001/04/xmlenc#aes128-cbc' => Algorithms::AESCBC[128],
|
9
|
-
'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => Algorithms::AESCBC[256]
|
9
|
+
'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => Algorithms::AESCBC[256],
|
10
|
+
'http://www.w3.org/2009/xmlenc11#aes128-gcm' => Algorithms::AESGCM[128],
|
11
|
+
'http://www.w3.org/2009/xmlenc11#aes192-gcm' => Algorithms::AESGCM[192],
|
12
|
+
'http://www.w3.org/2009/xmlenc11#aes256-gcm' => Algorithms::AESGCM[256]
|
10
13
|
}
|
11
14
|
TYPES = {
|
12
15
|
'http://www.w3.org/2001/04/xmlenc#Element' => :element,
|
@@ -3,7 +3,10 @@ module Xmlenc
|
|
3
3
|
ALGORITHMS = {
|
4
4
|
'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' => Algorithms::DES3CBC,
|
5
5
|
'http://www.w3.org/2001/04/xmlenc#aes128-cbc' => Algorithms::AESCBC[128],
|
6
|
-
'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => Algorithms::AESCBC[256]
|
6
|
+
'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => Algorithms::AESCBC[256],
|
7
|
+
'http://www.w3.org/2009/xmlenc11#aes128-gcm' => Algorithms::AESGCM[128],
|
8
|
+
'http://www.w3.org/2009/xmlenc11#aes192-gcm' => Algorithms::AESGCM[192],
|
9
|
+
'http://www.w3.org/2009/xmlenc11#aes256-gcm' => Algorithms::AESGCM[256]
|
7
10
|
}
|
8
11
|
|
9
12
|
TYPES = {
|
data/lib/xmlenc/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xmlenc::Algorithms::AESGCM do
|
4
|
+
let(:data) { "<CreditCard Currency=\"USD\" Limit=\"5,000\">\r\n <Number>4019 2445 0277 5567</Number>\r\n <Issuer>Bank of the Internet</Issuer>\r\n <Expiration Time=\"04/02\"/>\r\n </CreditCard>" }
|
5
|
+
|
6
|
+
describe 'aes128-gcm' do
|
7
|
+
let(:cipher_value) { Base64.decode64 "YjIkLPqklVVN1faEgndPFXgXaOlVVaL+5X8NCDkbgQsbv6D2Jo7d9NQCyMbp1MgU2myCUynzdXMKdVIaqTt14pkr+NtYD6kBFPUkTvbcMIc86L5aqoMIEeqeJCK3aYLNGcY05xxOpuHvMzh2tEoZPFLEd9WgsNGhfv+4GqKiXxMVrjeLp7Iz9dYB4XmfLnQr62m4vYsZpxzg0mkxX6miCDNplv4wVBSwMDCvAFbAoWltKd+upjwaPQDNLIp0GYfQdCr7cu6K0ep4sIc=" }
|
8
|
+
let(:key) { %w(1e8c108fc0521dcad99ff2daad45af64).pack('H*') }
|
9
|
+
let(:iv) { %w(6232242cfaa495554dd5f684).pack('H*') }
|
10
|
+
subject { described_class.new(128).setup(key) }
|
11
|
+
|
12
|
+
describe 'encrypt' do
|
13
|
+
it 'encrypts the data' do
|
14
|
+
allow(subject).to receive(:iv).and_return(iv)
|
15
|
+
expect(subject.encrypt(data)).to be == cipher_value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'decrypt' do
|
20
|
+
it 'decrypts the cipher_value' do
|
21
|
+
expect(subject.decrypt(cipher_value)).to be == data
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'aes192-gcm' do
|
27
|
+
let(:cipher_value) { Base64.decode64 "YjIkLPqklVVN1faETdI41CyJetO9+vdpho9swtvre7VRd5GpkFxp3lioUUlL2URCVx24YMHOzI6ksj0jQxASXn5uvNdIUrOxtTUzzUlIKk2Jbsi6uecP/YNz7NINxz4RqcjxiH+X8IF9etWAjRt+Z2zI/5YaUsQ/kPcrfesUxaH+6aMH9XWDXNqHdCjlxxMTw/4Sj9GqGmdC73CdokggeS8dfF05TZRF4lH2kTZ/RBgS7EEwwXZVKlq6yHfe5Jv2VxHqKJ8f/OSEyiw=" }
|
28
|
+
let(:key) { %w(68432eb84dcb27e6cf46cc8d2cb1659484bbea7d0a8131f4).pack('H*') }
|
29
|
+
let(:iv) { %w(6232242cfaa495554dd5f684).pack('H*') }
|
30
|
+
subject { described_class.new(192).setup(key) }
|
31
|
+
|
32
|
+
describe 'encrypt' do
|
33
|
+
it 'encrypts the data' do
|
34
|
+
allow(subject).to receive(:iv).and_return(iv)
|
35
|
+
expect(subject.encrypt(data)).to be == cipher_value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'decrypt' do
|
40
|
+
it 'decrypts the cipher_value' do
|
41
|
+
expect(subject.decrypt(cipher_value)).to be == data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'aes256-gcm' do
|
47
|
+
let(:cipher_value) { Base64.decode64 "YjIkLPqklVVN1faEcqScF7ALyB/fb+q3+HRW17n2rUqvdO8AmI4h7wXOwj5wgeP7KBCuR6IWQK9bUeZE+EoIR+tQNXmN8CofZ6s81QbZEPMiNdRnurXz0LNaSZUL1D1ivic62TYtfgqVX+z7wesGBviRM+vHcfRQlmN5sSzBtgPF9n5u2D6mpG9fa/+I33pAFDy2FeHI1CFPzLzbvKDqnjfM7zDd0YbsNi+5czoWl7likHNplPXR1jhLxOmKPWloKQVEG8f2KHsL/ZI=" }
|
48
|
+
let(:key) { %w(7b655b83e4821c9302d24be876b7783b2301b06b4ff89cabe8e9809d7602f207).pack('H*') }
|
49
|
+
let(:iv) { %w(6232242cfaa495554dd5f684).pack('H*') }
|
50
|
+
subject { described_class.new(256).setup(key) }
|
51
|
+
|
52
|
+
describe 'encrypt' do
|
53
|
+
it 'encrypts the data' do
|
54
|
+
allow(subject).to receive(:iv).and_return(iv)
|
55
|
+
expect(subject.encrypt(data)).to be == cipher_value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'decrypt' do
|
60
|
+
it 'decrypts the cipher_value' do
|
61
|
+
expect(subject.decrypt(cipher_value)).to be == data
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/xmlenc.gemspec
CHANGED
@@ -1,36 +1,28 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
4
2
|
require 'xmlenc/version'
|
5
3
|
|
6
4
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
5
|
+
spec.name = 'xmlenc'
|
8
6
|
spec.version = Xmlenc::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
7
|
+
spec.authors = ['Benoist']
|
8
|
+
spec.email = ['bclaassen@digidentity.eu']
|
9
|
+
spec.description = 'A (partial)implementation of the XMLENC specificiation'
|
10
|
+
spec.summary = 'A (partial)implementation of the XMLENC specificiation'
|
11
|
+
spec.homepage = 'https://github.com/digidentity/xmlenc'
|
12
|
+
spec.license = 'MIT'
|
15
13
|
|
16
14
|
spec.files = `git ls-files`.split($/)
|
17
15
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
17
|
+
spec.require_paths = ['lib']
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
spec.add_dependency "activesupport", ">= 3.0.0"
|
27
|
-
spec.add_dependency "activemodel", ">= 3.0.0"
|
28
|
-
spec.add_dependency "xmlmapper", '>= 0.7.3'
|
29
|
-
spec.add_runtime_dependency('nokogiri', '>= 1.6.0', '< 2.0.0')
|
30
|
-
end
|
19
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
20
|
+
spec.add_runtime_dependency 'activemodel', '>= 3.0.0'
|
21
|
+
spec.add_runtime_dependency 'xmlmapper', '>= 0.7.3'
|
22
|
+
spec.add_runtime_dependency 'nokogiri', '>= 1.6.0', '< 2.0.0'
|
31
23
|
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rspec-rails', '>= 2.14'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'coveralls'
|
36
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlenc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -76,28 +76,28 @@ dependencies:
|
|
76
76
|
name: bundler
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rspec-rails
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '2.14'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '2.14'
|
103
103
|
- !ruby/object:Gem::Dependency
|
@@ -138,12 +138,14 @@ files:
|
|
138
138
|
- ".gitignore"
|
139
139
|
- ".rspec"
|
140
140
|
- ".travis.yml"
|
141
|
+
- CHANGELOG.md
|
141
142
|
- Gemfile
|
142
143
|
- LICENSE.txt
|
143
144
|
- README.md
|
144
145
|
- Rakefile
|
145
146
|
- lib/xmlenc.rb
|
146
147
|
- lib/xmlenc/algorithms/aes_cbc.rb
|
148
|
+
- lib/xmlenc/algorithms/aes_gcm.rb
|
147
149
|
- lib/xmlenc/algorithms/des3_cbc.rb
|
148
150
|
- lib/xmlenc/algorithms/rsa_15.rb
|
149
151
|
- lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
|
@@ -181,6 +183,7 @@ files:
|
|
181
183
|
- spec/fixtures/template.xml
|
182
184
|
- spec/fixtures/template2.xml
|
183
185
|
- spec/lib/xmlenc/algorithms/aes_cbc_spec.rb
|
186
|
+
- spec/lib/xmlenc/algorithms/aes_gcm_spec.rb
|
184
187
|
- spec/lib/xmlenc/algorithms/des3_cbc_spec.rb
|
185
188
|
- spec/lib/xmlenc/algorithms/rsa_15_spec.rb
|
186
189
|
- spec/lib/xmlenc/algorithms/rsa_oaep_mgf1p_spec.rb
|
@@ -222,8 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
225
|
- !ruby/object:Gem::Version
|
223
226
|
version: '0'
|
224
227
|
requirements: []
|
225
|
-
|
226
|
-
rubygems_version: 2.5.1
|
228
|
+
rubygems_version: 3.1.4
|
227
229
|
signing_key:
|
228
230
|
specification_version: 4
|
229
231
|
summary: A (partial)implementation of the XMLENC specificiation
|
@@ -247,6 +249,7 @@ test_files:
|
|
247
249
|
- spec/fixtures/template.xml
|
248
250
|
- spec/fixtures/template2.xml
|
249
251
|
- spec/lib/xmlenc/algorithms/aes_cbc_spec.rb
|
252
|
+
- spec/lib/xmlenc/algorithms/aes_gcm_spec.rb
|
250
253
|
- spec/lib/xmlenc/algorithms/des3_cbc_spec.rb
|
251
254
|
- spec/lib/xmlenc/algorithms/rsa_15_spec.rb
|
252
255
|
- spec/lib/xmlenc/algorithms/rsa_oaep_mgf1p_spec.rb
|