xmldsig-fiscalizer 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/xmldsig_fiscalizer.rb +20 -0
- data/lib/{xmldsig → xmldsig_fiscalizer}/canonicalizer.rb +1 -1
- data/lib/{xmldsig → xmldsig_fiscalizer}/reference.rb +1 -1
- data/lib/{xmldsig → xmldsig_fiscalizer}/signature.rb +1 -1
- data/lib/{xmldsig → xmldsig_fiscalizer}/signed_document.rb +1 -1
- data/lib/{xmldsig → xmldsig_fiscalizer}/transforms.rb +1 -1
- data/lib/{xmldsig → xmldsig_fiscalizer}/transforms/canonicalize.rb +2 -2
- data/lib/{xmldsig → xmldsig_fiscalizer}/transforms/enveloped_signature.rb +2 -2
- data/lib/{xmldsig → xmldsig_fiscalizer}/transforms/transform.rb +1 -1
- data/lib/xmldsig_fiscalizer/version.rb +3 -0
- data/spec/lib/xmldsig/reference_spec.rb +5 -5
- data/spec/lib/xmldsig/signature_spec.rb +7 -7
- data/spec/lib/xmldsig/signed_document_spec.rb +10 -10
- data/spec/lib/xmldsig/transforms/enveloped_signature_spec.rb +4 -4
- data/spec/lib/xmldsig/transforms/transform_spec.rb +1 -1
- data/spec/lib/xmldsig_spec.rb +5 -5
- data/{xmldsig.gemspec → xmldsig_fiscalizer.gemspec} +2 -2
- metadata +12 -12
- data/lib/xmldsig.rb +0 -20
- data/lib/xmldsig/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c3fa6655afe076241160ba75a1e9299911b288
|
4
|
+
data.tar.gz: db08a908cb4c605a0324918617534d76d96d8cae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7440a205ec65096608ec420fed74b1cabaf5212e479406faaec456b8fe9eab2a440097fb12b72cb7c9f2cafe2b18cfd58c9428e6d0e46a7581cd300ca05c62a4
|
7
|
+
data.tar.gz: 9e3086759d3b99c68b7a6cd71fd88e5246efb34b22539ccdc59888bcde58b72052086908e03796583164f075962f45a9efdf5c301d416a23cbee6120f3037230
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
[![Build Status](https://secure.travis-ci.org/benoist/xmldsig.png?branch=master)](http://travis-ci.org/benoist/xmldsig)
|
2
|
-
#
|
2
|
+
# Xmldsig_fiscalizer
|
3
3
|
|
4
4
|
This gem is a (partial) implementation of the XMLDsig specification (http://www.w3.org/TR/xmldsig-core)
|
5
5
|
|
@@ -47,7 +47,7 @@ XML
|
|
47
47
|
private_key = OpenSSL::PKey::RSA.new(File.read("key.pem"))
|
48
48
|
certificate = OpenSSL::X509::Certificate.new(File.read("certificate.cer"))
|
49
49
|
|
50
|
-
unsigned_document =
|
50
|
+
unsigned_document = Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml)
|
51
51
|
signed_xml = unsigned_document.sign(private_key)
|
52
52
|
|
53
53
|
# With block
|
@@ -57,11 +57,11 @@ end
|
|
57
57
|
|
58
58
|
# Validation
|
59
59
|
|
60
|
-
signed_document =
|
60
|
+
signed_document = Xmldsig_fiscalizer::SignedDocument.new(signed_xml)
|
61
61
|
signed_document.validate(certificate)
|
62
62
|
|
63
63
|
# With block
|
64
|
-
signed_document =
|
64
|
+
signed_document = Xmldsig_fiscalizer::SignedDocument.new(signed_xml)
|
65
65
|
signed_document.validate do |signature_value, data|
|
66
66
|
certificate.public_key.verify(OpenSSL::Digest::SHA256.new, signature_value, data)
|
67
67
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "openssl"
|
3
|
+
require "base64"
|
4
|
+
require "xmldsig_fiscalizer/version"
|
5
|
+
require "xmldsig_fiscalizer/canonicalizer"
|
6
|
+
require "xmldsig_fiscalizer/signed_document"
|
7
|
+
require "xmldsig_fiscalizer/transforms/transform"
|
8
|
+
require "xmldsig_fiscalizer/transforms/canonicalize"
|
9
|
+
require "xmldsig_fiscalizer/transforms/enveloped_signature"
|
10
|
+
require "xmldsig_fiscalizer/transforms"
|
11
|
+
require "xmldsig_fiscalizer/reference"
|
12
|
+
require "xmldsig_fiscalizer/signature"
|
13
|
+
|
14
|
+
module Xmldsig_fiscalizer
|
15
|
+
NAMESPACES = {
|
16
|
+
"ds" => "http://www.w3.org/2000/09/xmldsig#",
|
17
|
+
"ec" => "http://www.w3.org/2001/10/xml-exc-c14n#",
|
18
|
+
"wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
|
19
|
+
}
|
20
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Xmldsig_fiscalizer
|
2
2
|
class Transforms < Array
|
3
3
|
class Canonicalize < Transform
|
4
4
|
def transform
|
@@ -13,7 +13,7 @@ module Xmldsig
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def inclusive_namespaces
|
16
|
-
inclusive_namespaces = transform_node.at_xpath("descendant::ec:InclusiveNamespaces",
|
16
|
+
inclusive_namespaces = transform_node.at_xpath("descendant::ec:InclusiveNamespaces", Xmldsig_fiscalizer::NAMESPACES)
|
17
17
|
if inclusive_namespaces && inclusive_namespaces.has_attribute?("PrefixList")
|
18
18
|
inclusive_namespaces.get_attribute("PrefixList").to_s.split(" ")
|
19
19
|
else
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Xmldsig_fiscalizer
|
2
2
|
class Transforms < Array
|
3
3
|
class EnvelopedSignature < Transform
|
4
4
|
def transform
|
5
|
-
node.xpath("descendant::ds:Signature",
|
5
|
+
node.xpath("descendant::ds:Signature", Xmldsig_fiscalizer::NAMESPACES).first.remove
|
6
6
|
node
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Xmldsig_fiscalizer::Reference do
|
4
4
|
let(:document) { Nokogiri::XML::Document.parse File.read("spec/fixtures/signed.xml") }
|
5
|
-
let(:reference) {
|
5
|
+
let(:reference) { Xmldsig_fiscalizer::Reference.new(document.at_xpath('//ds:Reference', Xmldsig_fiscalizer::NAMESPACES)) }
|
6
6
|
|
7
7
|
describe "#digest_value" do
|
8
8
|
it "returns the digest value in the xml" do
|
@@ -39,12 +39,12 @@ describe Xmldsig::Reference do
|
|
39
39
|
|
40
40
|
it "returns the reference node when using WS-Security style id attribute" do
|
41
41
|
node = document.at_xpath('//*[@ID]')
|
42
|
-
node.add_namespace('wsu',
|
42
|
+
node.add_namespace('wsu', Xmldsig_fiscalizer::NAMESPACES['wsu'])
|
43
43
|
node['wsu:Id'] = node['ID']
|
44
44
|
node.remove_attribute('ID')
|
45
45
|
|
46
46
|
reference.referenced_node.
|
47
|
-
attribute_with_ns('Id',
|
47
|
+
attribute_with_ns('Id', Xmldsig_fiscalizer::NAMESPACES['wsu']).value.
|
48
48
|
should == 'foo'
|
49
49
|
end
|
50
50
|
|
@@ -53,7 +53,7 @@ describe Xmldsig::Reference do
|
|
53
53
|
node.remove_attribute('ID')
|
54
54
|
|
55
55
|
expect { reference.referenced_node }.
|
56
|
-
to raise_error(
|
56
|
+
to raise_error(Xmldsig_fiscalizer::Reference::ReferencedNodeNotFound)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Xmldsig_fiscalizer::Signature do
|
4
4
|
let(:certificate) { OpenSSL::X509::Certificate.new(File.read("spec/fixtures/certificate.cer")) }
|
5
5
|
let(:other_certificate) { OpenSSL::X509::Certificate.new(File.read("spec/fixtures/certificate2.cer")) }
|
6
6
|
let(:private_key) { OpenSSL::PKey::RSA.new(File.read("spec/fixtures/key.pem")) }
|
7
7
|
let(:document) { Nokogiri::XML::Document.parse File.read("spec/fixtures/signed.xml") }
|
8
|
-
let(:signature_node) { document.at_xpath("//ds:Signature",
|
9
|
-
let(:signature) {
|
8
|
+
let(:signature_node) { document.at_xpath("//ds:Signature", Xmldsig_fiscalizer::NAMESPACES) }
|
9
|
+
let(:signature) { Xmldsig_fiscalizer::Signature.new(signature_node) }
|
10
10
|
|
11
11
|
describe "#sign" do
|
12
12
|
let(:document) { Nokogiri::XML::Document.parse File.read("spec/fixtures/unsigned.xml") }
|
13
|
-
let(:signature_node) { document.at_xpath("//ds:Signature",
|
14
|
-
let(:signature) {
|
13
|
+
let(:signature_node) { document.at_xpath("//ds:Signature", Xmldsig_fiscalizer::NAMESPACES) }
|
14
|
+
let(:signature) { Xmldsig_fiscalizer::Signature.new(signature_node) }
|
15
15
|
|
16
16
|
before :each do
|
17
17
|
signature.sign(private_key)
|
@@ -61,14 +61,14 @@ describe Xmldsig::Signature do
|
|
61
61
|
describe "#signed_info" do
|
62
62
|
it "returns the canonicalized signed info element" do
|
63
63
|
signature.signed_info.to_s.should ==
|
64
|
-
document.at_xpath("//ds:SignedInfo",
|
64
|
+
document.at_xpath("//ds:SignedInfo", Xmldsig_fiscalizer::NAMESPACES).to_s
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "#signature_value" do
|
69
69
|
it "returns the signature value" do
|
70
70
|
signature.signature_value.should ==
|
71
|
-
Base64.decode64(document.at_xpath("//ds:SignatureValue",
|
71
|
+
Base64.decode64(document.at_xpath("//ds:SignatureValue", Xmldsig_fiscalizer::NAMESPACES).content)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Xmldsig_fiscalizer::SignedDocument do
|
4
4
|
let(:signed_xml) { File.read("spec/fixtures/signed.xml") }
|
5
|
-
let(:signed_document) {
|
5
|
+
let(:signed_document) { Xmldsig_fiscalizer::SignedDocument.new(signed_xml) }
|
6
6
|
let(:unsigned_xml) { File.read("spec/fixtures/unsigned.xml") }
|
7
|
-
let(:unsigned_document) {
|
7
|
+
let(:unsigned_document) { Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml) }
|
8
8
|
let(:private_key) { OpenSSL::PKey::RSA.new(File.read("spec/fixtures/key.pem")) }
|
9
9
|
let(:certificate) { OpenSSL::X509::Certificate.new(File.read("spec/fixtures/certificate.cer")) }
|
10
10
|
let(:other_certificate) { OpenSSL::X509::Certificate.new(File.read("spec/fixtures/certificate2.cer")) }
|
@@ -18,10 +18,10 @@ describe Xmldsig::SignedDocument do
|
|
18
18
|
|
19
19
|
describe "#signatures" do
|
20
20
|
let(:unsigned_xml) { File.read("spec/fixtures/unsigned_nested_signature.xml") }
|
21
|
-
let(:unsigned_document) {
|
21
|
+
let(:unsigned_document) { Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml) }
|
22
22
|
|
23
23
|
it "returns only the signed nodes" do
|
24
|
-
signed_document.signatures.should be_all { |signature| signature.is_a?(
|
24
|
+
signed_document.signatures.should be_all { |signature| signature.is_a?(Xmldsig_fiscalizer::Signature) }
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns the nested signatures first" do
|
@@ -45,7 +45,7 @@ describe Xmldsig::SignedDocument do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "returns false if there are no signatures and validation is strict" do
|
48
|
-
xml_without_signature =
|
48
|
+
xml_without_signature = Xmldsig_fiscalizer::SignedDocument.new('<foo></foo>')
|
49
49
|
xml_without_signature.validate(certificate).should be_false
|
50
50
|
end
|
51
51
|
|
@@ -59,25 +59,25 @@ describe Xmldsig::SignedDocument do
|
|
59
59
|
describe "#sign" do
|
60
60
|
it "returns a signed document" do
|
61
61
|
signed_document = unsigned_document.sign(private_key)
|
62
|
-
|
62
|
+
Xmldsig_fiscalizer::SignedDocument.new(signed_document).validate(certificate).should be_true
|
63
63
|
end
|
64
64
|
|
65
65
|
it "accepts a block" do
|
66
66
|
signed_document = unsigned_document.sign do |data|
|
67
67
|
private_key.sign(OpenSSL::Digest::SHA256.new, data)
|
68
68
|
end
|
69
|
-
|
69
|
+
Xmldsig_fiscalizer::SignedDocument.new(signed_document).validate(certificate).should be_true
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
|
74
74
|
describe "Nested Signatures" do
|
75
75
|
let(:unsigned_xml) { File.read("spec/fixtures/unsigned_nested_signature.xml") }
|
76
|
-
let(:unsigned_document) {
|
76
|
+
let(:unsigned_document) { Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml) }
|
77
77
|
let(:signed_document) { unsigned_document.sign(private_key) }
|
78
78
|
|
79
79
|
it "when signed should be valid" do
|
80
|
-
|
80
|
+
Xmldsig_fiscalizer::SignedDocument.new(signed_document).validate(certificate).should be_true
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should sign 2 elements" do
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Xmldsig_fiscalizer::Transforms::EnvelopedSignature do
|
4
4
|
let(:unsigned_xml) { File.read('spec/fixtures/unsigned_nested_signature.xml') }
|
5
|
-
let(:unsigned_document) {
|
5
|
+
let(:unsigned_document) { Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml) }
|
6
6
|
|
7
7
|
it 'only removes the first signature element' do
|
8
8
|
node_with_nested_signature = unsigned_document.signatures.last.references.first.referenced_node
|
9
9
|
|
10
10
|
described_class.new(node_with_nested_signature, nil).transform
|
11
11
|
|
12
|
-
remaining_signatures = node_with_nested_signature.xpath('descendant::ds:Signature',
|
12
|
+
remaining_signatures = node_with_nested_signature.xpath('descendant::ds:Signature', Xmldsig_fiscalizer::NAMESPACES)
|
13
13
|
remaining_signatures.count.should == 1
|
14
|
-
signature =
|
14
|
+
signature = Xmldsig_fiscalizer::Signature.new(remaining_signatures.first)
|
15
15
|
|
16
16
|
signature.references.first.reference_uri.should == '#baz'
|
17
17
|
end
|
data/spec/lib/xmldsig_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Xmldsig_fiscalizer do
|
4
4
|
let(:private_key) { OpenSSL::PKey::RSA.new(File.read("spec/fixtures/key.pem")) }
|
5
5
|
let(:certificate) { OpenSSL::X509::Certificate.new(File.read("spec/fixtures/certificate.cer")) }
|
6
6
|
|
@@ -8,15 +8,15 @@ describe Xmldsig do
|
|
8
8
|
Dir["spec/fixtures/unsigned/*.xml"].each do |document|
|
9
9
|
describe "#{document}" do
|
10
10
|
let(:unsigned_xml) { File.read(document) }
|
11
|
-
let(:unsigned_document) {
|
11
|
+
let(:unsigned_document) { Xmldsig_fiscalizer::SignedDocument.new(unsigned_xml) }
|
12
12
|
let(:signed_document) { unsigned_document.sign(private_key) }
|
13
13
|
|
14
14
|
it "should be signable an validateable" do
|
15
|
-
|
15
|
+
Xmldsig_fiscalizer::SignedDocument.new(signed_document).validate(certificate).should be_true
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should have a signature element' do
|
19
|
-
|
19
|
+
Xmldsig_fiscalizer::SignedDocument.new(signed_document).signatures.count.should == 1
|
20
20
|
end
|
21
21
|
|
22
22
|
# TODO: remove this verification step when library matures
|
@@ -34,7 +34,7 @@ describe Xmldsig do
|
|
34
34
|
Dir["spec/fixtures/signed/*.txt"].each do |document|
|
35
35
|
describe "#{document}" do
|
36
36
|
let(:signed_xml) { Base64.decode64(File.read(document)) }
|
37
|
-
let(:signed_document) {
|
37
|
+
let(:signed_document) { Xmldsig_fiscalizer::SignedDocument.new(signed_xml) }
|
38
38
|
let(:certificate) { OpenSSL::X509::Certificate.new(File.read(document.gsub('.txt', '.cert'))) }
|
39
39
|
|
40
40
|
it "should be validateable" do
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/
|
2
|
+
require File.expand_path('../lib/xmldsig_fiscalizer/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["benoist"]
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "xmldsig-fiscalizer"
|
15
15
|
gem.license = 'MIT'
|
16
16
|
gem.require_paths = ["lib"]
|
17
|
-
gem.version =
|
17
|
+
gem.version = Xmldsig_fiscalizer::VERSION
|
18
18
|
|
19
19
|
gem.add_dependency("nokogiri")
|
20
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmldsig-fiscalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benoist
|
@@ -40,16 +40,16 @@ files:
|
|
40
40
|
- LICENSE
|
41
41
|
- README.md
|
42
42
|
- Rakefile
|
43
|
-
- lib/
|
44
|
-
- lib/
|
45
|
-
- lib/
|
46
|
-
- lib/
|
47
|
-
- lib/
|
48
|
-
- lib/
|
49
|
-
- lib/
|
50
|
-
- lib/
|
51
|
-
- lib/
|
52
|
-
- lib/
|
43
|
+
- lib/xmldsig_fiscalizer.rb
|
44
|
+
- lib/xmldsig_fiscalizer/canonicalizer.rb
|
45
|
+
- lib/xmldsig_fiscalizer/reference.rb
|
46
|
+
- lib/xmldsig_fiscalizer/signature.rb
|
47
|
+
- lib/xmldsig_fiscalizer/signed_document.rb
|
48
|
+
- lib/xmldsig_fiscalizer/transforms.rb
|
49
|
+
- lib/xmldsig_fiscalizer/transforms/canonicalize.rb
|
50
|
+
- lib/xmldsig_fiscalizer/transforms/enveloped_signature.rb
|
51
|
+
- lib/xmldsig_fiscalizer/transforms/transform.rb
|
52
|
+
- lib/xmldsig_fiscalizer/version.rb
|
53
53
|
- signing_service.rb
|
54
54
|
- spec/fixtures/certificate.cer
|
55
55
|
- spec/fixtures/certificate2.cer
|
@@ -75,7 +75,7 @@ files:
|
|
75
75
|
- spec/lib/xmldsig/transforms/transform_spec.rb
|
76
76
|
- spec/lib/xmldsig_spec.rb
|
77
77
|
- spec/spec_helper.rb
|
78
|
-
-
|
78
|
+
- xmldsig_fiscalizer.gemspec
|
79
79
|
homepage: https://github.com/infinum/xmldsig
|
80
80
|
licenses:
|
81
81
|
- MIT
|
data/lib/xmldsig.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "nokogiri"
|
2
|
-
require "openssl"
|
3
|
-
require "base64"
|
4
|
-
require "xmldsig/version"
|
5
|
-
require "xmldsig/canonicalizer"
|
6
|
-
require "xmldsig/signed_document"
|
7
|
-
require "xmldsig/transforms/transform"
|
8
|
-
require "xmldsig/transforms/canonicalize"
|
9
|
-
require "xmldsig/transforms/enveloped_signature"
|
10
|
-
require "xmldsig/transforms"
|
11
|
-
require "xmldsig/reference"
|
12
|
-
require "xmldsig/signature"
|
13
|
-
|
14
|
-
module Xmldsig
|
15
|
-
NAMESPACES = {
|
16
|
-
"ds" => "http://www.w3.org/2000/09/xmldsig#",
|
17
|
-
"ec" => "http://www.w3.org/2001/10/xml-exc-c14n#",
|
18
|
-
"wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
|
19
|
-
}
|
20
|
-
end
|
data/lib/xmldsig/version.rb
DELETED