/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/words/protocols/jabber/__pycache__/sasl.cpython-310.pyc (7829B)
o
b @ s d Z ddlZddlmZmZ ddlmZ ddlmZm Z ddl
mZ dZdd Z
G d
d deZG dd
d
eZG dd deZG dd deZedZdd ZG dd de jZdS )z
XMPP-specific SASL profile.
N) b64decode b64encode)defer)sasl_mechanisms xmlstream)domishz urn:ietf:params:xml:ns:xmpp-saslc C s8 g }| j tdf D ]}|jdkr|t| q|S )zJ
Parse the SASL feature to extract the available mechanism names.
mechanisms mechanism)featuresNS_XMPP_SASLelementsnameappendstr)xsr element r E/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/sasl.pyget_mechanisms s
r c @ e Zd ZdZdS ) SASLErrorz
SASL base exception.
N__name__
__module____qualname____doc__r r r r r r c @ r )SASLNoAcceptableMechanismzB
The server did not present an acceptable SASL mechanism.
Nr r r r r r % r r c @ s( e Zd ZdZdddZdefddZdS )
SASLAuthErrorz%
SASL Authentication failed.
Nc C s
|| _ d S N condition)selfr! r r r __init__0
zSASLAuthError.__init__returnc C s
d| j S )NzSASLAuthError with condition %rr r" r r r __str__3 r$ zSASLAuthError.__str__r )r r r r r# r r' r r r r r + s
r c @ r )SASLIncorrectEncodingErrora
SASL base64 encoding was incorrect.
RFC 3920 specifies that any characters not in the base64 alphabet
and padding characters present elsewhere than at the end of the string
MUST be rejected. See also L{fromBase64}.
This exception is raised whenever the encoded string does not adhere
to these additional restrictions or when the decoding itself fails.
The recommended behaviour for so-called receiving entities (like servers in
client-to-server connections, see RFC 3920 for terminology) is to fail the
SASL negotiation with a C{'incorrect-encoding'} condition. For initiating
entities, one should assume the receiving entity to be either buggy or
malevolent. The stream should be terminated and reconnecting is not
advised.
Nr r r r r r( 7 r r( z"^[0-9A-Za-z+/]*[0-9A-Za-z+/=]{,2}$c
C sD t | du r
t zt| W S ty! } ztt|d}~ww )a
Decode base64 encoded string.
This helper performs regular decoding of a base64 encoded string, but also
rejects any characters that are not in the base64 alphabet and padding
occurring elsewhere from the last or last two characters, as specified in
section 14.9 of RFC 3920. This safeguards against various attack vectors
among which the creation of a covert channel that "leaks" information.
N)
base64Patternmatchr( r Exceptionr )ser r r
fromBase64N s
r. c @ sX e Zd ZdZedfZdZdd Zdd Zddd Z dddZ
d
d Zdd Zdd Z
dS )SASLInitiatingInitializera
Stream initializer that performs SASL authentication.
The supported mechanisms by this initializer are C{DIGEST-MD5}, C{PLAIN}
and C{ANONYMOUS}. The C{ANONYMOUS} SASL mechanism is used when the JID, set
on the authenticator, does not have a localpart (username), requesting an
anonymous session where the username is generated by the server.
Otherwise, C{DIGEST-MD5} and C{PLAIN} are attempted, in that order.
r Nc C s | j jj}| j jj}t| j }|jdur8d|v r&td|jd|j|| _ dS d|v r5t
d|j|| _ dS t d|v rCt | _ dS t )aP
Select and setup authentication mechanism.
Uses the authenticator's C{jid} and C{password} attribute for the
authentication credentials. If no supported SASL mechanisms are
advertized by the receiving party, a failing deferred is returned with
a L{SASLNoAcceptableMechanism} exception.
Nz
DIGEST-MD5xmppPLAIN ANONYMOUS)
r
authenticatorjidpasswordr userr DigestMD5hostr Plainr Anonymous)r" r4 r5 r r r r setMechanismp s
z&SASLInitiatingInitializer.setMechanismc C sX | t | _| jd| j | jd| j | jd| j |
| j | jS )z5
Start SASL authentication exchange.
/challenge/success/failure)
r; r Deferred _deferredr addObserveronChallengeaddOnetimeObserver onSuccess onFailuresendAuthr getInitialResponser&