xmldsig 0.6.2 → 0.6.3
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/lib/xmldsig/version.rb +1 -1
 - data/spec/lib/xmldsig/reference_spec.rb +18 -15
 - data/spec/lib/xmldsig/signature_spec.rb +22 -20
 - data/spec/lib/xmldsig/signed_document_spec.rb +24 -24
 - data/spec/lib/xmldsig/transforms/enveloped_signature_spec.rb +2 -2
 - data/spec/lib/xmldsig/transforms/transform_spec.rb +1 -1
 - data/spec/lib/xmldsig_spec.rb +6 -6
 - data/spec/spec_helper.rb +0 -1
 - data/xmldsig.gemspec +1 -1
 - metadata +10 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ed8fb3a4e6485ddf83e241026a3847b5b2a77eec
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 600207fd49308dd772ce99a861868d240d9f6848
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 099249a39a5cd6e7cdeed766deac4c5217d32c810197b722e3bea3996fa1adc5715a78d811cb204d6afca0036e8e2a78dd252d2909b485994832e72af19816aa
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f26a7d2699aa4f2cc261d06874ed4f97e38ff2cdc55a5e6d480cf71f42f8bf11004b78b19f67e78cb5228fd082a8832e1e7c052976915a0bdb73e5eec5b13fe2
         
     | 
    
        data/lib/xmldsig/version.rb
    CHANGED
    
    
| 
         @@ -6,13 +6,13 @@ describe Xmldsig::Reference do 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              describe "#digest_value" do
         
     | 
| 
       8 
8 
     | 
    
         
             
                it "returns the digest value in the xml" do
         
     | 
| 
       9 
     | 
    
         
            -
                  reference.digest_value. 
     | 
| 
      
 9 
     | 
    
         
            +
                  expect(reference.digest_value).to eq(Base64.decode64("ftoSYFdze1AWgGHF5N9i9SFKThXkqH2AdyzA3/epbJw="))
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              describe "#document" do
         
     | 
| 
       14 
14 
     | 
    
         
             
                it "returns the document" do
         
     | 
| 
       15 
     | 
    
         
            -
                  reference.document. 
     | 
| 
      
 15 
     | 
    
         
            +
                  expect(reference.document).to eq(document)
         
     | 
| 
       16 
16 
     | 
    
         
             
                end
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
         @@ -21,20 +21,22 @@ describe Xmldsig::Reference do 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                it "sets the correct digest value" do
         
     | 
| 
       23 
23 
     | 
    
         
             
                  reference.sign
         
     | 
| 
       24 
     | 
    
         
            -
                  reference.digest_value. 
     | 
| 
      
 24 
     | 
    
         
            +
                  expect(reference.digest_value).to eq(Base64.decode64("ftoSYFdze1AWgGHF5N9i9SFKThXkqH2AdyzA3/epbJw="))
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
              describe "#referenced_node" do
         
     | 
| 
       29 
29 
     | 
    
         
             
                it "returns the referenced_node by id" do
         
     | 
| 
       30 
     | 
    
         
            -
                  reference.referenced_node.to_s. 
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(reference.referenced_node.to_s).to eq(
         
     | 
| 
       31 
31 
     | 
    
         
             
                    document.at_xpath("//*[@ID='foo']").to_s
         
     | 
| 
      
 32 
     | 
    
         
            +
                  )
         
     | 
| 
       32 
33 
     | 
    
         
             
                end
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
35 
     | 
    
         
             
                it "returns the referenced node by parent" do
         
     | 
| 
       35 
     | 
    
         
            -
                  reference. 
     | 
| 
       36 
     | 
    
         
            -
                  reference.referenced_node.to_s. 
     | 
| 
      
 36 
     | 
    
         
            +
                  allow(reference).to receive(:reference_uri).and_return("")
         
     | 
| 
      
 37 
     | 
    
         
            +
                  expect(reference.referenced_node.to_s).to eq(
         
     | 
| 
       37 
38 
     | 
    
         
             
                    document.root.to_s
         
     | 
| 
      
 39 
     | 
    
         
            +
                  )
         
     | 
| 
       38 
40 
     | 
    
         
             
                end
         
     | 
| 
       39 
41 
     | 
    
         | 
| 
       40 
42 
     | 
    
         
             
                it "returns the reference node when using WS-Security style id attribute" do
         
     | 
| 
         @@ -43,9 +45,9 @@ describe Xmldsig::Reference do 
     | 
|
| 
       43 
45 
     | 
    
         
             
                  node['wsu:Id'] = node['ID']
         
     | 
| 
       44 
46 
     | 
    
         
             
                  node.remove_attribute('ID')
         
     | 
| 
       45 
47 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                  reference.referenced_node.
         
     | 
| 
       47 
     | 
    
         
            -
                    attribute_with_ns('Id', Xmldsig::NAMESPACES['wsu']).value.
         
     | 
| 
       48 
     | 
    
         
            -
                     
     | 
| 
      
 48 
     | 
    
         
            +
                  expect(reference.referenced_node.
         
     | 
| 
      
 49 
     | 
    
         
            +
                    attribute_with_ns('Id', Xmldsig::NAMESPACES['wsu']).value).
         
     | 
| 
      
 50 
     | 
    
         
            +
                    to eq('foo')
         
     | 
| 
       49 
51 
     | 
    
         
             
                end
         
     | 
| 
       50 
52 
     | 
    
         | 
| 
       51 
53 
     | 
    
         
             
                it "returns the reference node when using a custom id attribute" do
         
     | 
| 
         @@ -54,8 +56,9 @@ describe Xmldsig::Reference do 
     | 
|
| 
       54 
56 
     | 
    
         
             
                  node.set_attribute('MyID', 'foo')
         
     | 
| 
       55 
57 
     | 
    
         
             
                  reference = Xmldsig::Reference.new(document.at_xpath('//ds:Reference', Xmldsig::NAMESPACES), 'MyID')
         
     | 
| 
       56 
58 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                  reference.referenced_node.to_s. 
     | 
| 
      
 59 
     | 
    
         
            +
                  expect(reference.referenced_node.to_s).to eq(
         
     | 
| 
       58 
60 
     | 
    
         
             
                    document.at_xpath("//*[@MyID='foo']").to_s
         
     | 
| 
      
 61 
     | 
    
         
            +
                  )
         
     | 
| 
       59 
62 
     | 
    
         
             
                end
         
     | 
| 
       60 
63 
     | 
    
         | 
| 
       61 
64 
     | 
    
         
             
                it "raises ReferencedNodeNotFound when the refenced node is not present" do
         
     | 
| 
         @@ -79,7 +82,7 @@ describe Xmldsig::Reference do 
     | 
|
| 
       79 
82 
     | 
    
         | 
| 
       80 
83 
     | 
    
         
             
              describe "#reference_uri" do
         
     | 
| 
       81 
84 
     | 
    
         
             
                it "returns the reference uri" do
         
     | 
| 
       82 
     | 
    
         
            -
                  reference.reference_uri. 
     | 
| 
      
 85 
     | 
    
         
            +
                  expect(reference.reference_uri).to eq("#foo")
         
     | 
| 
       83 
86 
     | 
    
         
             
                end
         
     | 
| 
       84 
87 
     | 
    
         
             
              end
         
     | 
| 
       85 
88 
     | 
    
         | 
| 
         @@ -92,11 +95,11 @@ describe Xmldsig::Reference do 
     | 
|
| 
       92 
95 
     | 
    
         
             
                    match = algorithm.match(/\d+/)[0].to_i
         
     | 
| 
       93 
96 
     | 
    
         
             
                    case match
         
     | 
| 
       94 
97 
     | 
    
         
             
                    when 512
         
     | 
| 
       95 
     | 
    
         
            -
                      reference.digest_method. 
     | 
| 
      
 98 
     | 
    
         
            +
                      expect(reference.digest_method).to eq(Digest::SHA512)
         
     | 
| 
       96 
99 
     | 
    
         
             
                    when 256
         
     | 
| 
       97 
     | 
    
         
            -
                      reference.digest_method. 
     | 
| 
      
 100 
     | 
    
         
            +
                      expect(reference.digest_method).to eq(Digest::SHA256)
         
     | 
| 
       98 
101 
     | 
    
         
             
                    when 1
         
     | 
| 
       99 
     | 
    
         
            -
                      reference.digest_method. 
     | 
| 
      
 102 
     | 
    
         
            +
                      expect(reference.digest_method).to eq(Digest::SHA1)
         
     | 
| 
       100 
103 
     | 
    
         
             
                    end
         
     | 
| 
       101 
104 
     | 
    
         
             
                  end
         
     | 
| 
       102 
105 
     | 
    
         
             
                end
         
     | 
| 
         @@ -105,6 +108,6 @@ describe Xmldsig::Reference do 
     | 
|
| 
       105 
108 
     | 
    
         
             
              it 'defaults to SHA256 for invalid algorithms' do
         
     | 
| 
       106 
109 
     | 
    
         
             
                document = Nokogiri::XML::Document.parse(IO.read("spec/fixtures/unsigned-invalid.xml"))
         
     | 
| 
       107 
110 
     | 
    
         
             
                reference = Xmldsig::Reference.new(document.at_xpath('//ds:Reference', Xmldsig::NAMESPACES))
         
     | 
| 
       108 
     | 
    
         
            -
                reference.digest_method. 
     | 
| 
      
 111 
     | 
    
         
            +
                expect(reference.digest_method).to eq(Digest::SHA256)
         
     | 
| 
       109 
112 
     | 
    
         
             
              end
         
     | 
| 
       110 
113 
     | 
    
         
             
            end
         
     | 
| 
         @@ -18,27 +18,27 @@ describe Xmldsig::Signature do 
     | 
|
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                it "sets the digest value" do
         
     | 
| 
       21 
     | 
    
         
            -
                  signature.references.first.digest_value. 
     | 
| 
      
 21 
     | 
    
         
            +
                  expect(signature.references.first.digest_value).to eq(Base64.decode64("ftoSYFdze1AWgGHF5N9i9SFKThXkqH2AdyzA3/epbJw="))
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                it "sets the signature value" do
         
     | 
| 
       25 
     | 
    
         
            -
                  signature.signature_value. 
     | 
| 
      
 25 
     | 
    
         
            +
                  expect(signature.signature_value).to eq(Base64.decode64("
         
     | 
| 
       26 
26 
     | 
    
         
             
                    E3yyqsSoxRkhYEuaEtR+SLg85gU5B4a7xUXA+d2Zn6j7F6z73dOd8iYHOusB
         
     | 
| 
       27 
27 
     | 
    
         
             
                    Ty3C/3ujbmPhHKg8uX9kUE8b+YoOqZt4z9pdxAq44nJEuijwi4doIPpHWirv
         
     | 
| 
       28 
28 
     | 
    
         
             
                    BnSoP5IoL0DYzGVrgj8udRzfAw5nNeV7wSrBZEn+yrxmUPJoUZc=
         
     | 
| 
       29 
     | 
    
         
            -
                  ")
         
     | 
| 
      
 29 
     | 
    
         
            +
                  "))
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                it "accepts a block" do
         
     | 
| 
       33 
33 
     | 
    
         
             
                  signature.sign do |data, signature_algorithm|
         
     | 
| 
       34 
     | 
    
         
            -
                    signature_algorithm. 
     | 
| 
      
 34 
     | 
    
         
            +
                    expect(signature_algorithm).to eq("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
         
     | 
| 
       35 
35 
     | 
    
         
             
                    private_key.sign(OpenSSL::Digest::SHA256.new, data)
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
     | 
    
         
            -
                  signature.signature_value. 
     | 
| 
      
 37 
     | 
    
         
            +
                  expect(signature.signature_value).to eq(Base64.decode64("
         
     | 
| 
       38 
38 
     | 
    
         
             
                    E3yyqsSoxRkhYEuaEtR+SLg85gU5B4a7xUXA+d2Zn6j7F6z73dOd8iYHOusB
         
     | 
| 
       39 
39 
     | 
    
         
             
                    Ty3C/3ujbmPhHKg8uX9kUE8b+YoOqZt4z9pdxAq44nJEuijwi4doIPpHWirv
         
     | 
| 
       40 
40 
     | 
    
         
             
                    BnSoP5IoL0DYzGVrgj8udRzfAw5nNeV7wSrBZEn+yrxmUPJoUZc=
         
     | 
| 
       41 
     | 
    
         
            -
                  ")
         
     | 
| 
      
 41 
     | 
    
         
            +
                  "))
         
     | 
| 
       42 
42 
     | 
    
         
             
                end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                describe "multiple references" do
         
     | 
| 
         @@ -46,55 +46,57 @@ describe Xmldsig::Signature do 
     | 
|
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  it "can sign the document" do
         
     | 
| 
       48 
48 
     | 
    
         
             
                    signature.sign(private_key)
         
     | 
| 
       49 
     | 
    
         
            -
                    signature. 
     | 
| 
      
 49 
     | 
    
         
            +
                    expect(signature).to be_valid(certificate)
         
     | 
| 
       50 
50 
     | 
    
         
             
                  end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
                  it "gets a digest per reference" do
         
     | 
| 
       53 
     | 
    
         
            -
                    signature.references.count. 
     | 
| 
      
 53 
     | 
    
         
            +
                    expect(signature.references.count).to eq(2)
         
     | 
| 
       54 
54 
     | 
    
         
             
                    signature.sign(private_key)
         
     | 
| 
       55 
     | 
    
         
            -
                    signature.references[0].digest_value. 
     | 
| 
       56 
     | 
    
         
            -
                    signature.references[1].digest_value. 
     | 
| 
      
 55 
     | 
    
         
            +
                    expect(signature.references[0].digest_value).to eq(Base64.decode64("P1nUq8Y/LPmd+EON/mcNMNRjT78="))
         
     | 
| 
      
 56 
     | 
    
         
            +
                    expect(signature.references[1].digest_value).to eq(Base64.decode64("RoGAaQeuNJuDMWcgsD7RuGbFACo="))
         
     | 
| 
       57 
57 
     | 
    
         
             
                  end
         
     | 
| 
       58 
58 
     | 
    
         
             
                end
         
     | 
| 
       59 
59 
     | 
    
         
             
              end
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
              describe "#signed_info" do
         
     | 
| 
       62 
62 
     | 
    
         
             
                it "returns the canonicalized signed info element" do
         
     | 
| 
       63 
     | 
    
         
            -
                  signature.signed_info.to_s. 
     | 
| 
      
 63 
     | 
    
         
            +
                  expect(signature.signed_info.to_s).to eq(
         
     | 
| 
       64 
64 
     | 
    
         
             
                      document.at_xpath("//ds:SignedInfo", Xmldsig::NAMESPACES).to_s
         
     | 
| 
      
 65 
     | 
    
         
            +
                  )
         
     | 
| 
       65 
66 
     | 
    
         
             
                end
         
     | 
| 
       66 
67 
     | 
    
         
             
              end
         
     | 
| 
       67 
68 
     | 
    
         | 
| 
       68 
69 
     | 
    
         
             
              describe "#signature_value" do
         
     | 
| 
       69 
70 
     | 
    
         
             
                it "returns the signature value" do
         
     | 
| 
       70 
     | 
    
         
            -
                  signature.signature_value. 
     | 
| 
      
 71 
     | 
    
         
            +
                  expect(signature.signature_value).to eq(
         
     | 
| 
       71 
72 
     | 
    
         
             
                      Base64.decode64(document.at_xpath("//ds:SignatureValue", Xmldsig::NAMESPACES).content)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  )
         
     | 
| 
       72 
74 
     | 
    
         
             
                end
         
     | 
| 
       73 
75 
     | 
    
         
             
              end
         
     | 
| 
       74 
76 
     | 
    
         | 
| 
       75 
77 
     | 
    
         
             
              describe "#valid?" do
         
     | 
| 
       76 
78 
     | 
    
         
             
                it "returns true with the correct certificate" do
         
     | 
| 
       77 
     | 
    
         
            -
                  signature.valid?(certificate). 
     | 
| 
      
 79 
     | 
    
         
            +
                  expect(signature.valid?(certificate)).to eq(true)
         
     | 
| 
       78 
80 
     | 
    
         
             
                end
         
     | 
| 
       79 
81 
     | 
    
         | 
| 
       80 
82 
     | 
    
         
             
                it "returns false if the xml changed" do
         
     | 
| 
       81 
     | 
    
         
            -
                  signature.references.first. 
     | 
| 
      
 83 
     | 
    
         
            +
                  allow(signature.references.first).to receive(:document).and_return(
         
     | 
| 
       82 
84 
     | 
    
         
             
                    Nokogiri::XML::Document.parse(File.read("spec/fixtures/signed.xml").gsub("\s\s", "\s"))
         
     | 
| 
       83 
85 
     | 
    
         
             
                  )
         
     | 
| 
       84 
86 
     | 
    
         
             
                  signature.valid?(certificate)
         
     | 
| 
       85 
     | 
    
         
            -
                  signature.errors. 
     | 
| 
      
 87 
     | 
    
         
            +
                  expect(signature.errors).to include(:digest_value)
         
     | 
| 
       86 
88 
     | 
    
         
             
                end
         
     | 
| 
       87 
89 
     | 
    
         | 
| 
       88 
90 
     | 
    
         
             
                it "returns false with a difference certificate" do
         
     | 
| 
       89 
     | 
    
         
            -
                  signature.valid?(other_certificate). 
     | 
| 
      
 91 
     | 
    
         
            +
                  expect(signature.valid?(other_certificate)).to eq(false)
         
     | 
| 
       90 
92 
     | 
    
         
             
                end
         
     | 
| 
       91 
93 
     | 
    
         | 
| 
       92 
94 
     | 
    
         
             
                it "accepts a block" do
         
     | 
| 
       93 
95 
     | 
    
         
             
                  signature.valid? do |signature_value, data, signature_algorithm|
         
     | 
| 
       94 
     | 
    
         
            -
                    signature_algorithm. 
     | 
| 
      
 96 
     | 
    
         
            +
                    expect(signature_algorithm).to eq("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
         
     | 
| 
       95 
97 
     | 
    
         
             
                    certificate.public_key.verify(OpenSSL::Digest::SHA256.new, signature_value, data)
         
     | 
| 
       96 
98 
     | 
    
         
             
                  end
         
     | 
| 
       97 
     | 
    
         
            -
                  signature.errors. 
     | 
| 
      
 99 
     | 
    
         
            +
                  expect(signature.errors).to be_empty
         
     | 
| 
       98 
100 
     | 
    
         
             
                end
         
     | 
| 
       99 
101 
     | 
    
         
             
              end
         
     | 
| 
       100 
102 
     | 
    
         | 
| 
         @@ -108,9 +110,9 @@ describe Xmldsig::Signature do 
     | 
|
| 
       108 
110 
     | 
    
         
             
                    signature.sign do |data, signature_algorithm|
         
     | 
| 
       109 
111 
     | 
    
         
             
                      case algorithm
         
     | 
| 
       110 
112 
     | 
    
         
             
                      when "sha1"
         
     | 
| 
       111 
     | 
    
         
            -
                        signature_algorithm. 
     | 
| 
      
 113 
     | 
    
         
            +
                        expect(signature_algorithm).to eq("http://www.w3.org/2000/09/xmldsig#rsa-#{algorithm}")
         
     | 
| 
       112 
114 
     | 
    
         
             
                      else
         
     | 
| 
       113 
     | 
    
         
            -
                        signature_algorithm. 
     | 
| 
      
 115 
     | 
    
         
            +
                        expect(signature_algorithm).to eq("http://www.w3.org/2001/04/xmldsig-more#rsa-#{algorithm}")
         
     | 
| 
       114 
116 
     | 
    
         
             
                      end
         
     | 
| 
       115 
117 
     | 
    
         
             
                      private_key.sign(OpenSSL::Digest.new(algorithm).new, data)
         
     | 
| 
       116 
118 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -12,7 +12,7 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       12 
12 
     | 
    
         
             
              describe "#initialize" do
         
     | 
| 
       13 
13 
     | 
    
         
             
                it "sets the document to a nokogiri document" do
         
     | 
| 
       14 
14 
     | 
    
         
             
                  document = described_class.new(signed_xml)
         
     | 
| 
       15 
     | 
    
         
            -
                  document.document. 
     | 
| 
      
 15 
     | 
    
         
            +
                  expect(document.document).to be_a(Nokogiri::XML::Document)
         
     | 
| 
       16 
16 
     | 
    
         
             
                end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                it "raises on badly formed XML" do
         
     | 
| 
         @@ -24,13 +24,13 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       24 
24 
     | 
    
         
             
                  EOXML
         
     | 
| 
       25 
25 
     | 
    
         
             
                  expect {
         
     | 
| 
       26 
26 
     | 
    
         
             
                    described_class.new(badly_formed)
         
     | 
| 
       27 
     | 
    
         
            -
                  }.to raise_error
         
     | 
| 
      
 27 
     | 
    
         
            +
                  }.to raise_error(Nokogiri::XML::SyntaxError)
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
                it "accepts a nokogiri document" do
         
     | 
| 
       31 
31 
     | 
    
         
             
                  doc             = Nokogiri::XML(unsigned_xml)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  signed_document = described_class.new(doc)
         
     | 
| 
       33 
     | 
    
         
            -
                  signed_document.document. 
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(signed_document.document).to be_a(Nokogiri::XML::Document)
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         
             
              end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
         @@ -39,59 +39,59 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       39 
39 
     | 
    
         
             
                let(:unsigned_document) { Xmldsig::SignedDocument.new(unsigned_xml) }
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                it "returns only the signed nodes" do
         
     | 
| 
       42 
     | 
    
         
            -
                  signed_document.signatures. 
     | 
| 
      
 42 
     | 
    
         
            +
                  expect(signed_document.signatures).to be_all { |signature| signature.is_a?(Xmldsig::Signature) }
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
                it "returns the outer signatures first" do
         
     | 
| 
       46 
     | 
    
         
            -
                  unsigned_document.signatures.first.references.first.reference_uri. 
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(unsigned_document.signatures.first.references.first.reference_uri).to eq('#foo')
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
| 
       48 
48 
     | 
    
         
             
              end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
              describe "#signed_nodes" do
         
     | 
| 
       51 
51 
     | 
    
         
             
                it "returns only the signed nodes" do
         
     | 
| 
       52 
     | 
    
         
            -
                  signed_document.signed_nodes.collect(&:name). 
     | 
| 
      
 52 
     | 
    
         
            +
                  expect(signed_document.signed_nodes.collect(&:name)).to eq(%w(Foo))
         
     | 
| 
       53 
53 
     | 
    
         
             
                end
         
     | 
| 
       54 
54 
     | 
    
         
             
              end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
              describe "#validate" do
         
     | 
| 
       57 
57 
     | 
    
         
             
                it "returns true if the signature and digest value are correct" do
         
     | 
| 
       58 
     | 
    
         
            -
                  signed_document.validate(certificate). 
     | 
| 
      
 58 
     | 
    
         
            +
                  expect(signed_document.validate(certificate)).to eq(true)
         
     | 
| 
       59 
59 
     | 
    
         
             
                end
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
                it "returns false if the certificate is not valid" do
         
     | 
| 
       62 
     | 
    
         
            -
                  signed_document.validate(other_certificate). 
     | 
| 
      
 62 
     | 
    
         
            +
                  expect(signed_document.validate(other_certificate)).to eq(false)
         
     | 
| 
       63 
63 
     | 
    
         
             
                end
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
                it "returns false if there are no signatures and validation is strict" do
         
     | 
| 
       66 
66 
     | 
    
         
             
                  xml_without_signature = Xmldsig::SignedDocument.new('<foo></foo>')
         
     | 
| 
       67 
     | 
    
         
            -
                  xml_without_signature.validate(certificate). 
     | 
| 
      
 67 
     | 
    
         
            +
                  expect(xml_without_signature.validate(certificate)).to eq(false)
         
     | 
| 
       68 
68 
     | 
    
         
             
                end
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                it "accepts a block" do
         
     | 
| 
       71 
     | 
    
         
            -
                  signed_document.validate do |signature_value, data|
         
     | 
| 
      
 71 
     | 
    
         
            +
                  expect(signed_document.validate do |signature_value, data|
         
     | 
| 
       72 
72 
     | 
    
         
             
                    certificate.public_key.verify(OpenSSL::Digest::SHA256.new, signature_value, data)
         
     | 
| 
       73 
     | 
    
         
            -
                  end. 
     | 
| 
      
 73 
     | 
    
         
            +
                  end).to eq(true)
         
     | 
| 
       74 
74 
     | 
    
         
             
                end
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
       76 
76 
     | 
    
         
             
                it "validates a document with a http://www.w3.org/2001/10/xml-exc-c14n#WithComments transform" do
         
     | 
| 
       77 
77 
     | 
    
         
             
                  unsigned_xml_with_comments       = File.read("spec/fixtures/signed_xml-exc-c14n#with_comments.xml")
         
     | 
| 
       78 
78 
     | 
    
         
             
                  unsigned_documents_with_comments = Xmldsig::SignedDocument.new(unsigned_xml_with_comments)
         
     | 
| 
       79 
79 
     | 
    
         
             
                  signed_xml_with_comments         = unsigned_documents_with_comments.sign(private_key)
         
     | 
| 
       80 
     | 
    
         
            -
                  Xmldsig::SignedDocument.new(signed_xml_with_comments).validate(certificate). 
     | 
| 
      
 80 
     | 
    
         
            +
                  expect(Xmldsig::SignedDocument.new(signed_xml_with_comments).validate(certificate)).to eq(true)
         
     | 
| 
       81 
81 
     | 
    
         
             
                end
         
     | 
| 
       82 
82 
     | 
    
         
             
              end
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
              describe "#sign" do
         
     | 
| 
       85 
85 
     | 
    
         
             
                it "returns a signed document" do
         
     | 
| 
       86 
86 
     | 
    
         
             
                  signed_document = unsigned_document.sign(private_key)
         
     | 
| 
       87 
     | 
    
         
            -
                  Xmldsig::SignedDocument.new(signed_document).validate(certificate). 
     | 
| 
      
 87 
     | 
    
         
            +
                  expect(Xmldsig::SignedDocument.new(signed_document).validate(certificate)).to eq(true)
         
     | 
| 
       88 
88 
     | 
    
         
             
                end
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
       90 
90 
     | 
    
         
             
                it "accepts a block" do
         
     | 
| 
       91 
91 
     | 
    
         
             
                  signed_document = unsigned_document.sign do |data|
         
     | 
| 
       92 
92 
     | 
    
         
             
                    private_key.sign(OpenSSL::Digest::SHA256.new, data)
         
     | 
| 
       93 
93 
     | 
    
         
             
                  end
         
     | 
| 
       94 
     | 
    
         
            -
                  Xmldsig::SignedDocument.new(signed_document).validate(certificate). 
     | 
| 
      
 94 
     | 
    
         
            +
                  expect(Xmldsig::SignedDocument.new(signed_document).validate(certificate)).to eq(true)
         
     | 
| 
       95 
95 
     | 
    
         
             
                end
         
     | 
| 
       96 
96 
     | 
    
         | 
| 
       97 
97 
     | 
    
         
             
                context 'with the force false' do
         
     | 
| 
         @@ -102,9 +102,9 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       102 
102 
     | 
    
         
             
                  let(:signed_document) { Xmldsig::SignedDocument.new(signed_xml) }
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
       104 
104 
     | 
    
         
             
                  it 'only signs the root signature and leaves the nested signature intact' do
         
     | 
| 
       105 
     | 
    
         
            -
                    signed_document.signatures.first.valid?(certificate). 
     | 
| 
       106 
     | 
    
         
            -
                    signed_document.signatures.last.valid?(certificate). 
     | 
| 
       107 
     | 
    
         
            -
                    signed_document.signatures.last.signature_value. 
     | 
| 
      
 105 
     | 
    
         
            +
                    expect(signed_document.signatures.first.valid?(certificate)).to eq(true)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    expect(signed_document.signatures.last.valid?(certificate)).to eq(false)
         
     | 
| 
      
 107 
     | 
    
         
            +
                    expect(signed_document.signatures.last.signature_value).to eq(unsigned_document.signatures.last.signature_value)
         
     | 
| 
       108 
108 
     | 
    
         
             
                  end
         
     | 
| 
       109 
109 
     | 
    
         
             
                end
         
     | 
| 
       110 
110 
     | 
    
         | 
| 
         @@ -116,9 +116,9 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       116 
116 
     | 
    
         
             
                  let(:signed_document) { Xmldsig::SignedDocument.new(signed_xml) }
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                  it 'only signs the root signature and leaves the nested signature intact' do
         
     | 
| 
       119 
     | 
    
         
            -
                    signed_document.signatures.first.valid?(certificate). 
     | 
| 
       120 
     | 
    
         
            -
                    signed_document.signatures.last.valid?(certificate). 
     | 
| 
       121 
     | 
    
         
            -
                    signed_document.signatures.last.signature_value. 
     | 
| 
      
 119 
     | 
    
         
            +
                    expect(signed_document.signatures.first.valid?(certificate)).to eq(true)
         
     | 
| 
      
 120 
     | 
    
         
            +
                    expect(signed_document.signatures.last.valid?(certificate)).to eq(true)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    expect(signed_document.signatures.last.signature_value).to_not be(unsigned_document.signatures.last.signature_value)
         
     | 
| 
       122 
122 
     | 
    
         
             
                  end
         
     | 
| 
       123 
123 
     | 
    
         
             
                end
         
     | 
| 
       124 
124 
     | 
    
         
             
              end
         
     | 
| 
         @@ -129,17 +129,17 @@ describe Xmldsig::SignedDocument do 
     | 
|
| 
       129 
129 
     | 
    
         
             
                let(:signed_document) { unsigned_document.sign(private_key) }
         
     | 
| 
       130 
130 
     | 
    
         | 
| 
       131 
131 
     | 
    
         
             
                it "when signed should be valid" do
         
     | 
| 
       132 
     | 
    
         
            -
                  Xmldsig::SignedDocument.new(signed_document).validate(certificate). 
     | 
| 
      
 132 
     | 
    
         
            +
                  expect(Xmldsig::SignedDocument.new(signed_document).validate(certificate)).to eq(true)
         
     | 
| 
       133 
133 
     | 
    
         
             
                end
         
     | 
| 
       134 
134 
     | 
    
         | 
| 
       135 
135 
     | 
    
         
             
                it "should sign 2 elements" do
         
     | 
| 
       136 
     | 
    
         
            -
                  unsigned_document.signed_nodes.count. 
     | 
| 
      
 136 
     | 
    
         
            +
                  expect(unsigned_document.signed_nodes.count).to eq(2)
         
     | 
| 
       137 
137 
     | 
    
         
             
                end
         
     | 
| 
       138 
138 
     | 
    
         | 
| 
       139 
139 
     | 
    
         
             
                it "allows individual signs" do
         
     | 
| 
       140 
140 
     | 
    
         
             
                  unsigned_document.signatures.last.sign(private_key)
         
     | 
| 
       141 
     | 
    
         
            -
                  unsigned_document.validate(certificate). 
     | 
| 
       142 
     | 
    
         
            -
                  unsigned_document.signatures.last.valid?(certificate). 
     | 
| 
      
 141 
     | 
    
         
            +
                  expect(unsigned_document.validate(certificate)).to eq(false)
         
     | 
| 
      
 142 
     | 
    
         
            +
                  expect(unsigned_document.signatures.last.valid?(certificate)).to eq(true)
         
     | 
| 
       143 
143 
     | 
    
         
             
                end
         
     | 
| 
       144 
144 
     | 
    
         
             
              end
         
     | 
| 
       145 
145 
     | 
    
         | 
| 
         @@ -10,9 +10,9 @@ describe Xmldsig::Transforms::EnvelopedSignature do 
     | 
|
| 
       10 
10 
     | 
    
         
             
                described_class.new(node_with_nested_signature, nil).transform
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                remaining_signatures = node_with_nested_signature.xpath('descendant::ds:Signature', Xmldsig::NAMESPACES)
         
     | 
| 
       13 
     | 
    
         
            -
                remaining_signatures.count. 
     | 
| 
      
 13 
     | 
    
         
            +
                expect(remaining_signatures.count).to eq(1)
         
     | 
| 
       14 
14 
     | 
    
         
             
                signature = Xmldsig::Signature.new(remaining_signatures.first)
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                signature.references.first.reference_uri. 
     | 
| 
      
 16 
     | 
    
         
            +
                expect(signature.references.first.reference_uri).to eq('#baz')
         
     | 
| 
       17 
17 
     | 
    
         
             
              end
         
     | 
| 
       18 
18 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,7 +3,7 @@ require 'spec_helper' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Xmldsig::Transforms::Transform do
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              it "raises a warning when transform is called" do
         
     | 
| 
       6 
     | 
    
         
            -
                described_class. 
     | 
| 
      
 6 
     | 
    
         
            +
                expect_any_instance_of(described_class).to receive(:warn)
         
     | 
| 
       7 
7 
     | 
    
         
             
                described_class.new(nil,nil).transform
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
    
        data/spec/lib/xmldsig_spec.rb
    CHANGED
    
    | 
         @@ -12,11 +12,11 @@ describe Xmldsig do 
     | 
|
| 
       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). 
     | 
| 
      
 15 
     | 
    
         
            +
                      expect(Xmldsig::SignedDocument.new(signed_document).validate(certificate)).to eq(true)
         
     | 
| 
       16 
16 
     | 
    
         
             
                    end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                    it 'should have at least 1 signature element' do
         
     | 
| 
       19 
     | 
    
         
            -
                      Xmldsig::SignedDocument.new(signed_document).signatures.count. 
     | 
| 
      
 19 
     | 
    
         
            +
                      expect(Xmldsig::SignedDocument.new(signed_document).signatures.count).to be >= 1
         
     | 
| 
       20 
20 
     | 
    
         
             
                    end
         
     | 
| 
       21 
21 
     | 
    
         
             
                  end
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
         @@ -30,7 +30,7 @@ describe Xmldsig do 
     | 
|
| 
       30 
30 
     | 
    
         
             
                    let(:certificate) { OpenSSL::X509::Certificate.new(File.read(document.gsub('.txt', '.cert'))) }
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                    it "should be validateable" do
         
     | 
| 
       33 
     | 
    
         
            -
                      signed_document.validate(certificate). 
     | 
| 
      
 33 
     | 
    
         
            +
                      expect(signed_document.validate(certificate)).to eq(true)
         
     | 
| 
       34 
34 
     | 
    
         
             
                    end
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
         @@ -64,11 +64,11 @@ describe Xmldsig do 
     | 
|
| 
       64 
64 
     | 
    
         
             
                  let(:signed_document) { unsigned_document.sign(private_key) }
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
66 
     | 
    
         
             
                  it "should be signable an validateable" do
         
     | 
| 
       67 
     | 
    
         
            -
                    Xmldsig::SignedDocument.new(signed_document, :id_attr => 'MyID').validate(certificate). 
     | 
| 
      
 67 
     | 
    
         
            +
                    expect(Xmldsig::SignedDocument.new(signed_document, :id_attr => 'MyID').validate(certificate)).to eq(true)
         
     | 
| 
       68 
68 
     | 
    
         
             
                  end
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                  it 'should have a signature element' do
         
     | 
| 
       71 
     | 
    
         
            -
                    Xmldsig::SignedDocument.new(signed_document, :id_attr => 'MyID').signatures.count. 
     | 
| 
      
 71 
     | 
    
         
            +
                    expect(Xmldsig::SignedDocument.new(signed_document, :id_attr => 'MyID').signatures.count).to eq(1)
         
     | 
| 
       72 
72 
     | 
    
         
             
                  end
         
     | 
| 
       73 
73 
     | 
    
         
             
                end
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
         @@ -77,7 +77,7 @@ describe Xmldsig do 
     | 
|
| 
       77 
77 
     | 
    
         
             
                  let(:signed_document) { Xmldsig::SignedDocument.new(signed_xml, :id_attr => 'MyID') }
         
     | 
| 
       78 
78 
     | 
    
         | 
| 
       79 
79 
     | 
    
         
             
                  it "should be validateable" do
         
     | 
| 
       80 
     | 
    
         
            -
                    signed_document.validate(certificate). 
     | 
| 
      
 80 
     | 
    
         
            +
                    expect(signed_document.validate(certificate)).to eq(true)
         
     | 
| 
       81 
81 
     | 
    
         
             
                  end
         
     | 
| 
       82 
82 
     | 
    
         
             
                end
         
     | 
| 
       83 
83 
     | 
    
         
             
              end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        data/xmldsig.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,29 +1,35 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: xmldsig
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.6. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.6.3
         
     | 
| 
       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: 2017-03-22 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: nokogiri
         
     | 
| 
       15 
15 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - - " 
     | 
| 
      
 17 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
19 
     | 
    
         
             
                    version: 1.6.8
         
     | 
| 
      
 20 
     | 
    
         
            +
                - - "<"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 22 
     | 
    
         
            +
                    version: 2.0.0
         
     | 
| 
       20 
23 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
24 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
25 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
26 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - - " 
     | 
| 
      
 27 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       25 
28 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
29 
     | 
    
         
             
                    version: 1.6.8
         
     | 
| 
      
 30 
     | 
    
         
            +
                - - "<"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: 2.0.0
         
     | 
| 
       27 
33 
     | 
    
         
             
            description: This gem is a (partial) implementation of the XMLDsig specification
         
     | 
| 
       28 
34 
     | 
    
         
             
            email:
         
     | 
| 
       29 
35 
     | 
    
         
             
            - benoist.claassen@gmail.com
         
     |