Ϫf"dZddlZddlZddlZddlZddlmZddlmZm Z m Z ddl m Z Gdde Z e e Gdd Ze e Gd d Ze e Gd d Zy)zF Protocol agnostic implementations of SASL authentication mechanisms. N)md5) Attribute Interface implementer) networkStringc(eZdZedZdZdZy)ISASLMechanismz#Common name for the SASL Mechanism.cy)z Get the initial client response, if defined for this mechanism. @return: initial client response string. @rtype: C{str}. Nr P/usr/lib/python3/dist-packages/twisted/words/protocols/jabber/sasl_mechanisms.pygetInitialResponsez!ISASLMechanism.getInitialResponser cy)z Get the response to a server challenge. @param challenge: server challenge. @type challenge: C{str}. @return: client response. @rtype: C{str}. Nr ) challenges r getResponsezISASLMechanism.getResponse!rr N)__name__ __module__ __qualname__rnamerrr r r r r s > ?D  r r c eZdZdZdZdZdZy) Anonymouszm Implements the ANONYMOUS SASL authentication mechanism. This mechanism is defined in RFC 2245. ANONYMOUScyNr selfs r rzAnonymous.getInitialResponse6r cyrr rrs r rzAnonymous.getResponse9 r N)rrr__doc__rrrr r r rr,s D r rc&eZdZdZdZdZdZdZy)Plainz Implements the PLAIN SASL authentication mechanism. The PLAIN SASL authentication mechanism is defined in RFC 2595. PLAINcF|xsd|_|xsd|_|xsd|_y)a  @param authzid: The authorization identity. @type authzid: L{unicode} @param authcid: The authentication identity. @type authcid: L{unicode} @param password: The plain-text password. @type password: L{unicode} N)authzidauthcidpassword)rr(r)r*s r __init__zPlain.__init__Hs%}" }"  B r c|jjddz|jjdzdz|jjdzS)Nzutf-8)r(encoder)r*rs r rzPlain.getInitialResponseXs[ LL   ( ll!!'* + mm""7+  , r cyrr r s r rzPlain.getResponsear!r N)rrrr"rr+rrr r r r$r$>s D'   r r$cDeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) DigestMD5z Implements the DIGEST-MD5 SASL authentication mechanism. The DIGEST-MD5 SASL authentication mechanism is defined in RFC 2831. z DIGEST-MD5c|||_||_||_|d||_||xjd|z c_yy)a @param serv_type: An indication of what kind of server authentication is being attempted against. For example, C{u"xmpp"}. @type serv_type: C{unicode} @param host: The authentication hostname. Also known as the realm. This is used as a scope to help select the right credentials. @type host: C{unicode} @param serv_name: An additional identifier for the server. @type serv_name: C{unicode} @param username: The authentication username to use to respond to a challenge. @type username: C{unicode} @param password: The authentication password to use to respond to a challenge. @type password: C{unicode} /N)usernamer* defaultRealm digest_uri)r serv_typehost serv_namer4r*s r r+zDigestMD5.__init__psK*!    &Kq/  OO9+ .O !r cyrr rs r rzDigestMD5.getInitialResponserr c|j|}d|vry|djd} |d}|j |||dS#t$r|jj |}Ycnoncer? digest-urisauthzidrNrHrK)itemsappendjoin)rrDdirective_listrrZ directives r _unparsezDigestMD5._unparseso%++- -KD%!4K%/  4K%/  ! !) , - yy((r c  d d} fd}  |dz|zdz|zdz|zdz|z} d|z} || | | |dz|zdz|zdzdzdz| | z} | S)z Calculates response with given encoded parameters. @return: The I{response} field of a response to a Digest-MD5 challenge of the given parameters. @rtype: L{bytes} c4t|jSr)rdigest)rTs r Hz'DigestMD5._calculateResponse..Hsq6==? "r c,tj|Sr)binasciib2a_hex)ns r HEXz)DigestMD5._calculateResponse..HEXs##A& &r c |dz|zS)N:r )krTris r KDz(DigestMD5._calculateResponse..KDsQX\? "r rps AUTHENTICATE:authr )rcnoncencnoncer4r*rFurirnrra1a2responseris @r _calculateResponsezDigestMD5._calculateResponses # ' #x$&-8 9D @5 H4 ORX X  # AbE  r!D(61D87BTICPQRTPUJV   r c  |jj|}|jj|}|jj|}t dd}|j }d} |j|||||||} |||||| || |jdd } |j| S#t$rwxYw)z Generate response-value. Creates a response to a challenge according to section 2.1.2.1 of RFC 2831 using the C{charset}, C{realm} and C{nonce} directives from the challenge. rI08xrsr=) r]r>r?r^sncrMr_sresponser<) r4r.r*r6 UnicodeErrorr _gen_noncer{re) rrErFrvr4r*r6rurtqoprzrDs r rCzDigestMD5._genResponse s }}++G4H}}++G4H//8J aW &"** Bx5*  "%!w/  }}Z((3   s AB55 Ccdtjtjtjfz}t |}t |j jdS)Nz%f:%f:%dr=)randomtimeosgetpidrr hexdigestr.)r nonceString nonceBytess r rzDigestMD5._gen_nonce0sM FMMOTYY["))+#NN ";/ :((*11'::r N) rrrr"rr+rrr@rer{rCrr r r r1r1fs9 D/:G"*X)>:%)N;r r1)r"rkrrrhashlibrzope.interfacerrrtwisted.python.compatrr rr$r1r r r rs   <</ Y , ^   " ^$ $ $ N ^L;L;L;r