Ejemplo n.º 1
0
    def getOtp(self, curTime=None):
        ## kay: init value
        res = (-1, 0, 0, 0)

        try:
            otplen = int(self.token.LinOtpOtpLen)
        except ValueError:
            return res

        secretHOtp = self.token.getHOtpKey()

        dpw = dpwOtp(secretHOtp, otplen)

        date_string = None
        if curTime:
            if type(curTime) == datetime.datetime:
                date_string = curTime.strftime("%d%m%y")
            elif type(curTime) == unicode:
                date_string = datetime.datetime.strptime(
                    curTime, "%Y-%m-%d %H:%M:%S.%f").strftime("%d%m%y")
            else:
                log.error(
                    "[getOtp] invalid curTime: %r. You need to specify a datetime.datetime"
                    % type(curTime))
        otpval = dpw.getOtp(date_string)
        pin = self.token.getPin()
        combined = "%s%s" % (otpval, pin)
        if getFromConfig("PrependPin") == "True":
            combined = "%s%s" % (pin, otpval)

        return (1, pin, otpval, combined)
Ejemplo n.º 2
0
    def getOtp(self, curTime=None):
        ## kay: init value
        res = (-1, 0, 0, 0)

        try:
            otplen = int(self.token.LinOtpOtpLen)
        except ValueError:
            return res

        secretHOtp = self.token.getHOtpKey()

        dpw = dpwOtp(secretHOtp, otplen)

        date_string = None
        if curTime:
            if type(curTime) == datetime.datetime:
                date_string = curTime.strftime("%d%m%y")
            elif type(curTime) == unicode:
                date_string = datetime.datetime.strptime(curTime, "%Y-%m-%d %H:%M:%S.%f").strftime("%d%m%y")
            else:
                log.error("[getOtp] invalid curTime: %r. You need to specify a datetime.datetime" % type(curTime))
        otpval = dpw.getOtp(date_string)
        pin = self.token.getPin()
        combined = "%s%s" % (otpval, pin)
        if getFromConfig("PrependPin") == "True" :
            combined = "%s%s" % (pin, otpval)

        return (1, pin, otpval, combined)
Ejemplo n.º 3
0
    def get_multi_otp(self, count=0, epoch_start=0, epoch_end=0, curTime=None):
        '''
        This returns a dictionary of multiple future OTP values of the Tagespasswort token

        parameter
            count    - how many otp values should be returned
            epoch_start    - time based tokens: start when
            epoch_end      - time based tokens: stop when

        return
            True/False
            error text
            OTP dictionary
        '''
        otp_dict = {"type": "DPW", "otp": {}}
        ret = False
        error = "No count specified"
        try:
            otplen = int(self.token.LinOtpOtpLen)
        except ValueError as ex:
            log.error("[get_multi_otp] %r" % ex)
            return (False, unicode(ex), otp_dict)

        secretHOtp = self.token.getHOtpKey()
        dpw = dpwOtp(secretHOtp, otplen)
        log.debug("[get_multi_otp] retrieving %i OTP values for token %s" %
                  (count, dpw))

        if count > 0:
            now = datetime.datetime.now()
            if curTime:
                if type(curTime) == datetime.datetime:
                    now = curTime
                elif type(curTime) == unicode:
                    now = datetime.datetime.strptime(curTime,
                                                     "%Y-%m-%d %H:%M:%S.%f")
                else:
                    log.error("[get_multi_otp] wrong curTime type: %s" %
                              type(curTime))
                    raise TokenAdminError(
                        "[get_multi_otp] wrong curTime type: %s (%s)" %
                        (type(curTime), curTime),
                        id=2001)
            for i in range(count):
                delta = datetime.timedelta(days=i)
                date_string = (now + delta).strftime("%d%m%y")
                otpval = dpw.getOtp(date_string=date_string)
                otp_dict["otp"][(now + delta).strftime("%y-%m-%d")] = otpval
            ret = True

        log.debug("[get_multi_otp] %s" % otp_dict)
        return (ret, error, otp_dict)
Ejemplo n.º 4
0
    def checkOtp(self, anOtpVal, counter, window, options=None):
        res = -1

        try:
            otplen = int(self.token.LinOtpOtpLen)
        except ValueError:
            return res

        secretHOtp = self.token.getHOtpKey()

        dpw = dpwOtp(secretHOtp, otplen)
        res = dpw.checkOtp(anOtpVal, window=window)

        return res
Ejemplo n.º 5
0
    def checkOtp(self, anOtpVal, counter, window, options=None):
        res = -1

        try:
            otplen = int(self.token.LinOtpOtpLen)
        except ValueError:
            return res

        secretHOtp = self.token.getHOtpKey()

        dpw = dpwOtp(secretHOtp, otplen)
        res = dpw.checkOtp(anOtpVal, window=window)

        return res
Ejemplo n.º 6
0
    def get_multi_otp(self, count=0, epoch_start=0, epoch_end=0, curTime=None):
        '''
        This returns a dictionary of multiple future OTP values of the Tagespasswort token

        parameter
            count    - how many otp values should be returned
            epoch_start    - time based tokens: start when
            epoch_end      - time based tokens: stop when

        return
            True/False
            error text
            OTP dictionary
        '''
        otp_dict = {"type" : "DPW", "otp": {}}
        ret = False
        error = "No count specified"
        try:
            otplen = int(self.token.LinOtpOtpLen)
        except ValueError as ex:
            log.error("[get_multi_otp] %r" % ex)
            return (False, unicode(ex), otp_dict)

        secretHOtp = self.token.getHOtpKey()
        dpw = dpwOtp(secretHOtp, otplen)
        log.debug("[get_multi_otp] retrieving %i OTP values for token %s" % (count, dpw))

        if count > 0:
            now = datetime.datetime.now()
            if curTime:
                if type(curTime) == datetime.datetime:
                    now = curTime
                elif type(curTime) == unicode:
                    now = datetime.datetime.strptime(curTime, "%Y-%m-%d %H:%M:%S.%f")
                else:
                    log.error("[get_multi_otp] wrong curTime type: %s" % type(curTime))
                    raise TokenAdminError("[get_multi_otp] wrong curTime type: %s (%s)" % (type(curTime), curTime), id=2001)
            for i in range(count):
                delta = datetime.timedelta(days=i)
                date_string = (now + delta).strftime("%d%m%y")
                otpval = dpw.getOtp(date_string=date_string)
                otp_dict["otp"][ (now + delta).strftime("%y-%m-%d")] = otpval
            ret = True

        log.debug("[get_multi_otp] %s" % otp_dict)
        return (ret, error, otp_dict)