I start developing our own firmware implementation of smartcard reader.
Smartcard reader is a small computer which interfaces smartcard and host computer.
Although it is obvious to abuse it for MITM attack (since it is the device in the middle, by its definition), some people have tendency excluding such a consideration of device for possible attack vectors.
I hope this project can remove a blind spot from "security" system.
The first thing is the hardware design.
It should be as simple as possible, so that it can be easily reproducible. Thus, my selection is STM32F103.
But not simpler, because it can be enhanced easily (like adding pinpad and display). So, it is not a device like FST-01/G/SZ.
Conclusion: I decided using STM32 Nucleo F103 as this reference design.
Please have a look at the article of STM32 Nucleo F103 for how-to make a USB device of STM32F103 using STM32 Nucleo F103.
For simplicity, I don't use any driver IC for smartcard; STM32F103 is directly connected to a smartcard. This is OK for experiment, because most smartcards support +3V3 voltage these days.
I add a 10k-ohm resistor and a connector. The connector is:
- Amphenol 7432E0225S01LF
The resistor is to pull up the signal of smartcard I/O line.
Circuit (just connections of wires and a resistor)
Here is a top view of smartcard pinout:
/---------+---------\ 1: Vcc | 1 | 5 | 2: RST +-----\ | /-----+ 3: CLK | 2 +--+ + 6 | 4: not used +------| |------+ 5: GND | 3 +--+--+ 7 | 6: not used +-----/ | \-----+ 7: I/O | 4 | 8 | 8: not used \---------+---------/
Beside, Amphenol 7432E0225S01LF has a pin for card insertion detection.
Use of Connector of STM32 Nucleo F103
We use pins from CN10 connector.
- PB4: card insertion detect (0 when detected)
- PB6: Vcc
- PB8: Vpp
- PB9: RST
- USART3_TX (PB10): I/O
- USART3_CK (PB12): CLK
We put a resistor of 10k-ohm between USART3_TX and PB6.
I decide using Chopstx, because it's my favorite.
Modification to Chopstx
I modify board settings for STM32 Nucleo F103.
I enhance USART driver to support smartcard communication.
In Chopstx 1.14, we can use USART3 to provide:
- USART3_CK: 3.6MHz clock
- USART3_TX: 9677 bps half-duplex communication
The change looks easy, but it took more than two days for me to figure out correct sequence of initialization of the USART for smartcard communication; Enabling SCEN-bit should be after CR1 setting. If not, TX works, but RX never works correctly.
The project name is ttxs, "Tian Tian Xiang Shang" (天天向上). The abbreviation looks like perumutation-ciphered text of "CCID". It means progress day by day.