xmldsig 0.2.9 → 0.2.10
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 +4 -4
 - data/CHANGELOG.md +3 -0
 - data/lib/xmldsig/canonicalizer.rb +6 -4
 - data/lib/xmldsig/transforms/canonicalize.rb +1 -1
 - data/lib/xmldsig/transforms/transform.rb +3 -2
 - data/lib/xmldsig/transforms.rb +2 -0
 - data/lib/xmldsig/version.rb +1 -1
 - data/spec/fixtures/signed_xml-exc-c14n#with_comments.xml +21 -0
 - data/spec/lib/xmldsig/signed_document_spec.rb +7 -0
 - metadata +4 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 227a4b8476b3589a1daedcb5fcf290f0aecf8188
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3617f08f692df2042ae4b29e630d481162add76b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 948280bdfbd54908b3c5955b2c164512983b24b4c7852436e36ec76b861bd603ad3f72b591e9a5c8471a6ca1231de57aa83631cf5ce6acc1f433101a7a6d0a49
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 28edb78b29c0792616bd82e351edf30156726469db9413a93b701f1007da1b0b26b0a3c32e203e2ad42f4e229ada259a901731fb1a2ba817cf868330ae6830a5
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
| 
         @@ -1,22 +1,24 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Xmldsig
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Canonicalizer
         
     | 
| 
       3 
     | 
    
         
            -
                attr_accessor :node, :method, :inclusive_namespaces
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_accessor :node, :method, :inclusive_namespaces, :with_comments
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                def initialize(node, method = nil, inclusive_namespaces = [])
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(node, method = nil, inclusive_namespaces = [], with_comments = false)
         
     | 
| 
       6 
6 
     | 
    
         
             
                  @node = node
         
     | 
| 
       7 
7 
     | 
    
         
             
                  @method = method
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @inclusive_namespaces = inclusive_namespaces
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @with_comments = with_comments
         
     | 
| 
       9 
10 
     | 
    
         
             
                end
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
                def canonicalize
         
     | 
| 
       12 
     | 
    
         
            -
                  node.canonicalize(mode(method), inclusive_namespaces)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  node.canonicalize(mode(method), inclusive_namespaces, with_comments)
         
     | 
| 
       13 
14 
     | 
    
         
             
                end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
                private
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
18 
     | 
    
         
             
                def mode(method)
         
     | 
| 
       18 
19 
     | 
    
         
             
                  case method
         
     | 
| 
       19 
     | 
    
         
            -
                    when "http://www.w3.org/2001/10/xml-exc-c14n#"
         
     | 
| 
      
 20 
     | 
    
         
            +
                    when "http://www.w3.org/2001/10/xml-exc-c14n#",
         
     | 
| 
      
 21 
     | 
    
         
            +
                         "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
         
     | 
| 
       20 
22 
     | 
    
         
             
                      Nokogiri::XML::XML_C14N_EXCLUSIVE_1_0
         
     | 
| 
       21 
23 
     | 
    
         
             
                    when "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
         
     | 
| 
       22 
24 
     | 
    
         
             
                      Nokogiri::XML::XML_C14N_1_0
         
     | 
| 
         @@ -2,7 +2,7 @@ module Xmldsig 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Transforms < Array
         
     | 
| 
       3 
3 
     | 
    
         
             
                class Canonicalize < Transform
         
     | 
| 
       4 
4 
     | 
    
         
             
                  def transform
         
     | 
| 
       5 
     | 
    
         
            -
                    self.node = Canonicalizer.new(node, algorithm, inclusive_namespaces).canonicalize
         
     | 
| 
      
 5 
     | 
    
         
            +
                    self.node = Canonicalizer.new(node, algorithm, inclusive_namespaces, with_comments).canonicalize
         
     | 
| 
       6 
6 
     | 
    
         
             
                    node
         
     | 
| 
       7 
7 
     | 
    
         
             
                  end
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
         @@ -2,11 +2,12 @@ module Xmldsig 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Transforms < Array
         
     | 
| 
       3 
3 
     | 
    
         
             
                class Transform
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                  attr_accessor :node, :transform_node
         
     | 
| 
      
 5 
     | 
    
         
            +
                  attr_accessor :node, :transform_node, :with_comments
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                  def initialize(node, transform_node)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  def initialize(node, transform_node, with_comments = false)
         
     | 
| 
       8 
8 
     | 
    
         
             
                    @node           = node
         
     | 
| 
       9 
9 
     | 
    
         
             
                    @transform_node = transform_node
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @with_comments  = with_comments
         
     | 
| 
       10 
11 
     | 
    
         
             
                  end
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
                  def transform
         
     | 
    
        data/lib/xmldsig/transforms.rb
    CHANGED
    
    | 
         @@ -19,6 +19,8 @@ module Xmldsig 
     | 
|
| 
       19 
19 
     | 
    
         
             
                        "http://www.w3.org/TR/2001/REC-xml-c14n-20010315",
         
     | 
| 
       20 
20 
     | 
    
         
             
                        "http://www.w3.org/2006/12/xml-c14n11"
         
     | 
| 
       21 
21 
     | 
    
         
             
                      Transforms::Canonicalize.new(node, transform_node)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    when "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"
         
     | 
| 
      
 23 
     | 
    
         
            +
                      Transforms::Canonicalize.new(node, transform_node, true)
         
     | 
| 
       22 
24 
     | 
    
         
             
                  end
         
     | 
| 
       23 
25 
     | 
    
         
             
                end
         
     | 
| 
       24 
26 
     | 
    
         | 
    
        data/lib/xmldsig/version.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <?xml version="1.0" encoding="UTF-8"?>
         
     | 
| 
      
 2 
     | 
    
         
            +
            <foo: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#" ID="foo">
         
     | 
| 
      
 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#WithComments"/>
         
     | 
| 
      
 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#WithComments">
         
     | 
| 
      
 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>
         
     | 
| 
         @@ -72,6 +72,13 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       72 
72 
     | 
    
         
             
                    certificate.public_key.verify(OpenSSL::Digest::SHA256.new, signature_value, data)
         
     | 
| 
       73 
73 
     | 
    
         
             
                  end.should be == true
         
     | 
| 
       74 
74 
     | 
    
         
             
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                it "validates a document with a http://www.w3.org/2001/10/xml-exc-c14n#WithComments transform" do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  unsigned_xml_with_comments = File.read("spec/fixtures/signed_xml-exc-c14n#with_comments.xml")
         
     | 
| 
      
 78 
     | 
    
         
            +
                  unsigned_documents_with_comments = Xmldsig::SignedDocument.new(unsigned_xml_with_comments)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  signed_xml_with_comments = unsigned_documents_with_comments.sign(private_key)
         
     | 
| 
      
 80 
     | 
    
         
            +
                  Xmldsig::SignedDocument.new(signed_xml_with_comments).validate(certificate).should be == true
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
       75 
82 
     | 
    
         
             
              end
         
     | 
| 
       76 
83 
     | 
    
         | 
| 
       77 
84 
     | 
    
         
             
              describe "#sign" do
         
     | 
    
        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.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.10
         
     | 
| 
       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 
     | 
    
         
            +
            date: 2015-10-30 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: nokogiri
         
     | 
| 
         @@ -60,6 +60,7 @@ files: 
     | 
|
| 
       60 
60 
     | 
    
         
             
            - spec/fixtures/signed/shib.cert
         
     | 
| 
       61 
61 
     | 
    
         
             
            - spec/fixtures/signed/shib.xml
         
     | 
| 
       62 
62 
     | 
    
         
             
            - spec/fixtures/signed_custom_attribute_id.xml
         
     | 
| 
      
 63 
     | 
    
         
            +
            - spec/fixtures/signed_xml-exc-c14n#with_comments.xml
         
     | 
| 
       63 
64 
     | 
    
         
             
            - spec/fixtures/unsigned-malicious.xml
         
     | 
| 
       64 
65 
     | 
    
         
             
            - spec/fixtures/unsigned.xml
         
     | 
| 
       65 
66 
     | 
    
         
             
            - spec/fixtures/unsigned/canonicalizer_1_0.xml
         
     | 
| 
         @@ -117,6 +118,7 @@ test_files: 
     | 
|
| 
       117 
118 
     | 
    
         
             
            - spec/fixtures/signed/shib.cert
         
     | 
| 
       118 
119 
     | 
    
         
             
            - spec/fixtures/signed/shib.xml
         
     | 
| 
       119 
120 
     | 
    
         
             
            - spec/fixtures/signed_custom_attribute_id.xml
         
     | 
| 
      
 121 
     | 
    
         
            +
            - spec/fixtures/signed_xml-exc-c14n#with_comments.xml
         
     | 
| 
       120 
122 
     | 
    
         
             
            - spec/fixtures/unsigned-malicious.xml
         
     | 
| 
       121 
123 
     | 
    
         
             
            - spec/fixtures/unsigned.xml
         
     | 
| 
       122 
124 
     | 
    
         
             
            - spec/fixtures/unsigned/canonicalizer_1_0.xml
         
     |