
    0j                     v    d dl Z d dlmZmZ d dlZddlmZ ddlmZ  ej        e	          Z
d Zd Zd Zd	 ZdS )
    N)datetime	timedelta   )Mex)parse_responsec                    |st          d          |!d|v rt          j        }nd|v rt          j        }|t          j        t          j        fvrt          d|z            t	          | ||||          } |j        |f|d|dd|}|j        dk    r t                              d	|j	                   t          |j	                  S )
Nz)WsTrust endpoint address can not be emptyz/trust/2005/usernamemixedz/trust/13/usernamemixedzZUnsupported soap action: %s. Contact your administrator to check your ADFS's MEX settings.z#application/soap+xml; charset=utf-8)zContent-type
SOAPAction)dataheadersi  z)Unsuccessful WsTrust request receives: %s)
ValueErrorr   ACTION_2005	ACTION_13
_build_rstpoststatus_codeloggerdebugtextr   )	usernamepasswordcloud_audience_urnendpoint_addresssoap_actionhttp_clientkwargsr
   resps	            \/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/msal/wstrust_request.pysend_requestr   %   s     FDEEE&*:::/KK&*:::-K3=#/::: LNYZ [ [ 	[(.0@+O OD;, 4@%B B    D 3@$)LLL $)$$$    c                     |                      dd                               dd                               dd                               dd                               d	d
          S )N&z&amp;"z&quot;'z&apos;<z&lt;>z&gt;)replace)ss    r   
escape_xmlr(   ?   sT    IIc7##++C::	h			f		ggc6224r   c                 ,    |                      d          S )Nz%Y-%m-%dT%H:%M:%SZ)strftime)datetime_objs    r   wsu_time_formatr,   E   s       !5666r   c                 @   t          j                    }d                    t          j        d         t          j        d         t          j        d         |t          t          j                              |t          |          t          |t          d          z             t          |           t          |          |t          j        k    rt          j        d         nt          j        d         ||t          j        k    rd	nd
|t          j        k    rdnd          S )Na  <s:Envelope xmlns:s='{s}' xmlns:wsa='{wsa}' xmlns:wsu='{wsu}'>
        <s:Header>
            <wsa:Action s:mustUnderstand='1'>{soap_action}</wsa:Action>
            <wsa:MessageID>urn:uuid:{message_id}</wsa:MessageID>
            <wsa:ReplyTo>
            <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
            </wsa:ReplyTo>
            <wsa:To s:mustUnderstand='1'>{endpoint_address}</wsa:To>

            <wsse:Security s:mustUnderstand='1'
            xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
                <wsu:Timestamp wsu:Id='_0'>
                    <wsu:Created>{time_now}</wsu:Created>
                    <wsu:Expires>{time_expire}</wsu:Expires>
                </wsu:Timestamp>
                <wsse:UsernameToken wsu:Id='ADALUsernameToken'>
                    <wsse:Username>{username}</wsse:Username>
                    <wsse:Password>{password}</wsse:Password>
                </wsse:UsernameToken>
            </wsse:Security>

        </s:Header>
        <s:Body>
        <wst:RequestSecurityToken xmlns:wst='{wst}'>
        <wsp:AppliesTo xmlns:wsp='http://schemas.xmlsoap.org/ws/2004/09/policy'>
            <wsa:EndpointReference>
                <wsa:Address>{applies_to}</wsa:Address>
            </wsa:EndpointReference>
        </wsp:AppliesTo>
        <wst:KeyType>{key_type}</wst:KeyType>
            <wst:RequestType>{request_type}</wst:RequestType>
        </wst:RequestSecurityToken>
        </s:Body>
        </s:Envelope>r'   wsuwsa10
   )minuteswstwst2005z7http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearerz9http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKeyz6http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issuez1http://schemas.xmlsoap.org/ws/2005/02/trust/Issue)r'   r.   wsar   
message_idr   time_nowtime_expirer   r   r2   
applies_tokey_typerequest_type)r   utcnowformatr   NSstruuiduuid4r,   r   r(   r   )r   r   r   r   r   nows         r   r   r   N   s    
/

C!B  fSksve}#&/#DJLL0A0A-$S))'i.C.C.C(CDD))Jx4H4H!,!=!=u36)CT)#-// ONK#-// RQC   
 
C0
r   )r?   r   r   loggingmexr   wstrust_responser   	getLogger__name__r   r   r(   r,   r    r   r   <module>rH      s   8  ( ( ( ( ( ( ( (        , , , , , ,		8	$	$% % %44 4 47 7 72
 2
 2
 2
 2
r   