Changeset 16538


Ignore:
Timestamp:
Aug 18, 2016, 5:46:56 PM (3 years ago)
Author:
dcorreia
Message:

Added function to support PIN verification.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/linuxloginsmartcardwizard/trunk/proto1/cardHelper.py

    r16535 r16538  
    166166        else:
    167167            print("There's no card present in the reader, terminating...")
     168
     169
     170def verifyCardPin():
     171    init()
     172    # Obtain the instance of readerSet
     173    readers = pteid.PTEID_ReaderSet.instance()
     174    count = readers.readerCount()
     175
     176    # Check if we have connected smart card readers
     177    if count:
     178        devices_names = []
     179
     180        # Obtain the names of all connected readers
     181        for idx in range(count):
     182            name = readers.getReaderName(idx)
     183            devices_names.append(name)
     184
     185        ctx_with_card = None
     186        # try to find a smart card in one of the detected readers
     187        for name in devices_names:
     188            reader_ctx = readers.getReaderByName(name)
     189
     190            if reader_ctx.isCardPresent():
     191                ctx_with_card = reader_ctx
     192                # found a card connected, don't look around in other readers
     193                break
     194
     195        # Now check if we have a card to access we can keep going
     196        if ctx_with_card:
     197            card = ctx_with_card.getEIDCard()
     198            p = card.getPins()
     199            for i in range(card.pinCount()):
     200                if "Autenticação" in p.getPinByNumber(i).getLabel():
     201                    print(p.getPinByNumber(i).verifyPin())
     202                    break
     203        release()
    168204
    169205
     
    202238
    203239if __name__ == "__main__":
    204     init()
    205     start()
    206     release()
     240    if "verifyPin" in sys.argv:
     241        init()
     242        verifyCardPin()
     243        release()
     244    else:
     245        init()
     246        start()
     247        release()
Note: See TracChangeset for help on using the changeset viewer.