def get_device(self, **kwargs): """ Uses the data from the setup step and generated key to recreate device. Only used for call / sms -- generator uses other procedure. """ method = self.get_method() kwargs = kwargs or {} kwargs['name'] = 'default' kwargs['user'] = self.request.user if method in ('call', 'sms'): kwargs['method'] = method kwargs['number'] = self.storage.validated_step_data\ .get(method, {}).get('number') return PhoneDevice(key=self.get_key(method), **kwargs) if method == 'yubikey': kwargs['public_id'] = self.storage.validated_step_data\ .get('yubikey', {}).get('token', '')[:-32] try: kwargs['service'] = ValidationService.objects.get( name='default') except ValidationService.DoesNotExist: raise KeyError( "No ValidationService found with name 'default'") except ValidationService.MultipleObjectsReturned: raise KeyError( "Multiple ValidationService found with name 'default'") return RemoteYubikeyDevice(**kwargs)
def get_device(self, **kwargs): """ Uses the data from the setup step and generated key to recreate device. Only used for call / sms -- generator uses other procedure. """ method = self.get_method() kwargs = kwargs or {} kwargs['name'] = 'default' kwargs['user'] = self.request.user if method in ('call', 'sms'): kwargs['method'] = method kwargs['number'] = self.storage.validated_step_data\ .get(method, {}).get('number') return PhoneDevice(key=self.get_key(method), **kwargs) if method == 'yubikey': kwargs['public_id'] = self.storage.validated_step_data\ .get('yubikey', {}).get('token', '')[:-32] try: kwargs['service'] = ValidationService.objects.get( name='default') except ValidationService.DoesNotExist: raise KeyError( "No ValidationService found with name 'default'") except ValidationService.MultipleObjectsReturned: raise KeyError( "Multiple ValidationService found with name 'default'") return RemoteYubikeyDevice(**kwargs) if method == 'cac': try: kwargs['cert_dn'] = self.request.META['HTTP_X_SSL_USER_DN'] verified = self.request.META['HTTP_X_SSL_AUTHENTICATED'] except KeyError: # HTTP headers not set messages.error(self.request, TWO_FACTOR_NO_CERT_MESSAGE) return redirect(reverse('two_factor:setup')) return X509Device(**kwargs)