示例#1
0
    def sendChallenge(self, msgno):
        """
        sendChallenge() formats and sends a reply to the client
        based on the userid and authentid sent as a message
        """
        try:
            challenge = self.generator.getChallenge(self.session.userid)
            data = self.encodeBlob(challenge)
            self.channel.sendReply(msgno, data)
            self.sentchallenge = 1

        except KeyError, e:
            log.error('KeyError fetching challenge. User not in dbase?')
            data = '<error code="535">Authentication Failed</error>'
            self.channel.sendError(msgno, data)
示例#2
0
    def test_createSASLOTPSession(self):
        """Test SASL OTP with no CDATA init"""

        factory = SASLOTPClientFactory()
        factory.addProfile(echoprofile)
        factory.addProfile(saslotpprofile)

        #        log.debug("Reactor state: %s" % reactor.removeAll())

        reactor.connectTCP("localhost", 1976, factory)
        reactor.run()

        if factory.reason:
            log.error("Error occurred in factory: %s" % factory.reason)
            raise Exception(factory.reason.getErrorMessage())
示例#3
0
    def processMessage(self, msg):
        """
        All processFrame should do is move the session from
        non-authenticated to authenticated.
        """
	try:
            error = self.parseError(msg.payload)
            if error:
                log.error("Error while authenticating: %s: %s" % (error[1], error[2]))
                return

            status = self.parseStatus(msg.payload)
            if status:
                # do status code processing
                log.debug("status: %s" % status)
                if status == 'complete':

                    self.session.authenticationSucceeded()

                elif status == 'abort':
                    # other end has aborted negotiation, so we reset
                    # to our initial state
                    self.authentid = None
                    self.authid = None

                elif status == 'continue':
                    log.debug("continue during authentication")

            else:
                authentid = self.decodeBlob(msg.payload)
                if authentid:
                    log.debug("authentid: %s" % authentid)
                    self.authentid = authentid
                    # I've now dealt with the message sufficiently for it to
                    # be marked as such, so we deallocate the msgno
                    self.channel.deallocateMsgno(msg.msgno)

                    data = '<blob status="complete"/>'
                    self.channel.sendReply(msg.msgno, data)
                    log.debug("Queued success message")

#                    self.session.authenticationComplete()

        except Exception, e:
            traceback.print_exc()
            raise TerminalProfileException("Exception: %s" % e)
示例#4
0
    def promptAndGenerate(self):
        """
        A testing method used to create an OTP from
        values entered at the command line.
        """
        try:
            # Get the inputs and validate them
            username = raw_input("Enter username: "******"Enter passphrase: ")
            self.validatePassphrase(passphrase)
            seed = raw_input("Enter seed: ")
            self.validateSeed(seed)
            algo = raw_input("Enter algorithm: ")
            self.validateAlgorithm(algo)
            sequence = string.atoi(raw_input("Enter sequence number: "))
            self.validateSequence(sequence)

            return self.createOTP(username, algo, seed, passphrase, sequence)

        except ValueError, e:
            log.error("Error: %s" % e)
示例#5
0
    def parseMSG(self, msg):
        """parseMSG grabs the MSG payload and works out what to do
        """
        try:
            number, delay, content = string.split(msg.payload, ' ', 2)
            number = int(number)
            delay = int(delay)
            log.debug("number: %d" % number)
            log.debug("delay: %d" % delay)
            log.debug("content: %s" % content)

            if number <= 0:
                self.channel.sendError(msg.msgno, 'Cannot echo a frame %d times.\n' % number)

            else:
                log.debug("Adding reverb for msgno: %d, %d times with %d second delay" % (msg.msgno, number, delay) )
                self.reverbDict[msg.msgno] = [number, delay, content]
                self.callLater(delay, self.sendReverb, (msg.msgno) )

        except ValueError, e:
            # A ValueError means the payload format is wrong.
            log.error('Payload format incorrect: %s' % e)
            self.channel.sendError(msg.msgno, 'Payload format incorrect\n')