xmldsig 0.6.3 → 0.6.4

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: ed8fb3a4e6485ddf83e241026a3847b5b2a77eec
4
- data.tar.gz: 600207fd49308dd772ce99a861868d240d9f6848
3
+ metadata.gz: 64e2371ac44ab8d5d30b2e1dfa83349a9ca0bb29
4
+ data.tar.gz: cbcf177d17808d6491cc86de1543bfee644a9759
5
5
  SHA512:
6
- metadata.gz: 099249a39a5cd6e7cdeed766deac4c5217d32c810197b722e3bea3996fa1adc5715a78d811cb204d6afca0036e8e2a78dd252d2909b485994832e72af19816aa
7
- data.tar.gz: f26a7d2699aa4f2cc261d06874ed4f97e38ff2cdc55a5e6d480cf71f42f8bf11004b78b19f67e78cb5228fd082a8832e1e7c052976915a0bdb73e5eec5b13fe2
6
+ metadata.gz: 30da1a037016e8414285ce55a4feeaa6279aab87f32343fab4004d02ce445f661349e1d4d5fb44ee397435f2d1f3b97a45abb0c902977cc2caa171129aed124a
7
+ data.tar.gz: 9f193467662531c2ff8a21bf22d16fea14801fc52527ece095c54a47690a34a7262f91b2f36b4f6461b1f23a132c47ca688ddc89c9eb2edf5cf4b47c3881fa3e
@@ -1,4 +1,7 @@
1
1
  # Changelog
2
+ v0.6.4
3
+ - Allow a custom XSD file for schema verifiation
4
+
2
5
  v0.6.2
3
6
  - Allowing other DigestMethod namespaces
4
7
 
@@ -17,6 +17,7 @@ module Xmldsig
17
17
  end
18
18
 
19
19
  XSD_FILE = File.read(File.expand_path('../xmldsig/xmldsig-core-schema.xsd', __FILE__))
20
+ XSD_X509_SERIAL_FIX_FILE = File.read(File.expand_path('../xmldsig/xmldsig-core-schema-x509-serial-fix.xsd', __FILE__))
20
21
  end
21
22
 
22
23
  require "xmldsig/canonicalizer"
@@ -30,10 +30,10 @@ module Xmldsig
30
30
  Base64.decode64 signature.at_xpath("descendant::ds:SignatureValue", NAMESPACES).content
31
31
  end
32
32
 
33
- def valid?(certificate = nil, &block)
33
+ def valid?(certificate = nil, schema = nil, &block)
34
34
  @errors = []
35
35
  references.each { |r| r.errors = [] }
36
- validate_schema
36
+ validate_schema(schema)
37
37
  validate_digest_values
38
38
  validate_signature_value(certificate, &block)
39
39
  errors.empty?
@@ -88,9 +88,9 @@ module Xmldsig
88
88
  Base64.strict_encode64(signature_value).chomp
89
89
  end
90
90
 
91
- def validate_schema
91
+ def validate_schema(schema)
92
92
  doc = Nokogiri::XML::Document.parse(signature.canonicalize)
93
- errors = Nokogiri::XML::Schema.new(Xmldsig::XSD_FILE).validate(doc)
93
+ errors = Nokogiri::XML::Schema.new(schema || Xmldsig::XSD_FILE).validate(doc)
94
94
  raise Xmldsig::SchemaError.new(errors.first.message) if errors.any?
95
95
  end
96
96
 
@@ -12,8 +12,8 @@ module Xmldsig
12
12
  @force = options[:force]
13
13
  end
14
14
 
15
- def validate(certificate = nil, &block)
16
- signatures.any? && signatures.all? { |signature| signature.valid?(certificate, &block) }
15
+ def validate(certificate = nil, schema = nil, &block)
16
+ signatures.any? && signatures.all? { |signature| signature.valid?(certificate, schema, &block) }
17
17
  end
18
18
 
19
19
  def sign(private_key = nil, instruct = true, &block)
@@ -1,3 +1,3 @@
1
1
  module Xmldsig
2
- VERSION = '0.6.3'
2
+ VERSION = '0.6.4'
3
3
  end
@@ -0,0 +1,262 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ <!DOCTYPE schema
4
+ PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"
5
+ [
6
+ <!ATTLIST schema
7
+ xmlns:ds CDATA #FIXED "http://www.w3.org/2000/09/xmldsig#">
8
+ <!ENTITY dsig 'http://www.w3.org/2000/09/xmldsig#'>
9
+ <!ENTITY % p ''>
10
+ <!ENTITY % s ''>
11
+ ]>
12
+ -->
13
+ <!-- Schema for XML Signatures
14
+ http://www.w3.org/2000/09/xmldsig#
15
+ $Revision: 4 $ on $Date: 2004-12-16 12:08:17 -0500 (Thu, 16 Dec 2004) $ by $Author: marcgratacos $
16
+ Copyright 2001 The Internet Society and W3C (Massachusetts Institute
17
+ of Technology, Institut National de Recherche en Informatique et en
18
+ Automatique, Keio University). All Rights Reserved.
19
+ http://www.w3.org/Consortium/Legal/
20
+ This document is governed by the W3C Software License [1] as described
21
+ in the FAQ [2].
22
+ [1] http://www.w3.org/Consortium/Legal/copyright-software-19980720
23
+ [2] http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
24
+ -->
25
+ <schema elementFormDefault="qualified" targetNamespace="http://www.w3.org/2000/09/xmldsig#" version="0.1" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
26
+ <!-- Basic Types Defined for Signatures -->
27
+ <simpleType name="CryptoBinary">
28
+ <restriction base="base64Binary" />
29
+ </simpleType>
30
+ <!-- Start Signature -->
31
+ <element name="Signature" type="ds:SignatureType" />
32
+ <complexType name="SignatureType">
33
+ <sequence>
34
+ <element ref="ds:SignedInfo" />
35
+ <element ref="ds:SignatureValue" />
36
+ <element minOccurs="0" ref="ds:KeyInfo" />
37
+ <element maxOccurs="unbounded" minOccurs="0" ref="ds:Object" />
38
+ </sequence>
39
+ <attribute name="Id" type="ID" use="optional" />
40
+ </complexType>
41
+ <element name="SignatureValue" type="ds:SignatureValueType" />
42
+ <complexType name="SignatureValueType">
43
+ <simpleContent>
44
+ <extension base="base64Binary">
45
+ <attribute name="Id" type="ID" use="optional" />
46
+ </extension>
47
+ </simpleContent>
48
+ </complexType>
49
+ <!-- Start SignedInfo -->
50
+ <element name="SignedInfo" type="ds:SignedInfoType" />
51
+ <complexType name="SignedInfoType">
52
+ <sequence>
53
+ <element ref="ds:CanonicalizationMethod" />
54
+ <element ref="ds:SignatureMethod" />
55
+ <element maxOccurs="unbounded" ref="ds:Reference" />
56
+ </sequence>
57
+ <attribute name="Id" type="ID" use="optional" />
58
+ </complexType>
59
+ <element name="CanonicalizationMethod" type="ds:CanonicalizationMethodType" />
60
+ <complexType mixed="true" name="CanonicalizationMethodType">
61
+ <sequence>
62
+ <any maxOccurs="unbounded" minOccurs="0" namespace="##any" />
63
+ <!-- (0,unbounded) elements from (1,1) namespace -->
64
+ </sequence>
65
+ <attribute name="Algorithm" type="anyURI" use="required" />
66
+ </complexType>
67
+ <element name="SignatureMethod" type="ds:SignatureMethodType" />
68
+ <complexType mixed="true" name="SignatureMethodType">
69
+ <sequence>
70
+ <element minOccurs="0" name="HMACOutputLength" type="ds:HMACOutputLengthType" />
71
+ <any maxOccurs="unbounded" minOccurs="0" namespace="##other" />
72
+ <!-- (0,unbounded) elements from (1,1) external namespace -->
73
+ </sequence>
74
+ <attribute name="Algorithm" type="anyURI" use="required" />
75
+ </complexType>
76
+ <!-- Start Reference -->
77
+ <element name="Reference" type="ds:ReferenceType" />
78
+ <complexType name="ReferenceType">
79
+ <sequence>
80
+ <element minOccurs="0" ref="ds:Transforms" />
81
+ <element ref="ds:DigestMethod" />
82
+ <element ref="ds:DigestValue" />
83
+ </sequence>
84
+ <attribute name="Id" type="ID" use="optional" />
85
+ <attribute name="URI" type="anyURI" use="optional" />
86
+ <attribute name="Type" type="anyURI" use="optional" />
87
+ </complexType>
88
+ <element name="Transforms" type="ds:TransformsType" />
89
+ <complexType name="TransformsType">
90
+ <sequence>
91
+ <element maxOccurs="unbounded" ref="ds:Transform" />
92
+ </sequence>
93
+ </complexType>
94
+ <element name="Transform" type="ds:TransformType" />
95
+ <complexType mixed="true" name="TransformType">
96
+ <choice maxOccurs="unbounded" minOccurs="0">
97
+ <any namespace="##other" processContents="lax" />
98
+ <!-- (1,1) elements from (0,unbounded) namespaces -->
99
+ <element name="XPath" type="string" />
100
+ </choice>
101
+ <attribute name="Algorithm" type="anyURI" use="required" />
102
+ </complexType>
103
+ <!-- End Reference -->
104
+ <element name="DigestMethod" type="ds:DigestMethodType" />
105
+ <complexType mixed="true" name="DigestMethodType">
106
+ <sequence>
107
+ <any maxOccurs="unbounded" minOccurs="0" namespace="##other" processContents="lax" />
108
+ </sequence>
109
+ <attribute name="Algorithm" type="anyURI" use="required" />
110
+ </complexType>
111
+ <element name="DigestValue" type="ds:DigestValueType" />
112
+ <simpleType name="DigestValueType">
113
+ <restriction base="base64Binary" />
114
+ </simpleType>
115
+ <!-- End SignedInfo -->
116
+ <!-- Start KeyInfo -->
117
+ <element name="KeyInfo" type="ds:KeyInfoType" />
118
+ <complexType mixed="true" name="KeyInfoType">
119
+ <choice maxOccurs="unbounded">
120
+ <element ref="ds:KeyName" />
121
+ <element ref="ds:KeyValue" />
122
+ <element ref="ds:RetrievalMethod" />
123
+ <element ref="ds:X509Data" />
124
+ <element ref="ds:PGPData" />
125
+ <element ref="ds:SPKIData" />
126
+ <element ref="ds:MgmtData" />
127
+ <any namespace="##other" processContents="lax" />
128
+ <!-- (1,1) elements from (0,unbounded) namespaces -->
129
+ </choice>
130
+ <attribute name="Id" type="ID" use="optional" />
131
+ </complexType>
132
+ <element name="KeyName" type="string" />
133
+ <element name="MgmtData" type="string" />
134
+ <element name="KeyValue" type="ds:KeyValueType" />
135
+ <complexType mixed="true" name="KeyValueType">
136
+ <choice>
137
+ <element ref="ds:DSAKeyValue" />
138
+ <element ref="ds:RSAKeyValue" />
139
+ <any namespace="##other" processContents="lax" />
140
+ </choice>
141
+ </complexType>
142
+ <element name="RetrievalMethod" type="ds:RetrievalMethodType" />
143
+ <complexType name="RetrievalMethodType">
144
+ <sequence>
145
+ <element minOccurs="0" ref="ds:Transforms" />
146
+ </sequence>
147
+ <attribute name="URI" type="anyURI" />
148
+ <attribute name="Type" type="anyURI" use="optional" />
149
+ </complexType>
150
+ <!-- Start X509Data -->
151
+ <element name="X509Data" type="ds:X509DataType" />
152
+ <complexType name="X509DataType">
153
+ <sequence maxOccurs="unbounded">
154
+ <choice>
155
+ <element name="X509IssuerSerial" type="ds:X509IssuerSerialType" />
156
+ <element name="X509SKI" type="base64Binary" />
157
+ <element name="X509SubjectName" type="string" />
158
+ <element name="X509Certificate" type="base64Binary" />
159
+ <element name="X509CRL" type="base64Binary" />
160
+ <any namespace="##other" processContents="lax" />
161
+ </choice>
162
+ </sequence>
163
+ </complexType>
164
+ <complexType name="X509IssuerSerialType">
165
+ <sequence>
166
+ <element name="X509IssuerName" type="string" />
167
+ <element name="X509SerialNumber" type="string" />
168
+ </sequence>
169
+ </complexType>
170
+ <!-- End X509Data -->
171
+ <!-- Begin PGPData -->
172
+ <element name="PGPData" type="ds:PGPDataType" />
173
+ <complexType name="PGPDataType">
174
+ <choice>
175
+ <sequence>
176
+ <element name="PGPKeyID" type="base64Binary" />
177
+ <element minOccurs="0" name="PGPKeyPacket" type="base64Binary" />
178
+ <any maxOccurs="unbounded" minOccurs="0" namespace="##other" processContents="lax" />
179
+ </sequence>
180
+ <sequence>
181
+ <element name="PGPKeyPacket" type="base64Binary" />
182
+ <any maxOccurs="unbounded" minOccurs="0" namespace="##other" processContents="lax" />
183
+ </sequence>
184
+ </choice>
185
+ </complexType>
186
+ <!-- End PGPData -->
187
+ <!-- Begin SPKIData -->
188
+ <element name="SPKIData" type="ds:SPKIDataType" />
189
+ <complexType name="SPKIDataType">
190
+ <sequence maxOccurs="unbounded">
191
+ <element name="SPKISexp" type="base64Binary" />
192
+ <any minOccurs="0" namespace="##other" processContents="lax" />
193
+ </sequence>
194
+ </complexType>
195
+ <!-- End SPKIData -->
196
+ <!-- End KeyInfo -->
197
+ <!-- Start Object (Manifest, SignatureProperty) -->
198
+ <element name="Object" type="ds:ObjectType" />
199
+ <complexType mixed="true" name="ObjectType">
200
+ <sequence maxOccurs="unbounded" minOccurs="0">
201
+ <any namespace="##any" processContents="lax" />
202
+ </sequence>
203
+ <attribute name="Id" type="ID" use="optional" />
204
+ <attribute name="MimeType" type="string" use="optional" />
205
+ <attribute name="Encoding" type="anyURI" use="optional" />
206
+ <!-- add a grep facet -->
207
+ </complexType>
208
+ <element name="Manifest" type="ds:ManifestType" />
209
+ <complexType name="ManifestType">
210
+ <sequence>
211
+ <element maxOccurs="unbounded" ref="ds:Reference" />
212
+ </sequence>
213
+ <attribute name="Id" type="ID" use="optional" />
214
+ </complexType>
215
+ <element name="SignatureProperties" type="ds:SignaturePropertiesType" />
216
+ <complexType name="SignaturePropertiesType">
217
+ <sequence>
218
+ <element maxOccurs="unbounded" ref="ds:SignatureProperty" />
219
+ </sequence>
220
+ <attribute name="Id" type="ID" use="optional" />
221
+ </complexType>
222
+ <element name="SignatureProperty" type="ds:SignaturePropertyType" />
223
+ <complexType mixed="true" name="SignaturePropertyType">
224
+ <choice maxOccurs="unbounded">
225
+ <any namespace="##other" processContents="lax" />
226
+ <!-- (1,1) elements from (1,unbounded) namespaces -->
227
+ </choice>
228
+ <attribute name="Target" type="anyURI" use="required" />
229
+ <attribute name="Id" type="ID" use="optional" />
230
+ </complexType>
231
+ <!-- End Object (Manifest, SignatureProperty) -->
232
+ <!-- Start Algorithm Parameters -->
233
+ <simpleType name="HMACOutputLengthType">
234
+ <restriction base="integer" />
235
+ </simpleType>
236
+ <!-- Start KeyValue Element-types -->
237
+ <element name="DSAKeyValue" type="ds:DSAKeyValueType" />
238
+ <complexType name="DSAKeyValueType">
239
+ <sequence>
240
+ <sequence minOccurs="0">
241
+ <element name="P" type="ds:CryptoBinary" />
242
+ <element name="Q" type="ds:CryptoBinary" />
243
+ </sequence>
244
+ <element minOccurs="0" name="G" type="ds:CryptoBinary" />
245
+ <element name="Y" type="ds:CryptoBinary" />
246
+ <element minOccurs="0" name="J" type="ds:CryptoBinary" />
247
+ <sequence minOccurs="0">
248
+ <element name="Seed" type="ds:CryptoBinary" />
249
+ <element name="PgenCounter" type="ds:CryptoBinary" />
250
+ </sequence>
251
+ </sequence>
252
+ </complexType>
253
+ <element name="RSAKeyValue" type="ds:RSAKeyValueType" />
254
+ <complexType name="RSAKeyValueType">
255
+ <sequence>
256
+ <element name="Modulus" type="ds:CryptoBinary" />
257
+ <element name="Exponent" type="ds:CryptoBinary" />
258
+ </sequence>
259
+ </complexType>
260
+ <!-- End KeyValue Element-types -->
261
+ <!-- End Signature -->
262
+ </schema>
@@ -0,0 +1,29 @@
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:KeyInfo>
21
+ <ds:X509Data>
22
+ <ds:X509IssuerSerial>
23
+ <ds:X509IssuerName>issuer</ds:X509IssuerName>
24
+ <ds:X509SerialNumber>1234567890123456789012345</ds:X509SerialNumber>
25
+ </ds:X509IssuerSerial>
26
+ </ds:X509Data>
27
+ </ds:KeyInfo>
28
+ </ds:Signature>
29
+ </foo:Foo>
@@ -98,6 +98,20 @@ describe Xmldsig::Signature do
98
98
  end
99
99
  expect(signature.errors).to be_empty
100
100
  end
101
+
102
+ context "when X509SerialNumber element is longer than 24 digits" do
103
+ let(:document) { Nokogiri::XML::Document.parse(File.read("spec/fixtures/unsigned-x509-serial-fix.xml")) }
104
+
105
+ before { signature.sign(private_key) }
106
+
107
+ it "returns false with the default validation scheme and true with the X509 serial fix scheme" do
108
+ aggregate_failures do
109
+ expect { signature.valid?(certificate) }.to raise_error Xmldsig::SchemaError, /is not a valid value of the atomic type 'xs:integer'/
110
+ expect(signature.valid?(certificate, Xmldsig::XSD_X509_SERIAL_FIX_FILE)).to eq(true)
111
+ expect(signature.errors).to eql []
112
+ end
113
+ end
114
+ end
101
115
  end
102
116
 
103
117
  ["sha1", "sha256", "sha384", "sha512"].each do |algorithm|
@@ -67,6 +67,10 @@ describe Xmldsig::SignedDocument do
67
67
  expect(xml_without_signature.validate(certificate)).to eq(false)
68
68
  end
69
69
 
70
+ it "accepts a custom schema" do
71
+ expect(signed_document.validate(certificate, Xmldsig::XSD_X509_SERIAL_FIX_FILE)).to eql true
72
+ end
73
+
70
74
  it "accepts a block" do
71
75
  expect(signed_document.validate do |signature_value, data|
72
76
  certificate.public_key.verify(OpenSSL::Digest::SHA256.new, signature_value, data)
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.license = 'MIT'
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Xmldsig::VERSION
18
+
19
+ gem.required_ruby_version = '>= 1.9.2'
18
20
 
19
21
  gem.add_dependency("nokogiri", '>= 1.6.8', '< 2.0.0')
20
22
  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.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - benoist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2017-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -56,6 +56,7 @@ files:
56
56
  - lib/xmldsig/transforms/enveloped_signature.rb
57
57
  - lib/xmldsig/transforms/transform.rb
58
58
  - lib/xmldsig/version.rb
59
+ - lib/xmldsig/xmldsig-core-schema-x509-serial-fix.xsd
59
60
  - lib/xmldsig/xmldsig-core-schema.xsd
60
61
  - signing_service.rb
61
62
  - spec/fixtures/certificate.cer
@@ -75,6 +76,7 @@ files:
75
76
  - spec/fixtures/unsigned-sha256.xml
76
77
  - spec/fixtures/unsigned-sha384.xml
77
78
  - spec/fixtures/unsigned-sha512.xml
79
+ - spec/fixtures/unsigned-x509-serial-fix.xml
78
80
  - spec/fixtures/unsigned-xmlenc-sha1.xml
79
81
  - spec/fixtures/unsigned.xml
80
82
  - spec/fixtures/unsigned/canonicalizer_1_0.xml
@@ -111,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
113
  requirements:
112
114
  - - ">="
113
115
  - !ruby/object:Gem::Version
114
- version: '0'
116
+ version: 1.9.2
115
117
  required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  requirements:
117
119
  - - ">="
@@ -141,6 +143,7 @@ test_files:
141
143
  - spec/fixtures/unsigned-sha256.xml
142
144
  - spec/fixtures/unsigned-sha384.xml
143
145
  - spec/fixtures/unsigned-sha512.xml
146
+ - spec/fixtures/unsigned-x509-serial-fix.xml
144
147
  - spec/fixtures/unsigned-xmlenc-sha1.xml
145
148
  - spec/fixtures/unsigned.xml
146
149
  - spec/fixtures/unsigned/canonicalizer_1_0.xml