Beispiel #1
0
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data()
        ctx['device'] = self.device

        if 'webauthn_register_ukey' in self.request.session:
            del self.request.session['webauthn_register_ukey']
        if 'webauthn_challenge' in self.request.session:
            del self.request.session['webauthn_challenge']

        challenge = generate_challenge(32)
        ukey = generate_ukey()

        self.request.session['webauthn_challenge'] = challenge
        self.request.session['webauthn_register_ukey'] = ukey

        make_credential_options = webauthn.WebAuthnMakeCredentialOptions(
            challenge,
            urlparse(settings.SITE_URL).netloc,
            urlparse(settings.SITE_URL).netloc,
            ukey,
            self.request.user.email,
            str(self.request.user),
            settings.SITE_URL
        )
        ctx['jsondata'] = json.dumps(make_credential_options.registration_dict)

        return ctx
Beispiel #2
0
 def get_context_data(self, **kwargs):
     ctx = super().get_context_data()
     if 'webauthn_challenge' in self.request.session:
         del self.request.session['webauthn_challenge']
     challenge = generate_challenge(32)
     self.request.session['webauthn_challenge'] = challenge
     devices = [
         device.webauthnuser
         for device in WebAuthnDevice.objects.filter(confirmed=True,
                                                     user=self.request.user)
     ] + [
         device.webauthnuser
         for device in U2FDevice.objects.filter(confirmed=True,
                                                user=self.request.user)
     ]
     if devices:
         webauthn_assertion_options = webauthn.WebAuthnAssertionOptions(
             devices, challenge)
         ad = webauthn_assertion_options.assertion_dict
         ad['extensions'] = {'appid': get_u2f_appid(self.request)}
         ctx['jsondata'] = json.dumps(ad)
     return ctx