コード例 #1
0
    def test_authenticate_soft_u2f(self):
        token = SoftU2FDevice()
        request = u2f.start_register(APP_ID)
        response = token.register(request.json, FACET)
        device, cert = u2f.complete_register(request, response)

        challenge1 = u2f.start_authenticate(device)
        challenge2 = u2f.start_authenticate(device)

        response2 = token.getAssertion(challenge2.json, FACET)
        response1 = token.getAssertion(challenge1.json, FACET)

        assert u2f.verify_authenticate(device, challenge1, response1)
        assert u2f.verify_authenticate(device, challenge2, response2)

        try:
            u2f.verify_authenticate(device, challenge1, response2)
        except:
            pass
        else:
            assert False, "Incorrect validation should fail!"

        try:
            u2f.verify_authenticate(device, challenge2, response1)
        except:
            pass
        else:
            assert False, "Incorrect validation should fail!"
コード例 #2
0
ファイル: views.py プロジェクト: tomsovic/Learn
def add_key(request):

    if request.method == 'POST':
        # Add the key
        keyresponseform = KeyResponseForm(request.POST)
        if keyresponseform.is_valid():
            response = keyresponseform.cleaned_data['response']
            challenge = request.session['u2f_registration_challenge']
            print(challenge)
            del request.session['u2f_registration_challenge']
            device, attestation_cert = u2f.complete_register(
                challenge, response)
            request.user.u2f_keys.create(
                public_key=device['publicKey'],
                key_handle=device['keyHandle'],
                app_id=device['appId'],
            )
            print("%s\n\n\n%s" % (device, attestation_cert))
            return HttpResponseRedirect('/dashboard/')

    # Else if its a GET variable
    # Send them the request
    origin = '{scheme}://{host}'.format(
        scheme='https' if request.is_secure() else 'http',
        host=request.get_host(),
    )
    origin = "https://www.bestedm.org"
    challenge = u2f.start_register(origin)
    request.session['u2f_registration_challenge'] = challenge
    #    sign_requests = [u2f.start_authenticate(d.to_json()) for d in request.user.u2f_keys.all()]

    context = {'challenge': json.dumps(challenge)}
    #               'sign_requests': sign_requests}

    return render(request, 'u2f/add_key.html', context)
コード例 #3
0
    def test_authenticate_soft_u2f(self):
        token = SoftU2FDevice()
        request = u2f.start_register(APP_ID)
        response = token.register(request.json, FACET)
        device, cert = u2f.complete_register(request, response)

        challenge1 = u2f.start_authenticate(device)
        challenge2 = u2f.start_authenticate(device)

        response2 = token.getAssertion(challenge2.json, FACET)
        response1 = token.getAssertion(challenge1.json, FACET)

        assert u2f.verify_authenticate(device, challenge1, response1)
        assert u2f.verify_authenticate(device, challenge2, response2)

        try:
            u2f.verify_authenticate(device, challenge1, response2)
        except:
            pass
        else:
            assert False, "Incorrect validation should fail!"

        try:
            u2f.verify_authenticate(device, challenge2, response1)
        except:
            pass
        else:
            assert False, "Incorrect validation should fail!"
コード例 #4
0
ファイル: views.py プロジェクト: FarhansCode/u2f-django-PoC
def add_key(request):

    if request.method == 'POST':
        # Add the key
        keyresponseform = KeyResponseForm(request.POST)
        if keyresponseform.is_valid():
            response = keyresponseform.cleaned_data['response']
            challenge = request.session['u2f_registration_challenge']
            print(challenge)
            del request.session['u2f_registration_challenge']
            device, attestation_cert = u2f.complete_register(challenge, response)
            request.user.u2f_keys.create(
                public_key=device['publicKey'],
                key_handle=device['keyHandle'],
                app_id=device['appId'],
            )
            print("%s\n\n\n%s" % (device, attestation_cert))
            return HttpResponseRedirect('/dashboard/')

    # Else if its a GET variable
    # Send them the request
    origin = '{scheme}://{host}'.format(
                scheme='https' if request.is_secure() else 'http',
                host=request.get_host(),
             )
    challenge = u2f.start_register(origin)
    request.session['u2f_registration_challenge'] = challenge
#    sign_requests = [u2f.start_authenticate(d.to_json()) for d in request.user.u2f_keys.all()]

    context = {'challenge': json.dumps(challenge)}
#               'sign_requests': sign_requests}

    return render(request, 'u2f/add_key.html', context)
コード例 #5
0
ファイル: views.py プロジェクト: ossobv/django-u2f
 def get_context_data(self, **kwargs):
     kwargs = super(AddKeyView, self).get_context_data(**kwargs)
     challenge = u2f.start_register(self.get_origin())
     self.request.session['u2f_registration_challenge'] = challenge
     kwargs['challenge'] = challenge
     # TODO: also blacklist the keys already added to the account (the
     # second argument of u2f.register)
     return kwargs
コード例 #6
0
    def enroll(self, username):
        if username not in self.users:
            self.users[username] = {}

        user = self.users[username]
        enroll = start_register(self.app_id)
        user['_u2f_enroll_'] = enroll.json
        return enroll.json
コード例 #7
0
ファイル: views.py プロジェクト: ossobv/django-u2f
 def get_context_data(self, **kwargs):
     kwargs = super(AddKeyView, self).get_context_data(**kwargs)
     challenge = u2f.start_register(self.get_origin())
     self.request.session['u2f_registration_challenge'] = challenge
     kwargs['challenge'] = challenge
     # TODO: also blacklist the keys already added to the account (the
     # second argument of u2f.register)
     return kwargs
コード例 #8
0
    def test_register_soft_u2f(self):
        token = SoftU2FDevice()

        request = u2f.start_register(APP_ID)
        response = token.register(request.json, FACET)

        device, cert = u2f.complete_register(request, response)
        assert device
コード例 #9
0
    def test_register_soft_u2f(self):
        token = SoftU2FDevice()

        request = u2f.start_register(APP_ID)
        response = token.register(request.json, FACET)

        device, cert = u2f.complete_register(request, response)
        assert device
コード例 #10
0
 def enroll(self, username, password):
     try:
         user = self.auth.get_user(username)
         user.set_password(password)
     except:
         user = self.auth.create_user(username, password)
     enroll = start_register(self.app_id)
     user.attributes['_u2f_enroll_'] = enroll.json
     return enroll.json
コード例 #11
0
 def enroll(self, username, password):
     try:
         user = self.auth.get_user(username)
         user.set_password(password)
     except:
         user = self.auth.create_user(username, password)
     enroll = start_register(self.app_id)
     user.attributes['_u2f_enroll_'] = enroll.json
     return enroll.json
コード例 #12
0
def start_register(app_id, devices, challenge=None):
    # RegisterRequest
    register_request = u2f_v2.start_register(app_id, challenge)

    # SignRequest[]
    sign_requests = start_authenticate(
        devices,
        'check-only'
    ).authenticateRequests

    return RegisterRequestData(
        registerRequests=[register_request],
        authenticateRequests=sign_requests
    )
コード例 #13
0
ファイル: views.py プロジェクト: BioSoundSystems/django-u2f
    def get_context_data(self, **kwargs):
        kwargs = super(AddKeyView, self).get_context_data(**kwargs)
        challenge = u2f.start_register(self.get_origin())
        self.request.session['u2f_registration_challenge'] = challenge
        kwargs['challenge'] = challenge

        # Create a SignRequest for each key that has already been added to the
        # account.
        # This can be passed to u2f.register as the second parameter to prevent
        # re-registering the same key for the same user.
        sign_requests = [
            u2f.start_authenticate(d.to_json()) for d in self.request.user.u2f_keys.all()
        ]
        kwargs['sign_requests'] = sign_requests

        return kwargs
コード例 #14
0
ファイル: controller.py プロジェクト: moreati/u2fval
    def register_start(self, username):
        # RegisterRequest
        register_request = start_register(self._client.app_id)
        self._memstore.store(self._client.id, username,
                             register_request.challenge,
                             {'request': register_request})

        # SignRequest[]
        sign_requests = []
        user = self._get_user(username)
        if user is not None:
            for dev in user.devices.values():
                sign_requests.append(
                    start_authenticate(dev.bind_data, 'check-only'))

        # To support multiple versions, add more RegisterRequests.
        return [register_request], sign_requests
コード例 #15
0
ファイル: controller.py プロジェクト: gegmar/u2fval
    def register_start(self, username):
        # RegisterRequest
        register_request = start_register(self._client.app_id)
        self._memstore.store(self._client.id, username,
                             register_request.challenge,
                             {'request': register_request})

        # SignRequest[]
        sign_requests = []
        user = self._get_user(username)
        if user is not None:
            for dev in user.devices.values():
                sign_requests.append(
                    start_authenticate(dev.bind_data, 'check-only'))

        # To support multiple versions, add more RegisterRequests.
        return [register_request], sign_requests
コード例 #16
0
    def get_context_data(self, **kwargs):
        kwargs = super(AddKeyView, self).get_context_data(**kwargs)
        challenge = u2f.start_register(self.get_origin())
        self.request.session['u2f_registration_challenge'] = challenge
        kwargs['challenge'] = challenge

        # Create a SignRequest for each key that has already been added to the
        # account.
        # This can be passed to u2f.register as the second parameter to prevent
        # re-registering the same key for the same user.
        sign_requests = [
            u2f.start_authenticate(d.to_json())
            for d in self.request.user.u2f_keys.all()
        ]
        kwargs['sign_requests'] = sign_requests

        return kwargs
コード例 #17
0
    def test_wrong_facet(self):
        token = SoftU2FDevice()
        request = u2f.start_register(APP_ID)
        response = token.register(request.json, "http://wrongfacet.com")

        try:
            u2f.complete_register(request, response, FACETS)
        except:
            pass
        else:
            assert False, "Incorrect facet should fail!"

        response2 = token.register(request.json, FACET)
        device, cert = u2f.complete_register(request, response2)

        challenge = u2f.start_authenticate(device)
        response = token.getAssertion(challenge.json, "http://notright.com")

        try:
            u2f.verify_authenticate(device, challenge, response, FACETS)
        except:
            pass
        else:
            assert False, "Incorrect facet should fail!"
コード例 #18
0
    def test_wrong_facet(self):
        token = SoftU2FDevice()
        request = u2f.start_register(APP_ID)
        response = token.register(request.json, "http://wrongfacet.com")

        try:
            u2f.complete_register(request, response, FACETS)
        except:
            pass
        else:
            assert False, "Incorrect facet should fail!"

        response2 = token.register(request.json, FACET)
        device, cert = u2f.complete_register(request, response2)

        challenge = u2f.start_authenticate(device)
        response = token.getAssertion(challenge.json, "http://notright.com")

        try:
            u2f.verify_authenticate(device, challenge, response, FACETS)
        except:
            pass
        else:
            assert False, "Incorrect facet should fail!"
コード例 #19
0
    def test_enroll_serialization(self):
        enroll1 = u2f.start_register('https://example.com')
        enroll2 = RegisterRequest(enroll1.json)

        assert enroll1.appId == enroll2.appId
        assert enroll1.json == enroll2.json
コード例 #20
0
def enroll_token():
    enroll = start_register('http://localhost:5000')
    session['u2f_enroll'] = enroll.json
    return Response(enroll.json, mimetype='application/json')
コード例 #21
0
ファイル: u2f_service.py プロジェクト: UWCS/CAS
def enroll_token():
    enroll = start_register('http://localhost:5000')
    session['u2f_enroll'] = enroll.json
    return Response(enroll.json, mimetype='application/json')
コード例 #22
0
    def test_enroll_serialization(self):
        enroll1 = u2f.start_register('https://example.com')
        enroll2 = RegisterRequest(enroll1.json)

        assert enroll1.appId == enroll2.appId
        assert enroll1.json == enroll2.json