xmldsig 0.2.5 → 0.2.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96f6cce84663869fcc116f7468d838596f071814
|
4
|
+
data.tar.gz: 4d4c59ff3419b6f450b804a3d7ae00c02a4d7c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47df30bf57027840f070b89c7008c0532f5461fb021da00671d149c7e9e4b519c1df39f5d92b574b4addf627ba9a9800dc340a4d417f64359c08c2a1ca60b982
|
7
|
+
data.tar.gz: 33f8d0eaf16ba7cdd032e9f1c2916e38d1d70b1c32fe9722868cf45bd53b7d6663da55361ee294a9dba5517a9ef8398f270f1bc4c44bbe58242cf47cbd5abb2b
|
@@ -3,7 +3,11 @@ module Xmldsig
|
|
3
3
|
attr_accessor :document
|
4
4
|
|
5
5
|
def initialize(document, options = {})
|
6
|
-
@document =
|
6
|
+
@document = if document.kind_of?(Nokogiri::XML::Document)
|
7
|
+
document
|
8
|
+
else
|
9
|
+
Nokogiri::XML(document, nil, nil, Nokogiri::XML::ParseOptions::STRICT)
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
def validate(certificate = nil, &block)
|
data/lib/xmldsig/version.rb
CHANGED
@@ -74,7 +74,7 @@ describe Xmldsig::Signature do
|
|
74
74
|
|
75
75
|
describe "#valid?" do
|
76
76
|
it "returns true with the correct certificate" do
|
77
|
-
signature.valid?(certificate).should
|
77
|
+
signature.valid?(certificate).should be == true
|
78
78
|
end
|
79
79
|
|
80
80
|
it "returns false if the xml changed" do
|
@@ -86,7 +86,7 @@ describe Xmldsig::Signature do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "returns false with a difference certificate" do
|
89
|
-
signature.valid?(other_certificate).should
|
89
|
+
signature.valid?(other_certificate).should be == false
|
90
90
|
end
|
91
91
|
|
92
92
|
it "accepts a block" do
|
@@ -26,6 +26,12 @@ describe Xmldsig::SignedDocument do
|
|
26
26
|
described_class.new(badly_formed)
|
27
27
|
}.to raise_error
|
28
28
|
end
|
29
|
+
|
30
|
+
it "accepts a nokogiri document" do
|
31
|
+
doc = Nokogiri::XML(unsigned_xml)
|
32
|
+
signed_document = described_class.new(doc)
|
33
|
+
signed_document.document.should be_a(Nokogiri::XML::Document)
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
describe "#signatures" do
|
@@ -49,36 +55,36 @@ describe Xmldsig::SignedDocument do
|
|
49
55
|
|
50
56
|
describe "#validate" do
|
51
57
|
it "returns true if the signature and digest value are correct" do
|
52
|
-
signed_document.validate(certificate).should
|
58
|
+
signed_document.validate(certificate).should be == true
|
53
59
|
end
|
54
60
|
|
55
61
|
it "returns false if the certificate is not valid" do
|
56
|
-
signed_document.validate(other_certificate).should
|
62
|
+
signed_document.validate(other_certificate).should be == false
|
57
63
|
end
|
58
64
|
|
59
65
|
it "returns false if there are no signatures and validation is strict" do
|
60
66
|
xml_without_signature = Xmldsig::SignedDocument.new('<foo></foo>')
|
61
|
-
xml_without_signature.validate(certificate).should
|
67
|
+
xml_without_signature.validate(certificate).should be == false
|
62
68
|
end
|
63
69
|
|
64
70
|
it "accepts a block" do
|
65
71
|
signed_document.validate do |signature_value, data|
|
66
72
|
certificate.public_key.verify(OpenSSL::Digest::SHA256.new, signature_value, data)
|
67
|
-
end.should
|
73
|
+
end.should be == true
|
68
74
|
end
|
69
75
|
end
|
70
76
|
|
71
77
|
describe "#sign" do
|
72
78
|
it "returns a signed document" do
|
73
79
|
signed_document = unsigned_document.sign(private_key)
|
74
|
-
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should
|
80
|
+
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be == true
|
75
81
|
end
|
76
82
|
|
77
83
|
it "accepts a block" do
|
78
84
|
signed_document = unsigned_document.sign do |data|
|
79
85
|
private_key.sign(OpenSSL::Digest::SHA256.new, data)
|
80
86
|
end
|
81
|
-
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should
|
87
|
+
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be == true
|
82
88
|
end
|
83
89
|
end
|
84
90
|
|
@@ -89,7 +95,7 @@ describe Xmldsig::SignedDocument do
|
|
89
95
|
let(:signed_document) { unsigned_document.sign(private_key) }
|
90
96
|
|
91
97
|
it "when signed should be valid" do
|
92
|
-
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should
|
98
|
+
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be == true
|
93
99
|
end
|
94
100
|
|
95
101
|
it "should sign 2 elements" do
|
@@ -98,8 +104,8 @@ describe Xmldsig::SignedDocument do
|
|
98
104
|
|
99
105
|
it "allows individual signs" do
|
100
106
|
unsigned_document.signatures.last.sign(private_key)
|
101
|
-
unsigned_document.validate(certificate).should
|
102
|
-
unsigned_document.signatures.last.valid?(certificate).should
|
107
|
+
unsigned_document.validate(certificate).should be == false
|
108
|
+
unsigned_document.signatures.last.valid?(certificate).should be == true
|
103
109
|
end
|
104
110
|
end
|
105
111
|
|
data/spec/lib/xmldsig_spec.rb
CHANGED
@@ -12,7 +12,7 @@ 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).should
|
15
|
+
Xmldsig::SignedDocument.new(signed_document).validate(certificate).should be == true
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should have a signature element' do
|
@@ -38,7 +38,7 @@ describe Xmldsig do
|
|
38
38
|
let(:certificate) { OpenSSL::X509::Certificate.new(File.read(document.gsub('.txt', '.cert'))) }
|
39
39
|
|
40
40
|
it "should be validateable" do
|
41
|
-
signed_document.validate(certificate).should
|
41
|
+
signed_document.validate(certificate).should be == true
|
42
42
|
end
|
43
43
|
end
|
44
44
|
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.2.
|
4
|
+
version: 0.2.6
|
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: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.4.5
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: This gem is a (partial) implementation of the XMLDsig specification (http://www.w3.org/TR/xmldsig-core)
|