nokogiri-xmlsec-me-harder 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +13 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +123 -0
  9. data/Rakefile +30 -0
  10. data/ext/nokogiri_ext_xmlsec/common.h +13 -0
  11. data/ext/nokogiri_ext_xmlsec/extconf.rb +27 -0
  12. data/ext/nokogiri_ext_xmlsec/init.c +76 -0
  13. data/ext/nokogiri_ext_xmlsec/nokogiri_decrypt_with_key.c +82 -0
  14. data/ext/nokogiri_ext_xmlsec/nokogiri_encrypt_with_key.c +169 -0
  15. data/ext/nokogiri_ext_xmlsec/nokogiri_helpers_set_attribute_id.c +76 -0
  16. data/ext/nokogiri_ext_xmlsec/nokogiri_init.c +32 -0
  17. data/ext/nokogiri_ext_xmlsec/nokogiri_sign_certificate.c +186 -0
  18. data/ext/nokogiri_ext_xmlsec/nokogiri_sign_rsa.c +167 -0
  19. data/ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_certificates.c +138 -0
  20. data/ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_named_keys.c +133 -0
  21. data/ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_rsa.c +76 -0
  22. data/ext/nokogiri_ext_xmlsec/options.c +166 -0
  23. data/ext/nokogiri_ext_xmlsec/options.h +36 -0
  24. data/ext/nokogiri_ext_xmlsec/shutdown.c +12 -0
  25. data/ext/nokogiri_ext_xmlsec/util.c +139 -0
  26. data/ext/nokogiri_ext_xmlsec/util.h +42 -0
  27. data/ext/nokogiri_ext_xmlsec/xmlsecrb.h +44 -0
  28. data/lib/nokogiri-xmlsec.rb +1 -0
  29. data/lib/xmlsec.rb +104 -0
  30. data/lib/xmlsec/version.rb +3 -0
  31. data/nokogiri-xmlsec-me-harder.gemspec +39 -0
  32. data/spec/fixtures/cert/server.crt +14 -0
  33. data/spec/fixtures/cert/server.csr +11 -0
  34. data/spec/fixtures/cert/server.key.decrypted +15 -0
  35. data/spec/fixtures/cert/server.key.encrypted +18 -0
  36. data/spec/fixtures/hate.xml +7 -0
  37. data/spec/fixtures/pwned.xml +1 -0
  38. data/spec/fixtures/rsa.pem +15 -0
  39. data/spec/fixtures/rsa.pub +6 -0
  40. data/spec/fixtures/sign2-doc.xml +6 -0
  41. data/spec/fixtures/sign2-result.xml +25 -0
  42. data/spec/fixtures/sign3-result.xml +38 -0
  43. data/spec/lib/nokogiri/xml/document/encryption_and_decryption_spec.rb +34 -0
  44. data/spec/lib/nokogiri/xml/document/signing_and_verifying_spec.rb +123 -0
  45. data/spec/lib/nokogiri/xml/document/unsafe_xml_spec.rb +61 -0
  46. data/spec/spec_helper.rb +10 -0
  47. metadata +213 -0
@@ -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
+ 0J52MvaStDWmHBtAdIXIot36hgYhzJGWNgThlsAgv8DpiQsy6vaunGj1lLO9WZKP
4
+ oefS2qlfd78w5mWl2HxaEIElRFqRKQkqOetMdJkri5yWHUEM2fy+sb8WdQIDAQAB
5
+ AoGAB1d8PcMLPicsZSNcn9VgD4o93MkTakLMpmFzfdqvWTLQ0wHztvFEj0r/Mgar
6
+ Lk19x4bMQAqXPZitylqqMVndi9U8squvAvkZcgYL57MNQRgmLtjSMfk4wCY9ieDa
7
+ newt4cP7nGN/ZkU5R0lRMGExKSrMZW8HAkK4WJpbfnOpwGECQQDkoggBRH4aFlaj
8
+ Xhw+mSIxOpmzFBhXZ0z+bvoCipPKIhbnwKt0dupn0xAwatNmakBt0p46SFOgW8QQ
9
+ TV51G/bdAkEAxm8yEod77IM6bhLL+3h/nsGOGsA0xs22U6FBrz34Nvd4gwmICMcF
10
+ t4P3iHYzJfUt+Z2zv5ucX2tuD4uoWsqIeQJAercdZNDGfmoPBpC0yESZPaMebCgV
11
+ CJTBlq8qMcL/oDa75Jhdbp2FI0T+I36zCP1up4OsucuoVyHqEnX0hRcFYQJAD3Nz
12
+ E6xHAviI4S9HgNI2JbduiDi1I1G7Q7HHuox5ulX0pUdlt0E/+bUl3hNOEkOQC+Ky
13
+ r1W/jFKCJGW8ey1QCQJAYDh1BmlLswafEnkNmwydNz4gVflHJvsF8A1c2wJVytkT
14
+ 3HVWvwOAfcumDNDNkSUJ+0DQs17qgOMCDwFgFzUb+Q==
15
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,18 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ Proc-Type: 4,ENCRYPTED
3
+ DEK-Info: DES-EDE3-CBC,6F8CC52C2E211FF4
4
+
5
+ T5g21oYrsS435g2GRNBFs+IwpKYAsF0RDt9SNuCXp6hD2MbcF3q8Su/wvj9inAZi
6
+ S7V8Qp8mmBsjo+vh0oTggVFmk7/fyTAa6ltQL+1UH7b8vecgGFKSBV8TG3+k9S4C
7
+ ZgXyR9pTgzQx+8M5LrnOnM8fpf638xouHvMo7zTFPhimehIMrMcXAyRZaRfcDhlg
8
+ YR+JRvSa0Q9vxhsC19fjfnlU7FdV8B9Ypo/+23TNmKpfU99oV6oPNoiWzkziKtvZ
9
+ mwYjrYw6r91ANFCRIux5+CjfOqVxissxzmZ5vyV89LoXjLAEDVmv2vJ+8w2b8zAN
10
+ FAXtcx74MutSQQBrG4xffwwRJwf0uPhzMohRoiholOoaMFSOFBasA+phn7hr7m9a
11
+ JWj4icCRVZlm+rztbbiapBUtm4ER1tdBGr84TgqasM5CK/qhXt9CCnUBRaimIwad
12
+ 9dib2jnkzuqlyrdzLyaFU0IRSq+GQAK7sgya/V2q96lWdzejMGx/07hL6lvPY/h7
13
+ o8puMwpCK4XKYantqXL26oCxSgcrlA2nlR+SfmRKhwDwy8rPsTBm55BxwGr8Jj+9
14
+ 6bY6VOR+vZkjSVDKNBOq8gUJvPksQV0CK0eSgPTli0ncCInzFPeLGISIa90rFD7I
15
+ 97w/ZzTywVnTWO9DhedliwqDSOOYTdVoRfygQfpaFoa1aqR9tKWoc30kbqXvgvUR
16
+ mlDwiY1zxpKsTHKu7omf0bp5m8dlW4EarWgTsTRQ8EOHoIucgjdaSxPEDDi8WGOW
17
+ Nbqb2ZZz7wsIL71XgC13A+va1C0F709PK/Xnd5IwRf8=
18
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE FrackinDocType [
3
+ <!ELEMENT i-hate-xml (#PCDATA)>
4
+ <!ATTLIST i-hate-xml ur_id_for_intra_doc_ref_test ID #IMPLIED>
5
+ ]>
6
+ <i-hate-xml ur_id_for_intra_doc_ref_test="some_frackin_id">
7
+ </i-hate-xml>
@@ -0,0 +1 @@
1
+ <pwned id="iminurdocreadinurfilez" />
@@ -0,0 +1,15 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIICXgIBAAKBgQC15La+LSmHNUs/yqzSuzKdBUED1OfaOZpBp8zxAAQy7VlTrqRh
3
+ /eiJH3VSeRRZEygORvtLgi/teF2P+z/mfJ6IHIdCdkn8MF4CCCQKkjm7JKRrKfK5
4
+ fOUp1NZF22oP8x0L4j67NYCtR9F6KIkV5A6FPAZGI8nsHnyJzRwqmG2xbQIDAQAB
5
+ AoGBAJDT2UW3g/dqUc4rPExWTUiFJG0+mpVBhDd+ukmyL6W1Iojk53I2z25PJAVU
6
+ 7wS1ohEsJ27J7Aty6Vx5Ozn0Q+zYVaKRSxcazNeGbwS0UaGrN0lMvWDs7RmVGCdx
7
+ bI2LUTQ88Bl94dW4QObAub+wMOL6xmVEVrJssZnm+CIqS2UBAkEA49QDNB//oHmi
8
+ iqD4SFotE8Lz80qBGHN15YIm80TKUR2k1LusZl6R5+2nYTF2vPsG+HGXPbkGhqTn
9
+ JL9GMBv7TQJBAMxinne8+bKTvOl/hhdAohFs7aHUBZhZOEuXIf1jYENASk2weYC6
10
+ 95SlHvWcwPHfqVbpwt83sGL8aDm8CCPYPqECQQDEFRQQx72GC0oG0FYAR4RmbrLx
11
+ YN1NAwqkVmlZlIogWEgmQ8Q0cw5Ws+cMMrtEGTU9nN4TZGymc8TwjqNFAsA9AkEA
12
+ ol8Cp/uQn6cxIIt4Gsb1OkTAcJ0BKOxQhfT2QtiNJEBSB3BYxsVCZWvcsaGrwzw9
13
+ yteBQlZ6odkGcD+Kc/eaoQJAH+0a7jlHDu2VCHI63OiNZQJ8J9oxaPvWZyKYSaCO
14
+ iGvon/Z6KGQhXMedPDaCH7UjeMle5AVhjSrSvF6OglgZ9g==
15
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,6 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC15La+LSmHNUs/yqzSuzKdBUED
3
+ 1OfaOZpBp8zxAAQy7VlTrqRh/eiJH3VSeRRZEygORvtLgi/teF2P+z/mfJ6IHIdC
4
+ dkn8MF4CCCQKkjm7JKRrKfK5fOUp1NZF22oP8x0L4j67NYCtR9F6KIkV5A6FPAZG
5
+ I8nsHnyJzRwqmG2xbQIDAQAB
6
+ -----END PUBLIC KEY-----
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <Envelope xmlns="urn:envelope">
3
+ <Data>
4
+ Hello, World!
5
+ </Data>
6
+ </Envelope>
@@ -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'), name: 'test'
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,123 @@
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
+ name: 'test',
36
+ cert: fixture('cert/server.crt'),
37
+ signature_alg: 'rsa-sha256',
38
+ digest_alg: 'sha256'
39
+ end
40
+
41
+ it 'should produce a signed document' do
42
+ expect(subject.to_s).to eql(fixture('sign3-result.xml'))
43
+ end
44
+
45
+ describe 'verifying the document with an array of X509 certificates' do
46
+ specify do
47
+ expect(subject.verify_with(cert: [fixture('cert/server.crt')])).to be_truthy
48
+ end
49
+
50
+ it 'should verify using system certificates' do
51
+ pending("Testing system certs requires admin privs. Read exception message in code.")
52
+ unless subject.verify_signature
53
+ raise <<-end_error
54
+ Could not use system certificates to verify the signature.
55
+ Note that this may not be a failing spec. You should copy
56
+ or symlink the file `spec/fixtures/cert/server.crt` into
57
+ the directory shown by running `openssl version -d`. After
58
+ doing so, run `sudo c_rehash CERT_PATH`, where
59
+ CERT_PATH is the same directory you copied the certificate
60
+ into (/usr/lib/ssl/certs by default on Ubuntu). After doing
61
+ that, run this spec again and see if it passes.
62
+ end_error
63
+ end
64
+ end
65
+ end
66
+
67
+ describe 'verifying the document with one X509 certificate' do
68
+ specify do
69
+ expect(subject.verify_with(cert: fixture('cert/server.crt'))).to be_truthy
70
+ end
71
+ end
72
+ end
73
+ describe 'test all signature algorithms' do
74
+ [ 'rsa-sha1', 'rsa-sha224', 'rsa-sha256', 'rsa-sha384', 'rsa-sha512' ].each do |signature_algorithm|
75
+ specify "All RSA signatures work with cert signing" do
76
+ subject.sign! key: fixture('cert/server.key.decrypted'),
77
+ cert: fixture('cert/server.crt'),
78
+ signature_alg: signature_algorithm,
79
+ digest_alg: 'sha256'
80
+ end
81
+ specify "All RSA signatures work with bare key signing" do
82
+ subject.sign! key: fixture('cert/server.key.decrypted'),
83
+ name: 'test',
84
+ signature_alg: signature_algorithm,
85
+ digest_alg: 'sha256'
86
+ end
87
+ end
88
+ [ 'ecdsa-sha1', 'ecdsa-sha224', 'ecdsa-sha256', 'ecdsa-sha384', 'ecdsa-sha512', 'dsa-sha1', 'dsa-sha256' ].each do |signature_algorithm|
89
+ specify "All non-RSA signatures work with cert signing" do
90
+ pending("use the right key type")
91
+ subject.sign! key: fixture('cert/server.key.decrypted'),
92
+ name: 'test',
93
+ cert: fixture('cert/server.crt'),
94
+ signature_alg: signature_algorithm,
95
+ digest_alg: 'sha256'
96
+ end
97
+ specify "All non-RSA signatures work with bare key" do
98
+ pending("use the right key type")
99
+ subject.sign! key: fixture('cert/server.key.decrypted'),
100
+ name: 'test',
101
+ signature_alg: signature_algorithm,
102
+ digest_alg: 'sha256'
103
+ end
104
+ end
105
+ end
106
+ describe 'test all digest algorithms' do
107
+ [ 'sha1', 'sha224', 'sha256', 'sha384', 'sha512' ].each do |digest_algorithm|
108
+ specify "All digests with cert" do
109
+ subject.sign! key: fixture('cert/server.key.decrypted'),
110
+ name: 'test',
111
+ cert: fixture('cert/server.crt'),
112
+ signature_alg: 'rsa-sha256',
113
+ digest_alg: digest_algorithm
114
+ end
115
+ specify "All digests with bare key" do
116
+ subject.sign! key: fixture('cert/server.key.decrypted'),
117
+ name: 'test',
118
+ signature_alg: 'rsa-sha256',
119
+ digest_alg: digest_algorithm
120
+ end
121
+ end
122
+ end
123
+ 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
@@ -0,0 +1,10 @@
1
+ require 'rspec'
2
+ require 'xmlsec'
3
+
4
+ def fixture_path(filename)
5
+ File.join(File.expand_path('../fixtures', __FILE__), filename)
6
+ end
7
+
8
+ def fixture(path)
9
+ File.read fixture_path(path)
10
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nokogiri-xmlsec-me-harder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Albert J. Wong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: |-
112
+ Adds support to Ruby for encrypting, decrypting,
113
+ signing and validating the signatures of XML documents, according to the
114
+ [XML Encryption Syntax and Processing](http://www.w3.org/TR/xmlenc-core/)
115
+ standard, by wrapping around the [xmlsec](http://www.aleksey.com/xmlsec) C
116
+ library and adding relevant methods to `Nokogiri::XML::Document`.
117
+ Implementation is based off nokogiri-xmlsec by
118
+ "Colin MacKenzie IV" <inisterchipmunk@gmail.com> with heavy modifications
119
+ and some API changes.
120
+ email:
121
+ - awong.dev@gmail.com
122
+ executables: []
123
+ extensions:
124
+ - ext/nokogiri_ext_xmlsec/extconf.rb
125
+ extra_rdoc_files: []
126
+ files:
127
+ - ".gitignore"
128
+ - ".rspec"
129
+ - ".travis.yml"
130
+ - Gemfile
131
+ - Guardfile
132
+ - LICENSE.txt
133
+ - README.md
134
+ - Rakefile
135
+ - ext/nokogiri_ext_xmlsec/common.h
136
+ - ext/nokogiri_ext_xmlsec/extconf.rb
137
+ - ext/nokogiri_ext_xmlsec/init.c
138
+ - ext/nokogiri_ext_xmlsec/nokogiri_decrypt_with_key.c
139
+ - ext/nokogiri_ext_xmlsec/nokogiri_encrypt_with_key.c
140
+ - ext/nokogiri_ext_xmlsec/nokogiri_helpers_set_attribute_id.c
141
+ - ext/nokogiri_ext_xmlsec/nokogiri_init.c
142
+ - ext/nokogiri_ext_xmlsec/nokogiri_sign_certificate.c
143
+ - ext/nokogiri_ext_xmlsec/nokogiri_sign_rsa.c
144
+ - ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_certificates.c
145
+ - ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_named_keys.c
146
+ - ext/nokogiri_ext_xmlsec/nokogiri_verify_signature_rsa.c
147
+ - ext/nokogiri_ext_xmlsec/options.c
148
+ - ext/nokogiri_ext_xmlsec/options.h
149
+ - ext/nokogiri_ext_xmlsec/shutdown.c
150
+ - ext/nokogiri_ext_xmlsec/util.c
151
+ - ext/nokogiri_ext_xmlsec/util.h
152
+ - ext/nokogiri_ext_xmlsec/xmlsecrb.h
153
+ - lib/nokogiri-xmlsec.rb
154
+ - lib/xmlsec.rb
155
+ - lib/xmlsec/version.rb
156
+ - nokogiri-xmlsec-me-harder.gemspec
157
+ - spec/fixtures/cert/server.crt
158
+ - spec/fixtures/cert/server.csr
159
+ - spec/fixtures/cert/server.key.decrypted
160
+ - spec/fixtures/cert/server.key.encrypted
161
+ - spec/fixtures/hate.xml
162
+ - spec/fixtures/pwned.xml
163
+ - spec/fixtures/rsa.pem
164
+ - spec/fixtures/rsa.pub
165
+ - spec/fixtures/sign2-doc.xml
166
+ - spec/fixtures/sign2-result.xml
167
+ - spec/fixtures/sign3-result.xml
168
+ - spec/lib/nokogiri/xml/document/encryption_and_decryption_spec.rb
169
+ - spec/lib/nokogiri/xml/document/signing_and_verifying_spec.rb
170
+ - spec/lib/nokogiri/xml/document/unsafe_xml_spec.rb
171
+ - spec/spec_helper.rb
172
+ homepage: https://github.com/omb-awong/xmlsec
173
+ licenses:
174
+ - MIT
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.2.2
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: Wrapper around http://www.aleksey.com/xmlsec to support XML encryption, decryption,
196
+ signing and signature validation in Ruby
197
+ test_files:
198
+ - spec/fixtures/cert/server.crt
199
+ - spec/fixtures/cert/server.csr
200
+ - spec/fixtures/cert/server.key.decrypted
201
+ - spec/fixtures/cert/server.key.encrypted
202
+ - spec/fixtures/hate.xml
203
+ - spec/fixtures/pwned.xml
204
+ - spec/fixtures/rsa.pem
205
+ - spec/fixtures/rsa.pub
206
+ - spec/fixtures/sign2-doc.xml
207
+ - spec/fixtures/sign2-result.xml
208
+ - spec/fixtures/sign3-result.xml
209
+ - spec/lib/nokogiri/xml/document/encryption_and_decryption_spec.rb
210
+ - spec/lib/nokogiri/xml/document/signing_and_verifying_spec.rb
211
+ - spec/lib/nokogiri/xml/document/unsafe_xml_spec.rb
212
+ - spec/spec_helper.rb
213
+ has_rdoc: