nokogiri-xmlsec-instructure 0.9.4
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 +7 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +124 -0
- data/Rakefile +30 -0
- data/ext/nokogiri_ext_xmlsec/common.h +13 -0
- data/ext/nokogiri_ext_xmlsec/extconf.rb +27 -0
- data/ext/nokogiri_ext_xmlsec/init.c +76 -0
- data/ext/nokogiri_ext_xmlsec/nokogiri_decrypt_with_key.c +82 -0
- data/ext/nokogiri_ext_xmlsec/nokogiri_encrypt_with_key.c +169 -0
- data/ext/nokogiri_ext_xmlsec/nokogiri_helpers_set_attribute_id.c +94 -0
- data/ext/nokogiri_ext_xmlsec/nokogiri_init.c +30 -0
- data/ext/nokogiri_ext_xmlsec/nokogiri_sign.c +252 -0
- data/ext/nokogiri_ext_xmlsec/nokogiri_verify_with.c +259 -0
- data/ext/nokogiri_ext_xmlsec/options.c +166 -0
- data/ext/nokogiri_ext_xmlsec/options.h +36 -0
- data/ext/nokogiri_ext_xmlsec/shutdown.c +12 -0
- data/ext/nokogiri_ext_xmlsec/util.c +139 -0
- data/ext/nokogiri_ext_xmlsec/util.h +42 -0
- data/ext/nokogiri_ext_xmlsec/xmlsecrb.h +42 -0
- data/lib/nokogiri-xmlsec.rb +1 -0
- data/lib/xmlsec.rb +102 -0
- data/lib/xmlsec/version.rb +3 -0
- data/nokogiri-xmlsec-instructure.gemspec +39 -0
- data/spec/fixtures/cert/server.crt +14 -0
- data/spec/fixtures/cert/server.csr +11 -0
- data/spec/fixtures/cert/server.key.decrypted +15 -0
- data/spec/fixtures/cert/server.key.encrypted +18 -0
- data/spec/fixtures/hate.xml +7 -0
- data/spec/fixtures/pwned.xml +1 -0
- data/spec/fixtures/rsa.pem +15 -0
- data/spec/fixtures/rsa.pub +6 -0
- data/spec/fixtures/sign2-doc.xml +6 -0
- data/spec/fixtures/sign2-result.xml +25 -0
- data/spec/fixtures/sign3-result.xml +38 -0
- data/spec/lib/nokogiri/xml/document/encryption_and_decryption_spec.rb +34 -0
- data/spec/lib/nokogiri/xml/document/signing_and_verifying_spec.rb +122 -0
- data/spec/lib/nokogiri/xml/document/unsafe_xml_spec.rb +61 -0
- data/spec/spec_helper.rb +10 -0
- metadata +211 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xmlsec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nokogiri-xmlsec-instructure"
|
8
|
+
spec.version = Xmlsec::VERSION
|
9
|
+
spec.authors = ["Albert J. Wong", "Cody Cutrer"]
|
10
|
+
spec.email = ["awong.dev@gmail.com", "cody@instructure.com"]
|
11
|
+
spec.description = %q{Adds support to Ruby for encrypting, decrypting,
|
12
|
+
signing and validating the signatures of XML documents, according to the
|
13
|
+
[XML Encryption Syntax and Processing](http://www.w3.org/TR/xmlenc-core/)
|
14
|
+
standard, and the [XML Signature Syntax and Processing](http://www.w3.org/TR/xmldsig-core/)
|
15
|
+
standard by wrapping around the [xmlsec](http://www.aleksey.com/xmlsec) C
|
16
|
+
library and adding relevant methods to `Nokogiri::XML::Document`.
|
17
|
+
Implementation is based off nokogiri-xmlsec by Colin MacKenzie IV with
|
18
|
+
very heavy modifications.}
|
19
|
+
spec.summary = %q{Wrapper around http://www.aleksey.com/xmlsec to
|
20
|
+
support XML encryption, decryption, signing and signature validation in
|
21
|
+
Ruby}
|
22
|
+
spec.homepage = "https://github.com/instructure/nokogiri-xmlsec-instructure"
|
23
|
+
spec.license = "MIT"
|
24
|
+
|
25
|
+
spec.files = `git ls-files`.split($/)
|
26
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
spec.extensions = %w{ext/nokogiri_ext_xmlsec/extconf.rb}
|
30
|
+
|
31
|
+
spec.add_dependency 'nokogiri'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
34
|
+
spec.add_development_dependency "rake"
|
35
|
+
spec.add_development_dependency "rake-compiler"
|
36
|
+
spec.add_development_dependency "rspec"
|
37
|
+
spec.add_development_dependency "guard-rspec"
|
38
|
+
spec.add_development_dependency "guard-rake"
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICLzCCAZgCCQCVuhhQ38rw0TANBgkqhkiG9w0BAQUFADBbMQswCQYDVQQGEwJV
|
3
|
+
UzEQMA4GA1UECAwHR2VvcmdpYTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ
|
4
|
+
dHkgTHRkMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTAgFw0xMzA1MjUxODQwMDRa
|
5
|
+
GA8zMDEyMDkyNTE4NDAwNFowWzELMAkGA1UEBhMCVVMxEDAOBgNVBAgMB0dlb3Jn
|
6
|
+
aWExITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEXMBUGA1UEAwwO
|
7
|
+
d3d3Lmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALE4oSql
|
8
|
+
eymfHtzOeY86WyvfsjZmaz2XnIo9dzZsK71yMEKkgvXQnnYy9pK0NaYcG0B0hcii
|
9
|
+
3fqGBiHMkZY2BOGWwCC/wOmJCzLq9q6caPWUs71Zko+h59LaqV93vzDmZaXYfFoQ
|
10
|
+
gSVEWpEpCSo560x0mSuLnJYdQQzZ/L6xvxZ1AgMBAAEwDQYJKoZIhvcNAQEFBQAD
|
11
|
+
gYEATyK/RlfpohUVimgFkycTF2hyusjctseXoZDCctgg/STMsL8iA0P9YB6k91GC
|
12
|
+
kWpwevuiwarD1MfSUV6goPINFkIBvfK+5R9lpHaTqqs615z8T9R5VJgaLcFe3tWd
|
13
|
+
7oq3V2q5Nl6MrZfXj2N07qe6/9zfdauxYO26vAEKCvIkbMo=
|
14
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1,11 @@
|
|
1
|
+
-----BEGIN CERTIFICATE REQUEST-----
|
2
|
+
MIIBmzCCAQQCAQAwWzELMAkGA1UEBhMCVVMxEDAOBgNVBAgMB0dlb3JnaWExITAf
|
3
|
+
BgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEXMBUGA1UEAwwOd3d3Lmdv
|
4
|
+
b2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALE4oSqleymfHtzO
|
5
|
+
eY86WyvfsjZmaz2XnIo9dzZsK71yMEKkgvXQnnYy9pK0NaYcG0B0hcii3fqGBiHM
|
6
|
+
kZY2BOGWwCC/wOmJCzLq9q6caPWUs71Zko+h59LaqV93vzDmZaXYfFoQgSVEWpEp
|
7
|
+
CSo560x0mSuLnJYdQQzZ/L6xvxZ1AgMBAAGgADANBgkqhkiG9w0BAQUFAAOBgQB6
|
8
|
+
8K0q16EAkGoYLFHvVHxpqk+annbB8ZqpbV43T12Ngx7KiMsdTjrgho0lP/OllHcr
|
9
|
+
3vQ0yHnI1K1EeV9Q+/lXqaRl9ws3PL1QMOFm4XD1uIEPG+umRYgrjuZhFab+2Zfs
|
10
|
+
rgyILF2yRSy0oVeTBxVK5igV6qYcXFFBRIj7nnV8Jg==
|
11
|
+
-----END CERTIFICATE REQUEST-----
|
@@ -0,0 +1,15 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIICWwIBAAKBgQCxOKEqpXspnx7cznmPOlsr37I2Zms9l5yKPXc2bCu9cjBCpIL1
|
3
|
+
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HIdC
|
4
|
+
dkn8MF4CCCQKkjm7JKRrKfK5fOUp1NZF22oP8x0L4j67NYCtR9F6KIkV5A6FPAZG
|
5
|
+
I8nsHnyJzRwqmG2xbQIDAQAB
|
6
|
+
-----END PUBLIC KEY-----
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<Envelope xmlns="urn:envelope">
|
3
|
+
<Data>
|
4
|
+
Hello, World!
|
5
|
+
</Data>
|
6
|
+
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
|
7
|
+
<SignedInfo>
|
8
|
+
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
|
9
|
+
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
|
10
|
+
<Reference>
|
11
|
+
<Transforms>
|
12
|
+
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
|
13
|
+
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
|
14
|
+
</Transforms>
|
15
|
+
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
|
16
|
+
<DigestValue>Gx8CGUsbi2qvBLd15VCmwELbDMND8F4vY3jPOc7/FJ0=</DigestValue>
|
17
|
+
</Reference>
|
18
|
+
</SignedInfo>
|
19
|
+
<SignatureValue>T2c7nqOw55P8hcP1qhvfPCwOSEAuo8HstZf9shlrggcarxfgWTKhA6UdrF4McfrS
|
20
|
+
XtcgHA7zy0Yzd2cgeGkKA2jgI+9QRhoQsifOMuI55sE5r+fpBs+goaxC57gmcBXj
|
21
|
+
XnuwIiWf7nfpF4hYZ841HzYd2HcpQKPTdbhvZUprvx8=</SignatureValue>
|
22
|
+
<KeyInfo>
|
23
|
+
<KeyName>test</KeyName>
|
24
|
+
</KeyInfo>
|
25
|
+
</Signature></Envelope>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<Envelope xmlns="urn:envelope">
|
3
|
+
<Data>
|
4
|
+
Hello, World!
|
5
|
+
</Data>
|
6
|
+
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
|
7
|
+
<SignedInfo>
|
8
|
+
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
|
9
|
+
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
|
10
|
+
<Reference>
|
11
|
+
<Transforms>
|
12
|
+
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
|
13
|
+
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
|
14
|
+
</Transforms>
|
15
|
+
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
|
16
|
+
<DigestValue>Gx8CGUsbi2qvBLd15VCmwELbDMND8F4vY3jPOc7/FJ0=</DigestValue>
|
17
|
+
</Reference>
|
18
|
+
</SignedInfo>
|
19
|
+
<SignatureValue>TGJ9fCzjppp3LgG4fiBJx+0R34wRa7il9XKKZ+kkOAdKkcW0PIAYKmjn0Tn8krGd
|
20
|
+
Gw6qtFFqjdohXfhkKmajXAFunEtd3J0kHFkf3obIwRB1qdsYmKXVFxUx3GqcIlph
|
21
|
+
vt9v/9FC12JAxwAiJXHuY2xN5uo3xSDER4+tCCy3/AI=</SignatureValue>
|
22
|
+
<KeyInfo>
|
23
|
+
<X509Data>
|
24
|
+
<X509Certificate>MIICLzCCAZgCCQCVuhhQ38rw0TANBgkqhkiG9w0BAQUFADBbMQswCQYDVQQGEwJV
|
25
|
+
UzEQMA4GA1UECAwHR2VvcmdpYTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ
|
26
|
+
dHkgTHRkMRcwFQYDVQQDDA53d3cuZ29vZ2xlLmNvbTAgFw0xMzA1MjUxODQwMDRa
|
27
|
+
GA8zMDEyMDkyNTE4NDAwNFowWzELMAkGA1UEBhMCVVMxEDAOBgNVBAgMB0dlb3Jn
|
28
|
+
aWExITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEXMBUGA1UEAwwO
|
29
|
+
d3d3Lmdvb2dsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALE4oSql
|
30
|
+
eymfHtzOeY86WyvfsjZmaz2XnIo9dzZsK71yMEKkgvXQnnYy9pK0NaYcG0B0hcii
|
31
|
+
3fqGBiHMkZY2BOGWwCC/wOmJCzLq9q6caPWUs71Zko+h59LaqV93vzDmZaXYfFoQ
|
32
|
+
gSVEWpEpCSo560x0mSuLnJYdQQzZ/L6xvxZ1AgMBAAEwDQYJKoZIhvcNAQEFBQAD
|
33
|
+
gYEATyK/RlfpohUVimgFkycTF2hyusjctseXoZDCctgg/STMsL8iA0P9YB6k91GC
|
34
|
+
kWpwevuiwarD1MfSUV6goPINFkIBvfK+5R9lpHaTqqs615z8T9R5VJgaLcFe3tWd
|
35
|
+
7oq3V2q5Nl6MrZfXj2N07qe6/9zfdauxYO26vAEKCvIkbMo=</X509Certificate>
|
36
|
+
</X509Data>
|
37
|
+
</KeyInfo>
|
38
|
+
</Signature></Envelope>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "encryption and decryption:" do
|
4
|
+
subject do
|
5
|
+
Nokogiri::XML(fixture('sign2-doc.xml'))
|
6
|
+
end
|
7
|
+
|
8
|
+
[ 'aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'tripledes-cbc' ].each do |block_encryption|
|
9
|
+
[ 'rsa-1_5', 'rsa-oaep-mgf1p' ].each do |key_transport|
|
10
|
+
describe "encrypting with an RSA public key with #{block_encryption} #{key_transport}" do
|
11
|
+
before do
|
12
|
+
@original = subject.to_s
|
13
|
+
subject.encrypt!(
|
14
|
+
key: fixture('rsa.pub'), name: 'test',
|
15
|
+
block_encryption: block_encryption, key_transport: key_transport)
|
16
|
+
end
|
17
|
+
|
18
|
+
# it generates a new key every time so will never match the fixture
|
19
|
+
specify { expect(subject.to_s == @original).to be_falsey }
|
20
|
+
specify { expect(subject.to_s =~ /Hello.*World/i).to be_falsey }
|
21
|
+
# specify { subject.to_s.should == fixture('encrypt2-result.xml') }
|
22
|
+
|
23
|
+
describe 'decrypting with the RSA private key' do
|
24
|
+
before do
|
25
|
+
subject.decrypt! key: fixture('rsa.pem')
|
26
|
+
end
|
27
|
+
|
28
|
+
specify { expect(subject.to_s == fixture('sign2-doc.xml')).to be_truthy }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "signing and verifying signatures:" do
|
4
|
+
subject do
|
5
|
+
Nokogiri::XML(fixture('sign2-doc.xml'))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'signing a document with an RSA key' do
|
9
|
+
before { subject.sign! key: fixture('rsa.pem'), name: 'test',
|
10
|
+
signature_alg: 'rsa-sha256', digest_alg: 'sha256'
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'should produce a signed document' do
|
14
|
+
expect(subject.to_s).to eql(fixture('sign2-result.xml'))
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'verifying the document with a single public key' do
|
18
|
+
it 'should be valid' do
|
19
|
+
expect(subject.verify_with(key: fixture('rsa.pub'))).to be_truthy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'verifying the document with a set of keys' do
|
24
|
+
it 'should be valid' do
|
25
|
+
expect(subject.verify_with({
|
26
|
+
'test' => fixture('rsa.pub')
|
27
|
+
})).to be_truthy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'signing a document with an RSA key and X509 certificate' do
|
33
|
+
before do
|
34
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
35
|
+
cert: fixture('cert/server.crt'),
|
36
|
+
signature_alg: 'rsa-sha256',
|
37
|
+
digest_alg: 'sha256'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should produce a signed document' do
|
41
|
+
expect(subject.to_s).to eql(fixture('sign3-result.xml'))
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'verifying the document with an array of X509 certificates' do
|
45
|
+
specify do
|
46
|
+
expect(subject.verify_with(cert: [fixture('cert/server.crt')])).to be_truthy
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should verify using system certificates' do
|
50
|
+
pending("Testing system certs requires admin privs. Read exception message in code.")
|
51
|
+
unless subject.verify_signature
|
52
|
+
raise <<-end_error
|
53
|
+
Could not use system certificates to verify the signature.
|
54
|
+
Note that this may not be a failing spec. You should copy
|
55
|
+
or symlink the file `spec/fixtures/cert/server.crt` into
|
56
|
+
the directory shown by running `openssl version -d`. After
|
57
|
+
doing so, run `sudo c_rehash CERT_PATH`, where
|
58
|
+
CERT_PATH is the same directory you copied the certificate
|
59
|
+
into (/usr/lib/ssl/certs by default on Ubuntu). After doing
|
60
|
+
that, run this spec again and see if it passes.
|
61
|
+
end_error
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'verifying the document with one X509 certificate' do
|
67
|
+
specify do
|
68
|
+
expect(subject.verify_with(cert: fixture('cert/server.crt'))).to be_truthy
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
describe 'test all signature algorithms' do
|
73
|
+
[ 'rsa-sha1', 'rsa-sha224', 'rsa-sha256', 'rsa-sha384', 'rsa-sha512' ].each do |signature_algorithm|
|
74
|
+
specify "All RSA signatures work with cert signing" do
|
75
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
76
|
+
cert: fixture('cert/server.crt'),
|
77
|
+
signature_alg: signature_algorithm,
|
78
|
+
digest_alg: 'sha256'
|
79
|
+
end
|
80
|
+
specify "All RSA signatures work with bare key signing" do
|
81
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
82
|
+
name: 'test',
|
83
|
+
signature_alg: signature_algorithm,
|
84
|
+
digest_alg: 'sha256'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
[ 'ecdsa-sha1', 'ecdsa-sha224', 'ecdsa-sha256', 'ecdsa-sha384', 'ecdsa-sha512', 'dsa-sha1', 'dsa-sha256' ].each do |signature_algorithm|
|
88
|
+
specify "All non-RSA signatures work with cert signing" do
|
89
|
+
pending("use the right key type")
|
90
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
91
|
+
name: 'test',
|
92
|
+
cert: fixture('cert/server.crt'),
|
93
|
+
signature_alg: signature_algorithm,
|
94
|
+
digest_alg: 'sha256'
|
95
|
+
end
|
96
|
+
specify "All non-RSA signatures work with bare key" do
|
97
|
+
pending("use the right key type")
|
98
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
99
|
+
name: 'test',
|
100
|
+
signature_alg: signature_algorithm,
|
101
|
+
digest_alg: 'sha256'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
describe 'test all digest algorithms' do
|
106
|
+
[ 'sha1', 'sha224', 'sha256', 'sha384', 'sha512' ].each do |digest_algorithm|
|
107
|
+
specify "All digests with cert" do
|
108
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
109
|
+
name: 'test',
|
110
|
+
cert: fixture('cert/server.crt'),
|
111
|
+
signature_alg: 'rsa-sha256',
|
112
|
+
digest_alg: digest_algorithm
|
113
|
+
end
|
114
|
+
specify "All digests with bare key" do
|
115
|
+
subject.sign! key: fixture('cert/server.key.decrypted'),
|
116
|
+
name: 'test',
|
117
|
+
signature_alg: 'rsa-sha256',
|
118
|
+
digest_alg: digest_algorithm
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "unsafe xml guards:" do
|
4
|
+
context "XML Signature URI" do
|
5
|
+
it "does not allow file path URIs in signing references" do
|
6
|
+
doc = Nokogiri::XML(fixture('hate.xml'))
|
7
|
+
expect{
|
8
|
+
doc.sign!(cert: fixture('cert/server.crt'),
|
9
|
+
key: fixture('cert/server.key.decrypted'),
|
10
|
+
name: 'test',
|
11
|
+
signature_alg: 'rsa-sha256',
|
12
|
+
digest_alg: 'sha256',
|
13
|
+
uri: "#{fixture_path("pwned.xml")}")}.to raise_error(
|
14
|
+
XMLSec::SigningError, /error=33:invalid URI type/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not allow file:// URIs in signing references" do
|
18
|
+
doc = Nokogiri::XML(fixture('hate.xml'))
|
19
|
+
expect{
|
20
|
+
doc.sign!(cert: fixture('cert/server.crt'),
|
21
|
+
key: fixture('cert/server.key.decrypted'),
|
22
|
+
name: 'test',
|
23
|
+
signature_alg: 'rsa-sha256',
|
24
|
+
digest_alg: 'sha256',
|
25
|
+
uri: "file://#{fixture_path("pwned.xml")}")}.to raise_error(
|
26
|
+
XMLSec::SigningError, /error=33:invalid URI type/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not allow network URIs in signing references" do
|
30
|
+
doc = Nokogiri::XML(fixture('hate.xml'))
|
31
|
+
expect{
|
32
|
+
doc.sign!(cert: fixture('cert/server.crt'),
|
33
|
+
key: fixture('cert/server.key.decrypted'),
|
34
|
+
name: 'test',
|
35
|
+
signature_alg: 'rsa-sha256',
|
36
|
+
digest_alg: 'sha256',
|
37
|
+
uri: "http://www.w3.org/2001/XMLSchema.xsd")}.to raise_error(
|
38
|
+
XMLSec::SigningError, /error=33:invalid URI type/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does allow empty signing references" do
|
42
|
+
doc = Nokogiri::XML(fixture('hate.xml'))
|
43
|
+
doc.sign!(cert: fixture('cert/server.crt'),
|
44
|
+
key: fixture('cert/server.key.decrypted'),
|
45
|
+
name: 'test',
|
46
|
+
signature_alg: 'rsa-sha256',
|
47
|
+
digest_alg: 'sha256',
|
48
|
+
uri: "")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "does allow same document signing references" do
|
52
|
+
doc = Nokogiri::XML(fixture('hate.xml'))
|
53
|
+
doc.sign!(cert: fixture('cert/server.crt'),
|
54
|
+
key: fixture('cert/server.key.decrypted'),
|
55
|
+
name: 'test',
|
56
|
+
signature_alg: 'rsa-sha256',
|
57
|
+
digest_alg: 'sha256',
|
58
|
+
uri: "#some_frackin_id")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|