Пример #1
0
def wait_for_card() -> CardConnectionDecorator:
    """
    Wait for card connection and return channel to the card.
    """

    channel = CardRequest(timeout=None).waitforcard().connection
    # uncomment for traching APDUs
    # observer = ConsoleCardConnectionObserver()
    # channel.addObserver(observer)
    print("[+] Selected reader:", channel.getReader())
    try:
        channel.connect(CardConnection.T1_protocol)
    except:
        print("[!] Fallback to T=0")
        channel.connect(CardConnection.T0_protocol)
    return channel
Пример #2
0
    def connect_to_chip(timeout, card_type=AnyCardType()):
        """
        Establish a connection with the first chip presented to the reader before the timeout.

        :param timeout: The number of seconds for a chip before timing out
        :param card_type: The card type to wait for
        :return: A connection to the chip or false if it the read times out.
        """
        try:
            _logger.debug('Entering SmartCard.connect_to_chip function.')
            connection = CardRequest(
                timeout=timeout, cardType=card_type).waitforcard().connection
            connection.connect()
            return connection
        except CardRequestTimeoutException as e:
            _logger.debug('Card connection timed out after {timeout} seconds.')
            return False
        except Exception as e:
            raise Exception('Card connection failed unexpectedly.') from e
Пример #3
0
                    default=None,
                    choices=['auth', 'sign'],
                    help='Which certificate to fetch')
parser.add_argument("--out",
                    required=True,
                    type=str,
                    help="File to store certifcate (PEM)")
args = parser.parse_args()

# this will wait for card inserted in any reader
channel = CardRequest(timeout=100,
                      cardType=AnyCardType()).waitforcard().connection
print "[+] Selected reader:", channel.getReader()

# using T=0 for compatibility and simplicity
channel.connect(CardConnection.T0_protocol)

# detect and print EstEID card type (EstEID spec page 14)
atr = channel.getATR()
if atr == [
        0x3B, 0xFE, 0x94, 0x00, 0xFF, 0x80, 0xB1, 0xFA, 0x45, 0x1F, 0x03, 0x45,
        0x73, 0x74, 0x45, 0x49, 0x44, 0x20, 0x76, 0x65, 0x72, 0x20, 0x31, 0x2E,
        0x30, 0x43
]:
    print "[+] EstEID v1.0 on Micardo Public 2.1"
elif atr == [
        0x3B, 0xDE, 0x18, 0xFF, 0xC0, 0x80, 0xB1, 0xFE, 0x45, 0x1F, 0x03, 0x45,
        0x73, 0x74, 0x45, 0x49, 0x44, 0x20, 0x76, 0x65, 0x72, 0x20, 0x31, 0x2E,
        0x30, 0x2B
]:
    print "[+] EstEID v1.0 on Micardo Public 3.0 (2006)"
Пример #4
0
class ReadCard:
    def __init__(self, srv, db, user, pwd):
        # this will wait until card inserted in any reader
        self.channel = CardRequest(
            timeout=10, cardType=AnyCardType()).waitforcard().connection

        # using T=0 for compatibility (i.e., DigiID) and simplicity
        self.channel.connect()
        print "[+] Leitor:", self.channel.getReader()

        # Card Results
        self.card_results()

        # Odoo connection
        common = xmlrpclib.ServerProxy('%s/xmlrpc/2/common' % (srv))
        self.api = xmlrpclib.ServerProxy('%s/xmlrpc/2/object' % (srv))
        self.uid = common.authenticate(db, user, pwd, {})
        self.pwd = pwd
        self.db = db
        self.model = 'res.partner'

        toaster.show_toast(
            "CART\xc3O DO CIDAD\xc3O",
            "A ligar ao odoo!",
            icon_path="custom.ico",
            duration=0,
        )

        # Insert in Odoo
        #a = self.get()
        id = self.set()
        print "/n>>> Registo inserido no odoo/n"

        url = 'http://odoo9-cartaocidadao-pedroposeiro.c9users.io/web#id=%s&view_type=form&model=res.partner' % (
            id)
        webbrowser.open_new(url)

    def execute(self, method, args, kwargs=None):
        return self.api.execute_kw(self.db, self.uid, self.pwd, self.model,
                                   method, args, kwargs or {})

    def get(self, ids=None):
        return self.execute(
            'search_read',
            [ids or [], ['id', 'name']],
        )

    def set(self, id=None):
        if id:
            self.execute('write', [[id], {'name': self.nome}])
        elif self.addr == 1:
            print u'%s' % (self.pais)
            id = self.execute('create', [{
                'name':
                u'%s %s' % (self.nome, self.apelido),
                'vat':
                u'PT%s' % (self.nif),
                'image':
                base64.b64encode(self.jpgdata),
                'street':
                u'%s %s' % (self.via, self.endereco),
                'street2':
                u'nº %s %s %s' % (self.porta, self.andar, self.lado),
                'city':
                u'%s' % (self.localidade),
                'zip':
                u'%s-%s %s' %
                (self.cod_postal_1, self.cod_postal_2, self.cod_postal_3),
            }])
        else:
            id = self.execute('create',
                              [{
                                  'name': u'%s %s' % (self.nome, self.apelido),
                                  'vat': u'PT%s' % (self.nif),
                                  'image': base64.b64encode(self.jpgdata)
                              }])
        return id