def test_calculateResponse(self): """ The response to a Digest-MD5 challenge is computed according to RFC 2831. """ charset = "utf-8" nonce = b"OA6MG9tEQGm2hh" nc = networkString("{:08x}".format(1)) cnonce = b"OA6MHXh6VqTrRk" username = "******" password = "******" host = "\u0418elwood.innosoft.com" digestURI = "imap/\u0418elwood.innosoft.com".encode(charset) mechanism = sasl_mechanisms.DigestMD5(b"imap", host, None, username, password) response = mechanism._calculateResponse( cnonce, nc, nonce, username.encode(charset), password.encode(charset), host.encode(charset), digestURI, ) self.assertEqual(response, b"7928f233258be88392424d094453c5e3")
def setMechanism(self): """ 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. """ jid = self.xmlstream.authenticator.jid password = self.xmlstream.authenticator.password mechanisms = get_mechanisms(self.xmlstream) if jid.user is not None: if 'DIGEST-MD5' in mechanisms: self.mechanism = sasl_mechanisms.DigestMD5( 'xmpp', jid.host, None, jid.user, password) elif 'PLAIN' in mechanisms: self.mechanism = sasl_mechanisms.Plain(None, jid.user, password) else: raise SASLNoAcceptableMechanism() else: if 'ANONYMOUS' in mechanisms: self.mechanism = sasl_mechanisms.Anonymous() else: raise SASLNoAcceptableMechanism()
def start(self): """ Start SASL authentication exchange. Used 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. """ jid = self.xmlstream.authenticator.jid password = self.xmlstream.authenticator.password mechanisms = get_mechanisms(self.xmlstream) if 'DIGEST-MD5' in mechanisms: self.mechanism = sasl_mechanisms.DigestMD5('xmpp', jid.host, None, jid.user, password) elif 'PLAIN' in mechanisms: self.mechanism = sasl_mechanisms.Plain(None, jid.user, password) else: return defer.fail(SASLNoAcceptableMechanism) self._deferred = defer.Deferred() self.xmlstream.addObserver('/challenge', self.onChallenge) self.xmlstream.addOnetimeObserver('/success', self.onSuccess) self.xmlstream.addOnetimeObserver('/failure', self.onFailure) self.sendAuth(self.mechanism.getInitialResponse()) return self._deferred
def test_getResponseNoRealmIDN(self): """ If the challenge does not include a realm and the host part of the JID includes bytes outside of the ASCII range, the response still includes the host part of the JID as the realm. """ self.mechanism = sasl_mechanisms.DigestMD5( u'xmpp', u'\u00e9chec.example.org', None, u'test', u'secret') challenge = b'nonce="1234",qop="auth",charset=utf-8,algorithm=md5-sess' directives = self.mechanism._parse( self.mechanism.getResponse(challenge)) self.assertEqual(directives[b'realm'], b'\xc3\xa9chec.example.org')
def test_calculateResponse(self): """ The response to a Digest-MD5 challenge is computed according to RFC 2831. """ charset = 'utf-8' nonce = b'OA6MG9tEQGm2hh' nc = networkString('%08x' % (1,)) cnonce = b'OA6MHXh6VqTrRk' username = u'\u0418chris' password = u'\u0418secret' host = u'\u0418elwood.innosoft.com' digestURI = u'imap/\u0418elwood.innosoft.com'.encode(charset) mechanism = sasl_mechanisms.DigestMD5( b'imap', host, None, username, password) response = mechanism._calculateResponse( cnonce, nc, nonce, username.encode(charset), password.encode(charset), host.encode(charset), digestURI) self.assertEqual(response, b'7928f233258be88392424d094453c5e3')
def setUp(self): self.mechanism = sasl_mechanisms.DigestMD5('xmpp', 'example.org', None, 'test', 'secret')
def setUp(self): self.mechanism = sasl_mechanisms.DigestMD5( "xmpp", "example.org", None, "test", "secret" )