xmlenc 0.6.0 → 0.6.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ca6e55c68b610b3555faafb61cdfbe906bf99c9
|
4
|
+
data.tar.gz: e09a38a6274ecbcbab0072740b7d77d465096db8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0afac48b7eacf0907ef0c8dd45a25924a8768be8ac7107d7e297d337bdbcd28ed5658eaf0e7340bfa2fe018e394764e37ae00397e695a94bad5bf8c9a1f6b1d1
|
7
|
+
data.tar.gz: 11e357408fd5b91fa3b1b6b7419c601bdd685a974d931d3e3b3b98d888678c4d61d283e2be6c947ef017d621d8ace6133b30f98101f33f49ad69d6f30c31d836
|
@@ -14,11 +14,15 @@ module Xmlenc
|
|
14
14
|
document.xpath('//xenc:EncryptedKey', NAMESPACES).collect { |n| EncryptedKey.new(n) }
|
15
15
|
end
|
16
16
|
|
17
|
-
def decrypt(key)
|
17
|
+
def decrypt(key, fail_silent = false)
|
18
18
|
encrypted_keys.each do |encrypted_key|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
begin
|
20
|
+
encrypted_data = encrypted_key.encrypted_data
|
21
|
+
data_key = encrypted_key.decrypt(key)
|
22
|
+
encrypted_data.decrypt(data_key)
|
23
|
+
rescue OpenSSL::PKey::RSAError => e
|
24
|
+
raise e unless fail_silent
|
25
|
+
end
|
22
26
|
end
|
23
27
|
@document.to_xml
|
24
28
|
end
|
data/lib/xmlenc/version.rb
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<PaymentInfo xmlns="http://example.org/paymentv2">
|
3
|
+
<Name>John Smith</Name>
|
4
|
+
<EncryptedData Id="ED" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
|
5
|
+
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
|
6
|
+
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
7
|
+
<ds:RetrievalMethod URI="#_EK"/>
|
8
|
+
<ds:RetrievalMethod URI="#_EK2"/>
|
9
|
+
<EncryptedKey Id="EK" xmlns="http://www.w3.org/2001/04/xmlenc#">
|
10
|
+
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
|
11
|
+
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
12
|
+
<ds:KeyName>my-rsa-key</ds:KeyName>
|
13
|
+
<ds:X509Data>
|
14
|
+
<ds:X509Certificate>
|
15
|
+
MIIDzTCCArWgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBljELMAkGA1UEBhMCVVMx
|
16
|
+
CzAJBgNVBAgTAk5ZMRIwEAYDVQQHEwlNYW5oYXR0YW4xFTATBgNVBAoTDExhdmEg
|
17
|
+
U3VwcmVtZTEUMBIGA1UECxMLSGVhZCBPZmZpY2UxFDASBgNVBAMTC1JTQSBUZXN0
|
18
|
+
IENBMSMwIQYJKoZIhvcNAQkBFhR0ZWNoQGxhdmFzdXByZW1lLm9yZzAeFw0wMjAx
|
19
|
+
MzExNjI5NDNaFw00MzAyMjUxNjI5NDNaMIGWMQswCQYDVQQGEwJVUzELMAkGA1UE
|
20
|
+
CBMCTlkxEjAQBgNVBAcTCU1hbmhhdHRhbjEVMBMGA1UEChMMTGF2YSBTdXByZW1l
|
21
|
+
MRQwEgYDVQQLEwtIZWFkIE9mZmljZTEUMBIGA1UEAxMLUlNBIFRlc3QgQ0ExIzAh
|
22
|
+
BgkqhkiG9w0BCQEWFHRlY2hAbGF2YXN1cHJlbWUub3JnMIIBIjANBgkqhkiG9w0B
|
23
|
+
AQEFAAOCAQ8AMIIBCgKCAQEAgj3TO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goxHvtITP9AR3JTMxUo3TF5ltW76DLDsEvWlE
|
43
|
+
uZKam0PYj6lYPKd4npUULeZyR/rDRrth/wFIBD8vbQlUsBHapNT9MbQfSKZemOuT
|
44
|
+
UJL9PNgsosySpKrX564oQw398XsxfTFxi4hqbdqzA/CLL418X01hUjIHdyv6XnA2
|
45
|
+
98Bmfv9WMPpX05udR4raDv5X8NWxjH00hAhasM3qumxoyCT6mAGfqvE23I+OXtrN
|
46
|
+
lUvE9mMjANw4zweCHsOcfw==
|
47
|
+
</CipherValue>
|
48
|
+
</CipherData>
|
49
|
+
<ReferenceList>
|
50
|
+
<DataReference URI="#ED"/>
|
51
|
+
</ReferenceList>
|
52
|
+
</EncryptedKey>
|
53
|
+
<EncryptedKey Id="EK2" xmlns="http://www.w3.org/2001/04/xmlenc#">
|
54
|
+
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
|
55
|
+
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
56
|
+
<ds:KeyName>my-rsa-key</ds:KeyName>
|
57
|
+
</ds:KeyInfo>
|
58
|
+
<CipherData>
|
59
|
+
<CipherValue>
|
60
|
+
dCxxYh3xGBTqlXbhmKxWzNMlHeE28E7vPrMyM5V4T+t1Iy2csj1BoQ7cqBjEhqEy
|
61
|
+
Eot4WNRYsY7P44mWBKurj2mdWQWgoxHvtITP9AR3JTMxUo3TF5ltW76DLDsEvWlE
|
62
|
+
uZKam0PYj6lYPKd4npUULeZyR/rDRrth/wFIBD8vbQlUsBHapNT9MbQfSKZemOuT
|
63
|
+
UJL9PNgsosySpKrX564oQw398XsxfTFxi4hqbdqzA/CLL418X01hUjIHdyv6XnA2
|
64
|
+
98Bmfv9WMPpX05udR4raDv5X8NWxjH00hAhasM3qumxoyCT6mAGfqvE23I+OXtrN
|
65
|
+
lUvE9mMjANw4zweCHsAaa==
|
66
|
+
</CipherValue>
|
67
|
+
</CipherData>
|
68
|
+
</EncryptedKey>
|
69
|
+
</ds:KeyInfo>
|
70
|
+
<CipherData>
|
71
|
+
<CipherValue>
|
72
|
+
u2vogkwlvFqeknJ0lYTBZkWS/eX8LR1fDPFMfyK1/UY0EyZfHvbONfDHcC/HLv/f
|
73
|
+
aAOOO2Y0GqsknP0LYT1OznkiJrzx134cmJCgbyrYXd3Mp21Pq3rs66JJ34Qt3/+I
|
74
|
+
EyJBUSMT8TdT3fBD44BtOqH2op/hy2g3hQPFZul4GiHBEnNJL/4nU1yad3bMvtAB
|
75
|
+
mzhx80lJvPGLcruj5V77WMvkvZfoeEqMq4qPWK02ZURsJsq0iZcJDi39NB7OCiON
|
76
|
+
</CipherValue>
|
77
|
+
</CipherData>
|
78
|
+
</EncryptedData>
|
79
|
+
</PaymentInfo>
|
@@ -47,5 +47,21 @@ describe Xmlenc::EncryptedDocument do
|
|
47
47
|
expect { subject.decrypt(private_key).chomp }.to raise_error(Xmlenc::EncryptedDataNotFound)
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
context 'when an EncryptedID also contains an EncryptedKey which cant be decrypted' do
|
52
|
+
let(:encrypted_xml) { File.read('spec/fixtures/encrypted_document_with_unknown_encrypted_key.xml') }
|
53
|
+
|
54
|
+
context 'when "fail_silent" is enabled' do
|
55
|
+
it 'decrypts the EncryptedID without raising an exception' do
|
56
|
+
expect(subject.decrypt(private_key, true).chomp).to eq plain_xml
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when "fail_silent" is disabled' do
|
61
|
+
it 'raises an exception' do
|
62
|
+
expect { subject.decrypt(private_key, false).chomp }.to raise_error(OpenSSL::PKey::RSAError)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
50
66
|
end
|
51
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlenc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benoist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- spec/fixtures/encrypted/java_to_ruby.txt
|
161
161
|
- spec/fixtures/encrypted_document.xml
|
162
162
|
- spec/fixtures/encrypted_document_no_ref_list.xml
|
163
|
+
- spec/fixtures/encrypted_document_with_unknown_encrypted_key.xml
|
163
164
|
- spec/fixtures/encrypted_document_without_data.xml
|
164
165
|
- spec/fixtures/key.pem
|
165
166
|
- spec/fixtures/phaos/enc-content-aes256-kt-rsa1_5.xml
|
@@ -223,6 +224,7 @@ test_files:
|
|
223
224
|
- spec/fixtures/encrypted/java_to_ruby.txt
|
224
225
|
- spec/fixtures/encrypted_document.xml
|
225
226
|
- spec/fixtures/encrypted_document_no_ref_list.xml
|
227
|
+
- spec/fixtures/encrypted_document_with_unknown_encrypted_key.xml
|
226
228
|
- spec/fixtures/encrypted_document_without_data.xml
|
227
229
|
- spec/fixtures/key.pem
|
228
230
|
- spec/fixtures/phaos/enc-content-aes256-kt-rsa1_5.xml
|