Xml encryption processing rules for xml elements and content
1 / 14

XML Encryption: Processing Rules for XML Elements and Content - PowerPoint PPT Presentation

  • Uploaded on

XML Encryption: Processing Rules for XML Elements and Content. Ed Simon XMLsec Inc. “XML Security Training and Consulting” http://xmlsec.com. Overview. The current XML Encryption Processing Rules (section 4) state that

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'XML Encryption: Processing Rules for XML Elements and Content' - everly

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Xml encryption processing rules for xml elements and content l.jpg

XML Encryption: Processing Rules for XML Elements and Content

Ed SimonXMLsec Inc.“XML Security Training and Consulting”http://xmlsec.com

Overview l.jpg

The current XML Encryption Processing Rules (section 4) state that

  • when encrypting an XML document’s child elements or element content, one must replace the plaintext content with <EncryptedData> elements

  • when decrypting, decrypted <EncryptedData> elements (of type Element or Content) must be replaced by the revealed XML

    If the requirement for replacement is not intentional, we should fix the text. If the requirement is intentional, I propose that it may be too limiting.

Overview3 l.jpg

Note: I am not suggesting that XML Encryption specify an API design, absolutely NOT! However, I don’t want XML Encryption to unnecessarily restrict API designs either.

Note 2: Slides with detailed code are included for completeness; they are not essential for understanding this topic.

How the current processing rules work l.jpg
How the current Processing Rules work


<?xml version="1.0" encoding="UTF-8"?>






<ExpiryDate> 2003 June 30 </ExpiryDate>


. . .



<?xml version="1.0" encoding="UTF-8"?>



<Name>Jose Aznar</Name>


<Number> 1000 1234 5678 0001 </Number>

<ExpiryDate> 2003 June 30 </ExpiryDate>



. . .


What the code looks like l.jpg
What the code looks like


// Encrypt the content of the <CreditCard>/<Number> elements

NodeIterator ni2 =


// Encrypt the nodes (only element content is encrypted)

while ((node = ni2.nextNode())!= null) {


xmlencEncryptor.encryptAndReplace((Element)node, true,

getEncryptedDataTemplate(desKey, true), desKey);


// Get the nodes to be decrypted

NodeList nl2 = DOMUtil.getElementsByTagNameNS(

doc, XEncryption.XMLENC_NS, "EncryptedData");

// Decrypt

for (int i = 0; i < nl2.getLength(); i++) {


Element el = (Element)nl2.item(i);



Other processing scenarios l.jpg
Other processing scenarios

Scenario A: The XML source has no encrypted parts and is protected through authorization instead. However, there is an authorized app which selects certain credit card info for processing. It wants to query <CreditCard> elements and/or content, encrypt, and import the resulting <EncryptedData> element into a SOAP message.

Scenario B: The XML source has encrypted elements and content accessible by a number of applications. When one of these applications queries an encrypted element, that app needs to decrypt the element but MUST NOT modify the source.

Scenario a soap msg w encrypted data l.jpg
Scenario A: SOAP msg w/ encrypted data


1. Select node

3. Form SOAP msg

2. Encrypt node (no replace)and return to application

Credit card info app

customer.xml(no encryption)

SOAP msg



Scenario a soap message l.jpg
Scenario A: SOAP message

<?xml version="1.0" encoding="UTF-8"?>

<Envelope xmlns="http://www.w3.org/2001/06/soap-envelope">


<VerifyCreditCardRequest xmlns="http://…/actions">

<EncryptedData Type="NodeList“ xmlns="http://…/xmlenc">

<EncryptionMethod Algorithm="urn:nist-gov:tripledes…">








Scenario a code l.jpg
Scenario A code


// Encrypt the content of the 2nd <CreditCard>/<Number> element

nodeToBeEncrypted = XPathAPI.selectSingleNode(doc,


// Encrypt the nodes (whole elements are encrypted)

Element elemEncryptedData =

xmlencEncryptor.encrypt((Element)nodeToBeEncrypted, false,

getEncryptedDataTemplate(desKey, false), desKey);

Document docSoap = new DocumentImpl();

Element elemEnvelope = docSoap.createElement("Envelope");

Element elemBody = docSoap.createElement("Body");

Element elemBodyChild = docSoap.createElement("VerifyCreditCardRequest");

Node nodeImported = docSoap.importNode(elemEncryptedData, true);





Scenario a code10 l.jpg
Scenario A code…

Note: The preceding code works (uses IBM’s XSS4J) but, according to the spec, its illegal because the XML source is not being replaced.

Scenario b encrypted customer db l.jpg
Scenario B: Encrypted customer DB


Customer name: H. LuCredit card#: 4011 23

1. Select <EncryptedData> node

3. Display info to authorized user

2. Decrypt node (no replace)and return to application

Interface to authorized user

Credit card info app


Scenario b code l.jpg
Scenario B code


// Get the nodes to be decrypted

Element elemEncryptedDataToDecrypt = (Element)

DOMUtil.getElementsByTagNameNS(doc, XEncryption.XMLENC_NS,


Element elemIV = (Element)


String strIV = elemIV.getFirstChild().getNodeValue();

Element elemCipherData = (Element)


String strCipherData = elemCipherData.getFirstChild().getNodeValue();

javax.crypto.spec.IvParameterSpec ivparmspec = new


Cipher desCipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");

desCipher.init(Cipher.DECRYPT_MODE, desKey, ivparmspec);

byte[] bytesPlainData = desCipher.doFinal(com.ibm.xml.dsig.Base64.decode(strCipherData));

String strCreditCardNumber = new String(bytesPlainData);

Scenario b code13 l.jpg
Scenario B code…

Don’t want to use decryptAndReplace() because I don’t want to modify the XML source.

But XML Encryption doesn’t allow Toolkits to give me an alternative so I have to use low-level security APIs instead!

Rather, XML Encryption should allow Toolkits to return the decrypted XML element or content without requiring replacement in the source.

Qaq quietly anticipated questions l.jpg
QAQ(Quietly Anticipated Questions)

Question: Why not create a dummy document before and/or after encrypting?

Answer: Yes, one could create a dummy document and copy in the relevant elements before encrypting or decrypting and still conform to the XML Encryption spec as it currently stands.However, this would be inefficient and often inelegant.

Question: The example code you showed doesn’t deal with more complex context situations such as inherited namespaces, default attributes, etc.. How will those artifacts affect the no-replacement processing of <EncryptedData> elements?

Answer: I think this question will only be answered through more coding and application experience. There could be some issues that arise.