xmlsec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ XML Security Library test file
4
+ -->
5
+ <Service version="2.0">
6
+ <Data>
7
+ <str> Hello, World! The euro sign (ą) </str>
8
+ <smfing>
9
+ <!-- XML Security Library test file -->
10
+ <test1 somettr="VALUE"/>
11
+ <TEST2 SOMETTR="VALUE"/>
12
+ </smfing>
13
+ </Data>
14
+ </Service>
@@ -0,0 +1,13 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIB+zCCAWQCCQCNDSfdaw1XODANBgkqhkiG9w0BAQUFADBCMQswCQYDVQQGEwJY
3
+ WDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBh
4
+ bnkgTHRkMB4XDTEyMDMxMjE0MjExNVoXDTEzMDMxMjE0MjExNVowQjELMAkGA1UE
5
+ BhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBD
6
+ b21wYW55IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAzAkX2JwvyH6h
7
+ UtXt9g7HAz/GQPe/nexZjGwVOfZtcLVR24wzSqMKUm+t+hsDrngZor7mYbkzrFwW
8
+ JZKuMzTdOBFMdJABXQ26ik4X5G3oQvLCvvfxqGoci4BnOa2TnxvpRw7g1jekjGxn
9
+ 393bFgOXJIi0gsjx+hcr20qLdaEnJycCAwEAATANBgkqhkiG9w0BAQUFAAOBgQBA
10
+ 8qZt/THE1SmLZ/55yTh3rxgcfdlJzk+iE9VYd9aseGHSbZmOEDjmtF6hNJBYw/BI
11
+ oxAOVnMI6cuAbNe5ydub5YeelyJGrlPEcIs+lm2GkUCRFZd4krVO4r2wptD0KP8a
12
+ 5iD8CBI9Bl39pXP7k6pEM1UVPUfxyT/h7I2dpqxp+Q==
13
+ -----END CERTIFICATE-----
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rspec'
4
+ require 'xmlsec'
5
+ require 'nokogiri'
6
+
@@ -0,0 +1,320 @@
1
+ require 'spec_helper'
2
+
3
+ describe XmlSec do
4
+
5
+ it "should sign unsigned.test.xml with unprotected private key" do
6
+ asset_dir = File.expand_path('../../assets', __FILE__)
7
+ xml = XmlSec::sign_file(
8
+ File.join(asset_dir, 'unsigned.test.xml'),
9
+ File.join(asset_dir, 'private.key.pem'),
10
+ nil,
11
+ nil,
12
+ nil
13
+ )
14
+ doc = Nokogiri::XML(xml)
15
+ doc.xpath(
16
+ "Service/xmlns:Signature/xmlns:SignatureValue",
17
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
18
+ ).count.should eql(1)
19
+
20
+ end
21
+
22
+ it "should sign unsigned.test.xml with protected private key" do
23
+ asset_dir = File.expand_path('../../assets', __FILE__)
24
+ xml = XmlSec::sign_file(
25
+ File.join(asset_dir, 'unsigned.test.xml'),
26
+ File.join(asset_dir, 'private.passw.key.pem'),
27
+ 'testas',
28
+ nil,
29
+ nil
30
+ )
31
+ doc = Nokogiri::XML(xml)
32
+ doc.xpath(
33
+ "Service/xmlns:Signature/xmlns:SignatureValue",
34
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
35
+ ).count.should eql(1)
36
+
37
+ end
38
+
39
+ it "should sign unsigned.test.xml with protected private key and add certificate" do
40
+ asset_dir = File.expand_path('../../assets', __FILE__)
41
+ xml = XmlSec::sign_file(
42
+ File.join(asset_dir, 'unsigned.test.xml'),
43
+ File.join(asset_dir, 'private.passw.key.pem'),
44
+ 'testas',
45
+ File.join(asset_dir, 'x509.crt'),
46
+ nil
47
+ )
48
+ doc = Nokogiri::XML(xml)
49
+ doc.xpath(
50
+ "Service/xmlns:Signature/xmlns:SignatureValue",
51
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
52
+ ).count.should eql(1)
53
+
54
+ doc.xpath(
55
+ "Service/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
56
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
57
+ ).count.should eql(1)
58
+
59
+ end
60
+
61
+ it "should sign unsigned.test.xml with unprotected private key and add certificate" do
62
+ asset_dir = File.expand_path('../../assets', __FILE__)
63
+ xml = XmlSec::sign_file(
64
+ File.join(asset_dir, 'unsigned.test.xml'),
65
+ File.join(asset_dir, 'private.key.pem'),
66
+ nil,
67
+ File.join(asset_dir, 'x509.crt'),
68
+ nil
69
+ )
70
+ doc = Nokogiri::XML(xml)
71
+
72
+ doc.xpath(
73
+ "Service/xmlns:Signature/xmlns:SignatureValue",
74
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
75
+ ).count.should eql(1)
76
+
77
+ doc.xpath(
78
+ "Service/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
79
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
80
+ ).count.should eql(1)
81
+ end
82
+
83
+ it "should sign unsigned.test.xml with unprotected private key, signature must be placed in <Security> tag" do
84
+ asset_dir = File.expand_path('../../assets', __FILE__)
85
+ xml = XmlSec::sign_file(
86
+ File.join(asset_dir, 'unsigned.test.xml'),
87
+ File.join(asset_dir, 'private.key.pem'),
88
+ nil,
89
+ nil,
90
+ 'Security'
91
+ )
92
+ doc = Nokogiri::XML(xml)
93
+ doc.xpath(
94
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
95
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
96
+ ).count.should eql(1)
97
+
98
+ end
99
+
100
+ it "should sign unsigned.test.xml with protected private key, signature must be placed in <Security> tag" do
101
+ asset_dir = File.expand_path('../../assets', __FILE__)
102
+ xml = XmlSec::sign_file(
103
+ File.join(asset_dir, 'unsigned.test.xml'),
104
+ File.join(asset_dir, 'private.passw.key.pem'),
105
+ 'testas',
106
+ nil,
107
+ 'Security'
108
+ )
109
+ doc = Nokogiri::XML(xml)
110
+ doc.xpath(
111
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
112
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
113
+ ).count.should eql(1)
114
+
115
+ end
116
+
117
+ it "should sign unsigned.test.xml with protected private key and add certificat, signature must be placed in <Security> tage" do
118
+ asset_dir = File.expand_path('../../assets', __FILE__)
119
+ xml = XmlSec::sign_file(
120
+ File.join(asset_dir, 'unsigned.test.xml'),
121
+ File.join(asset_dir, 'private.passw.key.pem'),
122
+ 'testas',
123
+ File.join(asset_dir, 'x509.crt'),
124
+ 'Security'
125
+ )
126
+ doc = Nokogiri::XML(xml)
127
+ doc.xpath(
128
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
129
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
130
+ ).count.should eql(1)
131
+
132
+ doc.xpath(
133
+ "Service/Security/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
134
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
135
+ ).count.should eql(1)
136
+
137
+ end
138
+
139
+ it "should sign unsigned.test.xml with unprotected private key and add certificate, signature must be placed in <Security> tag" do
140
+ asset_dir = File.expand_path('../../assets', __FILE__)
141
+ xml = XmlSec::sign_file(
142
+ File.join(asset_dir, 'unsigned.test.xml'),
143
+ File.join(asset_dir, 'private.key.pem'),
144
+ nil,
145
+ File.join(asset_dir, 'x509.crt'),
146
+ 'Security'
147
+ )
148
+ doc = Nokogiri::XML(xml)
149
+ File.open(File.join(asset_dir, 'signed.test.xml'), "w") {|f| f.puts xml }
150
+
151
+
152
+ doc.xpath(
153
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
154
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
155
+ ).count.should eql(1)
156
+
157
+ doc.xpath(
158
+ "Service/Security/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
159
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
160
+ ).count.should eql(1)
161
+ end
162
+
163
+ it "should sign xml string with unprotected private key" do
164
+ asset_dir = File.expand_path('../../assets', __FILE__)
165
+ xml = XmlSec::sign(
166
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
167
+ File.join(asset_dir, 'private.key.pem'),
168
+ nil,
169
+ nil,
170
+ nil
171
+ )
172
+ doc = Nokogiri::XML(xml)
173
+ doc.xpath(
174
+ "Service/xmlns:Signature/xmlns:SignatureValue",
175
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
176
+ ).count.should eql(1)
177
+
178
+ end
179
+
180
+ it "should sign xml string with protected private key" do
181
+ asset_dir = File.expand_path('../../assets', __FILE__)
182
+ xml = XmlSec::sign(
183
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
184
+ File.join(asset_dir, 'private.passw.key.pem'),
185
+ 'testas',
186
+ nil,
187
+ nil
188
+ )
189
+ doc = Nokogiri::XML(xml)
190
+ doc.xpath(
191
+ "Service/xmlns:Signature/xmlns:SignatureValue",
192
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
193
+ ).count.should eql(1)
194
+
195
+ end
196
+
197
+ it "should sign xml string with protected private key and add certificate" do
198
+ asset_dir = File.expand_path('../../assets', __FILE__)
199
+ xml = XmlSec::sign(
200
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
201
+ File.join(asset_dir, 'private.passw.key.pem'),
202
+ 'testas',
203
+ File.join(asset_dir, 'x509.crt'),
204
+ nil
205
+ )
206
+ doc = Nokogiri::XML(xml)
207
+ doc.xpath(
208
+ "Service/xmlns:Signature/xmlns:SignatureValue",
209
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
210
+ ).count.should eql(1)
211
+
212
+ doc.xpath(
213
+ "Service/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
214
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
215
+ ).count.should eql(1)
216
+
217
+ end
218
+
219
+ it "should sign xml string with unprotected private key and add certificate" do
220
+ asset_dir = File.expand_path('../../assets', __FILE__)
221
+ xml = XmlSec::sign(
222
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
223
+ File.join(asset_dir, 'private.key.pem'),
224
+ nil,
225
+ File.join(asset_dir, 'x509.crt'),
226
+ nil
227
+ )
228
+ doc = Nokogiri::XML(xml)
229
+
230
+ doc.xpath(
231
+ "Service/xmlns:Signature/xmlns:SignatureValue",
232
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
233
+ ).count.should eql(1)
234
+
235
+ doc.xpath(
236
+ "Service/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
237
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
238
+ ).count.should eql(1)
239
+ end
240
+
241
+ it "should sign xml string with unprotected private key, signature must be placed in <Security> tag" do
242
+ asset_dir = File.expand_path('../../assets', __FILE__)
243
+ xml = XmlSec::sign(
244
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
245
+ File.join(asset_dir, 'private.key.pem'),
246
+ nil,
247
+ nil,
248
+ 'Security'
249
+ )
250
+ doc = Nokogiri::XML(xml)
251
+ doc.xpath(
252
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
253
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
254
+ ).count.should eql(1)
255
+
256
+ end
257
+
258
+ it "should sign xml string with protected private key, signature must be placed in <Security> tag" do
259
+ asset_dir = File.expand_path('../../assets', __FILE__)
260
+ xml = XmlSec::sign(
261
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
262
+ File.join(asset_dir, 'private.passw.key.pem'),
263
+ 'testas',
264
+ nil,
265
+ 'Security'
266
+ )
267
+ doc = Nokogiri::XML(xml)
268
+ doc.xpath(
269
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
270
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
271
+ ).count.should eql(1)
272
+
273
+ end
274
+
275
+ it "should sign xml string with protected private key and add certificat, signature must be placed in <Security> tage" do
276
+ asset_dir = File.expand_path('../../assets', __FILE__)
277
+ xml = XmlSec::sign(
278
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
279
+ File.join(asset_dir, 'private.passw.key.pem'),
280
+ 'testas',
281
+ File.join(asset_dir, 'x509.crt'),
282
+ 'Security'
283
+ )
284
+ doc = Nokogiri::XML(xml)
285
+ doc.xpath(
286
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
287
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
288
+ ).count.should eql(1)
289
+
290
+ doc.xpath(
291
+ "Service/Security/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
292
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
293
+ ).count.should eql(1)
294
+
295
+ end
296
+
297
+ it "should sign xml string with unprotected private key and add certificate, signature must be placed in <Security> tag" do
298
+ asset_dir = File.expand_path('../../assets', __FILE__)
299
+ xml = XmlSec::sign(
300
+ '<?xml version="1.0" encoding="UTF-8"?><Service><Data>Hello</Data></Service>',
301
+ File.join(asset_dir, 'private.key.pem'),
302
+ nil,
303
+ File.join(asset_dir, 'x509.crt'),
304
+ 'Security'
305
+ )
306
+ doc = Nokogiri::XML(xml)
307
+
308
+ doc.xpath(
309
+ "Service/Security/xmlns:Signature/xmlns:SignatureValue",
310
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
311
+ ).count.should eql(1)
312
+
313
+ doc.xpath(
314
+ "Service/Security/xmlns:Signature/xmlns:KeyInfo/xmlns:X509Data/xmlns:X509Certificate",
315
+ "xmlns" => "http://www.w3.org/2000/09/xmldsig#"
316
+ ).count.should eql(1)
317
+ end
318
+
319
+
320
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe XmlSec do
4
+
5
+ it "should verify signed.test.xml with public key" do
6
+ asset_dir = File.expand_path('../../assets', __FILE__)
7
+ XmlSec::valid_file?(
8
+ File.join(asset_dir, 'signed.test.xml'),
9
+ File.join(asset_dir, 'public.key.pem'),
10
+ nil
11
+ ).should be_true
12
+
13
+ end
14
+
15
+ it "should verify signed.test.xml certificate" do
16
+ asset_dir = File.expand_path('../../assets', __FILE__)
17
+ XmlSec::valid_file?(
18
+ File.join(asset_dir, 'signed.test.xml'),
19
+ nil,
20
+ File.join(asset_dir, 'x509.crt')
21
+ ).should be_true
22
+
23
+ end
24
+
25
+
26
+ it "should verify xml string with public key" do
27
+ asset_dir = File.expand_path('../../assets', __FILE__)
28
+ XmlSec::valid?(
29
+ File.open(File.join(asset_dir, 'signed.test.xml'), 'rb') { |f| f.read },
30
+ File.join(asset_dir, 'public.key.pem'),
31
+ nil
32
+ ).should be_true
33
+
34
+ end
35
+
36
+ it "should verify xml string certificate" do
37
+ asset_dir = File.expand_path('../../assets', __FILE__)
38
+ XmlSec::valid?(
39
+ File.open(File.join(asset_dir, 'signed.test.xml'), 'rb') { |f| f.read },
40
+ nil,
41
+ File.join(asset_dir, 'x509.crt')
42
+ ).should be_true
43
+
44
+ end
45
+
46
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "Run all examples with RCov"
6
+ RSpec::Core::RakeTask.new('spec:rcov') do |t|
7
+ t.rcov = true
8
+ end
9
+ RSpec::Core::RakeTask.new('spec') do |t|
10
+ t.verbose = true
11
+ end
12
+
13
+ task :default => :spec
14
+ rescue LoadError
15
+ puts "rspec, or one of its dependencies, is not available. Install it with: sudo gem install rspec"
16
+ end
data/xmlsec.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "xmlsec/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "xmlsec"
7
+ s.version = XmlSec::VERSION
8
+ s.authors = ["Tomas Didziokas"]
9
+ s.email = ["tomas.did@gmail.com"]
10
+ s.homepage = "http://manodrabuziai.lt/"
11
+ s.extensions = ["ext/xmlsec/extconf.rb"]
12
+ s.summary = "summary"
13
+ s.description = 'description'
14
+
15
+ # s.rubyforge_project = "xmlsec"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ # tests
22
+ s.add_development_dependency 'rake-compiler', "~> 0.7.7"
23
+ s.add_development_dependency 'rake', '0.8.7' # NB: 0.8.7 required by rake-compiler 0.7.9
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'nokogiri', '1.5.0'
26
+
27
+ end
28
+