§
    Ìtºf�Y  ã            	       ó„  — d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ 	 d d	lmZ d d
lmZ d dlmZ dZn# e$ r dZY nw xY wdZd„ Z  G d„ de!¦  «        Z" ej#        e"¦  «          G d„ de"¦  «        Z$ ej#        e$¦  «          G d„ de!¦  «        Z% ej#        e%¦  «          G d„ de!¦  «        Z& ej#        e&¦  «          G d„ de&¦  «        Z' ej#        e'¦  «         d„ Z(d„ Z) G d„ de!¦  «        Z* ej#        e*¦  «          G d„ de!¦  «        Z+ ej#        e+¦  «         ed2d!„¦   «         Z,ed3d"„¦   «         Z-ed#„ ¦   «         Z.ed$„ ¦   «         Z/ed4d'„¦   «         Z0ed5d(„¦   «         Z1d)Z2	 ed6d+„¦   «         Z3ed,„ ¦   «         Z4d7d-e5d.e5d/e	e6         d0e
fd1„Z7dS )8é    N)ÚOptionalÚDict)Úpublic)Úxor)ÚIAuthenticator)Ú
PBKDF2HMAC)Úhashes)Údefault_backend©Úhash_secret©ÚType)ÚsaslprepTF)ÚAuthAnonymousÚ	AuthScramÚAuthCryptoSignÚAuthWampCraÚ
AuthTicketÚcreate_authenticatorÚpbkdf2Úgenerate_totp_secretÚcompute_totpÚ
check_totpÚqrcode_from_totpÚ
derive_keyÚgenerate_wcsÚcompute_wcsÚderive_scram_credentialc                 óx  — 	 t           j        t           t          j        t          t          j        t          t          j        t          t
          j        t
          t          j        t          t          j        t          i|          }n0# t          $ r# t          d 
                    | ¦  «        ¦  «        ‚w xY w |di |¤Ž}|S )a  
    Accepts various keys and values to configure an authenticator. The
    valid keys depend on the kind of authenticator but all can
    understand: `authextra`, `authid` and `authrole`

    :return: an instance implementing IAuthenticator with the given
        configuration.
    zUnknown authenticator '{}'© )r   Únamer   ÚAuthCryptoSignProxyr   r   ÚAuthAnonymousProxyr   ÚKeyErrorÚ
ValueErrorÚformat)r!   ÚkwargsÚklassÚauthenticators       úQ/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/wamp/auth.pyr   r   K   s«   € ð
åŒN�IÝÔ¥ÝÔ$Õ&9ÝÔ�kÝÔ¥ÝÔ#Õ%7ÝŒO�Zð
ð ôˆˆøõ ð 
ð 
ð 
ÝØ(×/Ò/°Ñ5Ô5ñ
ô 
ð 	
ð
øøøð
 �E�O�O˜F�O�O€MØÐs   ‚A?B Â-B/c                   ó:   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zd„ ZdS )r   Ú	anonymousc                 ó   — || _         d S ©N)Ú_args©ÚselfÚkws     r*   Ú__init__zAuthAnonymous.__init__k   s   € ØˆŒ
ˆ
ˆ
ó    c                 óP   — | j                              dt          ¦   «         ¦  «        S ©NÚ	authextra©r/   ÚgetÚdict©r1   s    r*   r7   zAuthAnonymous.authextran   ó   € àŒz�~Š~˜k­4©6¬6Ñ2Ô2Ð2r4   c                 ó    — t          d¦  «        ‚)Nz/on_challenge called on anonymous authentication)ÚRuntimeError©r1   ÚsessionÚ	challenges      r*   Úon_challengezAuthAnonymous.on_challenger   s   € ÝØ=ñ
ô 
ð 	
r4   c                 ó   — d S r.   r    ©r1   Úmsgr7   s      r*   Ú
on_welcomezAuthAnonymous.on_welcomew   ó   € Øˆtr4   N©	Ú__name__Ú
__module__Ú__qualname__r!   r3   Úpropertyr7   rB   rF   r    r4   r*   r   r   h   sa   € € € € € Ø€Dðð ð ð ð3ð 3ñ „Xð3ð
ð 
ð 
ð
ð ð ð ð r4   r   c                   ó   — e Zd ZdZdS )r#   zanonymous-proxyN©rI   rJ   rK   r!   r    r4   r*   r#   r#   ~   s   € € € € € Ø€D€D€Dr4   r#   c                   ó:   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zd„ ZdS )r   Úticketc                 óŽ   — || _         	 | j                              d¦  «        | _        d S # t          $ r t	          d¦  «        ‚w xY w)NrP   z.ticket authentication requires 'ticket=' kwarg)r/   ÚpopÚ_ticketr$   r%   r0   s     r*   r3   zAuthTicket.__init__ˆ   sW   € ØˆŒ
ð	Øœ:Ÿ>š>¨(Ñ3Ô3ˆDŒLˆLˆLøÝð 	ð 	ð 	ÝØ@ñô ð ð	øøøs	   ‰* ªAc                 óP   — | j                              dt          ¦   «         ¦  «        S r6   r8   r;   s    r*   r7   zAuthTicket.authextra‘   r<   r4   c                 ó*   — |j         dk    sJ ‚| j        S )NrP   )ÚmethodrS   r?   s      r*   rB   zAuthTicket.on_challenge•   s   € ØÔ 8Ò+Ð+Ð+Ð+ØŒ|Ðr4   c                 ó   — d S r.   r    rD   s      r*   rF   zAuthTicket.on_welcome™   rG   r4   NrH   r    r4   r*   r   r   …   sa   € € € € € Ø€Dðð ð ð ð3ð 3ñ „Xð3ðð ð ðð ð ð ð r4   r   c                   ó:   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zd„ ZdS )r   Ú
cryptosignc                 ó,  — |                      ¦   «         D ]3}|dvr-t          d                     || j        j        ¦  «        ¦  «        ‚Œ4dD ](}||vr"t          d                     |¦  «        ¦  «        ‚Œ)ddlm} |                     t          j	        |d         ¦  «        ¦  «        | _
        d|                     d	t          ¦   «         ¦  «        v r;|d	         d         }|| j
                             ¦   «         k    rt          d
¦  «        ‚nG|                     d	t          ¦   «         ¦  «        |d	<   | j
                             ¦   «         |d	         d<   |                     d	t          ¦   «         ¦  «                             dd ¦  «        | _        || _        d S )N)r7   ÚauthidÚauthroleÚprivkeyúUnexpected key '{}' for {})r]   z Must provide '{}' for cryptosignr   )ÚCryptosignKeyr]   Úpubkeyr7   z,Public key doesn't correspond to private keyÚchannel_binding)Úkeysr%   r&   Ú	__class__rI   Úautobahn.wamp.cryptosignr_   Ú
from_bytesÚbinasciiÚa2b_hexÚ_privkeyr9   r:   Ú
public_keyÚ_channel_bindingr/   )r1   r2   Úkeyr_   r`   s        r*   r3   zAuthCryptoSign.__init__£   s¤  € à—7’7‘9”9ð 	ð 	ˆCØÐHÐHÐHÝ Ø0×7Ò7¸¸T¼^Ô=TÑUÔUñô ð ð Ið ð 	ð 	ˆCØ˜"ˆ}ˆ}Ý Ø6×=Ò=¸cÑBÔBñô ð ð ð
 	;Ð:Ð:Ð:Ð:Ð:Ø%×0Ò0ÝÔ˜R 	œ]Ñ+Ô+ñ
ô 
ˆŒð �r—v’v˜k­4©6¬6Ñ2Ô2Ð2Ð2Ø˜”_ XÔ.ˆFØ˜œ×1Ò1Ñ3Ô3Ò3Ð3Ý ØBñô ð ð 4ð
 !Ÿfšf [µ$±&´&Ñ9Ô9ˆBˆ{‰OØ(,¬×(@Ò(@Ñ(BÔ(BˆBˆ{ŒO˜HÑ%à "§¢ {µD±F´FÑ ;Ô ;× ?Ò ?Ð@QÐSWÑ XÔ XˆÔØˆŒ
ˆ
ˆ
r4   c                 óP   — | j                              dt          ¦   «         ¦  «        S r6   r8   r;   s    r*   r7   zAuthCryptoSign.authextraÂ   r<   r4   c                 óš   — |j         j        j                             | j        d ¦  «        }| j                             ||| j        ¬¦  «        S )N)Ú
channel_idÚchannel_id_type)Ú
_transportÚtransport_detailsrn   r9   rj   rh   Úsign_challenge)r1   r@   rA   rn   s       r*   rB   zAuthCryptoSign.on_challengeÆ   sQ   € ØÔ'Ô9ÔD×HÒHÈÔI^Ð`dÑeÔeˆ
ØŒ}×+Ò+¨IØ7AØ<@Ô<Qð ,ñ Sô Sð 	Sr4   c                 ó   — d S r.   r    rD   s      r*   rF   zAuthCryptoSign.on_welcomeÌ   rG   r4   NrH   r    r4   r*   r   r       sd   € € € € € Ø€Dðð ð ð> ð3ð 3ñ „Xð3ðSð Sð Sðð ð ð ð r4   r   c                   ó   — e Zd ZdZdS )r"   zcryptosign-proxyNrN   r    r4   r*   r"   r"   Ó   s   € € € € € Ø€D€D€Dr4   r"   c           
      ó¤   — t          | t          j        |¦  «        ||ddt          j        d¬¦  «        }|                     d¦  «        \  }}}}}	}
|
S )z†
    Internal helper. Returns the salted/hashed password using the
    argon2id-13 algorithm. The return value is base64-encoded.
    é   é    é   ©ÚsecretÚsaltÚ	time_costÚmemory_costÚparallelismÚhash_lenÚtypeÚversionó   $)r   Úbase64Ú	b64decoder   ÚIDÚsplit)Úpasswordr{   Ú
iterationsÚmemoryÚrawhashÚ_ÚtagÚverÚoptionsÚ	salt_dataÚ	hash_datas              r*   Ú_hash_argon2id13_secretr‘   Ú   sc   € õ
 ØÝÔ˜dÑ#Ô#ØØØØÝŒWØð	ñ 	ô 	€Gð 29·²¸tÑ1DÔ1DÑ.€A€sˆC�˜) YØÐr4   c                 ó(   — t          | ||d¬¦  «        S )z2
    Internal helper for SCRAM authentication
    rw   )Úkeylen)r   )r‡   r{   rˆ   s      r*   Ú_hash_pbkdf2_secretr”   ð   s   € õ �(˜D *°RÐ8Ñ8Ô8Ð8r4   c                   ó>   — e Zd ZdZdZd„ Zed„ ¦   «         Zd„ Zd„ Z	dS )r   z¬
    Implements "wamp-scram" authentication for components.

    NOTE: This is a prototype of a draft spec; see
    https://github.com/wamp-proto/wamp-proto/issues/135
    Úscramc                 óN   — t           st          d¦  «        ‚|| _        d | _        d S )Nz^Cannot support WAMP-SCRAM without argon2_cffi and passlib libraries; install autobahn['scram'])Ú	HAS_ARGONr>   r/   Ú_client_noncer0   s     r*   r3   zAuthScram.__init__   s8   € Ýð 	Ýð?ñô ð ð ˆŒ
Ø!ˆÔÐÐr4   c                 óž   — | j         €>t          j        t          j        d¦  «        ¦  «                             d¦  «        | _         d| j         iS )Né   ÚasciiÚnonce)r™   rƒ   Ú	b64encodeÚosÚurandomÚdecoder;   s    r*   r7   zAuthScram.authextra	  sH   € ð ÔÐ%Ý!'Ô!1µ"´*¸R±.´.Ñ!AÔ!A×!HÒ!HÈÑ!QÔ!QˆDÔà�TÔ'ð
ð 	
r4   c                 ó¾  — |j         dk    sJ ‚| j        €J ‚g d¢}ddg}|D ]-}||j        vr"t          d                     |¦  «        ¦  «        ‚Œ.|j        D ]+}|||z   vr"t          d                     |¦  «        ¦  «        ‚Œ,|j                             dd¦  «        }|j        d         }|j        d	         }t          |j        d
         ¦  «        }	t          |j                             dd¦  «        ¦  «        }
| j        d                              d¦  «        }t          | j        d         ¦  «        }|j        d         }| j        }d                     d                     ||¦  «        d                     |||	¦  «        d                     ||¦  «        ¬¦  «                             d¦  «        | _
        |dk    r-|
dk    rt          d¦  «        ‚t          |||	|
¦  «        | _        n?|dk    rt          |||	¦  «        | _        n"t          d                     |¦  «        ¦  «        ‚t          j        | j        dt"          j        ¦  «                             ¦   «         }t#          j        d|¦  «                             ¦   «         }t          j        || j
        t"          j        ¦  «                             ¦   «         }t)          ||¦  «        }t+          j        |¦  «        S )Nr–   )r�   Úkdfr{   rˆ   r‰   ra   z?WAMP-SCRAM challenge option '{}' is  required but not specifiedz/WAMP-SCRAM challenge has unknown attribute '{}'Ú r�   r{   rˆ   éÿÿÿÿr‡   Úutf8r[   r£   z:{client_first_bare},{server_first},{client_final_no_proof}z	n={},r={}zr={},s={},i={}z	c={},r={})Úclient_first_bareÚserver_firstÚclient_final_no_proofrœ   úargon2id-13z>WAMP-SCRAM 'argon2id-13' challenge requires 'memory' parameterr   z%WAMP-SCRAM specified unknown KDF '{}'ó
   Client KeyÚsha256)rV   r™   Úextrar>   r&   r9   Úintr/   Úencoder   Ú_auth_messager%   r‘   Ú_salted_passwordr”   ÚhmacÚnewÚhashlibr¬   ÚdigestÚ	xor_arrayrƒ   rž   )r1   r@   rA   Úrequired_argsÚoptional_argsÚkra   Úserver_noncer{   rˆ   r‰   r‡   r[   Ú	algorithmÚclient_nonceÚ
client_keyÚ
stored_keyÚclient_signatureÚclient_proofs                      r*   rB   zAuthScram.on_challenge  sñ  € ØÔ 7Ò*Ð*Ð*Ð*ØÔ!Ð-Ð-Ð-Ø>Ð>Ð>ˆØ!Ð#4Ð5ˆØð 	ð 	ˆAØ˜	œÐ'Ð'Ý"ð2ß28²&¸±)´)ñô ð ð (ð
 ”ð 	ð 	ˆAØ˜¨Ñ5Ð5Ð5Ý"ØE×LÒLÈQÑOÔOñô ð ð 6ð
 $œ/×-Ò-Ð.?ÀÑDÔDˆØ ” wÔ/ˆØŒ˜vÔ&ˆÝ˜œ¨Ô6Ñ7Ô7ˆ
Ý�Y”_×(Ò(¨°2Ñ6Ô6Ñ7Ô7ˆØ”:˜jÔ)×0Ò0°Ñ8Ô8ˆÝ˜$œ* XÔ.Ñ/Ô/ˆØ”O EÔ*ˆ	ØÔ)ˆð I×OÒOØ"-×"4Ò"4°V¸\Ñ"JÔ"JØ-×4Ò4°\À4ÈÑTÔTØ&1×&8Ò&8¸È,Ñ&WÔ&Wð Pñ ô ÷
 Š&�‰/Œ/ð 	Ôð ˜Ò%Ð%Ø˜Š|ˆ|Ý ØTñô ð õ %<¸HÀdÈJÐX^Ñ$_Ô$_ˆDÔ!Ð!Ø˜(Ò"Ð"Ý$7¸À$È
Ñ$SÔ$SˆDÔ!Ð!åØ7×>Ò>¸yÑIÔIñô ð õ ”X˜dÔ3°]ÅGÄNÑSÔS×ZÒZÑ\Ô\ˆ
Ý”[ ¨:Ñ6Ô6×=Ò=Ñ?Ô?ˆ
åœ8 J°Ô0BÅGÄNÑSÔS×ZÒZÑ\Ô\ÐÝ  Ð-=Ñ>Ô>ˆåÔ Ñ-Ô-Ð-r4   c                 ó¬  — t          j        |d         ¦  «        }t          j        | j        dt
          j        ¦  «                             ¦   «         }t          j        || j        t
          j        ¦  «                             ¦   «         }t          j	        ||¦  «        s|j
                             d¦  «         dS |j
                             d¦  «         dS )a  
        When the server is satisfied, it sends a 'WELCOME' message.

        This hook allows us an opportunity to deny the session right
        before it gets set up -- we check the server-signature thus
        authorizing the server and if it fails we drop the connection.
        Úscram_server_signatureó
   Server Keyz-Verification of server SCRAM signature failedz1Verification of server SCRAM signature successfulN)rƒ   r„   r²   r³   r±   r´   r¬   rµ   r°   Úcompare_digestÚlogÚerrorÚinfo)r1   r@   r7   Úalleged_server_sigÚ
server_keyÚserver_signatures         r*   rF   zAuthScram.on_welcomeJ  s½   € õ $Ô-¨iÐ8PÔ.QÑRÔRÐÝ”X˜dÔ3°]ÅGÄNÑSÔS×ZÒZÑ\Ô\ˆ
Ýœ8 J°Ô0BÅGÄNÑSÔS×ZÒZÑ\Ô\ÐÝÔ"Ð#3Ð5GÑHÔHð 	CØŒK×ÒÐMÑNÔNÐNØBÐBØŒ×ÒØ?ñ	
ô 	
ð 	
ð ˆtr4   N)
rI   rJ   rK   Ú__doc__r!   r3   rL   r7   rB   rF   r    r4   r*   r   r   ÷   sn   € € € € € ðð ð €Dð"ð "ð "ð ð
ð 
ñ „Xð
ð6.ð 6.ð 6.ðpð ð ð ð r4   r   c                   ó:   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zd„ ZdS )r   Úwampcrac                 ó¤  — |                      ¦   «         D ]3}|dvr-t          d                     || j        j        ¦  «        ¦  «        ‚Œ4dD ](}||vr"t          d                     |¦  «        ¦  «        ‚Œ)|| _        |                     d¦  «        | _        t          | j        t          ¦  «        s!| j         
                    d¦  «        | _        d S d S )N)r7   r[   r\   rz   r^   )rz   r[   zMust provide '{}' for wampcrarz   r¦   )rb   r%   r&   rc   rI   r/   rR   Ú_secretÚ
isinstanceÚstrr¡   )r1   r2   rk   s      r*   r3   zAuthWampCra.__init__d  sì   € à—7’7‘9”9ð 	ð 	ˆCØÐGÐGÐGÝ Ø0×7Ò7¸¸T¼^Ô=TÑUÔUñô ð ð Hð (ð 	ð 	ˆCØ˜"ˆ}ˆ}Ý Ø3×:Ò:¸3Ñ?Ô?ñô ð ð ð
 ˆŒ
Ø—v’v˜hÑ'Ô'ˆŒÝ˜$œ,­Ñ,Ô,ð 	7Øœ<×.Ò.¨vÑ6Ô6ˆDŒLˆLˆLð	7ð 	7r4   c                 óP   — | j                              dt          ¦   «         ¦  «        S r6   r8   r;   s    r*   r7   zAuthWampCra.authextrav  r<   r4   c                 ó4  — | j                              d¦  «        }d|j        v r3t          ||j        d         |j        d         |j        d         ¦  «        }t	          ||j        d                              d¦  «        ¦  «        }|                     d¦  «        S )Nr¦   r{   rˆ   r“   rA   rœ   )rÏ   r¯   r­   r   r   r¡   )r1   r@   rA   rk   Ú	signatures        r*   rB   zAuthWampCra.on_challengez  s–   € ØŒl×!Ò! &Ñ)Ô)ˆØ�Y”_Ð$Ð$ÝØØ” Ô'Ø” Ô-Ø” Ô)ñ	ô ˆCõ  ØØŒO˜KÔ(×/Ò/°Ñ7Ô7ñ
ô 
ˆ	ð ×Ò Ñ(Ô(Ð(r4   c                 ó   — d S r.   r    rD   s      r*   rF   zAuthWampCra.on_welcomeŠ  rG   r4   NrH   r    r4   r*   r   r   a  sa   € € € € € Ø€Dð7ð 7ð 7ð$ ð3ð 3ñ „Xð3ð)ð )ð )ð ð ð ð ð r4   r   é
   c                 ó¨   — t          | ¦  «        t          k    sJ ‚t          j        t	          j        | ¦  «        ¦  «                             d¦  «        S )a  
    Generates a new Base32 encoded, random secret.

    .. seealso:: http://en.wikipedia.org/wiki/Base32

    :param length: The length of the entropy used to generate the secret.
    :type length: int

    :returns: The generated secret in Base32 (letters ``A-Z`` and digits ``2-7``).
       The length of the generated secret is ``length * 8 / 5`` octets.
    :rtype: unicode
    rœ   )r€   r®   rƒ   Ú	b32encoderŸ   r    r¡   ©Úlengths    r*   r   r   ‘  sD   € õ �‰<Œ<�3ÒÐÐÐÝÔ�BœJ vÑ.Ô.Ñ/Ô/×6Ò6°wÑ?Ô?Ð?r4   c                 óB  — t          | ¦  «        t          k    sJ ‚t          |¦  «        t          k    sJ ‚	 t          j        | ¦  «        }n# t
          $ r t          d¦  «        ‚w xY w|t          t          j        ¦   «         ¦  «        dz  z   }t          j	        d|¦  «        }t          j        ||t          j        ¦  «                             ¦   «         }d|d         z  }t          j        d|||dz   …         ¦  «        d         d	z  d
z  }d                     |¦  «        S )aF  
    Computes the current TOTP code.

    :param secret: Base32 encoded secret.
    :type secret: unicode
    :param offset: Time offset (in steps, use eg -1, 0, +1 for compliance with RFC6238)
        for which to compute TOTP.
    :type offset: int

    :returns: TOTP for current time (+/- offset).
    :rtype: unicode
    zinvalid secreté   z>Qé   rx   z>Ié   r   iÿÿÿi@B z{0:06d})r€   rÑ   r®   rƒ   Ú	b32decodeÚ	TypeErrorÚ	ExceptionÚtimeÚstructÚpackr²   r³   r´   Úsha1rµ   Úunpackr&   )rz   Úoffsetrk   ÚintervalrE   rµ   ÚoÚtokens           r*   r   r   £  s  € õ �‰<Œ<�3ÒÐÐÐÝ�‰<Œ<�3ÒÐÐÐð*ÝÔ˜vÑ&Ô&ˆˆøÝð *ð *ð *ÝÐ(Ñ)Ô)Ð)ð*øøøà��DœI™KœKÑ(Ô(¨BÑ.Ñ.€HÝ
Œ+�d˜HÑ
%Ô
%€CÝŒX�c˜3¥¤Ñ-Ô-×4Ò4Ñ6Ô6€FØ
ˆf�RŒjÑ€AÝŒ]˜4 ¨¨!¨a©%¨¤Ñ1Ô1°!Ô4°zÑAÀWÑL€EØ×Ò˜EÑ"Ô"Ð"s   ¶A ÁA%c                 ó>   — dD ]}|t          | |¦  «        k    r dS ŒdS )a  
    Check a TOTP value received from a principal trying to authenticate against
    the expected value computed from the secret shared between the principal and
    the authenticating entity.

    The Internet can be slow, and clocks might not match exactly, so some
    leniency is allowed. RFC6238 recommends looking an extra time step in either
    direction, which essentially opens the window from 30 seconds to 90 seconds.

    :param secret: The secret shared between the principal (eg a client) that
        is authenticating, and the authenticating entity (eg a server).
    :type secret: unicode
    :param ticket: The TOTP value to be checked.
    :type ticket: unicode

    :returns: ``True`` if the TOTP value is correct, else ``False``.
    :rtype: bool
    )r   rv   r¥   TF)r   )rz   rP   rç   s      r*   r   r   ¿  s9   € ð( ð ð ˆØ•\ &¨&Ñ1Ô1Ò1Ð1Ø�4�4ð 2àˆ5r4   c                 ó  — t          | ¦  «        t          k    r/t          d                     t          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        t          k    r/t          d                     t          |¦  «        ¦  «        ¦  «        ‚	 dd l}dd l}n# t          $ r t          d¦  «        ‚w xY w|                     d                     || |¦  «        d|j        j	        j
        ¬¦  «                             ¦   «         S )Nz&secret must be of type unicode, not {}z%label must be of type unicode, not {}r   zqrcode not installedz%otpauth://totp/{}?secret={}&issuer={}é   )Úbox_sizeÚimage_factory)r€   rÑ   rá   r&   ÚqrcodeÚqrcode.image.svgÚImportErrorÚmakeÚimageÚsvgÚSvgImageÚ	to_string)rz   ÚlabelÚissuerrð   s       r*   r   r   Ù  sü   € åˆF�|„|•sÒÐÝÐ@×GÒGÍÈVÉÌÑUÔUÑVÔVÐVåˆE�{„{•cÒÐÝÐ?×FÒFÅtÈEÁ{Ä{ÑSÔSÑTÔTÐTð0ØˆˆˆØÐÐÐÐøÝð 0ð 0ð 0ÝÐ.Ñ/Ô/Ð/ð0øøøð �;Š;Ø/×6Ò6°u¸fÀfÑMÔMØØ”lÔ&Ô/ð ñ 1ô 1÷ 2;²±´ð=s   ÂB ÂB3éè  rw   c                 óà  — t          | ¦  «        t          k    rHt          |¦  «        t          k    r0t          |¦  «        t          k    rt          |¦  «        t          k    st          d¦  «        ‚|€d}|t          u rt          d¦  «        ‚t          ¦   «         }t           t          t          | 	                    ¦   «         ¦  «        ¦   «         ||||¬¦  «        }| 
                    | ¦  «        S )a	  
    Returns a binary digest for the PBKDF2 hash algorithm of ``data``
    with the given ``salt``. It iterates ``iterations`` time and produces a
    key of ``keylen`` bytes. By default SHA-256 is used as hash function,
    a different hashlib ``hashfunc`` can be provided.

    :param data: The data for which to compute the PBKDF2 derived key.
    :type data: bytes
    :param salt: The salt to use for deriving the key.
    :type salt: bytes
    :param iterations: The number of iterations to perform in PBKDF2.
    :type iterations: int
    :param keylen: The length of the cryptographic key to derive.
    :type keylen: int
    :param hashfunc: Name of the hash algorithm to use
    :type hashfunc: str

    :returns: The derived cryptographic key.
    :rtype: bytes
    zInvalid argument typesNr¬   z=pbkdf2 now takes the name of a hash algorithm for 'hashfunc=')r»   rÚ   r{   rˆ   Úbackend)r€   Úbytesr®   r%   Úcallabler
   r   Úgetattrr	   ÚupperÚderive)Údatar{   rˆ   r“   Úhashfuncrü   r£   s          r*   r   r   í  sè   € õ, �‰JŒJ�%ÒÐÝ�‰JŒJ�%ÒÐÝ�ÑÔ¥Ò#Ð#Ý�‰LŒL�CÒÐÝÐ1Ñ2Ô2Ð2ð
 ÐØˆØ•8ÐÐåØKñ
ô 
ð 	
õ ÑÔ€Gõ Ø3•'�& (§.¢.Ñ"2Ô"2Ñ3Ô3Ñ5Ô5ØØØØðñ ô €Cð �:Š:�dÑÔÐr4   c                 ór  — t          | ¦  «        t          t          fvrt          d¦  «        ‚t          |¦  «        t          t          fvrt          d¦  «        ‚t          |¦  «        t          k    st          d¦  «        ‚t          |¦  «        t          k    st          d¦  «        ‚t          | ¦  «        t          k    r|                      d¦  «        } t          |¦  «        t          k    r|                     d¦  «        }t          | |||¦  «        }t          j        |¦  «         	                    ¦   «         S )a  
    Computes a derived cryptographic key from a password according to PBKDF2.

    .. seealso:: http://en.wikipedia.org/wiki/PBKDF2

    :param secret: The secret.
    :type secret: bytes or unicode
    :param salt: The salt to be used.
    :type salt: bytes or unicode
    :param iterations: Number of iterations of derivation algorithm to run.
    :type iterations: int
    :param keylen: Length of the key to derive in bytes.
    :type keylen: int

    :return: The derived key in Base64 encoding.
    :rtype: bytes
    z'secret' must be bytesz'salt' must be bytesz'iterations' must be an integerz'keylen' must be an integerr¦   )
r€   rÑ   rý   r%   r®   r¯   r   rf   Ú
b2a_base64Ústrip)rz   r{   rˆ   r“   rk   s        r*   r   r   !  s  € õ& �‰LŒL�S¥%˜LÐ(Ð(ÝÐ1Ñ2Ô2Ð2Ý�‰JŒJ�3¥˜,Ð&Ð&ÝÐ/Ñ0Ô0Ð0Ý�ÑÔ¥Ò#Ð#ÝÐ:Ñ;Ô;Ð;Ý�‰LŒL�CÒÐÝÐ6Ñ7Ô7Ð7ÝˆF�|„|•sÒÐØ—’˜vÑ&Ô&ˆÝˆD�z„z•SÒÐØ�{Š{˜6Ñ"Ô"ˆÝ
�˜˜z¨6Ñ
2Ô
2€CÝÔ˜sÑ#Ô#×)Ò)Ñ+Ô+Ð+r4   Ú>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789é   c                 ó´   — t          | ¦  «        t          k    sJ ‚d                     d„ t          | ¦  «        D ¦   «         ¦  «                             d¦  «        S )aw  
    Generates a new random secret for use with WAMP-CRA.

    The secret generated is a random character sequence drawn from

    - upper and lower case latin letters
    - digits
    -

    :param length: The length of the secret to generate.
    :type length: int

    :return: The generated secret. The length of the generated is ``length`` octets.
    :rtype: bytes
    r¤   c              3   óH   K  — | ]}t          j        t          ¦  «        V — Œd S r.   )ÚrandomÚchoiceÚWCS_SECRET_CHARSET)Ú.0r‹   s     r*   ú	<genexpr>zgenerate_wcs.<locals>.<genexpr>\  s-   è è € ÐLÐL¸•6”=Õ!3Ñ4Ô4ÐLÐLÐLÐLÐLÐLr4   rœ   )r€   r®   ÚjoinÚranger¯   rÙ   s    r*   r   r   J  sQ   € õ" �‰<Œ<�3ÒÐÐÐØ�7Š7ÐLÐL½eÀF¹m¼mÐLÑLÔLÑLÔL×SÒSÐT[Ñ\Ô\Ð\r4   c                 óâ  — t          | ¦  «        t          t          fv sJ ‚t          |¦  «        t          t          fv sJ ‚t          | ¦  «        t          k    r|                      d¦  «        } t          |¦  «        t          k    r|                     d¦  «        }t	          j        | |t          j        ¦  «                             ¦   «         }t          j
        |¦  «                             ¦   «         S )aY  
    Compute an WAMP-CRA authentication signature from an authentication
    challenge and a (derived) key.

    :param key: The key derived (via PBKDF2) from the secret.
    :type key: bytes
    :param challenge: The authentication challenge to sign.
    :type challenge: bytes

    :return: The authentication signature.
    :rtype: bytes
    r¦   )r€   rÑ   rý   r¯   r²   r³   r´   r¬   rµ   rf   r  r  )rk   rA   Úsigs      r*   r   r   _  s¾   € õ �‰9Œ9��e˜Ð$Ð$Ð$Ð$Ý�	‰?Œ?�s¥E˜lÐ*Ð*Ð*Ð*ÝˆC�y„y•CÒÐØ�jŠj˜Ñ Ô ˆÝˆI�„�#ÒÐØ×$Ò$ VÑ,Ô,ˆ	Ý
Œ(�3˜	¥7¤>Ñ
2Ô
2×
9Ò
9Ñ
;Ô
;€CÝÔ˜sÑ#Ô#×)Ò)Ñ+Ô+Ð+r4   Úemailr‡   r{   Úreturnc           
      ó¾  — t           s
J d¦   «         ‚ddlm} ddlm} |sWt	          j        ¦   «         }|                     |                      d¦  «        ¦  «         |                     ¦   «         dd…         }t          |¦  «        dk    sJ ‚ ||                     d¦  «        |dd	d
d|j
        d¬¦  «        }|                     d¦  «                             d¦  «        \  }}}	}
}}|dk    sJ ‚|	dk    sJ ‚d„ d„ |
                     d¦  «        D ¦   «         D ¦   «         }
|                     d¦  «        }t          j        |dt          j        ¦  «                             ¦   «         }t	          j        d|¦  «                             ¦   «         }t          j        |dt          j        ¦  «                             ¦   «         }dt          |
d         ¦  «        t          |
d         ¦  «        t!          j        |¦  «                             d¦  «        t!          j        |¦  «                             d¦  «        t!          j        |¦  «                             d¦  «        dœ}|S )a?  
    Derive WAMP-SCRAM credentials from user email and password. The SCRAM parameters used
    are the following (these are also contained in the returned credentials):

    * kdf ``argon2id-13``
    * time cost ``4096``
    * memory cost ``512``
    * parallelism ``1``

    See `draft-irtf-cfrg-argon2 <https://datatracker.ietf.org/doc/draft-irtf-cfrg-argon2/>`__ and
    `argon2-cffi <https://argon2-cffi.readthedocs.io/en/stable/>`__.

    :param email: User email.
    :param password: User password.
    :param salt: Optional salt to use (must be 16 bytes long). If none is given, compute salt
        from email as ``salt = SHA256(email)[:16]``.
    :return: WAMP-SCRAM credentials. When serialized, the returned credentials can be copy-pasted
        into the ``config.json`` node configuration for a Crossbar.io node.
    zmissing dependency argon2r   r   r   r¦   Nr›   i   i   rv   rw   rx   ry   rœ   ú$Úargon2idzv=19c                 ó   — i | ]\  }}||“Œ	S r    r    )r  r¹   Úvs      r*   ú
<dictcomp>z+derive_scram_credential.<locals>.<dictcomp>£  s.   € ð ð ð áˆAˆqð 	
ˆ1ðð ð r4   c                 ó8   — g | ]}|                      d ¦  «        ‘ŒS )ú=)r†   )r  Úxs     r*   ú
<listcomp>z+derive_scram_credential.<locals>.<listcomp>¦  s"   € Ð1Ð1Ð1˜!ˆ�Š�‰ŒÐ1Ð1Ð1r4   ú,r«   r¬   rÃ   rª   ÚmÚt)r£   r‰   rˆ   r{   z
stored-keyz
server-key)r˜   Úargon2.low_levelr   r   r´   r¬   Úupdater¯   rµ   Úlenr…   r¡   r†   r²   r³   r®   rf   Úb2a_hex)r  r‡   r{   r   r   r!  r�   r‹   rŒ   r  ÚparamsÚsalted_passwordr½   r¾   rÉ   Ú
credentials                   r*   r   r   w  s]  € õ( Ð1Ð1Ð1Ñ1Ô1Ð1Ø,Ð,Ð,Ð,Ð,Ð,Ø%Ð%Ð%Ð%Ð%Ð%ð ð ÝŒNÑÔˆØ	�Š�—’˜fÑ%Ô%Ñ&Ô&Ð&Ø�xŠx‰zŒz˜#˜2˜#ŒˆÝˆt‰9Œ9˜Š?ˆ?ˆ?ˆ?à�Ø�Š˜vÑ&Ô&ØØØØØØŒWØð	ñ 	ô 	€Ið -6×,<Ò,<¸WÑ,EÔ,E×,KÒ,KÈCÑ,PÔ,PÑ)€A€sˆAˆv�q˜/Ø�*ÒÐÐÐØ�Š;ˆ;ˆ;ˆ;ðð ð 	2Ð1˜vŸ|š|¨CÑ0Ô0Ð1Ñ1Ô1ðñ ô €Fð &×,Ò,¨WÑ5Ô5€OÝ”˜/¨=½'¼.ÑIÔI×PÒPÑRÔR€JÝ”˜X zÑ2Ô2×9Ò9Ñ;Ô;€JÝ”˜/¨=½'¼.ÑIÔI×PÒPÑRÔR€Jð Ý�f˜S”kÑ"Ô"Ý˜& œ+Ñ&Ô&ÝÔ  Ñ&Ô&×-Ò-¨gÑ6Ô6ÝÔ& zÑ2Ô2×9Ò9¸'ÑBÔBÝÔ& zÑ2Ô2×9Ò9¸'ÑBÔBðð €Jð Ðr4   )rÖ   )r   )rú   rw   N)rú   rw   )r  r.   )8rŸ   rƒ   rã   râ   rf   r²   r´   r  Útypingr   r   Úautobahn.utilr   r   r¶   Úautobahn.wamp.interfacesr   Ú)cryptography.hazmat.primitives.kdf.pbkdf2r   Úcryptography.hazmat.primitivesr	   Úcryptography.hazmat.backendsr
   r#  r   Úargon2r   Úpasslib.utilsr   r˜   rò   Ú__all__r   Úobjectr   Úregisterr#   r   r   r"   r‘   r”   r   r   r   r   r   r   r   r   r  r   r   rÑ   rý   r   r    r4   r*   ú<module>r5     s€  ðð6 
€	€	€	Ø €€€Ø €€€Ø €€€Ø €€€Ø €€€Ø €€€Ø €€€Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !à  Ð  Ð  Ð  Ð  Ð  Ø *Ð *Ð *Ð *Ð *Ð *Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3à @Ð @Ð @Ð @Ð @Ð @Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8ðØ,Ð,Ð,Ð,Ð,Ð,ØÐÐÐÐÐØ&Ð&Ð&Ð&Ð&Ð&Ø€I€IøØð ð ð Ø€I€I€Iðøøøð€ð&ð ð ð:ð ð ð ð �Fñ ô ð ð& €Ô ˜Ñ &Ô &Ð &ðð ð ð ð ˜ñ ô ð ð €Ô Ð*Ñ +Ô +Ð +ðð ð ð ð �ñ ô ð ð0 €Ô ˜
Ñ #Ô #Ð #ð-ð -ð -ð -ð -�Vñ -ô -ð -ð` €Ô ˜Ñ 'Ô 'Ð 'ðð ð ð ð ˜.ñ ô ð ð €Ô Ð+Ñ ,Ô ,Ð ,ðð ð ð,9ð 9ð 9ðdð dð dð dð d�ñ dô dð dðN €Ô ˜	Ñ "Ô "Ð "ð*ð *ð *ð *ð *�&ñ *ô *ð *ðZ €Ô ˜Ñ $Ô $Ð $ð ð@ð @ð @ñ „ð@ð" ð#ð #ð #ñ „ð#ð6 ðð ñ „ðð2 ð=ð =ñ „ð=ð& ð0ð 0ð 0ñ „ð0ðf ð,ð ,ð ,ñ „ð,ðD VÐ ðð
 ð]ð ]ð ]ñ „ð]ð( ð,ð ,ñ „ð,ð.?ð ? 3ð ?°#ð ?¸XÀe¼_ð ?ÐX\ð ?ð ?ð ?ð ?ð ?ð ?s   ÁA# Á#A-Á,A-