Exemplo n.º 1
0
def register(devices, params, facet):
    """
    Interactively registers a single U2F device, given the RegistrationRequest.
    """
    for device in devices[:]:
        try:
            device.open()
        except:
            devices.remove(device)

    sys.stderr.write('\nTouch the U2F device you wish to register...\n')
    try:
        while devices:
            removed = []
            for device in devices:
                try:
                    return u2f.register(device, params, facet)
                except exc.APDUError as e:
                    if e.code == APDU_USE_NOT_SATISFIED:
                        pass
                    else:
                        removed.append(device)
                except exc.DeviceError:
                    removed.append(device)
            devices = [d for d in devices if d not in removed]
            for d in removed:
                d.close()
            time.sleep(0.25)
    finally:
        for device in devices:
            device.close()
    sys.stderr.write('\nUnable to register with any U2F device.\n')
    sys.exit(1)
Exemplo n.º 2
0
def register(devices, params, facet):
    """
    Interactively registers a single U2F device, given the RegistrationRequest.
    """
    for device in devices[:]:
        try:
            device.open()
        except:
            devices.remove(device)

    sys.stderr.write('\nTouch the U2F device you wish to register...\n')
    try:
        while devices:
            removed = []
            for device in devices:
                try:
                    return u2f.register(device, params, facet)
                except exc.APDUError as e:
                    if e.code == APDU_USE_NOT_SATISFIED:
                        pass
                    else:
                        removed.append(device)
                except exc.DeviceError:
                    removed.append(device)
            devices = [d for d in devices if d not in removed]
            for d in removed:
                d.close()
            time.sleep(0.25)
    finally:
        for device in devices:
            device.close()
    sys.stderr.write('\nUnable to register with any U2F device.\n')
    sys.exit(1)
Exemplo n.º 3
0
Arquivo: main.py Projeto: peuter/gosa
    def setTwoFactorMethod(self, user_dn, factor_method, user_password=None):
        if factor_method == "u2f":
            print(_("checking U2F devices..."))
            # check for devices
            devices = u2f.list_devices()
            if len(devices) == 0:
                print(_("No U2F devices found, aborting!"))
                return

        response = self.proxy.setTwoFactorMethod(user_dn, factor_method, user_password)
        if response is None:
            return
        if factor_method == "u2f":
            # bind
            response = loads(response)
            for device in devices:
                # The with block ensures that the device is opened and closed.
                print(_("Please touch the flashing U2F device now."))
                with device as dev:
                    # Register the device with some service
                    for request in response['registerRequests']:
                        registration_response = u2f.register(device, request, request['appId'])
                        response = self.proxy.completeU2FRegistration(user_dn, registration_response)
                        if response is True:
                            print(_("U2F authentication has been enabled"))

        elif response.startswith("otpauth://"):
            url = pyqrcode.create(response, error='L')
            print(url.terminal(quiet_zone=1))
        else:
            print(response)
Exemplo n.º 4
0
def registerDevice(device, registrationRequestData):
    print "Touch the U2F device you wish to register..."
    while 1:
        try:
            registerResponse = u2f.register(
                device, json.dumps(registrationRequestData), serverUrl)
            registerResponse["version"] = "U2F_V2"
            params = "data=" + json.dumps(registerResponse)
            bindResponse = serverCall(serverUrl, "bind", params, False)
            if bindResponse != "true":
                return False
            return True
        except exc.APDUError as e:
            if e.code == APDU_USE_NOT_SATISFIED:
                pass
            else:
                return False
        except:
            return False

        time.sleep(0.25)
Exemplo n.º 5
0
            requests.get("http://localhost:8081/enroll").text)

        print registrationRequest

        registrationRequest = registrationRequest['registerRequests'][0]

        # Enumerate available devices
        devices = u2f.list_devices()

        for device in devices:
            # The with block ensures that the device is opened and closed.
            with device as dev:
                # Register the device with some service
                print 'Reg: press button . . .'
                sys.stdout.flush()
                registrationResponse = u2f.register(device,
                                                    registrationRequest, facet)
                print registrationResponse
                registrationResponse['version'] = 'U2F_V2'
                bindres = (requests.post("http://localhost:8081/bind",
                                         data={
                                             'data':
                                             json.dumps(registrationResponse)
                                         }).text)

                if bindres == 'true':
                    print 'Success reg'
                else:
                    print 'Fail reg'
                sys.stdout.flush()

                sign = json.loads(