示例#1
0
    def request_pin_code(self, sender, **kw):
        obj = kw['obj']
        print("%s dice:\n\n" % (obj.data['M'][0]['A'][0]['d'], ))
        print(obj.data['M'][0]['A'][0]['c'])

        obj.response['pin'] = input('Insert your pin: ')
        obj.response['code'] = input('Insert the code: ')
        obj.response['rejected'] = False
        signals.receive(obj, notify=True)
示例#2
0
 def notify_user(self, sender, obj):
     if obj._type == signals.NOTIFTY_INFO:
         QtWidgets.QMessageBox.information(self.usrSlots.currentWidget(),
                                           'Información Importante',
                                           obj.data['message'])
     elif obj._type == signals.NOTIFTY_ERROR:
         QtWidgets.QMessageBox.critical(self.usrSlots.currentWidget(),
                                        'Error', obj.data['message'])
     elif obj._type == signals.NOTIFY_WARNING:
         QtWidgets.QMessageBox.warning(self.usrSlots.currentWidget(),
                                       'Atención', obj.data['message'])
     signals.receive(obj, notify=True)
示例#3
0
    def get_pin(self, pin=None, slot=None):
        """Obtiene el pin de la tarjeta para iniciar sesión"""

        if isinstance(pin, Secret):
            return str(pin)

        if pin:
            return pin

        if 'PKCS11_PIN' in os.environ:
            pin = os.environ['PKCS11_PIN']
        else:
            try:
                serial = self.get_slot(
                    slot=slot).get_token().serial.decode('utf-8')
            except:
                serial = 'N/D'
                # Fixme: aqui debería manejarse mejor

            sobj = signals.SignalObject(signals.PIN_REQUEST,
                                        {'serial': serial})
            respobj = signals.receive(signals.send('pin', sobj))
            if 'pin' in respobj.response and respobj.response['pin']:
                pin = str(Secret(respobj.response['pin'], decode=True))
            if respobj.response['rejected']:
                raise UserRejectPin()
        if pin is None:
            raise PinNotProvided(
                'Sorry PIN is needed, we will remove this, but for now use export PKCS11_PIN=<pin> '
                'before call python.')
        return pin
示例#4
0
 def request_pin(self, sender, obj):
     serial = obj.data['serial']
     alias = self.session_storage.alias.filter(serial)
     alias_text = alias[0] if alias else serial
     text, ok = QInputDialog.getText(self.usrSlots.currentWidget(),
                                     "Atención",
                                     f"Ingrese su pin para {alias_text}",
                                     QLineEdit.Password)
     if ok and text:
         obj.response = {
             'pin': str(Secret(text)),
             'serial': serial,
             'rejected': False
         }
     else:
         obj.response = {'pin': "", 'serial': serial, 'rejected': True}
     signals.receive(obj, notify=True)
示例#5
0
    def get_pin(self, pin=None):
        """Obtiene el pin de la tarjeta para iniciar sessión"""

        if pin:
            return pin

        if 'PKCS11_PIN' in os.environ:
            return os.environ['PKCS11_PIN']
        else:
            try:
                serial = self.get_slot().get_tokens()[0].serial.decode('utf-8')
            except:
                serial = 'N/D'
                # Fixme: aqui debería manejarse mejor
            respobj = signals.receive(
                signals.send(
                    'pin',
                    signals.SignalObject(signals.PIN_REQUEST,
                                         {'serial': serial})))
            return respobj.response['pin']

        raise Exception(
            'Sorry PIN is Needed, we will remove this, but for now use export \
            PKCS11_PIN=<pin> before call python')
示例#6
0
    def wrapper(*args, **kwargs):
        instance = args[0]
        count = 0
        try_again = True
        dev = None
        slot = kwargs['slot'] if 'slot' in kwargs else None
        while try_again and count < 3:
            try:
                dev = func(*args, **kwargs)
                try_again = False
            except pkcs11.exceptions.PinLocked as e:
                signals.send(
                    'notify',
                    signals.SignalObject(
                        signals.NOTIFTY_ERROR, {
                            'message':
                            "Tarjeta bloqueada, por favor contacte con su proveedor para desbloquearla"
                        }))
                logger.error(
                    "Tarjeta bloqueada, por favor contacte con su proveedor para desbloquearla "
                    + str(instance.serial))
                try_again = False
            except pkcs11.exceptions.TokenNotRecognised as e:
                signals.send(
                    'notify',
                    signals.SignalObject(
                        signals.NOTIFTY_ERROR, {
                            'message':
                            "No se puede obtener la identificación de la "
                            "persona, posiblemente porque la tarjeta está "
                            "mal conectada"
                        }))
                logger.error("Tarjeta no detectada %r" % (e, ))
                try_again = False
            except pkcs11.exceptions.PinIncorrect as e:
                count += 1
                logger.info("Pin incorrecto para el slot %s  intento %d" %
                            (str(slot), count))
                obj = signals.SignalObject(
                    signals.NOTIFTY_ERROR, {
                        'message':
                        "Pin incorrecto, recuerde después de 3 intentos su tarjeta puede bloquearse, este es el intento %d"
                        % (count)
                    })
                signals.send('notify', obj)
                signals.receive(obj)
                try_again = True
            except PinNotProvided as e:
                signals.send(
                    'notify',
                    signals.SignalObject(
                        signals.NOTIFTY_ERROR, {
                            'message':
                            "No se ha logrado identificar el PIN correcto con ninguno de los mecanismos establecidos"
                        }))
                logger.error(
                    "Pin no provisto, el sistema no identificó un pin adecuado"
                )
                try_again = True
                count += 1
            except pkcs11.exceptions.DataInvalid as e:
                signals.send(
                    'notify',
                    signals.SignalObject(
                        signals.NOTIFTY_ERROR, {
                            'message':
                            "No se ha logrado firmar, posiblemente porque el mecanismo usado en la aplicación no está disponible en su tarjeta"
                        }))
                logger.error("Error al firmar documento %r" % (e, ))
                try_again = False

        if count == 3:
            signals.send(
                'notify',
                signals.SignalObject(
                    signals.NOTIFTY_ERROR, {
                        'message':
                        "Se ha excedido el número de intentos, puede que su tarjeta haya sido bloqueada"
                    }))

        return dev