Ubuntu/MAC Smart Card Operation overview 1-access PC/SC Card Reader

Source: Internet
Author: User

Because PC/SC is a Windows system, it serves applications at the system API level. So for a long time, card readers and tools related to smart cards have been concentrated on Windows, while on Unix systems, card readers have been reluctant to accept. Fortunately, with the open-source organization m.u. s. c.l. with the active efforts of E (movment for the use of smart in Linux environment), pcsclite has become a de facto standard for the PC/SC device framework and application interfaces under xnix, the Mac lion system has already integrated this service in the release version. The following uses the Ubuntu 12.0.4 release as an example.

 

# First install the pcsc daemon pcscd and tools

Sudo apt-get-y install libusb-Dev

Sudo apt-get-y install pcscd

 

# Then install a card reader driver that supports pcsc (for example, the built-in ACR acs38u, and other card readers can download and install it on the website)

Sudo apt-get-y install libacr38u

 

# Connect the card reader, plug the card, and run the scan tool to verify the installation result

Pcsc_scan

The result is as follows:
PC/SC device restart
V 1.4.18 (c) 2001-2011, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC Lite version: 1.7.4
Using Reader plug 'n' play mechanic
Scanning present readers...
0: ACS acr38u 00

Thu Sep 20 12:55:08 2012
Reader 0: ACS acr38u 00 00
Card state: card inserted, shared mode,
Recognition: 3B 1D 94 42 72 6f 61 64 54 68 69 6e 6B 69 00 00

Recognition: 3B 1D 94 42 72 6f 61 64 54 68 69 6e 6B 69 00 00
+ Ts = 3B --> direct convention
+ T0 = 1d, y (1): 0001, K: 13 (historical bytes)
TA (1) = 94 --> Fi = 512, DI = 8, 64 cycles/ETU

62500 bits/s at 4 MHz, fmax for Fi = 5 MHz = & gt; 78125 bits/s
+ Historical Bytes: 42 72 6f 61 64 54 68 69 6e 6B 69 00 00
CATEGORY Indicator byte: 42 (proprietary format)

Possibly identified card (using/usr/share/pcsc/smartcard_list.txt ):
None

Your card is not present in the database.
You can get the latest version of the database from
Http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt
Or use: wget http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt -- output-document =/home/caesarzou/.smartcard_list.txt

If your ASD is still not in the latest version then please send a mail
To <ludovic.rousseau@free.fr> containing:

 

# So far, the PC/SC driver has been connected. Now let's try to send an APDU

Sudo apt-get-y install pcsc-Tools

Gscriptor

This is a graphical interface tool. In the script box, enter:

00a4040000

Click the run button. The connection prompt is displayed, and the result is displayed:

Beginning script execution...

Sending: 00 A4 04 00 00
Written ed: 6C 12
Wrong length le: shocould be 0x12

Script was executed without error...

# Congratulations, card access is successful. Now you must be impatient. Do you want to create your own applications?

# Install the Development Library

Sudo apt-Get install libpcsclite-Dev

# Install eclipse CDT as the development environment

Sudo apt-get-y install g ++
Sudo apt-get-y install eclipse-CDT

# Open eclipse, create a new C Project, and add

# Include <pcsc/winscard. h>

# Link to the pcsclite Library: Add pcsclite in C/C ++ build/GCC linker/Libraries

# Now you will be happy to find that the Type Definitions and interfaces provided in winscard. h are the same as those provided in windows. We copy a section from WindowsCodeCome here:

 

# Include <stdio. h> # include <pcsc/winscard. h> int main (void) {scardcontext m_hcontext; scardhandle m_hcard; scard_io_request IO; char pmszreaders [100]; byte capdu [] = {0x00, 0xa4, 0x256x100}; byte rapdu [+ 2]; dword cch =; DWORD I = 0; // insertif (scard_s_success! = Scardestablishcontext (scard_scope_user, null, null, & m_hcontext) {printf ("context error"); Return-1 ;}// list readerif (scard_s_success! = Scardlistreaders (m_hcontext, null, pmszreaders, & CCH) {printf ("list reader error"); Return-2;} printf ("list readers \ n "); while (I <CCH) {printf ("% s \ n", pmszreaders + I); I ++ = strlen (pmszreaders); I ++;} // connect first readerio. cbpcilength = sizeof (scard_io_request); If (scard_s_success! = Scardconnect (m_hcontext, pmszreaders, scard_cmd_shared, scard_protocol_t0 | scard_protocol_t1, & m_hcard, & Io. dwprotocol) {printf ("Connect card error"); Return-3;} // transmit apducch = 256 + 2; If (scard_s_success! = Scardtransmit (m_hcard, & Io, capdu, 5, null, rapdu, & CCH) {printf ("transmit APDU error"); Return-4 ;} // echoprintf ("transmit APDU \ n"); printf ("capdu:"); for (I = 0; I <5; I ++) {sprintf (pmszreaders, "% 02x", capdu [I]); printf ("% s", pmszreaders);} printf ("\ n"); printf ("rapdu :"); for (I = 0; I <CCH; I ++) {sprintf (pmszreaders, "% 02x", rapdu [I]); printf ("% s ", pmszreaders);} printf ("\ n"); // disconnectscarddisconnect (m_hcard, scard_e Ject_card); // ejectscardreleasecontext (m_hcontext); // puts ("!!! Hello world !!! ");/* Prints !!! Hello world !!! */Return 0 ;}

# Compile, run, and output:
List readers
ACS acr38u 00

Transmit APDU
Capdu: 00a4040000
Rapdu: 6c12

 

Success! Next, I will talk about the configuration based on the javacard environment and tool on Ubuntu, so stay tuned.

 

Note:

The header file of libpcsclite on Ubuntu is located in/usr/include/pcsc by default. multiple directories are added. Some versions may have # include file errors during compilation. You can modify them as follows:

Sudo Vim/usr/include/pcsc/winscard. h

Change # include <pcsclite. h> to # include <pcsc/pcsclite>, save and exit

Sudo Vim/usr/include/pcsc/pcsclite. h

Change # include <wintypes. h> to # include <pcsc/wintypes. h>.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.