xmlenc 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/xmlenc.rb +2 -2
- data/lib/xmlenc/builder/cipher_data.rb +1 -1
- data/lib/xmlenc/builder/complex_types/encrypted_type.rb +4 -4
- data/lib/xmlenc/builder/data_reference.rb +1 -1
- data/lib/xmlenc/builder/digest_method.rb +2 -2
- data/lib/xmlenc/builder/encrypted_data.rb +4 -4
- data/lib/xmlenc/builder/encrypted_key.rb +1 -1
- data/lib/xmlenc/builder/encryption_method.rb +3 -3
- data/lib/xmlenc/builder/key_info.rb +2 -2
- data/lib/xmlenc/builder/reference_list.rb +2 -2
- data/lib/xmlenc/encrypted_data.rb +2 -2
- data/lib/xmlenc/encrypted_key.rb +2 -2
- data/lib/xmlenc/version.rb +1 -1
- data/spec/lib/xmlenc/builder/base_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/complex_types/encrypted_type_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/data_reference_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/digest_method_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/encrypted_data_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/encrypted_key_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/encryption_method_spec.rb +1 -1
- data/spec/lib/xmlenc/builder/reference_list_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80959c76fdd31d7d40f3d1d5bb83ffda5d783b0b
|
4
|
+
data.tar.gz: a768a769b244114f6051a718fd3ae30c082cd785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09762e2cfa2bb910535b8a7eb89ee6b7dd052683ab5f1e41adff4c80c11bb8166da21bc69e827b2122c5230c62a8f1a65eabb163630d520d3f58664184ccbc1e
|
7
|
+
data.tar.gz: b7dde51da4ba68ef9df4026b37d87ca630ccf60077cd9bd735f23ff433a12c9e2730df160964c718c916cf29c9d6ccca2fb30eb5ef010cd3831397191dbe1be4
|
data/README.md
CHANGED
@@ -25,7 +25,8 @@ key_pem = File.read('path/to/key.pem')
|
|
25
25
|
xml = File.read('path/to/file.xml')
|
26
26
|
|
27
27
|
private_key = OpenSSL::PKey::RSA.new(key_pem)
|
28
|
-
|
28
|
+
encrypted_document = Xmlenc::EncryptedDocument.new(xml)
|
29
|
+
decrypted_document = encrypted_document.decrypt(private_key)
|
29
30
|
```
|
30
31
|
|
31
32
|
### Supported algorithms
|
data/lib/xmlenc.rb
CHANGED
@@ -7,8 +7,8 @@ require 'nokogiri'
|
|
7
7
|
|
8
8
|
module Xmlenc
|
9
9
|
NAMESPACES = {
|
10
|
-
xenc
|
11
|
-
ds
|
10
|
+
:xenc => 'http://www.w3.org/2001/04/xmlenc#',
|
11
|
+
:ds => 'http://www.w3.org/2000/09/xmldsig#'
|
12
12
|
}
|
13
13
|
|
14
14
|
class UnsupportedError < StandardError
|
@@ -8,11 +8,11 @@ module Xmlenc
|
|
8
8
|
included do
|
9
9
|
register_namespace "xenc", Xmlenc::NAMESPACES[:xenc]
|
10
10
|
|
11
|
-
has_one :encryption_method, Xmlenc::Builder::EncryptionMethod, xpath
|
12
|
-
has_one :key_info, Xmlenc::Builder::KeyInfo, xpath
|
13
|
-
has_one :cipher_data, Xmlenc::Builder::CipherData, xpath
|
11
|
+
has_one :encryption_method, Xmlenc::Builder::EncryptionMethod, :xpath => "./"
|
12
|
+
has_one :key_info, Xmlenc::Builder::KeyInfo, :xpath => "./"
|
13
|
+
has_one :cipher_data, Xmlenc::Builder::CipherData, :xpath => "./"
|
14
14
|
|
15
|
-
validates :cipher_data, presence
|
15
|
+
validates :cipher_data, :presence => true
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(attributes = {})
|
@@ -8,9 +8,9 @@ module Xmlenc
|
|
8
8
|
register_namespace "ds", Xmlenc::NAMESPACES[:ds]
|
9
9
|
namespace "ds"
|
10
10
|
|
11
|
-
attribute :algorithm, String, tag
|
11
|
+
attribute :algorithm, String, :tag => "Algorithm"
|
12
12
|
|
13
|
-
validates :algorithm, presence
|
13
|
+
validates :algorithm, :presence => true
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -16,8 +16,8 @@ module Xmlenc
|
|
16
16
|
tag "EncryptedData"
|
17
17
|
namespace "xenc"
|
18
18
|
|
19
|
-
attribute :id, String, tag
|
20
|
-
attribute :type, String, tag
|
19
|
+
attribute :id, String, :tag => "Id"
|
20
|
+
attribute :type, String, :tag => "Type"
|
21
21
|
|
22
22
|
def type
|
23
23
|
'http://www.w3.org/2001/04/xmlenc#Element'
|
@@ -30,10 +30,10 @@ module Xmlenc
|
|
30
30
|
|
31
31
|
def encrypt(data)
|
32
32
|
encryptor = algorithm.setup
|
33
|
-
encrypted = encryptor.encrypt(data, node
|
33
|
+
encrypted = encryptor.encrypt(data, :node => encryption_method)
|
34
34
|
cipher_data.cipher_value = Base64.encode64(encrypted)
|
35
35
|
|
36
|
-
encrypted_key = EncryptedKey.new(data
|
36
|
+
encrypted_key = EncryptedKey.new(:data => encryptor.key)
|
37
37
|
encrypted_key.add_data_reference(id)
|
38
38
|
encrypted_key
|
39
39
|
end
|
@@ -8,14 +8,14 @@ module Xmlenc
|
|
8
8
|
register_namespace "xenc", Xmlenc::NAMESPACES[:xenc]
|
9
9
|
namespace "xenc"
|
10
10
|
|
11
|
-
attribute :algorithm, String, tag
|
11
|
+
attribute :algorithm, String, :tag => "Algorithm"
|
12
12
|
has_one :digest_method, Xmlenc::Builder::DigestMethod
|
13
13
|
|
14
|
-
validates :algorithm, presence
|
14
|
+
validates :algorithm, :presence => true
|
15
15
|
|
16
16
|
def initialize(attributes = {})
|
17
17
|
digest_method_algorithm = attributes.delete(:digest_method_algorithm)
|
18
|
-
attributes[:digest_method] = Xmlenc::Builder::DigestMethod.new(algorithm
|
18
|
+
attributes[:digest_method] = Xmlenc::Builder::DigestMethod.new(:algorithm => digest_method_algorithm)
|
19
19
|
super
|
20
20
|
end
|
21
21
|
end
|
@@ -8,9 +8,9 @@ module Xmlenc
|
|
8
8
|
register_namespace "ds", Xmlenc::NAMESPACES[:ds]
|
9
9
|
namespace "ds"
|
10
10
|
|
11
|
-
element :key_name, String, namespace
|
11
|
+
element :key_name, String, :namespace => "ds", :tag => "KeyName"
|
12
12
|
|
13
|
-
has_one :encrypted_key, Xmlenc::Builder::EncryptedKey, xpath
|
13
|
+
has_one :encrypted_key, Xmlenc::Builder::EncryptedKey, :xpath => "./"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -8,11 +8,11 @@ module Xmlenc
|
|
8
8
|
register_namespace "xenc", Xmlenc::NAMESPACES[:xenc]
|
9
9
|
namespace "xenc"
|
10
10
|
|
11
|
-
has_many :data_references, Xmlenc::Builder::DataReference, xpath
|
11
|
+
has_many :data_references, Xmlenc::Builder::DataReference, :xpath => "./"
|
12
12
|
|
13
13
|
def add_data_reference(data_id)
|
14
14
|
self.data_references ||= []
|
15
|
-
self.data_references << DataReference.new(uri
|
15
|
+
self.data_references << DataReference.new(:uri => "##{data_id}")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -35,14 +35,14 @@ module Xmlenc
|
|
35
35
|
|
36
36
|
def decrypt(key)
|
37
37
|
decryptor = algorithm.setup(key)
|
38
|
-
decrypted = decryptor.decrypt(Base64.decode64(cipher_value), node
|
38
|
+
decrypted = decryptor.decrypt(Base64.decode64(cipher_value), :node => encryption_method)
|
39
39
|
@node.replace(decrypted) unless @node == document.root
|
40
40
|
decrypted
|
41
41
|
end
|
42
42
|
|
43
43
|
def encrypt(data)
|
44
44
|
encryptor = algorithm.setup
|
45
|
-
encrypted = encryptor.encrypt(data, node
|
45
|
+
encrypted = encryptor.encrypt(data, :node => encryption_method)
|
46
46
|
self.cipher_value = Base64.encode64(encrypted)
|
47
47
|
encryptor.key
|
48
48
|
end
|
data/lib/xmlenc/encrypted_key.rb
CHANGED
@@ -31,12 +31,12 @@ module Xmlenc
|
|
31
31
|
|
32
32
|
def decrypt(key)
|
33
33
|
decryptor = algorithm.new(key)
|
34
|
-
decryptor.decrypt(Base64.decode64(cipher_value), node
|
34
|
+
decryptor.decrypt(Base64.decode64(cipher_value), :node => encryption_method)
|
35
35
|
end
|
36
36
|
|
37
37
|
def encrypt(key, data)
|
38
38
|
encryptor = algorithm.new(key)
|
39
|
-
encrypted = encryptor.encrypt(data, node
|
39
|
+
encrypted = encryptor.encrypt(data, :node => encryption_method)
|
40
40
|
self.cipher_value = Base64.encode64(encrypted)
|
41
41
|
end
|
42
42
|
|
data/lib/xmlenc/version.rb
CHANGED
@@ -9,7 +9,7 @@ end
|
|
9
9
|
describe BaseDummy do
|
10
10
|
describe "parse override" do
|
11
11
|
it "sets the from_xml flag" do
|
12
|
-
BaseDummy.parse("<tag></tag>", single
|
12
|
+
BaseDummy.parse("<tag></tag>", :single => true).from_xml?.should be_true
|
13
13
|
end
|
14
14
|
|
15
15
|
it "raises an error if the message cannot be parsed" do
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
describe Xmlenc::Builder::ComplexTypes::EncryptedType do
|
10
10
|
|
11
11
|
let(:xml) { File.read File.join("spec", "fixtures", "encrypted_document.xml") }
|
12
|
-
subject { EncryptedTypeDummy.new.parse(xml, single
|
12
|
+
subject { EncryptedTypeDummy.new.parse(xml, :single => true) }
|
13
13
|
|
14
14
|
describe "required fields" do
|
15
15
|
it "should have the cipher data field" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Xmlenc::Builder::DataReference do
|
4
4
|
|
5
5
|
let(:xml) { File.read File.join("spec", "fixtures", "template2.xml") }
|
6
|
-
subject { described_class.parse(xml, single
|
6
|
+
subject { described_class.parse(xml, :single => true) }
|
7
7
|
|
8
8
|
describe "#parse" do
|
9
9
|
it "should have uri attribute" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Xmlenc::Builder::DigestMethod do
|
4
4
|
|
5
5
|
let(:xml) { File.read File.join("spec", "fixtures", "template2.xml") }
|
6
|
-
subject { described_class.parse(xml, single
|
6
|
+
subject { described_class.parse(xml, :single => true) }
|
7
7
|
|
8
8
|
describe "#parse" do
|
9
9
|
it "should have one algorithm" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Xmlenc::Builder::EncryptedData do
|
4
4
|
|
5
5
|
let(:xml) { File.read File.join("spec", "fixtures", "encrypted_document.xml") }
|
6
|
-
subject { described_class.parse(xml, single
|
6
|
+
subject { described_class.parse(xml, :single => true) }
|
7
7
|
|
8
8
|
describe "required fields" do
|
9
9
|
it "should have the cipher data field" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Xmlenc::Builder::EncryptedKey do
|
4
4
|
|
5
5
|
let(:xml) { File.read File.join("spec", "fixtures", "encrypted_document.xml") }
|
6
|
-
subject { described_class.parse(xml, single
|
6
|
+
subject { described_class.parse(xml, :single => true) }
|
7
7
|
|
8
8
|
describe "required fields" do
|
9
9
|
it "should have the cipher data field" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Xmlenc::Builder::EncryptionMethod do
|
4
4
|
|
5
5
|
let(:xml) { File.read File.join("spec", "fixtures", "encrypted_document.xml") }
|
6
|
-
subject { described_class.parse(xml, single
|
6
|
+
subject { described_class.parse(xml, :single => true) }
|
7
7
|
|
8
8
|
describe "required fields" do
|
9
9
|
it "should have the algorithm field" do
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Xmlenc::Builder::ReferenceList do
|
4
4
|
|
5
5
|
let(:xml) { File.read File.join("spec", "fixtures", "template2.xml") }
|
6
|
-
subject { described_class.parse(xml, single
|
6
|
+
subject { described_class.parse(xml, :single => true) }
|
7
7
|
|
8
8
|
describe "#parse" do
|
9
9
|
it "has data" do
|
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.1.
|
4
|
+
version: 0.1.6
|
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: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
195
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.
|
196
|
+
rubygems_version: 2.4.5
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: A (partial)implementation of the XMLENC specificiation
|