xmldsig 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f23a822603d9deb9781149f9440df390aa386fc2
4
- data.tar.gz: 8501502a05a8e89e1c58cabcde2ea86a0dd57dfd
3
+ metadata.gz: 23aefdcfb75c3ff59055a9751c19d5872f16819a
4
+ data.tar.gz: 17ec48f80925f06c21759cd7c21407531d51811b
5
5
  SHA512:
6
- metadata.gz: 60def31b212dc61e5cf32b3062ecc5969106c9ee6555878c1a79463b0de80b002ce7301c1bb38f181adc78ec3d43edd1b2d2fc1fe4f0edc6ca14dd372a6ec018
7
- data.tar.gz: ca9edf2fe24d1297cd9d64121f1154aa637d5bce0e601b27c3323de16b28e7d2a7e6207b50e9ef5d9cbbd064e961a637234b8f4e41f3e742fccc69f8c7ad158f
6
+ metadata.gz: fe51378403b39e0c55f729304816bba9b68108e98c4fa9d5fc7415ecf4d6a6860b58626cfb2c96c6f489b584d16859d0d2ec1a98ba6aaa3c25a3d35d25c6b47f
7
+ data.tar.gz: bef5d4bebd40e3abcc5023f7f4e622d3d0a1a0cf9221e99212f9bd7f7cc5e4c9a09e06e62a5b18f638438d847e2b7351836e72c6ea81b24426acaa28af6733cc
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ v0.4.1 22-03-2015
4
+ - Added support for SHA256, SHA384 and SHA512
5
+
3
6
  v0.4.0 20-11-2015
4
7
  - Breaking change: Signing now leaves previously signed signatures in tact. Use Xmldsig::SignedDocument.new(unsigned_xml, force: true) to resign all signatures
5
8
 
@@ -58,8 +58,10 @@ module Xmldsig
58
58
  def digest_method
59
59
  algorithm = reference.at_xpath("descendant::ds:DigestMethod", NAMESPACES).get_attribute("Algorithm")
60
60
  case algorithm
61
+ when "http://www.w3.org/2001/04/xmlenc#sha512"
62
+ Digest::SHA512
61
63
  when "http://www.w3.org/2001/04/xmlenc#sha256"
62
- Digest::SHA2
64
+ Digest::SHA256
63
65
  when "http://www.w3.org/2000/09/xmldsig#sha1"
64
66
  Digest::SHA1
65
67
  end
@@ -72,6 +72,10 @@ module Xmldsig
72
72
  def signature_method
73
73
  algorithm = signature_algorithm && signature_algorithm =~ /sha(.*?)$/i && $1.to_i
74
74
  case algorithm
75
+ when 512
76
+ OpenSSL::Digest::SHA512
77
+ when 384
78
+ OpenSSL::Digest::SHA384
75
79
  when 256 then
76
80
  OpenSSL::Digest::SHA256
77
81
  else
@@ -1,3 +1,3 @@
1
1
  module Xmldsig
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foo:Foo ID="foo" xmlns:foo="http://example.com/foo#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#">
3
+ <foo:Bar>bar</foo:Bar>
4
+ <ds:Signature>
5
+ <ds:SignedInfo>
6
+ <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
7
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
8
+ <ds:Reference URI="#foo">
9
+ <ds:Transforms>
10
+ <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
11
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
12
+ <ec:InclusiveNamespaces PrefixList="foo"/>
13
+ </ds:Transform>
14
+ </ds:Transforms>
15
+ <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
16
+ <ds:DigestValue></ds:DigestValue>
17
+ </ds:Reference>
18
+ </ds:SignedInfo>
19
+ <ds:SignatureValue></ds:SignatureValue>
20
+ </ds:Signature>
21
+ </foo:Foo>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foo:Foo ID="foo" xmlns:foo="http://example.com/foo#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#">
3
+ <foo:Bar>bar</foo:Bar>
4
+ <ds:Signature>
5
+ <ds:SignedInfo>
6
+ <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
7
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
8
+ <ds:Reference URI="#foo">
9
+ <ds:Transforms>
10
+ <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
11
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
12
+ <ec:InclusiveNamespaces PrefixList="foo"/>
13
+ </ds:Transform>
14
+ </ds:Transforms>
15
+ <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
16
+ <ds:DigestValue></ds:DigestValue>
17
+ </ds:Reference>
18
+ </ds:SignedInfo>
19
+ <ds:SignatureValue></ds:SignatureValue>
20
+ </ds:Signature>
21
+ </foo:Foo>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foo:Foo ID="foo" xmlns:foo="http://example.com/foo#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#">
3
+ <foo:Bar>bar</foo:Bar>
4
+ <ds:Signature>
5
+ <ds:SignedInfo>
6
+ <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
7
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"/>
8
+ <ds:Reference URI="#foo">
9
+ <ds:Transforms>
10
+ <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
11
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
12
+ <ec:InclusiveNamespaces PrefixList="foo"/>
13
+ </ds:Transform>
14
+ </ds:Transforms>
15
+ <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>
16
+ <ds:DigestValue></ds:DigestValue>
17
+ </ds:Reference>
18
+ </ds:SignedInfo>
19
+ <ds:SignatureValue></ds:SignatureValue>
20
+ </ds:Signature>
21
+ </foo:Foo>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <foo:Foo ID="foo" xmlns:foo="http://example.com/foo#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#">
3
+ <foo:Bar>bar</foo:Bar>
4
+ <ds:Signature>
5
+ <ds:SignedInfo>
6
+ <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
7
+ <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"/>
8
+ <ds:Reference URI="#foo">
9
+ <ds:Transforms>
10
+ <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
11
+ <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
12
+ <ec:InclusiveNamespaces PrefixList="foo"/>
13
+ </ds:Transform>
14
+ </ds:Transforms>
15
+ <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha512"/>
16
+ <ds:DigestValue></ds:DigestValue>
17
+ </ds:Reference>
18
+ </ds:SignedInfo>
19
+ <ds:SignatureValue></ds:SignatureValue>
20
+ </ds:Signature>
21
+ </foo:Foo>
@@ -82,4 +82,22 @@ describe Xmldsig::Reference do
82
82
  reference.reference_uri.should == "#foo"
83
83
  end
84
84
  end
85
+
86
+ ["sha1", "sha256", "sha512"].each do |algorithm|
87
+ describe "digest method #{algorithm}" do
88
+ let(:document) { Nokogiri::XML::Document.parse File.read("spec/fixtures/unsigned-#{algorithm}.xml") }
89
+ let(:reference) { Xmldsig::Reference.new(document.at_xpath('//ds:Reference', Xmldsig::NAMESPACES)) }
90
+
91
+ it "uses the correct digest algorithm" do
92
+ case algorithm
93
+ when "sha512"
94
+ reference.digest_method.should == Digest::SHA512
95
+ when "sha256"
96
+ reference.digest_method.should == Digest::SHA256
97
+ when "sha1"
98
+ reference.digest_method.should == Digest::SHA1
99
+ end
100
+ end
101
+ end
102
+ end
85
103
  end
@@ -97,4 +97,24 @@ describe Xmldsig::Signature do
97
97
  signature.errors.should be_empty
98
98
  end
99
99
  end
100
+
101
+ ["sha1", "sha256", "sha384", "sha512"].each do |algorithm|
102
+ describe "sign method #{algorithm}" do
103
+ let(:document) { Nokogiri::XML::Document.parse File.read("spec/fixtures/unsigned-#{algorithm}.xml") }
104
+ let(:signature_node) { document.at_xpath("//ds:Signature", Xmldsig::NAMESPACES) }
105
+ let(:signature) { Xmldsig::Signature.new(signature_node) }
106
+
107
+ it "uses the correct signature algorithm" do
108
+ signature.sign do |data, signature_algorithm|
109
+ case algorithm
110
+ when "sha1"
111
+ signature_algorithm.should == "http://www.w3.org/2000/09/xmldsig#rsa-#{algorithm}"
112
+ else
113
+ signature_algorithm.should == "http://www.w3.org/2001/04/xmldsig-more#rsa-#{algorithm}"
114
+ end
115
+ private_key.sign(OpenSSL::Digest.new(algorithm).new, data)
116
+ end
117
+ end
118
+ end
119
+ end
100
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmldsig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - benoist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -64,6 +64,10 @@ files:
64
64
  - spec/fixtures/signed_custom_attribute_id.xml
65
65
  - spec/fixtures/signed_xml-exc-c14n#with_comments.xml
66
66
  - spec/fixtures/unsigned-malicious.xml
67
+ - spec/fixtures/unsigned-sha1.xml
68
+ - spec/fixtures/unsigned-sha256.xml
69
+ - spec/fixtures/unsigned-sha384.xml
70
+ - spec/fixtures/unsigned-sha512.xml
67
71
  - spec/fixtures/unsigned.xml
68
72
  - spec/fixtures/unsigned/canonicalizer_1_0.xml
69
73
  - spec/fixtures/unsigned/canonicalizer_1_1.xml
@@ -107,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
111
  version: '0'
108
112
  requirements: []
109
113
  rubyforge_project:
110
- rubygems_version: 2.4.6
114
+ rubygems_version: 2.5.1
111
115
  signing_key:
112
116
  specification_version: 4
113
117
  summary: This gem is a (partial) implementation of the XMLDsig specification (http://www.w3.org/TR/xmldsig-core)
@@ -124,6 +128,10 @@ test_files:
124
128
  - spec/fixtures/signed_custom_attribute_id.xml
125
129
  - spec/fixtures/signed_xml-exc-c14n#with_comments.xml
126
130
  - spec/fixtures/unsigned-malicious.xml
131
+ - spec/fixtures/unsigned-sha1.xml
132
+ - spec/fixtures/unsigned-sha256.xml
133
+ - spec/fixtures/unsigned-sha384.xml
134
+ - spec/fixtures/unsigned-sha512.xml
127
135
  - spec/fixtures/unsigned.xml
128
136
  - spec/fixtures/unsigned/canonicalizer_1_0.xml
129
137
  - spec/fixtures/unsigned/canonicalizer_1_1.xml