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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2af9d1508d566e056ff120a185ca6a714b1da10f
4
- data.tar.gz: eaeedd065b180313b84e6919ef386ecd98b7169c
3
+ metadata.gz: d0c3fa6655afe076241160ba75a1e9299911b288
4
+ data.tar.gz: db08a908cb4c605a0324918617534d76d96d8cae
5
5
  SHA512:
6
- metadata.gz: fb6470d68f64f84802c1fa60c5cd5c6edcf8059d077a6c292bb1dcee729a7114e0a656007b061e9872d0755348fd8a35350109cdf1e064de58f4a6308277838d
7
- data.tar.gz: 909f60a9657222993191e72e7d69de72ad07bdac7aa2afcf9eaf1e72c72eec4349b74dea5bb206e777ecc63e58b179b11116d32d84cdac16829c06cd313a4b5c
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
- # Xmldsig
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 = Xmldsig::SignedDocument.new(unsigned_xml)
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 = Xmldsig::SignedDocument.new(signed_xml)
60
+ signed_document = Xmldsig_fiscalizer::SignedDocument.new(signed_xml)
61
61
  signed_document.validate(certificate)
62
62
 
63
63
  # With block
64
- signed_document = Xmldsig::SignedDocument.new(signed_xml)
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 Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class Canonicalizer
3
3
  attr_accessor :node, :method, :inclusive_namespaces
4
4
 
@@ -1,4 +1,4 @@
1
- module Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class Reference
3
3
  attr_accessor :reference, :errors
4
4
 
@@ -1,4 +1,4 @@
1
- module Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class Signature
3
3
  attr_accessor :signature
4
4
 
@@ -1,4 +1,4 @@
1
- module Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class SignedDocument
3
3
  attr_accessor :document
4
4
 
@@ -1,4 +1,4 @@
1
- module Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class Transforms < Array
3
3
 
4
4
  def apply(node)
@@ -1,4 +1,4 @@
1
- module Xmldsig
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", Xmldsig::NAMESPACES)
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 Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class Transforms < Array
3
3
  class EnvelopedSignature < Transform
4
4
  def transform
5
- node.xpath("descendant::ds:Signature", Xmldsig::NAMESPACES).first.remove
5
+ node.xpath("descendant::ds:Signature", Xmldsig_fiscalizer::NAMESPACES).first.remove
6
6
  node
7
7
  end
8
8
  end
@@ -1,4 +1,4 @@
1
- module Xmldsig
1
+ module Xmldsig_fiscalizer
2
2
  class Transforms < Array
3
3
  class Transform
4
4
 
@@ -0,0 +1,3 @@
1
+ module Xmldsig_fiscalizer
2
+ VERSION = '0.2.5'
3
+ end
@@ -1,8 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Xmldsig::Reference do
3
+ describe Xmldsig_fiscalizer::Reference do
4
4
  let(:document) { Nokogiri::XML::Document.parse File.read("spec/fixtures/signed.xml") }
5
- let(:reference) { Xmldsig::Reference.new(document.at_xpath('//ds:Reference', Xmldsig::NAMESPACES)) }
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', Xmldsig::NAMESPACES['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', Xmldsig::NAMESPACES['wsu']).value.
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(Xmldsig::Reference::ReferencedNodeNotFound)
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 Xmldsig::Signature do
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", Xmldsig::NAMESPACES) }
9
- let(:signature) { Xmldsig::Signature.new(signature_node) }
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", Xmldsig::NAMESPACES) }
14
- let(:signature) { Xmldsig::Signature.new(signature_node) }
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", Xmldsig::NAMESPACES).to_s
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", Xmldsig::NAMESPACES).content)
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 Xmldsig::SignedDocument do
3
+ describe Xmldsig_fiscalizer::SignedDocument do
4
4
  let(:signed_xml) { File.read("spec/fixtures/signed.xml") }
5
- let(:signed_document) { Xmldsig::SignedDocument.new(signed_xml) }
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) { Xmldsig::SignedDocument.new(unsigned_xml) }
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) { Xmldsig::SignedDocument.new(unsigned_xml) }
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?(Xmldsig::Signature) }
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 = Xmldsig::SignedDocument.new('<foo></foo>')
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
- Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be_true
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
- Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be_true
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) { Xmldsig::SignedDocument.new(unsigned_xml) }
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
- Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be_true
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 Xmldsig::Transforms::EnvelopedSignature do
3
+ describe Xmldsig_fiscalizer::Transforms::EnvelopedSignature do
4
4
  let(:unsigned_xml) { File.read('spec/fixtures/unsigned_nested_signature.xml') }
5
- let(:unsigned_document) { Xmldsig::SignedDocument.new(unsigned_xml) }
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', Xmldsig::NAMESPACES)
12
+ remaining_signatures = node_with_nested_signature.xpath('descendant::ds:Signature', Xmldsig_fiscalizer::NAMESPACES)
13
13
  remaining_signatures.count.should == 1
14
- signature = Xmldsig::Signature.new(remaining_signatures.first)
14
+ signature = Xmldsig_fiscalizer::Signature.new(remaining_signatures.first)
15
15
 
16
16
  signature.references.first.reference_uri.should == '#baz'
17
17
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Xmldsig::Transforms::Transform do
3
+ describe Xmldsig_fiscalizer::Transforms::Transform do
4
4
 
5
5
  it "raises a warning when transform is called" do
6
6
  described_class.any_instance.should_receive(:warn)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Xmldsig do
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) { Xmldsig::SignedDocument.new(unsigned_xml) }
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
- Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be_true
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
- Xmldsig::SignedDocument.new(signed_document).signatures.count.should == 1
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) { Xmldsig::SignedDocument.new(signed_xml) }
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/xmldsig/version', __FILE__)
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 = Xmldsig::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
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/xmldsig.rb
44
- - lib/xmldsig/canonicalizer.rb
45
- - lib/xmldsig/reference.rb
46
- - lib/xmldsig/signature.rb
47
- - lib/xmldsig/signed_document.rb
48
- - lib/xmldsig/transforms.rb
49
- - lib/xmldsig/transforms/canonicalize.rb
50
- - lib/xmldsig/transforms/enveloped_signature.rb
51
- - lib/xmldsig/transforms/transform.rb
52
- - lib/xmldsig/version.rb
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
- - xmldsig.gemspec
78
+ - xmldsig_fiscalizer.gemspec
79
79
  homepage: https://github.com/infinum/xmldsig
80
80
  licenses:
81
81
  - MIT
@@ -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
@@ -1,3 +0,0 @@
1
- module Xmldsig
2
- VERSION = '0.2.4'
3
- end