Exemplo n.º 1
0
    def _genOtpKey_(self, otpkeylen: int = None) -> str:
        """
        private method, to create an otpkey

        :param otpkeylen: optional or 20
        :return: token seed / secret
        """
        if otpkeylen is None:
            if hasattr(self, "otpkeylen"):
                otpkeylen = getattr(self, "otpkeylen")
            else:
                otpkeylen = 20
        return generate_otpkey(otpkeylen)
Exemplo n.º 2
0
    def _genOtpKey_(self, otpkeylen=None):
        '''
        private method, to create an otpkey

        :param otpkeylen: optional or 20
        :return: token seed / secret
        '''
        if otpkeylen is None:
            if hasattr(self, 'otpkeylen'):
                otpkeylen = getattr(self, 'otpkeylen')
            else:
                otpkeylen = 20
        return generate_otpkey(otpkeylen)
Exemplo n.º 3
0
    def _genOtpKey_(self, otpkeylen=None):
        '''
        private method, to create an otpkey

        :param otpkeylen: optional or 20
        :return: token seed / secret
        '''
        if otpkeylen is None:
            if hasattr(self, 'otpkeylen'):
                otpkeylen = getattr(self, 'otpkeylen')
            else:
                otpkeylen = 20
        return generate_otpkey(otpkeylen)
Exemplo n.º 4
0
    def update(self, param):
        '''
        update - process the initialization parameters

        :param param: dict of initialization parameters
        :type param: dict

        :return: nothing
        '''

        ## check for the required parameters
        val = param.get("hashlib")
        if val is not None:
            self.hashlibStr = val
        else:
            self.hashlibStr = 'sha1'

        otpKey = ''

        if (self.hKeyRequired is True):
            genkey = int(param.get("genkey", 0))
            if 1 == genkey:
                # if hashlibStr not in keylen dict, this will raise an Exception
                otpKey = generate_otpkey(keylen.get(self.hashlibStr))
                del param['genkey']
            else:
                # genkey not set: check otpkey is given
                # this will raise an exception if otpkey is not present
                try:
                    otpKey = param['otpkey']
                except KeyError:
                    raise ParameterError("Missing parameter: 'serial'")

        # finally set the values for the update

        param['otpkey'] = otpKey
        param['hashlib'] = self.hashlibStr

        val = param.get("otplen")
        if val is not None:
            self.setOtpLen(int(val))
        else:
            self.setOtpLen(getFromConfig("DefaultOtpLen"))

        val = param.get("timeStep")
        if val is not None:
            self.timeStep = val

        val = param.get("timeWindow")
        if val is not None:
            self.timeWindow = val

        val = param.get("timeShift")
        if val is not None:
            self.timeShift = val

        HmacTokenClass.update(self, param)

        if self.timeWindow is not None and self.timeWindow != '':
            self.addToTokenInfo("timeWindow", self.timeWindow)
        if self.timeShift is not None and self.timeShift != '':
            self.addToTokenInfo("timeShift", self.timeShift)
        if self.timeStep is not None and self.timeStep != '':
            self.addToTokenInfo("timeStep", self.timeStep)
        if self.hashlibStr:
            self.addToTokenInfo("hashlib", self.hashlibStr)

        return
Exemplo n.º 5
0
    def update(self, param):
        '''
        update - process the initialization parameters

        :param param: dict of initialization parameters
        :type param: dict

        :return: nothing
        '''
        log.debug("[update] begin. Process the initialization parameters: param %r" % (param))

        ## check for the required parameters
        val = getParam(param, "hashlib", optional)
        if val is not None:
            self.hashlibStr = val
        else:
            self.hashlibStr = 'sha1'

        otpKey = ''

        if (self.hKeyRequired == True):
            genkey = int(getParam(param, "genkey", optional) or 0)
            if 1 == genkey:
                # if hashlibStr not in keylen dict, this will raise an Exception
                otpKey = generate_otpkey(keylen.get(self.hashlibStr))
                del param['genkey']
            else:
                # genkey not set: check otpkey is given
                # this will raise an exception if otpkey is not present
                otpKey = getParam(param, "otpkey", required)

        # finally set the values for the update
        param['otpkey'] = otpKey
        param['hashlib'] = self.hashlibStr

        val = getParam(param, "otplen", optional)
        if val is not None:
            self.setOtpLen(int(val))
        else:
            self.setOtpLen(getFromConfig("DefaultOtpLen"))

        val = getParam(param, "timeStep", optional)
        if val is not None:
            self.timeStep = val

        val = getParam(param, "timeWindow", optional)
        if val is not None:
            self.timeWindow = val

        val = getParam(param, "timeShift", optional)
        if val is not None:
            self.timeShift = val


        HmacTokenClass.update(self, param)

        self.addToTokenInfo("timeWindow", self.timeWindow)
        self.addToTokenInfo("timeShift", self.timeShift)
        self.addToTokenInfo("timeStep", self.timeStep)
        self.addToTokenInfo("hashlib", self.hashlibStr)

        log.debug("[update]  end. Processing the initialization parameters done.")
        return
Exemplo n.º 6
0
    def update(self, param):
        '''
        update - process the initialization parameters

        :param param: dict of initialization parameters
        :type param: dict

        :return: nothing
        '''

        ## check for the required parameters
        val = param.get("hashlib")
        if val is not None:
            self.hashlibStr = val
        else:
            self.hashlibStr = 'sha1'

        otpKey = ''

        if (self.hKeyRequired is True):
            genkey = int(param.get("genkey", 0))
            if 1 == genkey:
                # if hashlibStr not in keylen dict, this will raise an Exception
                otpKey = generate_otpkey(keylen.get(self.hashlibStr))
                del param['genkey']
            else:
                # genkey not set: check otpkey is given
                # this will raise an exception if otpkey is not present
                try:
                    otpKey = param['otpkey']
                except KeyError:
                    raise ParameterError("Missing parameter: 'serial'")

        # finally set the values for the update

        param['otpkey'] = otpKey
        param['hashlib'] = self.hashlibStr

        val = param.get("otplen")
        if val is not None:
            self.setOtpLen(int(val))
        else:
            self.setOtpLen(getFromConfig("DefaultOtpLen"))

        val = param.get("timeStep")
        if val is not None:
            self.timeStep = val

        val = param.get("timeWindow")
        if val is not None:
            self.timeWindow = val

        val = param.get("timeShift")
        if val is not None:
            self.timeShift = val

        HmacTokenClass.update(self, param)

        if self.timeWindow is not None and self.timeWindow != '':
            self.addToTokenInfo("timeWindow", self.timeWindow)
        if self.timeShift is not None and self.timeShift != '':
            self.addToTokenInfo("timeShift", self.timeShift)
        if self.timeStep is not None and self.timeStep != '':
            self.addToTokenInfo("timeStep", self.timeStep)
        if self.hashlibStr:
            self.addToTokenInfo("hashlib", self.hashlibStr)

        return