HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/site-packages/zmq/auth/__pycache__/base.cpython-36.pyc
3

VS�_�9�@stdZddlZddlZddlmZddlmZmZmZm	Z	ddl
mZddlm
Z
dZd	ZGd
d�de�ZddgZdS)
z*Base implementation of 0MQ authentication.�N)�z85)�bytes�unicode�b�u)�_check_version�)�load_certificates�*s1.0c@s�eZdZdZd$dd�Zdd�Zdd	�Zd
d�Zdd
�Zd%dd�Z	d&dd�Z
d'dd�Zdd�Zd(dd�Z
dd�Zdd�Zdd�Zdd �Zd)d"d#�ZdS)*�
Authenticatora�Implementation of ZAP authentication for zmq connections.

    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.
    N�utf-8cCsbtdd�|ptjj�|_||_d|_i|_d|_t	�|_
t	�|_i|_i|_
|pZtjd�|_dS)N�rZsecurityFzzmq.auth)r
r)r�zmqZContext�instance�context�encoding�	allow_any�credentials_providers�
zap_socket�set�	whitelist�	blacklist�	passwords�certs�loggingZ	getLogger�log)�selfrrr�r�/usr/lib64/python3.6/base.py�__init__s
zAuthenticator.__init__cCs4|jjtj�|_d|j_|jjd�|jjd�dS)zCreate and bind the ZAP socketrzinproc://zeromq.zap.01ZStartingN)	rZsocketrZREPrZlingerZbindr�debug)rrrr�start0szAuthenticator.startcCs|jr|jj�d|_dS)zClose the ZAP socketN)r�close)rrrr�stop7s
zAuthenticator.stopcGs2|jrtd��|jjddj|��|jj|�dS)aaAllow (whitelist) IP address(es).
        
        Connections from addresses not in the whitelist 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.
        
        whitelist is mutually exclusive with blacklist.
        z-Only use a whitelist or a blacklist, not bothzAllowing %s�,N)r�
ValueErrorrr �joinr�update)r�	addressesrrr�allow=s
zAuthenticator.allowcGs2|jrtd��|jjddj|��|jj|�dS)z�Deny (blacklist) IP address(es).
        
        Addresses not in the blacklist will be allowed to continue with authentication.
        
        Blacklist is mutually exclusive with whitelist.
        z-Only use a whitelist or a blacklist, not bothz
Denying %sr$N)rr%rr r&rr')rr(rrr�denyLszAuthenticator.denyr
cCs |r||j|<|jjd|�dS)z�Configure 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.
        zConfigure plain: %sN)rrr )r�domainrrrr�configure_plainXs
zAuthenticator.configure_plaincCsp|jjd||�|tkr d|_nLd|_yt|�|j|<Wn2tk
rj}z|jjd||�WYdd}~XnXdS)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.
        zConfigure curve: %s[%s]TFz&Failed to load CURVE certs from %s: %sN)rr �CURVE_ALLOW_ANYrr	r�	Exception�error)rr+�location�errr�configure_curvecszAuthenticator.configure_curvecCs,d|_|dk	r||j|<n|jjd|�dS)aConfigure 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 "*".

        To allow all client keys without checking, specify CURVE_ALLOW_ANY for the location.
        FNz0None credentials_provider provided for domain:%s)rrrr/)rr+Zcredentials_providerrrr�configure_curve_callback|sz&Authenticator.configure_curve_callbackcCstj|�jd�S)aReturn 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)rZclient_public_keyrrr�
curve_user_id�szAuthenticator.curve_user_idcCsdS)z�Configure GSSAPI authentication
        
        Currently this is a no-op because there is nothing to configure with GSSAPI.
        Nr)rr+r0rrr�configure_gssapi�szAuthenticator.configure_gssapics�t|�dkrJ�jjd|�t|�dkr4�jjd�n�j|ddd�dS|dd�\}}}}}}|dd�}t|�jd	�}t|�jd	�}|tkr��jjd
|��j|dd�dS�jjd||||||�d
}	d
}
d}�j�r|�jkr�d}	�jjd|�nd}
d}�jjd|�n>�j	�rR|�j	k�r@d}
d}�jjd|�nd}	�jjd|�td�}|
�s�|dk�r�|	�r��jjd�d}	�n|dk�r�t|�dk�r��jjd|��j|dd�dS�fdd�|D�\}}
�j
|||
�\}	}n�|dk�rJt|�dk�r �jjd|��j|dd�dS|d }�j||�\}	}|	�r��j|�}nT|d!k�r�t|�dk�r��jjd"|��j|dd�dS|d }}�j
||�\}	}|	�r��j|d#d$|�n�j|d|�dS)%zPerform ZAP authentication�z*Invalid ZAP message, not enough frames: %r�zNot enough information to replyrs400sNot enough framesN�replacezInvalid ZAP version: %rsInvalid versionzQversion: %r, request_id: %r, domain: %r, address: %r, identity: %r, mechanism: %rFs	NO ACCESSTzPASSED (whitelist) address=%ssAddress not in whitelistz$DENIED (not in whitelist) address=%ssAddress is blacklistedzDENIED (blacklist) address=%sz$PASSED (not in blacklist) address=%s�	anonymoussNULLzALLOWED (NULL)sPLAINzInvalid PLAIN credentials: %rsInvalid credentialscsg|]}t|�jd��qS)r;)rr)�.0�c)rrr�
<listcomp>�sz4Authenticator.handle_zap_message.<locals>.<listcomp>sCURVEzInvalid CURVE credentials: %rrsGSSAPIzInvalid GSSAPI credentials: %rs200sOK)�lenrr/�_send_zap_replyrr�VERSIONr rr�_authenticate_plain�_authenticate_curver7�_authenticate_gssapi)r�msg�version�
request_idr+ZaddressZidentityZ	mechanismZcredentials�allowedZdenied�reason�username�password�key�	principalr)rr�handle_zap_message�s�




z Authenticator.handle_zap_messagecCs�d}d}|jr~|sd}||jkrR||j|krL||j||krFd}qPd}qVd}nd}|rn|jjd|||�q�|jjd	|�nd
}|jjd|�||fS)zPLAIN ZAP authenticationF�r
TsInvalid passwordsInvalid usernamesInvalid domainz1ALLOWED (PLAIN) domain=%s username=%s password=%sz	DENIED %ssNo passwords definedzDENIED (PLAIN) %s)rrr )rr+rKrLrIrJrrrrCs&
z!Authenticator._authenticate_plaincCs�d}d}|jr$d}d}|jjd�n�|jikr�|s6d}||jkr�tj|�}|j|j||�rfd}d}nd}|rrdnd	}|jjd
|||�q�d}n^|s�d}||jkr�tj|�}|j|j|�r�d}d}nd}|r�dnd	}|jjd|||�nd}||fS)
zCURVE ZAP authenticationFrPTsOKz ALLOWED (CURVE allow any client)r
sUnknown keyZALLOWEDZDENIEDz0%s (CURVE auth_callback) domain=%s client_key=%ssUnknown domainz"%s (CURVE) domain=%s client_key=%s)	rrr rrr5�callbackr�get)rr+Z
client_keyrIrJZz85_client_keyZstatusrrrrD9s@




z!Authenticator._authenticate_curvecCs|jjd||�dS)zPNothing to do for GSSAPI, which has already been handled by an external service.z'ALLOWED (GSSAPI) domain=%s principal=%sT�OK)TrS)rr )rr+rNrrrrElsz"Authenticator._authenticate_gssapir<cCs\|dkr|nd}t|t�r(|j|jd�}d}|jjd||�t|||||g}|jj|�dS)z.Send a ZAP reply to finish the authentication.s200rPr;zZAP reply code=%s text=%sN)	�
isinstancerr5rrr rBrZsend_multipart)rrHZstatus_codeZstatus_textZuser_idZmetadataZreplyrrrrAqs
zAuthenticator._send_zap_reply)NrN)r
N)r
N)r
N)r
N)r<)�__name__�
__module__�__qualname__�__doc__rr!r#r)r*r,r2r3r7r8rOrCrDrErArrrrrs 




"
^!3rr-)rXrrZ	zmq.utilsrZzmq.utils.strtypesrrrrZ	zmq.errorrrr	r-rB�objectr�__all__rrrr�<module>sj