예제 #1
0
    def __init__(self,
                 key=None,
                 keylen=20,
                 algo=None,
                 digits=6,
                 offset=0,
                 jitter=0,
                 timestep=60):
        ''' no key given - create one '''
        if key is None:
            self.key = binascii.hexlify(geturandom(keylen))
        else:
            self.key = key.decode('hex')
            keylen = len(self.key)

        if algo is None:
            if keylen == 20:
                algo = sha1
            elif keylen == 32:
                algo = sha256
            elif keylen == 64:
                algo = sha512
        else:
            algo = algo

        self.offset = offset
        self.jitter = jitter
        self.timestep = timestep
        self.digits = digits

        self.hmacOtp = HmacOtp(self.key, digits=self.digits, hashfunc=algo)

        return
예제 #2
0
def generate_otpkey(key_size=20):
    '''
    generates the HMAC key of keysize. Should be 20 or 32
    THe key is returned as a hexlified string
    '''
    log.debug("generating key of size %s" % key_size)
    return binascii.hexlify(geturandom(key_size))
예제 #3
0
    def __init__(self, key=None, keylen=20, algo=None, digits=6, offset=0, jitter=0, timestep=60):


        ''' no key given - create one '''
        if key is None:
            self.key = binascii.hexlify(geturandom(keylen))
        else:
            self.key = key.decode('hex')
            keylen = len(self.key)

        if algo is None:
            if keylen == 20:
                algo = sha1
            elif keylen == 32:
                algo = sha256
            elif keylen == 64:
                algo = sha512
        else:
            algo = algo

        self.offset = offset
        self.jitter = jitter
        self.timestep = timestep
        self.digits = digits


        self.hmacOtp = HmacOtp(self.key, digits=self.digits, hashfunc=algo)

        return
예제 #4
0
def generate_otpkey(key_size=20):
    '''
    generates the HMAC key of keysize. Should be 20 or 32
    THe key is returned as a hexlified string
    '''
    log.debug("generating key of size %s" % key_size)
    return binascii.hexlify(geturandom(key_size))
예제 #5
0
 def setHashedPin(self, pin):
     seed = geturandom(16)
     self.LinOtpSeed = unicode(binascii.hexlify(seed))
     self.LinOtpPinHash = unicode(binascii.hexlify(hash_digest(pin, seed)))
     return self.LinOtpPinHash
예제 #6
0
 def setHashedPin(self, pin):
     seed = geturandom(16)
     self.LinOtpSeed = unicode(binascii.hexlify(seed))
     self.LinOtpPinHash = unicode(binascii.hexlify(hash_digest(pin, seed)))
     return self.LinOtpPinHash