def master_cmd_failauth(self, args): auth_id = int(args[1]) context = self.pending_auths.get(auth_id, None) if context is None: return None exception = AuthFailedException( "Master server refused authentication attempt.") return self._auth_failed(context, exception)
def answer_challenge(self, auth_domain, auth_id, answer): auth_service = self._get_auth_service(auth_domain) if auth_service is None: return defer.fail( AuthFailedException( "Could not determine which master server to send your request to." )) return auth_service.answer_challenge(auth_domain, auth_id, answer)
def try_authenticate(self, auth_domain, auth_name): auth_service = self._get_auth_service(auth_domain) if auth_service is None: return defer.fail( AuthFailedException( "Could not determine which master server to send your request to." )) return auth_service.try_authenticate(auth_domain, auth_name)
def answer_challenge(self, auth_id, answer): context = self.pending_auths.get(auth_id, None) if context is None: return None if context.state is not authentication_states.PENDING_ANSWER: logger.error( "Answer challenge called when another state was expected.") exception = AuthFailedException( "Master server client protocol error.") return self._auth_failed(context, exception) if self.active_connection is None: return defer.fail( AuthFailedException("No Master server connection.")) self.active_connection.send_confauth(auth_id, answer) context.state = authentication_states.PENDING_RESPONSE context.deferred = defer.Deferred() return context.deferred
def master_cmd_succauth(self, args): auth_id = int(args[1]) context = self.pending_auths.get(auth_id, None) if context is None: return None if context.state is not authentication_states.PENDING_RESPONSE: logger.error( "Master server sent authentication success when another state was expected." ) exception = AuthFailedException("Master server protocol error.") return self._auth_failed(context, exception) self._auth_succeeded(context)
def try_auth(self, auth_domain, authname): logger.debug( "Attempting client auth request; authname = {!r}".format(authname)) if self.active_connection is None: return defer.fail( AuthFailedException("No Master server connection.")) context = AuthenticationContext(next(self._auth_id), auth_domain, authname) self.active_connection.send_reqauth(context.auth_id, context.auth_name) self.pending_auths[context.auth_id] = context context.timeout_deferred = self.clock.callLater( 5, self._auth_timeout, context) return context.deferred
def master_cmd_chalauth(self, args): auth_id = int(args[1]) context = self.pending_auths.get(auth_id, None) if context is None: return None if context.state is not authentication_states.PENDING_CHALLENGE: logger.error( "Master server sent challenge when another state was expected." ) exception = AuthFailedException("Master server protocol error.") return self._auth_failed(context, exception) challenge = args[2] if len(challenge) != AUTHCHALLEN: logger.error( "Master server sent challenge with an invalid length of {}.". format(len(challenge))) return self._auth_failed( context, AuthFailedException("Master server protocol error.")) context.state = authentication_states.PENDING_ANSWER auth_challenge = AuthChallenge(auth_id, context.auth_domain, challenge) context.deferred.callback(auth_challenge)
def _auth_failed(self, context, exception=None): exception = exception or AuthFailedException("Authentication failed.") if not context.deferred.called: context.deferred.errback(exception) self._auth_finished(context)
def _auth_timeout(self, context): self._auth_failed(context, AuthFailedException("Authentication timed out."))
def answer_challenge(self, auth_domain, auth_id, answer): return defer.fail( AuthFailedException( "Could not determine which master server to send your request to." ))
def try_authenticate(self, auth_domain, auth_name): return defer.fail( AuthFailedException( "Could not determine which master server to send your request to." ))