def authenticate(self, username = None, otp = None):
		if not otp:
			return None

		count = len(otp)
		device_id = otp[0][:12]

		try:
			yubico = YubicoKey.objects.get(user__username = username, \
									device_id = device_id)
		except YubicoKey.DoesNotExist:
			return None
		
		if not yubico.user.is_active or not yubico.enabled:
			return None
		
		secret_key = yubico.secret_key or None
		client = Yubico(yubico.client_id, secret_key)
		
		try:
			if count > 1:
				# More then 1 OTP provided, using multi mode
				status = client.verify_multi(otp_list = otp, max_time_window = YUBICO_MULTI_TIMEOUT)
			else:
				status = client.verify(otp[0])
		except YubicoError:
			return None
		
		if not status:
			return None
		
		return yubico.user
Ejemplo n.º 2
0
	def __check_otp_online(self):
		""" Returns None if the connection cannot be made, True is the OTP is valid and False otherwise. """
		
		yubico = Yubico(self.client_id)
		
		try:
			status = yubico.verify(self.otp)
		except YubicoError:
			return False
		
		if status is False:
			return False
		elif status is None:
			return None
		
		return True
Ejemplo n.º 3
0
# - coding: utf-8  -
from yubico.yubico import Yubico
from yubico.yubico_exceptions import YubicoError



yubico = Yubico('10516', 'B0IpBq0fiNLHeEwbGMhVZuxofLg=')

def verify_yubikey(otp):
    try:
        return yubico.verify(otp)
    except YubicoError:
        return  False