Giter VIP home page Giter VIP logo

pyscard's Introduction

pyscard: smartcard library for python

pyscard - python smart card library - is a python module adding smart cards support to python.

alt text

Documentation

https://pyscard.sourceforge.io/user-guide.html#pyscard-user-guide

Installation

Use python3 -m pip install pyscard

See INSTALL.md for more details.

Samples

Continuous Integration status

Coveralls: Coverage Status

pyscard's People

Contributors

1-byte avatar bittner avatar ccpost avatar davecahill avatar donwayo avatar elouanpetereau avatar jgiannuzzi avatar kevingriffin avatar kristinux avatar ludovicrousseau avatar mbokil avatar merrickheley avatar moreati avatar rockwelln avatar stefand986 avatar valdur55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyscard's Issues

Building along with Anaconda python

Hi,

I've build pyscard with git clone and sudo python setup.py install
Installation showed me this.

running install
running bdist_egg
running egg_info
writing requirements to pyscard.egg-info/requires.txt
writing pyscard.egg-info/PKG-INFO
writing top-level names to pyscard.egg-info/top_level.txt
writing dependency_links to pyscard.egg-info/dependency_links.txt
reading manifest file 'pyscard.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.html' under directory 'smartcard/doc'
warning: no files found matching '*.css' under directory 'smartcard/doc'
warning: no files found matching '*.js' under directory 'smartcard/doc'
warning: no files found matching '*.txt' under directory 'smartcard/doc'
writing manifest file 'pyscard.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/guid.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardNames.py -> build/bdist.linux-x86_64/egg/smartcard
creating build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCCardRequest.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCPart10.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCCardConnection.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCReaderGroups.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCExceptions.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCReader.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
copying build/lib.linux-x86_64-2.7/smartcard/pcsc/PCSCContext.py -> build/bdist.linux-x86_64/egg/smartcard/pcsc
creating build/bdist.linux-x86_64/egg/smartcard/scard
copying build/lib.linux-x86_64-2.7/smartcard/scard/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/scard
copying build/lib.linux-x86_64-2.7/smartcard/scard/scard.py -> build/bdist.linux-x86_64/egg/smartcard/scard
copying build/lib.linux-x86_64-2.7/smartcard/scard/_scard.so -> build/bdist.linux-x86_64/egg/smartcard/scard
creating build/bdist.linux-x86_64/egg/smartcard/util
copying build/lib.linux-x86_64-2.7/smartcard/util/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/util
copying build/lib.linux-x86_64-2.7/smartcard/CardType.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/__init__.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardConnection.py -> build/bdist.linux-x86_64/egg/smartcard
creating build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/APDUTracerPanel.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/SimpleSCardAppEventObserver.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/ReaderToolbar.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/SimpleSCardApp.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/SimpleSCardAppFrame.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/APDUHexValidator.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/wx/CardAndReaderTreePanel.py -> build/bdist.linux-x86_64/egg/smartcard/wx
copying build/lib.linux-x86_64-2.7/smartcard/System.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/ExclusiveConnectCardConnection.py -> build/bdist.linux-x86_64/egg/smartcard
creating build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/SWExceptions.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/op21_ErrorChecker.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/ISO7816_8ErrorChecker.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/ISO7816_9ErrorChecker.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/ISO7816_4_SW1ErrorChecker.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/ErrorChecker.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/ISO7816_4ErrorChecker.py -> build/bdist.linux-x86_64/egg/smartcard/sw
copying build/lib.linux-x86_64-2.7/smartcard/sw/ErrorCheckingChain.py -> build/bdist.linux-x86_64/egg/smartcard/sw
creating build/bdist.linux-x86_64/egg/smartcard/pyro
copying build/lib.linux-x86_64-2.7/smartcard/pyro/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/pyro
copying build/lib.linux-x86_64-2.7/smartcard/pyro/PyroReader.py -> build/bdist.linux-x86_64/egg/smartcard/pyro
copying build/lib.linux-x86_64-2.7/smartcard/CardConnectionDecorator.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/ulist.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/ReaderMonitoring.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/Synchronization.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/AbstractCardRequest.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/ClassLoader.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/Observer.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardConnectionEvent.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/PassThruCardService.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardRequest.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/ATR.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardConnectionObserver.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardService.py -> build/bdist.linux-x86_64/egg/smartcard
creating build/bdist.linux-x86_64/egg/smartcard/reader
copying build/lib.linux-x86_64-2.7/smartcard/reader/ReaderFactory.py -> build/bdist.linux-x86_64/egg/smartcard/reader
copying build/lib.linux-x86_64-2.7/smartcard/reader/__init__.py -> build/bdist.linux-x86_64/egg/smartcard/reader
copying build/lib.linux-x86_64-2.7/smartcard/reader/Reader.py -> build/bdist.linux-x86_64/egg/smartcard/reader
copying build/lib.linux-x86_64-2.7/smartcard/reader/ReaderGroups.py -> build/bdist.linux-x86_64/egg/smartcard/reader
copying build/lib.linux-x86_64-2.7/smartcard/Session.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/ExclusiveTransmitCardConnection.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/Card.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/Exceptions.py -> build/bdist.linux-x86_64/egg/smartcard
copying build/lib.linux-x86_64-2.7/smartcard/CardMonitoring.py -> build/bdist.linux-x86_64/egg/smartcard
byte-compiling build/bdist.linux-x86_64/egg/smartcard/guid.py to guid.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardNames.py to CardNames.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCCardRequest.py to PCSCCardRequest.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCPart10.py to PCSCPart10.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCCardConnection.py to PCSCCardConnection.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCReaderGroups.py to PCSCReaderGroups.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCExceptions.py to PCSCExceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCReader.py to PCSCReader.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pcsc/PCSCContext.py to PCSCContext.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/scard/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/scard/scard.py to scard.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/util/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardType.py to CardType.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardConnection.py to CardConnection.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/APDUTracerPanel.py to APDUTracerPanel.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/SimpleSCardAppEventObserver.py to SimpleSCardAppEventObserver.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/ReaderToolbar.py to ReaderToolbar.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/SimpleSCardApp.py to SimpleSCardApp.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/SimpleSCardAppFrame.py to SimpleSCardAppFrame.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/APDUHexValidator.py to APDUHexValidator.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/wx/CardAndReaderTreePanel.py to CardAndReaderTreePanel.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/System.py to System.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/ExclusiveConnectCardConnection.py to ExclusiveConnectCardConnection.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/SWExceptions.py to SWExceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/op21_ErrorChecker.py to op21_ErrorChecker.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/ISO7816_8ErrorChecker.py to ISO7816_8ErrorChecker.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/ISO7816_9ErrorChecker.py to ISO7816_9ErrorChecker.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/ISO7816_4_SW1ErrorChecker.py to ISO7816_4_SW1ErrorChecker.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/ErrorChecker.py to ErrorChecker.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/ISO7816_4ErrorChecker.py to ISO7816_4ErrorChecker.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/sw/ErrorCheckingChain.py to ErrorCheckingChain.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pyro/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/pyro/PyroReader.py to PyroReader.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardConnectionDecorator.py to CardConnectionDecorator.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/ulist.py to ulist.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/ReaderMonitoring.py to ReaderMonitoring.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/Synchronization.py to Synchronization.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/AbstractCardRequest.py to AbstractCardRequest.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/ClassLoader.py to ClassLoader.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/Observer.py to Observer.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardConnectionEvent.py to CardConnectionEvent.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/PassThruCardService.py to PassThruCardService.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardRequest.py to CardRequest.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/ATR.py to ATR.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardConnectionObserver.py to CardConnectionObserver.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardService.py to CardService.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/reader/ReaderFactory.py to ReaderFactory.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/reader/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/reader/Reader.py to Reader.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/reader/ReaderGroups.py to ReaderGroups.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/Session.py to Session.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/ExclusiveTransmitCardConnection.py to ExclusiveTransmitCardConnection.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/Card.py to Card.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/Exceptions.py to Exceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/smartcard/CardMonitoring.py to CardMonitoring.pyc
creating stub loader for smartcard/scard/_scard.so
byte-compiling build/bdist.linux-x86_64/egg/smartcard/scard/_scard.py to _scard.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pyscard.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyscard.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyscard.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyscard.egg-info/pbr.json -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyscard.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyscard.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
smartcard.scard.scard: module references __file__
smartcard.wx.__init__: module references __file__
creating 'dist/pyscard-1.9.6-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pyscard-1.9.6-py2.7-linux-x86_64.egg
creating /usr/local/lib/python2.7/dist-packages/pyscard-1.9.6-py2.7-linux-x86_64.egg
Extracting pyscard-1.9.6-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
Adding pyscard 1.9.6 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/pyscard-1.9.6-py2.7-linux-x86_64.egg
Processing dependencies for pyscard==1.9.6
Finished processing dependencies for pyscard==1.9.6

When opening up python and doing,

from smartcard.System import readers

I get this

>>> from smartcard.System import readers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "smartcard/__init__.py", line 32, in <module>
    from smartcard.System import listReaders
  File "smartcard/System.py", line 28, in <module>
    import smartcard.reader.ReaderFactory
  File "smartcard/reader/ReaderFactory.py", line 34, in <module>
    from smartcard.pcsc.PCSCReader import PCSCReader
  File "smartcard/pcsc/PCSCReader.py", line 28, in <module>
    from smartcard.pcsc.PCSCContext import PCSCContext
  File "smartcard/pcsc/PCSCContext.py", line 27, in <module>
    from smartcard.scard import *
  File "smartcard/scard/__init__.py", line 1, in <module>
    from smartcard.scard.scard import *
  File "smartcard/scard/scard.py", line 122, in <module>
    _scard = swig_import_helper()
  File "smartcard/scard/scard.py", line 121, in swig_import_helper
    return importlib.import_module('_scard')
  File "/home/quinten/anaconda2/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named _scard

The pyscard package is in the regular usr/loca/lib/python2.7/dist-packages/...
And should be in the Anaconda python directory.

Is there a way I can build this to a anaconda directory?

Exception ListReadersException: ('Failed to list readers', 2148532253) spam after pcscd service stop.

Hi,
As using http://pyscard.sourceforge.net/user-guide.html#monitoring-smart-cards and sending machine to reboot causes traceback spam in terminal.
After pcscd service stop, app will spam same traceback message endlessy or until app closes.

In other hand, http://pyscard.sourceforge.net/user-guide.html#monitoring-readers will give only one traceback and not more.

Digging into code gives answer for problem:
It will spam forever:

traceback.print_exc()

It gives one traceback:

traceback.print_exc()

Simple fix for problem: #22

UnicodeDecodeError

Hello,
I am using pyscard library in my NFC reader project. When I run, it give me error. I have tried your example code (link), but error is the same .
Error log is here:
F:\Python\Python36\python.exe "F:/My documents/My project/selectDF_TELECOM.py"
insert a card (SIM card if possible) within 10s
connecting to ACS ACR1252 CL Reader PICC 0

A0 A4 00 00 02 7F 10
Traceback (most recent call last):
disconnecting from ACS ACR1252 CL Reader PICC 0
File "F:/My documents/My project/selectDF_TELECOM.py", line 51, in
disconnecting from ACS ACR1252 CL Reader PICC 0
response, sw1, sw2 = cardservice.connection.transmit(apdu)
File "F:\Python\Python36\lib\site-packages\smartcard\CardConnectionDecorator.py", line 82, in transmit
return self.component.transmit(bytes, protocol)
File "F:\Python\Python36\lib\site-packages\smartcard\CardConnection.py", line 146, in transmit
data, sw1, sw2 = self.doTransmit(bytes, protocol)
File "F:\Python\Python36\lib\site-packages\smartcard\pcsc\PCSCCardConnection.py", line 205, in doTransmit
SCardGetErrorMessage(hresult))
File "F:\Python\Python36\lib\site-packages\smartcard\scard\scard.py", line 1278, in SCardGetErrorMessage
return _scard.SCardGetErrorMessage(lErrCode)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 0: invalid continuation byte

Process finished with exit code 1

I have marked in debugging mode, that variable hresult is 31.
hresult, response = SCardTransmit( self.hcard, pcscprotocolheader, bytes)

I am using:
Windows 8.1 64 bit
Python 3.6
pyscard 1.9.6
NFC tag: NXP NTAG213
NFC reader: ACR1252u sometimes ACM1252u

signed tarballs or tags

Would it be possible to generate signed release tarballs or signed tags on github with a PGP key ?

SCardConnect() for Direct Control returns error.

I checked the below code in Windows 7 x64, but it failed in Mac.
I've got the error

hret, hcard, dwActiveProtocol = SCardConnect( hcontext, readers[0], SCARD_SHARE_DIRECT, 0)

If I changed '0' to T0 or T1, it works but it was not what I want.

Here's the full code.

#! /usr/bin/env python

from smartcard.scard import *
from smartcard.util import *

CMD = [0xFF, 0x00, 0x48, 0x00, 0x00]
IOCTL_CCID_ESCAPE = SCARD_CTL_CODE(3500)
finalFlag = 0

print("\n===== To set PC/SC Reader (ACR122U) to Direct Mode =====\n")

hret, hcontext = SCardEstablishContext(SCARD_SCOPE_SYSTEM)
if hret != SCARD_S_SUCCESS:
    raise error 

hret, readers = SCardListReaders(hcontext, [])
if hret != SCARD_S_SUCCESS:
    raise error( 'Failed to list readers: ' + SCardGetErrorMessage(hret))
if len(readers) < 1:
    raise Exception('No smart card readers')
print('PCSC Readers:', readers, "\n")

hret, hcard, dwActiveProtocol = SCardConnect( hcontext, readers[0], SCARD_SHARE_DIRECT, 0)

if hret != SCARD_S_SUCCESS:
    raise error

hret, response = SCardControl(hcard, IOCTL_CCID_ESCAPE, CMD)
print("----- Trying to set to direct mode -----")
print("> " , toHexString(CMD, HEX))
print("< " , toHexString(response, HEX))
if hret != SCARD_S_SUCCESS:
    raise error
if hret == SCARD_S_SUCCESS:
    finalFlag = 1

hret = SCardDisconnect(hcard, SCARD_UNPOWER_CARD)
if hret != SCARD_S_SUCCESS:
    raise error

hret = SCardReleaseContext (hcontext)
if hret != SCARD_S_SUCCESS:
    raise error

Move from Epydoc to Sphinx

From epydoc Debian package:

epydoc (3.0.1+dfsg-16) unstable; urgency=medium

If possible, please consider moving away from the use of Epydoc. Epydoc is
basically unmaintained upstream. Also, it is only supported for Python 2,
so it will reach its end of life along with Python 2 sometime in 2020.

I will continue to maintain the Epydoc packages in Debian as long as I can,
acting as de facto upstream. However, once Python 2 is unsupported in
Debian, I'm not sure that we'll have too many options to keep it alive.
Migrating it to Python 3 is a fairly large job that I don't have the time or
the expertise to take on right now.

For my own Python code, I have recently converted to Sphinx using the
Napolean plugin. At [1], I can offer you a hack-ish script to convert
common Epydoc markup to Google-style docstrings. It's not perfect, but it
would get you much of the way toward working code.

[1] https://bitbucket.org/cedarsolutions/cedar-backup3/src/73037a2/util/sphinx-convert

-- Kenneth J. Pronovici [email protected] Sun, 12 Nov 2017 20:39:48 +0000

signed releases

Version 1.9.4 shipped with a gpg signature to verify source tarball. We already used this to verify source when building the Arch Linux package. Can we continue to ship signatures for future releases, please?
Thanks a lot!

rmthread should be cleaned up when the last observer is removed

self.rmthread = None

Currently when the last observer is removed the reference to rmthread is dropped:

if self.countObservers() == 0:
    if self.rmthread != None:
        self.rmthread = None

Should the thread not be stopped and joined if it is no longer needed? A suggested fix would be:

if self.countObservers() == 0:
    if self.rmthread != None:
        self.rmthread.stop()
        self.rmthread.join()
        self.rmthread = None

I'd be happy to make a pull request with this fix if this change is acceptable.

1.9.0 release not working for python 2.7

$ python
Python 2.7.10 (default, Jul  5 2015, 14:15:43) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import smartcard
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/smartcard/__init__.py", line 32, in <module>
    from smartcard.System import listReaders
  File "/usr/lib64/python2.7/site-packages/smartcard/System.py", line 28, in <module>
    import smartcard.reader.ReaderFactory
  File "/usr/lib64/python2.7/site-packages/smartcard/reader/ReaderFactory.py", line 34, in <module>
    from smartcard.pcsc.PCSCReader import PCSCReader
  File "/usr/lib64/python2.7/site-packages/smartcard/pcsc/PCSCReader.py", line 28, in <module>
    from smartcard.pcsc.PCSCContext import PCSCContext
  File "/usr/lib64/python2.7/site-packages/smartcard/pcsc/PCSCContext.py", line 27, in <module>
    from smartcard.scard import *
  File "/usr/lib64/python2.7/site-packages/smartcard/scard/__init__.py", line 1, in <module>
    from smartcard.scard.scard import *
  File "/usr/lib64/python2.7/site-packages/smartcard/scard/scard.py", line 830, in <module>
    SCARD_SCOPE_USER = _scard.SCARD_SCOPE_USER
AttributeError: 'module' object has no attribute 'SCARD_SCOPE_USER'

Seems like something up with swig, but I'm not a python guy. Any help appreciated!

can't install via pip

Tried installing it and failed, here:

$ pip install pyscard
Collecting pyscard
  Downloading pyscard-1.9.4.tar.gz (147kB)
    100% |โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 153kB 656kB/s 
Building wheels for collected packages: pyscard
  Running setup.py bdist_wheel for pyscard ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-tIB33N/pyscard/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmp9dtVK0pip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  running build_ext
  building 'smartcard.scard._scard' extension
  swigging smartcard/scard/scard.i to smartcard/scard/scard_wrap.c
  swig -python -outdir smartcard/scard -DPCSCLITE -o smartcard/scard/scard_wrap.c smartcard/scard/scard.i
  unable to execute 'swig': No such file or directory
  error: command 'swig' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pyscard
  Running setup.py clean for pyscard
Failed to build pyscard
Installing collected packages: pyscard
  Running setup.py install for pyscard ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-tIB33N/pyscard/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-lG9WSB-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    running build_ext
    building 'smartcard.scard._scard' extension
    swigging smartcard/scard/scard.i to smartcard/scard/scard_wrap.c
    swig -python -outdir smartcard/scard -DPCSCLITE -o smartcard/scard/scard_wrap.c smartcard/scard/scard.i
    unable to execute 'swig': No such file or directory
    error: command 'swig' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-tIB33N/pyscard/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-lG9WSB-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-tIB33N/pyscard/

signed releases

Same as #38... Please keep providing gpg signatures for releases. Thanks!

Installation error on Mac High Sierra

I got errors while I'm trying to install pyscard 1.9.6 with Python 3.6.4 on my Mac - High Sierra
pcsctest worked fine.

In file included from smartcard/scard/winscarddll.c:26:
smartcard/scard/winscarddll.h:280:13: error: unknown type name 'LPTSTR'
OUT LPTSTR mszReaders,
^
smartcard/scard/winscarddll.h:286:13: error: unknown type name 'LPTSTR'
OUT LPTSTR mszGroups,
^
smartcard/scard/winscarddll.h:304:9: error: unknown type name 'LPTSTR'
OUT LPTSTR szReaderName,
^
smartcard/scard/winscarddll.c:529:13: error: unknown type name 'LPTSTR'
OUT LPTSTR mszReaders,
^
smartcard/scard/winscarddll.c:543:13: error: unknown type name 'LPTSTR'
OUT LPTSTR mszGroups,
^
smartcard/scard/winscarddll.c:582:9: error: unknown type name 'LPTSTR'
OUT LPTSTR szReaderName,

CCID Escape command illegal function (Windows 7)

OS: Windows 7 SP1 64-bit
Python: 2.7.11
Pyscard: 1.9.2

I have a problem sending an CCID Escape command via pyscard to my CCID Reader.
When I execute the code snippet I get:
scard.error: Failed to control: Illegal function.

I wrote the same sequence in C using the original API and it works without problems.
Is it possible that pyscard does not support Escape commands?

#! /usr/bin/env python

from smartcard.scard import *

hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_SYSTEM)
if hresult != SCARD_S_SUCCESS:
    raise error, 'Failed to establish context: ' + SCardGetErrorMessage(hresult)

hresult, readers = SCardListReaders(hcontext, [])
if hresult != SCARD_S_SUCCESS:
    raise error(
        'Failed to list readers: ' + \
        SCardGetErrorMessage(hresult))
if len(readers) < 1:
    raise Exception('No smart card readers')
print('PCSC Readers:', readers)

hresult, hcard, dwActiveProtocol = SCardConnect(
    hcontext, readers[0], SCARD_SHARE_DIRECT, 0)
if hresult != SCARD_S_SUCCESS:
    raise error, 'Failed to control: ' + SCardGetErrorMessage(hresult)

CMD = [0xA0, 0x00]
IOCTL_CCID_ESCAPE = SCARD_CTL_CODE(3500)

hresult, response = SCardControl(hcard, IOCTL_CCID_ESCAPE, CMD)
if hresult != SCARD_S_SUCCESS:
    raise error, 'Failed to control: ' + SCardGetErrorMessage(hresult)

print(response)
print "Done"

No module named 'smartcard.scard._scard'

I am running Python 3.6 on Windows 10
I have installed pyscard 1.9.7 from the executable file

It works perfectly in the example,
But, when I try to use it in Odoo, it triggers an error:
No module named 'smartcard.scard._scard'
What is wrong ?
LOG:
File "C:\Program Files (x86)\Odoo 11.0e\server\odoo\addons\pos_pricing\models\__init__.py", line 26, in <module> from . import nfctool File "C:\Program Files (x86)\Odoo 11.0e\server\odoo\addons\pos_pricing\models\nfctool.py", line 1, in <module> from smartcard.System import readers File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\__init__.py", line 29, in <module> from smartcard.System import listReaders File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\System.py", line 28, in <module> import smartcard.reader.ReaderFactory File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\reader\ReaderFactory.py", line 34, in <module> from smartcard.pcsc.PCSCReader import PCSCReader File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\pcsc\PCSCReader.py", line 28, in <module> from smartcard.pcsc.PCSCContext import PCSCContext File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\pcsc\PCSCContext.py", line 27, in <module> from smartcard.scard import * File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\scard\__init__.py", line 1, in <module> from smartcard.scard.scard import * File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\scard\scard.py", line 119, in <module> _scard = swig_import_helper() File "C:\Program Files (x86)\Odoo 11.0e\server\smartcard\scard\scard.py", line 118, in swig_import_helper return importlib.import_module(mname) File "C:\Program Files (x86)\Odoo 11.0e\python\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ModuleNotFoundError: No module named 'smartcard.scard._scard'

Thanks for your help

Install pyscard in windows

Hi, I didn't see any exe or msi file for pyscard 1.9. May I ask how should I install it in windows?

Thank you
Jenny

APDU with ICODE DNA (ISO 15693)

Hello,
I'm trying to send APDU on an ICODE DNA iso 15693 tag with an Orcanthus reader (http://www.orcanthus.eu/fr/product_84/lecteur+sans+contact+de+bureau.htm)
The tag is successfully detected, I can send the apdu to retrieve the serial number.
But, when I try to execute another APDU, it fails with :

INFO:root:Waiting for tag (timeout=10.0s)
INFO:root:Connecting to tag
DEBUG:root:Sending APDU FF CA 00 00 00
DEBUG:root:Got response 90 00 1B 96 9D 00 18 01 04 E0
[27, 150, 157, 0, 24, 1, 4, 224]
DEBUG:root:Sending APDU 02 20 05
Traceback (most recent call last):
  File "minimalApp.py", line 31, in send_apdu
    data, sw1, sw2 = self.cardservice.connection.transmit(apdu)
  File "/usr/lib/python2.7/dist-packages/smartcard/CardConnectionDecorator.py", line 82, in transmit
    return self.component.transmit(bytes, protocol)
  File "/usr/lib/python2.7/dist-packages/smartcard/CardConnection.py", line 144, in transmit
    data, sw1, sw2 = self.doTransmit(bytes, protocol)
  File "/usr/lib/python2.7/dist-packages/smartcard/pcsc/PCSCCardConnection.py", line 198, in doTransmit
    SCardGetErrorMessage(hresult))
CardConnectionException: Failed to transmit with protocol T1. Transaction failed.

Unable to connect with protocol: T1. Card protocol mismatch.

Do you have any idea why it fails ?
Or does your library not support iso 15693?

Thanks in advance!

Here is the following code that launch the exception :

import logging
import traceback

from smartcard.CardRequest import CardRequest
from smartcard.CardType import ATRCardType
from smartcard.sw.ErrorCheckingChain import ErrorCheckingChain
from smartcard.sw.ISO7816_4ErrorChecker import ISO7816_4ErrorChecker
from smartcard.sw.ISO7816_4_SW1ErrorChecker import ISO7816_4_SW1ErrorChecker
from smartcard.sw.SWExceptions import WarningProcessingException
from smartcard.util import toHexString, toBytes

logging.basicConfig(level=logging.DEBUG)

class Orcanthus:
    def __init__(self, timeout=10.0):
        logging.info('Waiting for tag (timeout={:.1f}s)'.format(timeout))
        cardtype = ATRCardType(toBytes('3B 80 80 01 01'))
        cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
        self.cardservice = cardrequest.waitforcard()
        errorchain = []
        errorchain = [ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker()),
                      ErrorCheckingChain(errorchain, ISO7816_4_SW1ErrorChecker())]
        errorchain[0].addFilterException(WarningProcessingException)
        self.cardservice.connection.setErrorCheckingChain(errorchain)
        logging.info('Connecting to tag')
        self.cardservice.connection.connect()

    def send_apdu(self, apdu):
        logging.debug('Sending APDU {}'.format(toHexString(apdu)))
        try:
            data, sw1, sw2 = self.cardservice.connection.transmit(apdu)
        except Exception, e:
            tb = traceback.format_exc()
            print tb
            self.cardservice.connection.connect()
            raise e
        logging.debug('Got response {}'.format(toHexString([sw1] + [sw2] + data)))
        return data


class IcodeDna:
    APDU_GET_UID = [0xFF, 0xCA, 0x00, 0x00, 0x00]
    APDU_READ_PAGE = [0x02, 0x20, 0x05]

    def __init__(self, reader):
        self.reader = reader

    def transceive(self, apdu):
        return self.reader.send_apdu(apdu)

    def get_uid(self):
        return self.transceive(self.APDU_GET_UID)

    def read_page(self):
        return self.transceive(self.APDU_READ_PAGE)


if __name__ == '__main__':
    try:
        reader = Orcanthus()
        icode_dna_tag = IcodeDna(reader)
        print icode_dna_tag.get_uid()
        print icode_dna_tag.read_page()
    except Exception as e:
        print "{}".format(e)

pyscard installation via pip fails on win7 x64 (missing dependencys?)

Hello,

i'm trying to install pyscard but pip installation fails. Seems like missing dependency's(?)
OS Win 7-x64
Command: python -m pip install pyscard
Tested with Python 3.4.4-x64, 3.4.4-x86, 3.6.2-x64, 3.6.2-x86

Output from Pycharm


Collecting pyscard
  Using cached pyscard-1.9.6.tar.gz
Installing collected packages: pyscard
  Running setup.py install for pyscard: started
    Running setup.py install for pyscard: finished with status 'error'
    Complete output from command F:\Python\Python3-6-2-x86\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\luckystrike\\AppData\\Local\\Temp\\pycharm-packaging\\pyscard\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\LUCKYS~1\AppData\Local\Temp\pip-f4lnwpya-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    running build_ext
    building 'smartcard.scard._scard' extension
    swigging smartcard/scard/scard.i to smartcard/scard/scard_wrap.c
    swig.exe -python -outdir smartcard/scard -DWIN32 -o smartcard/scard/scard_wrap.c smartcard/scard/scard.i
    error: command 'swig.exe' failed: No such file or directory

Command "F:\Python\Python3-6-2-x86\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\luckystrike\\AppData\\Local\\Temp\\pycharm-packaging\\pyscard\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\LUCKYS~1\AppData\Local\Temp\pip-f4lnwpya-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\luckystrike\AppData\Local\Temp\pycharm-packaging\pyscard\

Output from CMD


F:\Python\Python3-4-4-x64>python -m pip install pyscard
Collecting pyscard
  Using cached pyscard-1.9.6.tar.gz
Installing collected packages: pyscard
  Running setup.py install for pyscard ... error
    Complete output from command F:\Python\Python3-4-4-x64\python.exe -u -c "imp
ort setuptools, tokenize;__file__='C:\\Users\\LUCKYS~1\\AppData\\Local\\Temp\\pi
p-build-toq198jf\\pyscard\\setup.py';f=getattr(tokenize, 'open', open)(__file__)
;code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exe
c'))" install --record C:\Users\LUCKYS~1\AppData\Local\Temp\pip-4sq8kep9-record\
install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    running build_ext
    building 'smartcard.scard._scard' extension
    swigging smartcard/scard/scard.i to smartcard/scard/scard_wrap.c
    swig.exe -python -outdir smartcard/scard -DWIN32 -o smartcard/scard/scard_wr
ap.c smartcard/scard/scard.i
    error: command 'swig.exe' failed: No such file or directory

Command "F:\Python\Python3-4-4-x64\python.exe -u -c "import setuptools, tokenize
;__file__='C:\\Users\\LUCKYS~1\\AppData\\Local\\Temp\\pip-build-toq198jf\\pyscar
d\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('
\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C
:\Users\LUCKYS~1\AppData\Local\Temp\pip-4sq8kep9-record\install-record.txt --sin
gle-version-externally-managed --compile" failed with error code 1 in C:\Users\L
UCKYS~1\AppData\Local\Temp\pip-build-toq198jf\pyscard\

Swig.exe failed No such file or directory
I'll guess this is some undocumented dependency?
http://www.swig.org/download.html This one? Which version?

Inconsistent state after unexpected disconnect

We have developed a simple smartcard using application, but are having issues when the nfc card is removed too soon.

Setup: Ubuntu 16.04 (pcscd 1.8.14, libnfc5 1.7.1, libccid 1.14.22), ACS122U nfc reader, Mifare classic nfc cards.

We try to detect an available NFC card by:

cardrequest = CardRequest(timeout=1, cardType=AnyCardType())
cardservice = cardrequest.waitforcard()
cardservice.connection.connect()
cardservice.connection.getATR()

After a successful connection we can authenticate, read the tag, and decrement it.
But when we remove the card from the reader too soon, the transaction breaks (most of the time during the authentication). However, when we try to check for subsequent presented cards, the above routine successfully connects and returns without errors, also when no card is actually present.

After the above situation, authenticating with the card fails, and our code crashes. How would we detect correctly whether a card is presented?

I also installed the upstream drivers from https://www.acs.com.hk/en/driver/3/acr122u-usb-nfc-reader/, but this makes no difference.

pyscard and OSX

I am trying to get pyscard to run under OSX. I have successfully managed to get it run under Linux VM on the same computer using a USB based reader.

However on native OSX I cannot make pyscard to find my reader.

Are there any up-to-date instructions what native dependencies and setup pyscard needs in order to run under OSX (10.11.6).

smartcard.System.readers will occasionally fail to list readers

Hi, I am using version 1.9.4 in python2.
I will occasionally get this error. I have two smartcards attached. The problem will be solved if I re-import the module. Anyone has any clue or suggestion here? Thanks a lot~

Traceback (most recent call last):
................
card_readers = readers()
File "/usr/lib/python2.7/dist-packages/smartcard/System.py", line 42, in readers
return smartcard.reader.ReaderFactory.ReaderFactory.readers(groups)
File "/usr/lib/python2.7/dist-packages/smartcard/reader/ReaderFactory.py", line 58, in readers
zreaders += fm(groups)
File "/usr/lib/python2.7/dist-packages/smartcard/pcsc/PCSCReader.py", line 110, in readers
for reader in PCSCreaders(hcontext, groups):
File "/usr/lib/python2.7/dist-packages/smartcard/pcsc/PCSCReader.py", line 49, in PCSCreaders
raise ListReadersException(hresult)
ListReadersException: 'Failure to list readers: Service not available.'

Cannot send command to reader

For example Get firmware version as described on
https://www.acs.com.hk/en/products/159/acr1281u-c1-dualboost-ii-usb-dual-interface-reader/

There should be separate way to send command not to card but to reader (pc to RDR escape as in ACR documentation).
This is APDU commands so I cannot use doCommand that send one code.

In fact I am looking for a way to communicate with SAM (secure access module) installed on the reader.
I can communicate with card in proximity with the reader but see no way to execute reader commands specifically to select SAM.

Smart cards can't be recognized from a USB type C port

Information about your card

  1. Vendor: Gemalto card and smart card reader
  2. Product: Gemalto USB Shell Token
  3. Version: V2

My Macbook has only USB type C which requires an adapter to connect to a smart card reader of USB type A.

Expected behavior
I expect ATR and the reader to be found.

Full log
Re-run your command with -d -v -i switches
$ java -jar gp.jar -d -v -i
GlobalPlatformPro 18.09.14-0-gb439b52
Running on Mac OS X 10.13.6 x86_64, Java 11.0.1 by Oracle Corporation

Detected readers from JNA2PCSC

No smart card readers with a card found

Additional context
I suspect it is due to the USB type adapter. Since in my old Mac with USB type A, the smart card can be found. Do I need to do anything special to read from USB type C?

Thanks

linux / python 2.7.3 smartcard/scard/__init__.py : from smartcard.scard.scard import * ImportError: No module named scard

Hello,

I'm having some trouble with pyscard 1.9.1 installed via pip on an Intel Edison

running any example results in:

python pcsc_omnikey.py
Traceback (most recent call last):
  File "pcsc_omnikey.py", line 2, in <module>
    from smartcard.System import readers
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/__init__.py", line 32, in <module>
    from smartcard.System import listReaders
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/System.py", line 28, in <module>
    import smartcard.reader.ReaderFactory
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/reader/ReaderFactory.py", line 34, in <module>
    from smartcard.pcsc.PCSCReader import PCSCReader
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/pcsc/PCSCReader.py", line 28, in <module>
    from smartcard.pcsc.PCSCContext import PCSCContext
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/pcsc/PCSCContext.py", line 27, in <module>
    from smartcard.scard import *
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/scard/__init__.py", line 1, in <module>
    from smartcard.scard.scard import *
ImportError: No module named scard

If I modify smartcard/scard/init.py, changing it to

# from smartcard.sdcard.sdcard import * # original  
from smartcard.sdcard import * # modified

I get the following:

python pcsc_omnikey.py                            
Traceback (most recent call last):
  File "pcsc_omnikey.py", line 2, in <module>
    from smartcard.System import readers
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/__init__.py", line 32, in <module>
    from smartcard.System import listReaders
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/System.py", line 28, in <module>
    import smartcard.reader.ReaderFactory
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/reader/ReaderFactory.py", line 34, in <module>
    from smartcard.pcsc.PCSCReader import PCSCReader
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/pcsc/PCSCReader.py", line 29, in <module>
    from smartcard.pcsc.PCSCCardConnection import PCSCCardConnection
  File "/home/root/pyenv/lib/python2.7/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 60, in <module>
    dictProtocolHeader = {SCARD_PCI_T0: 'T0', SCARD_PCI_T1: 'T1',
NameError: name 'SCARD_PCI_T0' is not defined

Python 3.4, Windows OS, UnicodeDecodeError

data, sw1, sw2 = self.cardservice.connection.transmit(apdu)
File "C:\Python34\lib\site-packages\pyscard-1.9.0-py3.4-win-amd64.egg\smartcard\CardConnectionDecorator.py", line 82, in transmit
return self.component.transmit(bytes, protocol)
File "C:\Python34\lib\site-packages\pyscard-1.9.0-py3.4-win-amd64.egg\smartcard\CardConnection.py", line 142, in transmit
data, sw1, sw2 = self.doTransmit(bytes, protocol)
File "C:\Python34\lib\site-packages\pyscard-1.9.0-py3.4-win-amd64.egg\smartcard\pcsc\PCSCCardConnection.py", line 205, in doTransmit
SCardGetErrorMessage(hresult))
File "C:\Python34\lib\site-packages\pyscard-1.9.0-py3.4-win-amd64.egg\smartcard\scard\scard.py", line 1241, in SCardGetErrorMessage
return _scard.SCardGetErrorMessage(lErrCode)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 0: invalid continuation byte

CardConnectionException: Card not connected or Failed to transmit with protocol T0. Card protocol mismatch.

I've got the ACR122U reader connected to Ubuntu 18.10 machine.
I am using RFIDIOt sample scripts which do use the: pyscard.
For instance cardselect.py: https://github.com/AdamLaurie/RFIDIOt/blob/master/cardselect.py

Everything worked fine until it stopped same day it was all configured.

I am getting the immediate exception (in case card is not present):

07:50 $ ./cardselect.py 
Traceback (most recent call last):
  File "./cardselect.py", line 25, in <module>
    import rfidiot
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/__init__.py", line 194, in <module>
    card= RFIDIOt.rfidiot(readernum,readertype,line,speed,timeout,rfidiotglobals.Debug,noinit,nfcreader)
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 161, in __init__
    self.acs_set_retry(to)
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 1320, in acs_set_retry
    return self.acs_send_apdu(self.PCSC_APDU['ACS_SET_RETRY'])
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 1187, in acs_send_apdu
    result, sw1, sw2= self.acs_transmit_apdu(apduout)
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 1211, in acs_transmit_apdu
    result, sw1, sw2= self.pcsc_connection.transmit(apdu,protocol= self.pcsc_protocol)
  File "/usr/local/lib/python2.7/dist-packages/smartcard/CardConnectionDecorator.py", line 82, in transmit
    return self.component.transmit(bytes, protocol)
  File "/usr/local/lib/python2.7/dist-packages/smartcard/CardConnection.py", line 146, in transmit
    data, sw1, sw2 = self.doTransmit(bytes, protocol)
  File "/usr/local/lib/python2.7/dist-packages/smartcard/pcsc/PCSCCardConnection.py", line 198, in doTransmit
    raise CardConnectionException('Card not connected')
smartcard.Exceptions.CardConnectionException: Card not connected

or immediate exception when card is present:

07:51 $ ./cardselect.py 
Traceback (most recent call last):
  File "./cardselect.py", line 25, in <module>
    import rfidiot
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/__init__.py", line 194, in <module>
    card= RFIDIOt.rfidiot(readernum,readertype,line,speed,timeout,rfidiotglobals.Debug,noinit,nfcreader)
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 161, in __init__
    self.acs_set_retry(to)
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 1320, in acs_set_retry
    return self.acs_send_apdu(self.PCSC_APDU['ACS_SET_RETRY'])
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 1187, in acs_send_apdu
    result, sw1, sw2= self.acs_transmit_apdu(apduout)
  File "/usr/local/lib/python2.7/dist-packages/rfidiot/RFIDIOt.py", line 1211, in acs_transmit_apdu
    result, sw1, sw2= self.pcsc_connection.transmit(apdu,protocol= self.pcsc_protocol)
  File "/usr/local/lib/python2.7/dist-packages/smartcard/CardConnectionDecorator.py", line 82, in transmit
    return self.component.transmit(bytes, protocol)
  File "/usr/local/lib/python2.7/dist-packages/smartcard/CardConnection.py", line 146, in transmit
    data, sw1, sw2 = self.doTransmit(bytes, protocol)
  File "/usr/local/lib/python2.7/dist-packages/smartcard/pcsc/PCSCCardConnection.py", line 205, in doTransmit
    SCardGetErrorMessage(hresult))
smartcard.Exceptions.CardConnectionException: Failed to transmit with protocol T0. Card protocol mismatch.

My setup is mostly this:

sudo apt-get install libccid pcscd libpcsclite-dev libpcsclite1 pcsc-tools
# Install official drivers
sudo dpkg -i libacsccid1_1.1.6-1~ubuntu18.10.1_amd64.deb


sudo modprobe -r pn533_usb
sudo service pcscd restart

sudo pip install pyscard

# Then build the the RFIDIOt etc

After this the: pcsc_scan works perfectly fine.

Any idea what I am doing wrong? Thanks !

Exception ListReadersException raised after disconnecting PCSC reader

Hi,

I've noticed pyscard is not able to maintain the list of readers when a reader is connected / disconnected to / from my computer which runs on Windows 8.1 (64 bits).

I've written the following piece of code from the documentation to see if connections and disconnections of the reader are well detected :

from sys import stdin, exc_info
from time import sleep
from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver

class printobserver( ReaderObserver ):
    def update( self, observable, (addedreaders, removedreaders) ):
        print "Added readers", addedreaders
        print "Removed readers", removedreaders

if __name__ == "__main__":
    try:
        print "Add or remove a smartcard reader to the system."
        print "This program will exit in 60 seconds"
        print ""
        readermonitor = ReaderMonitor()
        readerobserver = printobserver()
        readermonitor.addObserver( readerobserver )

        sleep(60)
    except error:
        print exc_info()[0], ': ', exc_info()[1]
    finally : 
        readermonitor.deleteObserver(readerobserver)

If the reader is connected before launching the program, it is well detected. But if it is connected / deconnected during the observer loop a ListReadersException is raised.

To avoid the problem, is there a way to force the reload of the entire pyscard module on demand ?

Cheers,

Thierry.

weird crash on RPi

first up - thank you for maintaining pyscard! its been working well for the last year on the RaspberryPi's we've been using

but... I did some pretty major changes to the code, and now I'm getting a weird crash:

INFO:root:['ACS ACR122U 00 00']
INFO:root:Waiting for smartcard or RFID.
INFO:root:


INFO:root:retry:
INFO:root:+Inserted: 3B8F8001804F0CA000000306030001000000006A
INFO:root:tagid AD6BC255
INFO:root:+Removed: 3B8F8001804F0CA000000306030001000000006A
INFO:root:+Inserted: 3B8F8001804F0CA000000306030001000000006A
INFO:root:tagid AD6BC255
INFO:root:+Inserted: 
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/smartcard/CardMonitoring.py", line 176, in run
    (addedcards, removedcards))
  File "/usr/lib/python2.7/dist-packages/smartcard/Observer.py", line 63, in notifyObservers
    observer.update(self, arg)
  File "./rfid-mifare/main.py", line 61, in update
    connection.connect( CardConnection.T1_protocol )
  File "/usr/lib/python2.7/dist-packages/smartcard/CardConnectionDecorator.py", line 54, in connect
    self.component.connect(protocol, mode, disposition)
  File "/usr/lib/python2.7/dist-packages/smartcard/pcsc/PCSCCardConnection.py", line 128, in connect
    SCardGetErrorMessage(hresult))
CardConnectionException: Unable to connect with protocol: T1. Card is unpowered.

it doesn't happen on my amd64 box :)

I'm going to take the code apart to try to localise it - I think it started happening when I added python logging, but atm, i thought I'd just record this in case it helps someone.

Using the observer based approach randomly fails with CardRequestTimeoutException

I've been using the sample_TransmitCardObserver.py example for reading mifare-tags. I do want to run this script as a daemon, but I'm getting random CardRequestTimeoutException: Time-out during card request errors.
Those keep mostly popping up, when quickly interacting with the reader and the tag - putting it to the reader only for a short time and pulling it away.
The full trace is as follows:

Traceback (most recent call last):
  File "lib/python3.6/site-packages/smartcard/CardMonitoring.py", line 160, in run
    currentcards = self.cardrequest.waitforcardevent()
  File "lib/python3.6/site-packages/smartcard/CardRequest.py", line 72, in waitforcardevent
    return self.pcsccardrequest.waitforcardevent()
  File "lib/python3.6/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 309, in waitforcardevent
    raise CardRequestTimeoutException()
smartcard.Exceptions.CardRequestTimeoutException: Time-out during card request

After this happens the program just hangs indefinitely.
I tracked the issue down to: #22
Without this PR, the Monitor just keeps on going, printing the occasional stack-trace, but otherwise seeming to work fine.
I'm now using pyscard exclusively with this patch locally undone. I would however love to see this fixed here. I guess for now I'd prefer for #22 to be un-merged. If the only downside of that is "duplicate error message printouts" not being prevented, I would prefer the monitoring-thread not being stopped on a CardRequestTimeoutException and mostly working flawlessly otherwise.

Crash when using sys.exit()

When I use sys.exit() in my program it often throws AttributeError exception.

Test program:

#!/usr/bin/env python3

from smartcard.CardType import AnyCardType
from smartcard.CardConnection import CardConnection
from smartcard.CardRequest import CardRequest

from sys import exit

cardtype = AnyCardType()
cardrequest = CardRequest( timeout=1, cardType=cardtype )
cardservice = cardrequest.waitforcard()

cardservice.connection.connect()

exit(0)

Error:

Exception ignored in: <bound method CardService.__del__ of <smartcard.PassThruCardService.PassThruCardService object at 0x101500828>>
Traceback (most recent call last):
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/CardService.py", line 52, in __del__
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/CardConnectionDecorator.py", line 58, in disconnect
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/pcsc/PCSCCardConnection.py", line 154, in disconnect
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/scard/scard.py", line 545, in SCardDisconnect
AttributeError: 'NoneType' object has no attribute 'SCardDisconnect'
Exception ignored in: <bound method PCSCCardConnection.__del__ of <smartcard.pcsc.PCSCCardConnection.PCSCCardConnection object at 0x1015007b8>>
Traceback (most recent call last):
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/pcsc/PCSCCardConnection.py", line 88, in __del__
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/pcsc/PCSCCardConnection.py", line 154, in disconnect
  File "/Users/sigsergv/projects/nfc/pyscard-demos/.venv/lib/python3.5/site-packages/pyscard-1.9.5-py3.5-macosx-10.6-intel.egg/smartcard/scard/scard.py", line 545, in SCardDisconnect
AttributeError: 'NoneType' object has no attribute 'SCardDisconnect'

Looks like the destructor is executing twice when using sys.exit().

Global PCSCContext doesn't handle Smart Card Reader Manager restart

Since the PCSCContext is global this gets into a broken state if the smart card service restarts. This is especially a problem on Windows, as starting with Windows 8 the service automatically shuts down when the last reader is unplugged, and re-started when one is inserted. On Linux this can be reproduced by restarting pcscd. I currently have a workaround for this where I catch the ListReadersException and then manually unset the context with PCSCContext.instance = None, which causes a new one to be created upon invoking System.readers() again.

I have reproduced this using pyscard 1.9.4 on both Python 2.7 and 3.5

Steps to reproduce:

>>> from smartcard import System
>>> System.readers()
['A connected reader']

Now, unplug and re-insert the reader on Windows (or restart pcscd on Linux)...

>>> System.readers()
Traceback ...<snip>...
smartcard.pcsc.PCSCException.ListReadersException: 'Failure to list readers: The Smart Card Resource Manager has shut down.'
>>> from smartcard.pcsc.PCSCContext import PCSCContext
>>> PCSCContext.instance = None
>>> System.readers()
['A connected reader']

getting started question

Hello,

How do you use this package to access a card and get the user credentials from a ping?

Is there a sample that shows this?

Thanks!

can't install or build module

That's the error:

$ python setup.py build
running build
running build_py
running build_ext
building 'smartcard.scard._scard' extension
swigging smartcard/scard/scard.i to smartcard/scard/scard_wrap.c
swig -python -outdir smartcard/scard -DPCSCLITE -o smartcard/scard/scard_wrap.c smartcard/scard/scard.i
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/smartcard
creating build/temp.linux-x86_64-2.7/smartcard/scard
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVER_PRODUCTVERSION=1,9,4,0000 -DVER_PRODUCTVERSION_STR=1.9.4 -DPCSCLITE=1 -Ismartcard/scard/ -I/usr/include/PCSC -I/usr/include/python2.7 -c smartcard/scard/helpers.c -o build/temp.linux-x86_64-2.7/smartcard/scard/helpers.o
smartcard/scard/helpers.c:28:22: fatal error: winscard.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Python 3.4 Install

Using
python setup.py install
from the github repository I am getting:
error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).

Is there any precompiled binary or VS project files I could use to install?

Cards take too long to disconnect after authentication

I have a script that authenticates Mifare Classic 1K. However, the reader takes around 2 second to be ready to sense another card. This issue happens if I attempt to authenticate the card using stored key.
If I remove the code that authenticates (or throw the error Card not supported always), it takes less than 0.1 sec to sense the card is removed. Any ideas of the reason?
P.S. The buzzer and LED control don't affect the bug. If removed, the led is turned off for 2 seconds after the communication.
I am using Python27x64 on Windows10.

Here is my code:

class PrintObserver(CardObserver):
	"""A simple card observer that is notified
	when cards are inserted/removed from the system and
	prints the list of cards
	"""
	MifareClassic = [0x3B, 0x8F, 0x80, 0x01, 0x80, 0x4F, 0x0C, 0xA0, 0x00, 0x00, 0x03, 0x06, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x6A]

	Auth = [*********] #removed key info

	WrongBeeb = [0xFF, 0x00, 0x40, 0x5a, 0x04, 0x01, 0x01, 0x02, 0x01]
	AuthBlock15 = [0xFF, 0xB0, 0x00, 0x3c, 0x10]
	SuccessBeeb = [0xFF, 0x00, 0x40, 0x5a, 0x04, 0x01, 0x00, 0x01, 0x01]

	def update(self, observable, actions):
		(addedcards, removedcards) = actions
		for card in addedcards:
			try:
				card.connection = card.createConnection()
				card.connection.connect()
				if card.atr != self.MifareClassic:
					raise Exception("Card not supported")
				data, sw1, sw2 = card.connection.transmit(self.Auth)
				if (sw1, sw2) == (0x90, 0x0):
					data, sw1, sw2 = card.connection.transmit(self.AuthBlock15)
					print ("block "+ str(15) +":\t"+ toHexString(data) +" | "+''.join(chr(i) for i in data))
					card.connection.transmit(self.SuccessBeeb)
				elif (sw1, sw2) == (0x63, 0x0):
					raise Exception("Key not working")
			except Exception as e:
				try:
					card.connection.transmit(self.WrongBeeb)
				except:
					pass
				print(e.message)
				pass

CardMonitor memory leak.

My program which uses heavily pyscard CardMonitor leaks memory.
Atm i am using pyscad 1.9.4.

Memory leak occurs with raspbian (raspberrypi). With computer i can't reproduce memory leak.

Minimal code for code leaking, is this:https://paste.debian.net/911098/

Application have runned one day and pmap output is: http://pastebin.com/K3hexCrZ
Basically Monitoring smartcard insertion/removal example.

Suspicios parts are: XXXXX 2048K rw--- [ anon ]

And content inside them: http://pastebin.com/Aa8J7SVW
I looked more parts of it and there are same repeating pattern.

And there is pmap output after application restart: http://pastebin.com/E9Uwce0W

Installation log: http://paste.debian.net/911086/

I wrote down 2048K parts own at every half hour.

2017-01-16 00:30:01 ; 0 ;
2017-01-16 01:00:01 ; 0 ;
2017-01-16 01:30:01 ; 0 ;
2017-01-16 02:00:01 ; 1 ;
2017-01-16 02:30:01 ; 1 ;
2017-01-16 03:00:02 ; 1 ;
2017-01-16 03:30:01 ; 2 ;
2017-01-16 04:00:01 ; 2 ;
2017-01-16 04:30:01 ; 2 ;
2017-01-16 05:00:01 ; 3 ;
2017-01-16 05:30:01 ; 3 ;
2017-01-16 06:00:01 ; 3 ;
2017-01-16 06:30:01 ; 4 ;
2017-01-16 07:00:01 ; 4 ;
2017-01-16 07:30:01 ; 4 ;
2017-01-16 08:00:01 ; 5 ;
2017-01-16 08:30:01 ; 5 ;
2017-01-16 09:00:02 ; 6 ;
2017-01-16 09:15:01 ; 6 ;

I digged even deeper and collecked more fequently and other statistic about pmap output.
Found a interesting behaviour, memory leak has steps. At first 1024K is captured and next step is 2048K.

Configurable polling interval?

Can you please make the card monitoring thread's polling interval configurable?

My current hack works, but makes me sad:

        self._monitor = CardMonitor()
        self._monitor.addObserver(self)

        success = False
        attempts = 0
        sleeptime = 0.01
        while attempts < 5:
            try:
                self._monitor.rmthread.cardrequest.pcsccardrequest.pollinginterval = 5
                success = True
                break
            except:
                time.sleep(sleeptime)
                sleeptime = 0.1
            attempts += 1
        if success:
            print("Successfully set polling interval")
        else:
            print("Failed to set polling interval")

CardMonitoringThread's cardrequest field doesn't exist until the thread starts. So I have to wait before I can monkey-patch the polling interval value.

It'd be infinitely better if I could just set the polling interval when I create a CardMonitor instance, or if I could use a function call to set it (or both!)

empty response -> crash on empty sw1

looks a lot like LudovicRousseau/pyscard-contrib#2

trying any example with transmit (here http://pyscard.sourceforge.net/pyscard-framework.html#selecting-the-df-telecom-of-a-card), with any tag, i get:

insert a card (SIM card if possible) within 10s
connecting to ACS ACR122U PICC Interface 00 00
> A0 A4 00 00 02 7F 10
Traceback (most recent call last):
  File "ct4.py", line 56, in <module>
    response, sw1, sw2 = cardservice.connection.transmit(apdu)
  File "/usr/local/lib/python2.7/dist-packages/pyscard-1.9.2-py2.7-linux-x86_64.egg/smartcard/CardConnectionDecorator.py", line 82, in transmit
    return self.component.transmit(bytes, protocol)
  File "/usr/local/lib/python2.7/dist-packages/pyscard-1.9.2-py2.7-linux-x86_64.egg/smartcard/CardConnection.py", line 146, in transmit
    data, sw1, sw2 = self.doTransmit(bytes, protocol)
  File "/usr/local/lib/python2.7/dist-packages/pyscard-1.9.2-py2.7-linux-x86_64.egg/smartcard/pcsc/PCSCCardConnection.py", line 207, in doTransmit
    sw1 = (response[-2] + 256) % 256
IndexError: list index out of range
disconnecting from ACS ACR122U PICC Interface 00 00
disconnecting from ACS ACR122U PICC Interface 00 00

when i get down to it with pudb, response is just [] in there, so of course it's out of range. First tried with python-pysdcard from ubuntu repository, then i built/installed from source (this repository). I'm having a look into scard.i, and SCardTransmit, but i have no experience with swig, so i'm not positive i'll find the cause on my own, so any idea welcome :). If i start gscriptor and run a script like FFCA000000, i do get an answer, so i guess pcscd is working correctly.

Doesn't seem to find ACR-1255U reader

I have an ACR1255U reader connected via USB, however this is all I get:

>>> import smartcard.System
>>> print smartcard.System.readers()
[]

My ACR122 however, shows up just fine!

Debian package is missing dependency

Hi,

I don't know if this belongs here, but after installing your package on Debian via

apt install python-pyscard

You get the error:

smartcard.pcsc.PCSCExceptions.EstablishContextException: 'Failure to establish context: Service not available.'

when using your library.

This is because the service pcscd is not installed. Which can easily be fixed of course.

My question now is, why the dependencies of the debian package:

Depends: libc6 (>= 2.14), python (>= 2.7), python (<< 2.8)

Do not contain pcscd?

My system:

Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux

Greets

T0/T1 marshaling confusion

I've been tracking a strange issue that I believe is due to a problem in the swig code for scard. I'm talking to a SLE5542 using an ACR39U reader and I've got a piece of C code for reading memory off of that card that works but the corresponding python code using the scard interface does not. All of this was done using fresh clones of pcsc-lite and pyscard from github.

The C code is in https://gist.github.com/leifj/140f9c79d99af078c5167f587cd81b69

This code works as expected and it depends on using the T0 protocol which triggers the correct processing of "pseudo" APDUs in the driver. So far so good. However ...

Using scard I expect code like this to work:

hresult, hcard, dwActiveProtocol = SCardConnect(
                hcontext,
                reader,
                SCARD_SHARE_DIRECT, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)

SELECT_CARD_TYPE = [0xFF,0xA4,0x00,0x00,0x01,0x06]
hresult, response = SCardTransmit(hcard, SCARD_PCI_T0, SELECT_CARD_TYPE)
if hresult != SCARD_S_SUCCESS:
    raise error, 'Failed to transmit: ' + SCardGetErrorMessage(hresult)

Using this code I get a protocol mismatch (between the card protocol and requested protocol) and when I step through pcscd with gdb while running this python code, I find that the message string received by ContextThread in winscard_svc.c has a '1' in the pioSendPciProtocol field instead of the expected 0. A sample gdb snippet:

13553973 winscard_svc.c:351:ContextThread() Received command: TRANSMIT from client 14
353                     switch (header.command)
(gdb) 
621                                     READ_BODY(trStr)
(gdb) 
623                                     if (MSGCheckHandleAssociation(trStr.hCard, threadContext))
(gdb) p trStr
$3 = {hCard = 1821360693, ioSendPciProtocol = 1, ioSendPciLength = 16, cbSendLength = 6, ioRecvPciProtocol = 3, ioRecvPciLength = 16, 
  pcbRecvLength = 65548, rv = 0}
(gdb) c
Continuing.

Continuing to step through this I confirm that the subsequent call to SCardTransmit is attempted using the T1 protocol which of course results in a protocol mismatch later on.

There seems to be a marshalling error somewhere in pyscard.

pyscard 1.9.1 and py2exe

Hello,

I have a script which works fine using Pyscard 1.9.1 with Python 3.4.3 on Windows 7. Py2exe generates an EXE file from my script, no error or warning are reported by Py2exe during generation but when I run the EXE file, I get this error:

  File "C:\Python34\lib\site-packages\smartcard\scard\scard.py", line 121, in swig_import_helper
    import _scard
ImportError: No module named '_scard'

I face the same issue when I want to build EXE file for Py2exe examples provided with Pyscard 1.6.12

What causes this error? How can I create EXE files using Pyscard?

Thank you for your help.

Error while installing from PyPi

I tried installing pyscard 1.9.3 through PyPi since the pip install bug seemed to be fixed, however I'm still having problems. I first downloaded the archive from sourceforge and try to build the wheel by myself:

$ tar xvzf pyscard-1.9.3.tar.gz
$ cd pyscard-1.9.3
$ pip wheel .
$ cd /path/to/my/project/
$ pip install /path/to/pyscard-1.9.3-cp34-cp34m-linux_x86_64.whl
$ ipython
In [1]: import smartcard
...
ImportError: No module named 'smartcard.scard.scard'

Running a simple pip install pyscard fails with the same error too.
I then tried the same process straight from the master branch to see if I could reproduce the error:

$ cd /path/to/pyscard/repo/
$ pip wheel .
$ cd /path/to/my/project/
$ pip install /path/to/pyscard-1.9.3-cp34-cp34m-linux_x86_64.whl
$ ipython
In [1]: import smartcard

In [2]: 

I got no error when building the wheel from the cloned repository.

Is there a problem with the archive uploaded to the official PyPi?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.