ó
†rŽKc           @   s  d  Z  d d l m Z d d l Td d l m Z d d l m Z d d l m	 Z	 d d l
 m
 Z
 m Z y d d l m Z Wn! e k
 r� d d l m Z n Xd Z d Z d Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s*   
The I{wsse} module provides WS-Security.
iÿÿÿÿ(   t	   getLogger(   t   *(   t   Object(   t   Element(   t   UTC(   t   datetimet	   timedelta(   t   md5t   dss"   http://www.w3.org/2000/09/xmldsig#t   wssesQ   http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsdt   wsusR   http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsdt   wsencs!   http://www.w3.org/2001/04/xmlenc#t   Securityc           B   s    e  Z d  Z d „  Z d „  Z RS(   s5  
    WS-Security object.
    @ivar tokens: A list of security tokens
    @type tokens: [L{Token},...]
    @ivar signatures: A list of signatures.
    @type signatures: TBD
    @ivar references: A list of references.
    @type references: TBD
    @ivar keys: A list of encryption keys.
    @type keys: TBD
    c         C   s>   t  j |  ƒ t |  _ g  |  _ g  |  _ g  |  _ g  |  _ d S(   t    N(   R   t   __init__t   Truet   mustUnderstandt   tokenst
   signaturest
   referencest   keys(   t   self(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   >   s    				c         C   s\   t  d d t ƒ} | j d t |  j ƒ j ƒ  ƒ x$ |  j D] } | j | j ƒ  ƒ q; W| S(   sr   
        Get xml representation of the object.
        @return: The root node.
        @rtype: L{Element}
        R   t   nsR   (	   R   t   wssenst   sett   strR   t   lowerR   t   appendt   xml(   R   t   roott   t(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   G   s
    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   1   s   		t   Tokenc           B   sD   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   s    I{Abstract} security token. c         C   s
   t  j ƒ  S(   N(   R   t   now(   t   cls(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR#   W   s    c         C   s
   t  j ƒ  S(   N(   R   t   utcnow(   R$   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyt   utc[   s    c         C   s   t  ƒ  } t | ƒ S(   N(   R   R   (   R$   R&   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyt   sysdate_   s    	c         C   s   t  j |  ƒ d  S(   N(   R   R   (   R   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   d   s    (   R   R    R!   t   classmethodR#   R&   R'   R   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR"   T   s
   t   UsernameTokenc           B   s>   e  Z d  Z d d d „ Z d d „ Z d d „ Z d „  Z RS(   sD  
    Represents a basic I{UsernameToken} WS-Secuirty token.
    @ivar username: A username.
    @type username: str
    @ivar password: A password.
    @type password: str
    @ivar nonce: A set of bytes to prevent reply attacks.
    @type nonce: str
    @ivar created: The token created.
    @type created: L{datetime}
    c         C   s5   t  j |  ƒ | |  _ | |  _ d |  _ d |  _ d S(   s‹   
        @param username: A username.
        @type username: str
        @param password: A password.
        @type password: str
        N(   R"   R   t   usernamet   passwordt   Nonet   noncet   created(   R   R*   R+   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   u   s
    			c         C   sƒ   | d k rv g  } | j |  j ƒ | j |  j ƒ | j t j ƒ  ƒ t ƒ  } | j d j | ƒ ƒ | j	 ƒ  |  _
 n	 | |  _
 d S(   sÇ   
        Set I{nonce} which is arbitraty set of bytes to prevent
        reply attacks.
        @param text: The nonce text value.
            Generated when I{None}.
        @type text: str
        t   :N(   R,   R   R*   R+   R"   R'   R   t   updatet   joint	   hexdigestR-   (   R   t   textt   st   m(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyt   setnonce‚   s    	c         C   s+   | d k r t j ƒ  |  _ n	 | |  _ d S(   s›   
        Set I{created}.
        @param dt: The created date & time.
            Set as datetime.utc() when I{None}.
        @type dt: L{datetime}
        N(   R,   R"   R&   R.   (   R   t   dt(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyt
   setcreated•   s    c         C   s  t  d d t ƒ} t  d d t ƒ} | j |  j ƒ | j | ƒ t  d d t ƒ} | j |  j ƒ | j | ƒ |  j d k	 r± t  d d t ƒ} | j |  j ƒ | j | ƒ n  |  j d k	 rþ t  d d t	 ƒ} | j t
 t |  j ƒ ƒ ƒ | j | ƒ n  | S(   sr   
        Get xml representation of the object.
        @return: The root node.
        @rtype: L{Element}
        R)   R   t   Usernamet   Passwordt   Noncet   CreatedN(   R   R   t   setTextR*   R   R+   R-   R,   R.   t   wsunsR   R   (   R   R   t   ut   pt   n(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   ¢   s     N(   R   R    R!   R,   R   R6   R8   R   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR)   h   s
   t	   Timestampc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   sÂ   
    Represents the I{Timestamp} WS-Secuirty token.
    @ivar created: The token created.
    @type created: L{datetime}
    @ivar expires: The token expires.
    @type expires: L{datetime}
    iZ   c         C   s9   t  j |  ƒ t  j ƒ  |  _ |  j t d | ƒ |  _ d S(   sS   
        @param validity: The time in seconds.
        @type validity: int
        t   secondsN(   R"   R   R&   R.   R   t   expires(   R   t   validity(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   Ã   s    c         C   sŒ   t  d d t ƒ} t  d d t ƒ} | j t t |  j ƒ ƒ ƒ t  d d t ƒ} | j t t |  j ƒ ƒ ƒ | j | ƒ | j | ƒ | S(   NRB   R   R<   t   Expires(   R   R>   R=   R   R   R.   RD   R   (   R   R   R.   RD   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyR   Ì   s    (   R   R    R!   R   R   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyRB   º   s   	N(   s   dss"   http://www.w3.org/2000/09/xmldsig#(   s   wssesQ   http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd(   s   wsusR   http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd(   s   wsencs!   http://www.w3.org/2001/04/xmlenc#(   R!   t   loggingR    t   sudst   suds.sudsobjectR   t   suds.sax.elementR   t   suds.sax.dateR   R   R   t   hashlibR   t   ImportErrort   dsnsR   R>   t   wsencnsR   R"   R)   RB   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/wsse.pyt   <module>   s,   
    #R