�
�/$ZB � �& � d Z ddlmZ ddlZddlZddlZddlmZ ddlm Z m
Z
mZmZm
Z
ddlZn
# e$ r dZY nw xY wdZdZdZd Zd
ZdZd"d
�Zd� Zdddeefd�Zd"d�Zd� Zd#d�Zd#d�Zd#d�Zedk r�dZ ee � � Z! e"e!� � ee ddd� � Z# e"ee#z � � dZ ee dz ddded�� � Z# e"e ee#z z � � e e$d� � �% � � � � Z& ee#d e#d e&d�!� � sJ �dS dS )$z,Pythonic XML Security Library implementation� )�print_functionN)�StringIO)�BIO�EVP�RSA�X509�m2a�
<SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="%(ref_uri)s">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>%(digest_value)s</DigestValue>
</Reference>
</SignedInfo>
z�
<?xml version="1.0" encoding="UTF-8"?>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
%(signed_info)s
<SignatureValue>%(signature_value)s</SignatureValue>
%(key_info)s
%(ref_xml)s
</Signature>
aO
<SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>%(digest_value)s</DigestValue>
</Reference>
</SignedInfo>
z�<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
%(signed_info)s
<SignatureValue>%(signature_value)s</SignatureValue>
%(key_info)s
</Signature>z�
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>%(modulus)s</Modulus>
<Exponent>%(exponent)s</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
z�
<KeyInfo>
<X509Data>
<X509IssuerSerial>
<X509IssuerName>%(issuer_name)s</X509IssuerName>
<X509SerialNumber>%(serial_number)s</X509SerialNumber>
</X509IssuerSerial>
</X509Data>
</KeyInfo>
Tc �( � t � � }t �Dt j � t | � � � � }|� ||�� � n&ddlm} || � � � ||�� � |� � � S )z@Return the canonical (c14n) form of the xml document for hashingN)� exclusive� )�SimpleXMLElement)r �lxml�etree�parse�
write_c14n� simplexmlr
�getvalue)�xml�c14n_exc�output�etr
s �5/usr/lib/python3/dist-packages/pysimplesoap/xmlsec.py�canonicalizer b s� � � �Z�Z�F���
�Z�
�
�h�s�m�m�
,�
,��
�
�
�f��
�1�1�1�1� 0�/�/�/�/�/������(�(��8�(�D�D�D��?�?���� c �r � t j t j | � � � � � � � S )z/Create a SHA1 hash and return the base64 string)�base64� b64encode�hashlib�sha1�digest)�payloads r �sha1_hash_digestr" |