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
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))
def setSoPin(self, soPin): # TODO: we could log the PIN here log.debug('setSoPin()') iv = geturandom(16) enc_soPin = encrypt(soPin, iv) self.LinOtpTokenPinSO = unicode(binascii.hexlify(enc_soPin)) self.LinOtpTokenPinSOIV = unicode(binascii.hexlify(iv))
def setHashedPin(self, pin): log.debug('setHashedPin()') seed = geturandom(16) self.LinOtpSeed = unicode(binascii.hexlify(seed)) self.LinOtpPinHash = unicode(binascii.hexlify(hash(pin, seed))) return self.LinOtpPinHash
def setHKey(self, hOtpKey, reset_failcount=True): log.debug('setHKey()') iv = geturandom(16) #bhOtpKey = binascii.unhexlify(hOtpKey) enc_otp_key = encrypt(hOtpKey, iv) self.LinOtpKeyEnc = unicode(binascii.hexlify(enc_otp_key)) self.LinOtpKeyIV = unicode(binascii.hexlify(iv)) self.LinOtpCount = 0 if True == reset_failcount: self.LinOtpFailCount = 0
def setUserPin(self, userPin): log.debug('setUserPin()') iv = geturandom(16) enc_userPin = encrypt(userPin, iv) self.LinOtpTokenPinUser = unicode(binascii.hexlify(enc_userPin)) self.LinOtpTokenPinUserIV = unicode(binascii.hexlify(iv))
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