In `dm.xmlsec.binding` ("https://pypi.org/project/dm.xmlsec.binding/"),
I integrate
Aleksey Sanin's XML security library ("http://www.aleksey.com/xmlsec")
with `lxml`, both `libxml2` based.
Recently, one of its encryption/decryption tests started to fail.
This test uses a tree of the form:
<root>
...
<to_be_encrypted>...</to_be_encrypted>
...
</root>
The encryption transforms it (directly at the `libxml2` level)
to the form
<root>
...
<encrypted>...</encypted>
...
</root>
An `lxml` proxy to the new node `encrypted` is returned.
The test calls `getroottree` on this proxy to update
`lxml`'s view of the modified tree.
In older `lxml` versions, this has been successful.
However, in `lxml==4.9.1` (maybe already before this version)
the view is inconsistent:
with `ENC="{http://www.w3.org/2001/04/xmlenc#}EncryptedData`
and an element `E`, I get:
`E[0].tag == ENC` but `E.find(ENC) is None`.
Apparently, `__getitem__` (behind `E[0]`) is aware of the modification
but `find` is not.
How the `lxml` view of a tree modified at the `libxml2` leval
can be reliably updated?
For preciseness
===============
The XML serialization of the inconsistent view is:
<!--
XML Security Library example: Original XML doc file before encryption (encrypt2
example).
-->
<Envelope xmlns="urn:envelope">
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#"
Type="http://www.w3.org/2001/04/xmlenc#Element">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>deskey.bin</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>FwsuAoPgBzvCjr3K2q+VLcX4U+NzpHZ6orcSzbe3OrTcu3PrxWnHqg==</CipherValue>
</CipherData>
</EncryptedData>
</Envelope>
The `E` in the section above is this document's root element
(i.e. `{urn:envelope}Envelope`). Its child `0` has been
replaced by the encryption. It is this element which is not seen
by `find`.
--
Dieter
_______________________________________________
lxml - The Python XML Toolkit mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/lxml.python.org/
Member address: [email protected]