
    hA                         S r SSKrSSKrSSKJrJrJrJrJrJ	r	J
r
Jr  SSKrSSKJr  SSKJr  SSKJr  SrS	r " S
 S5      rSS/rg)z*Base implementation of 0MQ authentication.    N)Any	AwaitableDictListOptionalSetTupleUnion)_check_version)z85   )load_certificates*s   1.0c                   l   \ rS rSr% SrS\S'   \\S'   \\S'   \\\	4   \S'   S\S	'   \
\   \S
'   \
\   \S'   \\\\\4   4   \S'   \\\\\	4   4   \S'   \	\S'      S/S\S   S\S\	4S jjrS0S jrS0S jrS\SS4S jrS\SS4S jr S1S\S\\\\4      SS4S jjr S2S\S\\\R*                  4   SS4S jjr S1S\S\	SS4S jjrS\S\4S jr S1S\S\\   SS4S jjrS \\   4S! jrS\S"\S#\S\\\4   4S$ jrS\S%\S\\\4   4S& jrS\S'\S\\\4   4S( jr S3S)\S*\S+\S,\SS4
S- jjr S.r!g)4Authenticator   a  Implementation of ZAP authentication for zmq connections.

This authenticator class does not register with an event loop. As a result,
you will need to manually call `handle_zap_message`::

    auth = zmq.Authenticator()
    auth.allow("127.0.0.1")
    auth.start()
    while True:
        await auth.handle_zap_msg(auth.zap_socket.recv_multipart())

Alternatively, you can register `auth.zap_socket` with a poller.

Since many users will want to run ZAP in a way that does not block the
main thread, other authentication classes (such as :mod:`zmq.auth.thread`)
are provided.

Note:

- libzmq provides four levels of security: default NULL (which the Authenticator does
  not see), and authenticated NULL, PLAIN, CURVE, and GSSAPI, which the Authenticator can see.
- until you add policies, all incoming NULL connections are allowed.
  (classic ZeroMQ behavior), and all PLAIN and CURVE connections are denied.
- GSSAPI requires no configuration.
zzmq.Contextcontextencoding	allow_anycredentials_providersz
zmq.Socket
zap_socket_allowed_denied	passwordscertslogNc                 J   [        SS5        U=(       d    [        R                  R                  5       U l        X l        SU l        0 U l        S U l        [        5       U l
        [        5       U l        0 U l        0 U l        U=(       d    [        R                  " S5      U l        g )N)   r   securityFzzmq.auth)r   zmqContextinstancer   r   r   r   r   setr   r   r   r   logging	getLoggerr   )selfr   r   r   s       `C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\zmq/auth/base.py__init__Authenticator.__init__:   s}     	vz*8#++"6"6"8 %'"u  
7'++J7    returnc                    U R                   R                  [        R                  [        R                  S9U l        SU R
                  l        U R
                  R                  S5        U R                  R                  S5        g)zCreate and bind the ZAP socket)socket_classr   zinproc://zeromq.zap.01StartingN)
r   socketr    REPSocketr   lingerbindr   debugr&   s    r'   startAuthenticator.startP   sT    ,,--cggCJJ-O!"56z"r*   c                 h    U R                   (       a  U R                   R                  5         SU l         g)zClose the ZAP socketN)r   closer5   s    r'   stopAuthenticator.stopW   s     ??OO!!#r*   	addressesc                     U R                   (       a  [        S5      eU R                  R                  SSR	                  U5      5        U R
                  R                  U5        g)a  Allow IP address(es).

Connections from addresses not explicitly allowed will be rejected.

- For NULL, all clients from this address will be accepted.
- For real auth setups, they will be allowed to continue with authentication.

allow is mutually exclusive with deny.
z Only use allow or deny, not bothzAllowing %s,N)r   
ValueErrorr   r4   joinr   updater&   r<   s     r'   allowAuthenticator.allow]   sD     <<?@@}chhy&9:Y'r*   c                     U R                   (       a  [        S5      eU R                  R                  SSR	                  U5      5        U R
                  R                  U5        g)zDeny IP address(es).

Addresses not explicitly denied will be allowed to continue with authentication.

deny is mutually exclusive with allow.
z"Only use a allow or deny, not bothz
Denying %sr>   N)r   r?   r   r4   r@   r   rA   rB   s     r'   denyAuthenticator.denyl   sD     ==ABB|SXXi%89I&r*   domainc                 f    U(       a  X R                   U'   U R                  R                  SU5        g)zConfigure PLAIN authentication for a given domain.

PLAIN authentication uses a plain-text password file.
To cover all domains, use "*".
You can modify the password file at any time; it is reloaded automatically.
zConfigure plain: %sNr   r   r4   )r&   rH   r   s      r'   configure_plainAuthenticator.configure_plainx   s&     %.NN6",f5r*   locationc                    U R                   R                  SX5        U[        :X  a  SU l        gSU l         [	        U5      U R
                  U'   g! [         a&  nU R                   R                  SX#5         SnAgSnAff = f)a  Configure CURVE authentication for a given domain.

CURVE authentication uses a directory that holds all public client certificates,
i.e. their public keys.

To cover all domains, use "*".

You can add and remove certificates in that directory at any time. configure_curve must be called
every time certificates are added or removed, in order to update the Authenticator's state

To allow all client keys without checking, specify CURVE_ALLOW_ANY for the location.
zConfigure curve: %s[%s]TFz&Failed to load CURVE certs from %s: %sN)r   r4   CURVE_ALLOW_ANYr   r   r   	Exceptionerror)r&   rH   rM   es       r'   configure_curveAuthenticator.configure_curve   sn    " 	0&C&!DN"DNV%6x%@

6" VGUUVs   A 
B A;;B credentials_providerc                 n    SU l         Ub  X R                  U'   gU R                  R                  SU5        g)a9  Configure CURVE authentication for a given domain.

CURVE authentication using a callback function validating
the client public key according to a custom mechanism, e.g. checking the
key against records in a db. credentials_provider is an object of a class which
implements a callback method accepting two parameters (domain and key), e.g.::

    class CredentialsProvider(object):

        def __init__(self):
            ...e.g. db connection

        def callback(self, domain, key):
            valid = ...lookup key and/or domain in db
            if valid:
                logging.info('Authorizing: {0}, {1}'.format(domain, key))
                return True
            else:
                logging.warning('NOT Authorizing: {0}, {1}'.format(domain, key))
                return False

To cover all domains, use "*".
FNz0None credentials_provider provided for domain:%s)r   r   r   rQ   )r&   rH   rU   s      r'   configure_curve_callback&Authenticator.configure_curve_callback   s2    6 +1E&&v.HHNNMvVr*   client_public_keyc                 L    [         R                  " U5      R                  S5      $ )a  Return the User-Id corresponding to a CURVE client's public key

Default implementation uses the z85-encoding of the public key.

Override to define a custom mapping of public key : user-id

This is only called on successful authentication.

Parameters
----------
client_public_key: bytes
    The client public key used for the given message

Returns
-------
user_id: unicode
    The user ID as text
ascii)r   encodedecode)r&   rY   s     r'   curve_user_idAuthenticator.curve_user_id   s    & zz+,33G<<r*   c                     g)znConfigure GSSAPI authentication

Currently this is a no-op because there is nothing to configure with GSSAPI.
N )r&   rH   rM   s      r'   configure_gssapiAuthenticator.configure_gssapi   s    r*   msgc           	      .  ^ #    [        U5      S:  a^  T R                  R                  SU5        [        U5      S:  a  T R                  R                  S5        gT R                  US   SS5        gUSS u  p#pEpgUSS nUR	                  T R
                  S	5      nUR	                  T R
                  S	5      nU[        :w  a0  T R                  R                  S
U5        T R                  USS5        gT R                  R                  SUUUUUU5        Sn	Sn
SnT R                  (       aP  UT R                  ;   a  Sn	T R                  R                  SU5        OSn
SnT R                  R                  SU5        O`T R                  (       aO  UT R                  ;   a!  Sn
SnT R                  R                  SU5        OSn	T R                  R                  SU5        SnU
(       Gd  US:X  a&  U	(       d  T R                  R                  S5        Sn	GOTUS:X  ab  [        U5      S:w  a0  T R                  R                  SU5        T R                  USS5        gU 4S jU 5       u  pT R                  XLU5      u  pOUS:X  ax  [        U5      S:w  a0  T R                  R                  SU5        T R                  USS5        gUS   nT R                  XN5      I Sh  vN u  pU	(       a  T R                  U5      nOnUS :X  ah  [        U5      S:w  a0  T R                  R                  S!U5        T R                  USS5        gUS   nUR	                  S"5      nT R                  XO5      u  pU	(       a  T R                  US#S$U5        gT R                  USU5        g N7f)%zPerform ZAP authentication   z*Invalid ZAP message, not enough frames: %r   zNot enough information to replyr   s   400s   Not enough framesNreplacezInvalid ZAP version: %rs   Invalid versionzQversion: %r, request_id: %r, domain: %r, address: %r, identity: %r, mechanism: %rFs	   NO ACCESSTzPASSED (allowed) address=%ss   Address not allowedzDENIED (not allowed) address=%ss   Address deniedzDENIED (denied) address=%szPASSED (not denied) address=%s	anonymouss   NULLzALLOWED (NULL)s   PLAINzInvalid PLAIN credentials: %rs   Invalid credentialsc              3   Z   >#    U  H   oR                  TR                  S 5      v   M"     g7f)rh   N)r]   r   ).0cr&   s     r'   	<genexpr>3Authenticator.handle_zap_message.<locals>.<genexpr>$  s$      &@K1HHT]]I66s   (+s   CURVEzInvalid CURVE credentials: %rr   s   GSSAPIzInvalid GSSAPI credentials: %rutf8   200   OK)lenr   rQ   _send_zap_replyr]   r   VERSIONr4   r   r   _authenticate_plain_authenticate_curver^   _authenticate_gssapi)r&   rd   version
request_idrH   addressidentity	mechanismcredentialsalloweddeniedreasonusernamepasswordkey	principals   `               r'   handle_zap_message Authenticator.handle_zap_message   s9    s8a<HHNNGM3x!|@A  $$SVV5IJDGGAVh!"gt}}i8..	:gHHNN4c:  V5GH8		
 ==$--'<gF/@'J\\$,,&*;WE?I G#G/0h&{#q(HHNN#BKP((V=ST&@K&" #'":":6X"Vh&{#q(HHNN#BKP((V=ST!!n(,(@(@(M"M#11#6Hi'{#q(HHNN#C[Q((V=ST'N	$++F3"&";";F"N  VUHE  VV<# #Ns   KNNB>Nr   r   c                    SnSnU R                   (       a  U(       d  SnXR                   ;   a0  X R                   U   ;   a  X0R                   U   U   :X  a  SnOSnOSnOSnU(       a!  U R                  R                  SUUU5        XE4$ U R                  R                  S	U5         XE4$ S
nU R                  R                  SU5        XE4$ )zPLAIN ZAP authenticationFr*   r   Ts   Invalid passwords   Invalid usernames   Invalid domainz1ALLOWED (PLAIN) domain=%s username=%s password=%sz	DENIED %ss   No passwords definedzDENIED (PLAIN) %srJ   )r&   rH   r   r   r~   r   s         r'   ru   !Authenticator._authenticate_plainC  s     >>'~~f55>>&#9(#CC"&!40F*G	  {F3  -FHHNN.7r*   
client_keyc                   #    SnSnU R                   (       a"  SnSnU R                  R                  S5        X44$ U R                  0 :w  a  U(       d  SnXR                  ;   a  [        R
                  " U5      nU R                  U   R                  X5      n[        U[        5      (       a
  UI Sh  vN nU(       a  SnSnOSnU(       a  S	OS
nU R                  R                  SUUU5        X44$ Sn X44$ U(       d  SnXR                  ;   al  [        R
                  " U5      nU R                  U   R                  U5      (       a  SnSnOSnU(       a  S	OS
nU R                  R                  SUUU5        X44$ SnX44$  N7f)zCURVE ZAP authenticationFr*   Trq   z ALLOWED (CURVE allow any client)r   Ns   Unknown keyALLOWEDDENIEDz0%s (CURVE auth_callback) domain=%s client_key=%ss   Unknown domainz"%s (CURVE) domain=%s client_key=%s)r   r   r4   r   r   r\   callback
isinstancer   r   get)r&   rH   r   r~   r   z85_client_keyrstatuss           r'   rv   !Authenticator._authenticate_curvei  s     >>GFHHNN=>f e ''2-333!$J!7..v6??Wa++A"G"F+F&-8F"	@ 3 +2 - #!$J!7::f%)).99"G"F+F&-88"	  +Q  s   B.F 0E>1CF r   c                 <    U R                   R                  SX5        g)zPNothing to do for GSSAPI, which has already been handled by an external service.z'ALLOWED (GSSAPI) domain=%s principal=%s)Trq   )r   r4   )r&   rH   r   s      r'   rw   "Authenticator._authenticate_gssapi  s    @&Tr*   ry   status_codestatus_textuser_idc                     US:X  a  UOSn[        U[        5      (       a  UR                  U R                  S5      nSnU R                  R                  SX#5        [        XX4U/nU R                  R                  U5        g)z.Send a ZAP reply to finish the authentication.rp   r*   rh   zZAP reply code=%s text=%sN)	r   strr\   r   r   r4   rt   r   send_multipart)r&   ry   r   r   r   metadatareplys          r'   rs   Authenticator._send_zap_reply  sk     )F2'gs##nnT]]I>G2KM*;R&&u-r*   )
r   r   r   r   r   r   r   r   r   r   )Nzutf-8N)r+   N)r   N)r   .)ri   )"__name__
__module____qualname____firstlineno____doc____annotations__r   boolr   r   r   bytesr   r(   r6   r:   rC   rF   rK   r
   osPathLikerS   rW   r^   rb   r   r   r	   ru   rv   rw   rs   __static_attributes__ra   r*   r'   r   r      sm   4 MOS>)#hXCc3h'((T%*%%&&	H ,0	8-(8 8 	8,#( ( (
's 
't 
' HL66,4T#s(^,D6	6 FIVV+0bkk1A+BV	V8 >B W W7: W	 WD=u = =, <@+3C=	b=DK b=H$$%($47$	tU{	$L<<',<	tU{	<|3 5 U4QV;EW  #.. . 	.
 . 
. .r*   r   rO   )r   r$   r   typingr   r   r   r   r   r   r	   r
   r    	zmq.errorr   	zmq.utilsr   r   r   rO   rt   r   __all__ra   r*   r'   <module>r      sI    0
  	 J J J 
 $  $
f. f.R -
.r*   