So to make life a bit easier we’ll store the list of smart card readers and access the one we want from the list #!/usr/bin/env python3 I want to use my USB SIM reader (The one identified by Identiv SCR35xx USB Smart Card Reader CCID Interface 00 00), so the next step will be to start a connection with this reader, which is the first in the list. So we can see when we run readers() we’re returned a list of readers on the system. (If your device doesn’t show up in this list, double check it’s PCSC compatible, and you can see it in your OS.) Here we can see the two readers that are present on my system (To add some confusion I have two readers connected – One built in Smart Card reader and one USB SIM reader): Running this will output a list of the readers on the system: So let’s get started by getting pyscard to list the readers we have available on our system: #!/usr/bin/env python3
pyscard supports Windows and Linux and you can install it using PIP with: pip install pyscard We’ll use pyscard to interface with the PCSC interface. I’m going to use Python3 to interface with these cards, but keep in mind you can find similar smart card libraries in most common programming languages.Īt this stage as we’re just interfacing with Smart Cards, our library won’t have anything SIM-specific (yet).
Throughout this series we’ll be using a few Python libraries to interface with the Smart Cards, but under the hood all will be using PCSC to communicate. To abstract away some complexity we’re going to use the industry-standard PCSC (PC – Smart Card) interface to communicate with our SIM card. To keep it simple, we’re not going to concern ourselves too much with the physical layer side of things for interfacing with the card, so we’ll start with sending raw APDUs to the cards, and then we’ll use some handy libraries to make life easier. USB SIM / Smart Card reader supports all the standard form factors makes life a lot easier! You may end up fiddling around with the plastic adapters to change the SIM form factor between regular smart card, SIM card (standard), micro and nano.
While reading what the hex should look like on the screen is all well and good, actually interacting with cards is the name of the game, so that’s what we’ll be doing today, and we’ll start to abstract some of the complexity away. Interacting with a card involves sending the APDU data to the card as hex, which luckily isn’t as complicated as it seems.
So in our last post we took a whirlwind tour of what an APDU does, is, and contains. This is part 3 of an n part tutorial series on working with SIM cards.