Skip to content

Commit 4a7ff19

Browse files
committed
Remove the force_element_to_content its unneeded
The force_element_to_content was added due to the way that xmlsec1 was believed to behave. An example at https://users.dcc.uchile.cl/~pcamacho/tutorial/web/xmlsec/xmlsec.html set the --node-xpath /PayInfo/CreditCard/Number/text() and used http://www.w3.org/2001/04/xmlenc#Element for the template. Instead it should have been --node-xpath /PayInfo/CreditCard/Number/text() withe the http://www.w3.org/2001/04/xmlenc#Content in the template. That works fine.
1 parent 83b98b1 commit 4a7ff19

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

lib/XML/Enc.pm

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ XML::Enc - XML Encryption
2828
{
2929
key => 't/sign-private.pem',
3030
no_xml_declaration => 1,
31-
force_element_to_content => 0,
3231
},
3332
);
3433
$decrypted = $enc->decrypt($xml);
@@ -113,14 +112,6 @@ Used in encryption. Optional. Default method: rsa-1_5
113112
114113
=back
115114
116-
=item B<force_element_to_content>
117-
118-
Used for decryption to treat an Element EncryptedData type as Content
119-
if the decrypted data is not XML. xmlsec appears to have a bug where it
120-
uses the Element EncryptedData type in order to encrypt what is actually Content.
121-
Strangely it appears to have no issue decrypting the data if the Type is changed
122-
to Content
123-
124115
=back
125116
126117
=cut
@@ -150,10 +141,6 @@ sub new {
150141
my $key_method = exists($params->{'key_transport'}) ? $params->{'key_transport'} : 'rsa-1_5';
151142
$self->{'key_transport'} = $self->_setKeyEncryptionMethod($key_method);
152143

153-
my $force_element_to_content = exists($params->{'force_element_to_content'}) ?
154-
$params->{'force_element_to_content'} : 0;
155-
$self->{'force_element_to_content'} = $force_element_to_content;
156-
157144
return $self;
158145
}
159146

@@ -215,15 +202,6 @@ sub decrypt {
215202
if (defined $newnode) {
216203
$encryptednode->addSibling($newnode);
217204
$encryptednode->unbindNode();
218-
#print $newnode->serialize();
219-
} else {
220-
if ($self->{force_element_to_content}) {
221-
# Invalid XML simply add it to the node
222-
$data =~ s/[\/<>]//mg; # Remove any stray XML characters
223-
my $parent = $encryptednode->parentNode;
224-
$parent->removeChildNodes;
225-
$parent->appendText($data);
226-
}
227205
}
228206
} else {
229207
# http://www.w3.org/2001/04/xmlenc#Content

t/07-decrypt-xmlsec.t

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ XML Security Library example: Original XML
6868
-->
6969
<EncryptedData
7070
xmlns="http://www.w3.org/2001/04/xmlenc#"
71-
Type="http://www.w3.org/2001/04/xmlenc#Element">
71+
Type="http://www.w3.org/2001/04/xmlenc#Content">
7272
<EncryptionMethod Algorithm=
7373
"http://www.w3.org/2001/04/xmlenc#$dm"/>
7474
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
@@ -124,15 +124,14 @@ SKIP: {
124124
print CONTENT $content_tmpl;
125125
close CONTENT;
126126

127-
$encrypt_response = `xmlsec1 encrypt --pubkey-cert-pem t/sign-certonly.pem --session-key $sesskey{$dm} --xml-data plaintext.xml --output encrypted-content.xml --node-xpath '/PayInfo/CreditCard/Number/text()' content-template.xml 2>&1`;
127+
$encrypt_response = `xmlsec1 encrypt --pubkey-cert-pem t/sign-certonly.pem --session-key $sesskey{$dm} --xml-data plaintext.xml --output encrypted-content.xml --node-xpath '/PayInfo/CreditCard/Number' content-template.xml 2>&1`;
128128

129129
$encrypted = read_text('encrypted-content.xml');
130130

131131
unlink 'plaintext.xml';
132132
unlink 'content-template.xml';
133133
unlink 'encrypted-content.xml';
134134

135-
$decrypter->{force_element_to_content} = 1;
136135
# Decrypt using XML::Enc
137136
ok($decrypter->decrypt($encrypted) =~ /1076 2478 0678 5589/,
138137
"Decrypted $dm $km xmlsec1 Content");

0 commit comments

Comments
 (0)