|
From: <lu...@us...> - 2014-11-11 19:56:59
|
Revision: 635
http://sourceforge.net/p/pyscard/code/635
Author: ludov
Date: 2014-11-11 19:56:56 +0000 (Tue, 11 Nov 2014)
Log Message:
-----------
Fix tidy warning
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
Modified Paths:
--------------
trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
Modified: trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
===================================================================
--- trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 19:49:32 UTC (rev 634)
+++ trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 19:56:56 UTC (rev 635)
@@ -1,3 +1,5 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
<html>
<head>
<title>pyscard smartcard module</title>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lu...@us...> - 2014-11-11 19:58:57
|
Revision: 636
http://sourceforge.net/p/pyscard/code/636
Author: ludov
Date: 2014-11-11 19:58:50 +0000 (Tue, 11 Nov 2014)
Log Message:
-----------
Fix tidy warning
line 60 column 3 - Warning: missing <li>
Modified Paths:
--------------
trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
Modified: trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
===================================================================
--- trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 19:56:56 UTC (rev 635)
+++ trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 19:58:50 UTC (rev 636)
@@ -56,12 +56,13 @@
</li>
</ul>
</li>
- <li><a HREF="#readers"> Smartcard readers</a> </li>
+ <li><a HREF="#readers"> Smartcard readers</a>
<ul>
<li> <a HREF="#listingreaders">Listing smartcard readers</a>
<li><a href="#readergroups">Organizing smartcard readers into groups</a>
<li><a href="#readermonitoring">Monitoring readers</a>
</ul>
+ </li>
<li><a href="#smartcards">Smart cards</a>
<ul>
<li><a href="#monitoringsmartcards">Monitoring smart cards</a></li>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lu...@us...> - 2014-11-11 20:00:50
|
Revision: 638
http://sourceforge.net/p/pyscard/code/638
Author: ludov
Date: 2014-11-11 20:00:41 +0000 (Tue, 11 Nov 2014)
Log Message:
-----------
Fix tidy warning
line 1235 column 5 - Warning: <a> anchor "smartcards" already defined
Modified Paths:
--------------
trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
Modified: trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
===================================================================
--- trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 20:00:19 UTC (rev 637)
+++ trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 20:00:41 UTC (rev 638)
@@ -63,7 +63,7 @@
<li><a href="#readermonitoring">Monitoring readers</a>
</ul>
</li>
- <li><a href="#smartcards">Smart cards</a>
+ <li><a href="#smartcards2">Smart cards</a>
<ul>
<li><a href="#monitoringsmartcards">Monitoring smart cards</a></li>
<li><a href="#sendingapdutocards">Sending APDUs to a smart card obtained
@@ -1232,7 +1232,7 @@
print exc_info()[0], ': ', exc_info()[1]
</font></pre>
<p><a href="#top">to the top</a>
-<h2><a name="smartcards"></a>Smart Cards</h2>
+<h2><a name="smartcards2"></a>Smart Cards</h2>
<h3><a name="monitoringsmartcards"></a>Monitoring Smart Cards</h3>
<p>You can monitor the insertion or removal of cards using the <a href="epydoc/smartcard.CardMonitoring.CardObserver-class.html">CardObserver</a>
interface.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lu...@us...> - 2014-11-11 20:05:44
|
Revision: 639
http://sourceforge.net/p/pyscard/code/639
Author: ludov
Date: 2014-11-11 20:05:36 +0000 (Tue, 11 Nov 2014)
Log Message:
-----------
Fix tidy warnings
line 100 column 1 - Warning: trimming empty <p>
line 149 column 1 - Warning: trimming empty <h2>
line 150 column 1 - Warning: trimming empty <h2>
line 151 column 1 - Warning: trimming empty <h2>
line 152 column 1 - Warning: trimming empty <h2>
line 153 column 1 - Warning: trimming empty <h3>
line 154 column 1 - Warning: trimming empty <h3>
line 157 column 1 - Warning: trimming empty <p>
line 167 column 1 - Warning: trimming empty <p>
line 322 column 1 - Warning: trimming empty <h3>
line 341 column 1 - Warning: trimming empty <h3>
line 448 column 1 - Warning: trimming empty <p>
line 457 column 4 - Warning: trimming empty <font>
line 457 column 1 - Warning: trimming empty <p>
line 459 column 1 - Warning: trimming empty <h2>
line 547 column 1 - Warning: trimming empty <h3>
line 731 column 1 - Warning: trimming empty <h3>
line 753 column 1 - Warning: trimming empty <h3>
line 839 column 1 - Warning: trimming empty <h3>
line 873 column 1 - Warning: trimming empty <h3>
line 912 column 1 - Warning: trimming empty <h3>
line 954 column 1 - Warning: trimming empty <p>
line 955 column 1 - Warning: trimming empty <p>
line 970 column 1 - Warning: trimming empty <h3>
line 973 column 1 - Warning: trimming empty <p>
line 974 column 1 - Warning: trimming empty <p>
line 1043 column 1 - Warning: trimming empty <h3>
line 1095 column 1 - Warning: trimming empty <p>
line 1110 column 1 - Warning: trimming empty <h3>
line 1189 column 1 - Warning: trimming empty <h3>
line 1361 column 1 - Warning: trimming empty <p>
line 1384 column 1 - Warning: trimming empty <p>
Modified Paths:
--------------
trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
Modified: trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
===================================================================
--- trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 20:00:41 UTC (rev 638)
+++ trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 20:05:36 UTC (rev 639)
@@ -97,7 +97,6 @@
<hr>
<a name="copyright"></a>
<h2>Copyright</h2>
-<p>
<pre>Copyright 2001-2009 <a href="http://www.gemalto.com">gemalto</a><br>Author: Jean-Daniel Aussel, <a href="mailto:jea...@ge...">mailto:jea...@ge...</a></pre>
<p>This file is part of pyscard.</p>
@@ -146,15 +145,8 @@
<p>
<hr>
<h2><a name="quickstart"></a>Quick-start</h2>
-<h2></h2>
-<h2></h2>
-<h2></h2>
-<h2></h2>
-<h3></h3>
-<h3></h3>
<p>We will see in this section some variations on how to send APDU commands to
a smart card.</p>
-<p></p>
<h3><a name="readercentric"></a>The reader-centric approach</h3>
<p>A PC application interacts with a card by sending list of bytes, known as Application
Protocol Data Units (APDU). The format of these APDUs is defined in the ISO7816-4
@@ -164,7 +156,6 @@
use the reader-centric approach.</p>
<p>In the reader-centric approach, we open a connection with a card thru a smart
card reader, and send APDU commands to the card using the connection:</p>
-<p></p>
<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
from smartcard.System import readers<br>
>>> from smartcard.util import toHexString<br>
@@ -319,7 +310,6 @@
<p>Other CardTypes are available, and new CardTypes can be created, as described
below.</p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h4><a name="anycardrequest"></a>Requesting any card</h4>
<p>The <a href="epydoc/smartcard.CardType.AnyCardType-class.html">AnyCardType</a>
is useful for requesting any card in any reader:</p>
@@ -338,7 +328,6 @@
>>> print cardservice.connection.getReader()<br>
SchlumbergerSema Reflex USB v.2 0</font></p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h4><a name="customtyperequest"></a>Custom CardTypes</h4>
<p>Custom CardTypes can be created, e.g. a card type that checks the ATR and the
historical bytes of the card. To create a custom CardType, deriver your CardType
@@ -445,7 +434,6 @@
response: 00 00 00 00 7F 10 02 00 00 00 00 00 0D 13 00 0A 04 00 83 8A 83 8A
00 01 00 00 status words: 90 0<br>
>>></font></p>
-<p></p>
<h3><a name="objectcentric"></a>The object-centric approach</h3>
<p>In the object-centric approach, we associate a high-level object with a set
of smart cards supported by the object. For example we associate a javacard
@@ -454,9 +442,7 @@
Once a card supported by the object is inserted, we perform the required function
by calling the objec methods.</p>
<p><i>To be written...</i></p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF"> </font>
<hr>
-<h2></h2>
<h2><a name="apdutracing"></a>Tracing APDUs</h2>
<h3><a name="bruteforcetracing"></a>The brute force</h3>
<p>A straightforward way of tracing command and response APDUs is to insert print
@@ -544,7 +530,6 @@
00 01 00 00 status words: 90 0<br>
>>></font></p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h3><a name="connectionobservers"></a>Using card connection observers to trace
apdu transmission</h3>
<p>The prefered solution is to implement a card connection observer, and register
@@ -728,7 +713,6 @@
00 00 90 0<br>
>>></font></p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h2><a name="apduerror"></a>Testing for APDU transmission errors</h2>
<p>Upon transmission and processing of an APDU, the smart card returns a pair
of status words, SW1 and SW2, to report various success or error codes following
@@ -750,7 +734,6 @@
word errors.</p>
<h3><a name="bruteforceerror"></a>The brute force for testing APDU transmission
errors</h3>
-<h3></h3>
<p>As for APDU tracing, a straightforward way of checking for errors in response
APDUs during the execution of scripts is to insert testt statements after the
transmit() method calls:</p>
@@ -836,7 +819,6 @@
<p>The prefered solution is for testing errors is to use smarcard.sw.ErrorChecker,
as described in the following section.</p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h3><a name="errorcheckingchains"></a>Checking APDU transmission errors with error
checkers</h3>
<p>Status word errors can occur from different sources. The ISO7816-4 standards
@@ -870,7 +852,6 @@
<p>The first call to error checker does not raise an exception, since 90 00 does
not report any error. The second calls however raises a CheckingErrorException.</p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h4><a name="errorcheckingchains2"></a>Error checking chains</h4>
<p>Error checkers can be chained into <a href="epydoc/smartcard.sw.ErrorCheckingChain.ErrorCheckingChain-class.html">error
checking chain</a>. Each checker in the chain is called until an error condition
@@ -909,7 +890,6 @@
does not report any error. The second calls however raises a CheckingErrorException,
caused by the iso7816-9 error checker.</p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h4><a name="filteringerrors"></a>Filtering exceptions</h4>
<p>You can filter undesired exceptions in a chain by adding a filtered exception
to the error checking chain:</p>
@@ -951,8 +931,6 @@
>>> errorchain[0].addFilterException( WarningProcessingException )<br>
>>> errorchain[0]( [], 0x62, 0x00 )<br>
>>></font></p>
-<p></p>
-<p></p>
<p>The first call to the error chain with sw1 sw2 = 62 00 raises a <a href="epydoc/smartcard.sw.SWExceptions.WarningProcessingException-class.html">WarningProcessingException</a>.</p>
<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
errorchain[0]( [], 0x62, 0x00 )<br>
@@ -967,11 +945,8 @@
>>> errorchain[0]( [], 0x62, 0x00 )<br>
>>></font></p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h4><a name="cardconnectionchecking"></a>Detecting response APDU errors for a
card connection</h4>
-<p></p>
-<p></p>
<p>To detect APDU response errors during transmission, simply set the error checking
chain of the connection used for transmission:</p>
<p><font face="Courier New, Courier, mono" size="3" color="#0033ff">from smartcard.CardType
@@ -1040,7 +1015,6 @@
as the card connection error checking chain. The card connection will use the
chain for error checking upon reception of a response apdu:</p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h4><a name="customerrorcheckers"></a>Writing a custom error checker</h4>
<p>Implementing a custom error checker requires implementing a sub-class of <a href="epydoc/smartcard.sw.op21_ErrorChecker.op21_ErrorChecker-class.html">ErrorChecker</a>,
and overriding the __call__ method. The following error checker raises a <a href="epydoc/smartcard.sw.SWExceptions.SecurityRelatedException-class.html">SecurityRelatedException</a>
@@ -1092,7 +1066,6 @@
apdu = GET_RESPONSE + [sw2]<br>
response, sw1, sw2 = cardservice.connection.transmit(
apdu )</font></p>
-<p></p>
<p><font color="#0033ff" face="Courier New, Courier, mono" size="3"><br>
</font></p>
<hr>
@@ -1107,7 +1080,6 @@
0']<br>
>>></font></p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h3><a name="readergroups"></a>Organizing Smartcard Readers into reader groups</h3>
<p>Reader group management is only available on Windows, since PCSC-lite does
not currently supports reader groups management.
@@ -1186,7 +1158,6 @@
['SCard$DefaultReaders']<br>
>>></font></p>
<p><a href="#top">to the top</a></p>
-<h3></h3>
<h3><a name="readermonitoring"></a>Monitoring readers</h3>
<p>You can monitor the insertion or removal of readers using the <a href="epydoc/smartcard.ReaderMonitoring.ReaderObserver-class.html">ReaderObserver</a>
interface.
@@ -1358,7 +1329,6 @@
print "%.2x %.2x" % (sw1, sw2)
</font></pre>
-<p>
<p><a href="#top">to the top</a> </p>
<h3><a name="cardconnectiondecorators"></a>Card Connection Decorators</h3>
<p>APDUs are transmitted to a card using the CardConnection object. It is sometime
@@ -1381,7 +1351,6 @@
return [ 0x3f ] + atr [1:]
</font></pre>
-<p>
<p>To apply the decorator, just construct the decorator around the CardConnection
instance to wrap and use the decorator in place of the card connection object:</p>
<pre><font face="Courier New, Courier, mono" size="3" color="#0033FF">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lu...@us...> - 2014-11-11 20:07:15
|
Revision: 640
http://sourceforge.net/p/pyscard/code/640
Author: ludov
Date: 2014-11-11 20:07:11 +0000 (Tue, 11 Nov 2014)
Log Message:
-----------
Reformat and convert to Unix file format
run "tidy -im"
Modified Paths:
--------------
trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
Modified: trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html
===================================================================
--- trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 20:05:36 UTC (rev 639)
+++ trunk/pyscard/src/smartcard/doc/pyscard-usersguide.html 2014-11-11 20:07:11 UTC (rev 640)
@@ -1,1909 +1,2693 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
-<html>
-<head>
- <title>pyscard smartcard module</title>
- <body BGCOLOR="#ffffff">
-
-<h1 align="center">pyscard user's guide</h1>
-<a href="http://sourceforge.net/projects/pyscard">
- <img
- src="http://sflogo.sourceforge.net/sflogo.php?group_id=196342&type=11" width="120" height="30" align="right" alt="Get pyscard at SourceForge.net. Fast, secure and Free Open Source software downloads" />
- </a>
-
-
-<pre> </pre>
-
- <hr>
-<h1><a name="top"></a>Contents </h1>
-
-<ul>
- <li> <a HREF="#copyright">Copyright</a>
- <li> <a HREF="#introduction">Introduction</a>
- <li><a href="#smartcards">Smart Cards</a>
- <li><a href="#quickstart">Quick-Start </a>
- <ul>
- <li><a href="#readercentric">The reader-centric approach</a></li>
- <li><a href="#atr">The Answer To Reset (ATR)</a></li>
- <li><a href="#cardcentric">The card-centric approach</a>
- <ul>
- <li><a href="#atrrequest">Requesting a card with a known ATR</a></li>
- <li><a href="#anycardrequest">Requesting any card</a></li>
- <li><a href="#customtyperequest">Designing custom card type requests</a></li>
- </ul>
- </li>
- <li><a href="#objectcentric">The object-centric approach</a></li>
- </ul>
- <li><a href="#apdutracing">Tracing APDUs</a>
- <ul>
- <li><a href="#bruteforcetracing">The brute force</a></li>
- <li><a href="#connectionobservers">Using card connection observers to trace
- apdu transmission</a></li>
- </ul>
- </li>
- <li><a href="#apduerror">Testing for APDU transmission errors </a>
- <ul>
- <li><a href="#bruteforceerror">The brute force</a></li>
- <li><a href="#errorcheckingchains">Using error checking chains to check
- for apdu transmission errors</a>
- <ul>
- <li><a href="#errorcheckers">Error checkers</a></li>
- <li><a href="#errorcheckingchains2">Error checking chains</a></li>
- <li><a href="#filteringerrors">Filtering errors</a></li>
- <li><a href="#cardconnectionchecking">Checking errors for a card connection</a></li>
- <li><a href="#customerrorcheckers">Writing custom error checkers</a></li>
- </ul>
- </li>
- </ul>
- </li>
- <li><a HREF="#readers"> Smartcard readers</a>
- <ul>
- <li> <a HREF="#listingreaders">Listing smartcard readers</a>
- <li><a href="#readergroups">Organizing smartcard readers into groups</a>
- <li><a href="#readermonitoring">Monitoring readers</a>
- </ul>
- </li>
- <li><a href="#smartcards2">Smart cards</a>
- <ul>
- <li><a href="#monitoringsmartcards">Monitoring smart cards</a></li>
- <li><a href="#sendingapdutocards">Sending APDUs to a smart card obtained
- from card monitoring</a></li>
- </ul>
- <li><a href="#connections">Connections</a>
- <ul>
- <li><a href="#cardrequestconnection">Creating a connection from a CardRequest</a></li>
- <li><a href="#cardmonitoringconnection">Creating a connection from CardMonitoring</a></li>
- <li><a href="#cardconnectiondecorators">Card connection decorators</a>
- <ul>
- <li><a href="#exclusiveconnectiondecorator">Exclusive card connection
- decorator</a></li>
- <li><a href="#exclusivetransmitdecorator">Exclusive transmit card connection
- decorator</a></li>
- <li><a href="#securechanneldecorator">Secure channel decorator</a></li>
- </ul>
- </li>
- </ul>
- </li>
- <li><a href="smartcard.html"> Smartcard reference</a>
- <li><a href="#cryptography">A word on cryptography</a>
- <ul>
- <li><a href="#binstring">Binary strings and list of bytes</a></li>
- <li><a href="#hashing">Hashing</a></li>
- <li><a href="#secretkey">Secret key cryptography</a></li>
- </ul>
-
- <li><a href="#License">License</a> </li>
-</ul>
-<hr>
-<a name="copyright"></a>
-<h2>Copyright</h2>
-
-<pre>Copyright 2001-2009 <a href="http://www.gemalto.com">gemalto</a><br>Author: Jean-Daniel Aussel, <a href="mailto:jea...@ge...">mailto:jea...@ge...</a></pre>
-<p>This file is part of pyscard.</p>
-<p>pyscard is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the Free
- Software Foundation; either version 2.1 of the License, or (at your option)
- any later version.</p>
-<p>pyscard is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- details.</p>
-<p>You should have received a copy of the GNU Lesser General Public License along
- with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin
- St, Fifth Floor, Boston, MA 02110-1301 USA<br>
-</p>
-<hr>
-<a name="introduction"></a><h2>Introduction</h2>
-<p> The pyscard smartcard library is a framework for building smart card
- aware applications in Python. The smartcard module is built on top of the <a href="scard.html">
- PCSC API</a> Python wrapper module.
-<p>pyscard supports Windows 2000 and XP by using the <a href="http://msdn2.microsoft.com/en-us/library/aa374731.aspx#smart_card_functions">Microsoft
- Smart Card Base</a> components, and linux and Mac OS X by using <a href="http://pcsclite.alioth.debian.org/">PCSC-lite</a>.
-<hr>
-<h2><a name="smartcards"></a>Smart Cards</h2>
-<p>Smart cards are plastic cards having generally the size of a credit card and
- embedding a microprocessor. Smart cards communicate with the outside world thru
- a serial port interface and an half-duplex protocol. Smartcards usually interface
- with a dedicated terminal, such as a point-of-sale terminal or a mobile phone.
- Sometime, smart cards have to be interfaced with personal computers. This is
- the case for some applications such as secure login, mail cyphering or digital
- signature, but also for some PC based smart card tools used to personnalize
- or edit the content of smart cards. Smart cards are interfaced with a personnal
- computer using a smart card reader. The smart card reader connects on one side
- to the serial port of the smart card, and on the other side to the PC, often
- nowadays thru a USB port.</p>
-<p>The PCSC workgroup has defined a standard API to interface smart card and smart
- card readers to a PC. The resulting reference implementation on linux and Mac
- OS X operating systems is <a href="http://pcsclite.alioth.debian.org/">PC/SC-lite</a>.
- All windows operating systems also include out of the box smart card support,
- usually called <a href="http://msdn2.microsoft.com/en-us/library/aa374731.aspx#smart_card_functions">PCSC</a>.</p>
-<p>The PCSC API is implemented in C language, and several bridges are provided
- to access the PCSC API from different languages such as java or visual basic.
- pyscard is a python framework to develop smart card PC applications on linux,
- Mac OS X and windows. pyscard lower layers interface to the PCSC API to access
- the smart cards and smart card readers.</p>
-<p>
-<hr>
-<h2><a name="quickstart"></a>Quick-start</h2>
-<p>We will see in this section some variations on how to send APDU commands to
- a smart card.</p>
-<h3><a name="readercentric"></a>The reader-centric approach</h3>
-<p>A PC application interacts with a card by sending list of bytes, known as Application
- Protocol Data Units (APDU). The format of these APDUs is defined in the ISO7816-4
- standard. To send APDUs to a card, the application needs first to connect to
- a card thru a smart card reader. Smart card aware applications that first select
- a smart card reader, then connect to the card inserted in the smart card reader
- use the reader-centric approach.</p>
-<p>In the reader-centric approach, we open a connection with a card thru a smart
- card reader, and send APDU commands to the card using the connection:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.System import readers<br>
- >>> from smartcard.util import toHexString<br>
- >>><br>
- >>> r=readers()<br>
- >>> print r<br>
- ['SchlumbergerSema Reflex USB v.2 0', 'Utimaco CardManUSB 0']<br>
- >>> connection = r[0].createConnection()<br>
- >>> connection.connect()<br>
- >>> SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]<br>
- >>> DF_TELECOM = [0x7F, 0x10]<br>
- >>> data, sw1, sw2 = connection.transmit( SELECT + DF_TELECOM )<br>
- >>> print "%x %x" % (sw1, sw2)<br>
- 9f 1a<br>
- >>></font>
-<p>The list of available readers is retrieved with the <font face="Courier New, Courier, mono" size="2">readers()</font>
- function. We create a connection with the first reader (index 0 for reader 1,
- 1 for reader 2, ...) with the <font face="Courier New, Courier, mono" size="2">r[0].createConnection()</font>
- call and connect to the card with the <font face="Courier New, Courier, mono" size="2">connect()</font>
- method of the connection. We can then send APDU commands to the card with the
- <font face="Courier New, Courier, mono"> <font size="2"> transmit()</font></font>
- method.
-<p>Scripts written with the reader centric approach however have the following
- drawbacks:
-<ul>
- <li>the reader index or reader name is hardcoded in the scripts; the scripts
- must be edited to match each user configuration; for example in the previous
- script, we would have to edit the script and change r[0] to r[1] for using
- the second reader</li>
- <li>there is no a-priori knowledge that the card is in the reader; to detect
- card insertion, we would have to execute the script and eventually catch a
- CardConnectionException that would indicate that there is no card in the reader.</li>
- <li>there is no built-in check that the card in the reader is of the card type
- we expect; in the previous example, we might try to select the DF_TELECOM
- of an EMV card.</li>
-</ul>
-<p>Most of these issues are solved with the card-centric approach, based on card
- type detection techniques, such as using the Answer To Reset (ATR) of the card.</p>
-<p><a href="#top">to the top</a></p>
-<h3><a name="atr"></a>The Answer To Reset (ATR)</h3>
-<p>The first answer of a smart card inserted in a smart card reader is call the
- ATR. The purpose of the ATR is to describe the supported communication parameters.
- The smart card reader, smart card reader driver, and operating system will use
- these parameters to establish a communication with the card. The ATR is described
- in the ISO7816-3 standard. The first bytes of the ATR describe the voltage convention
- (direct or inverse), followed by bytes describing the available communication
- interfaces and their respective parameters. These interface bytes are then followed
- by Historical Bytes which are not standardized, and are useful for transmitting
- proprietary informations such as the card type, the version of the embedded
- software, or the card state. Finally these historical bytes are eventually followd
- by a checksum byte.</p>
-<p>The class <a href="epydoc/smartcard.ATR.ATR-class.html">smartcard.ATR</a> is
- a pyscard utility class that can interpret the content of an ATR:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">
- #! /usr/bin/env python<br>
-from smartcard.ATR import ATR<br>
-from smartcard.util import toHexString<br>
-<br>
-atr = ATR([0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73,<br>
- 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81,0xCD,0xB9] )<br>
-
-print atr<br>
-print 'historical bytes: ', toHexString( atr.getHistoricalBytes() )<br>
-print 'checksum: ', "0x%X" % atr.getChecksum()<br>
-print 'checksum OK: ', atr.checksumOK<br>
-print 'T0 supported: ', atr.isT0Supported()<br>
-print 'T1 supported: ', atr.isT1Supported()<br>
-print 'T15 supported: ', atr.isT15Supported()<br>
-
- </font></p>
-<p>Which results in the following output:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">
-3B 9E 95 80 1F C3 80 31 A0 73 BE 21 13 67 29 02 01 01 81 CD B9<br>
-historical bytes: 80 31 A0 73 BE 21 13 67 29 02 01 01 81 CD<br>
-checksum: 0xB9<br>
-checksum OK: True<br>
-T0 supported: True<br>
-T1 supported: False<br>
-T15 supported: True<br> </font></p>
-<p>In practice, the ATR can be used to detect a particular card, either by trying
- to match a card with a complete ATR, or by matching a card with some data in
- the historical bytes. Smart card aware PC applications that detects smart cards
- based on the content of the ATR use the card-centric approach, independently
- on the smart card reader in which the card is inserted..<br>
-</p>
-<h3><a name="cardcentric"></a>The card-centric approach</h3>
-<p>In the card-centric approach, we create a request for a specific type of card
- and wait until a card matching the request is inserted. Once a matching card
- is introduced, a connection to the card is automatically created and we can
- send APDU commands to the card using this connection.</p>
-<h4><a name="atrrequest"></a>Requesting a card by ATR</h4>
-<p>The following scripts requests a card with a known ATR:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import ATRCardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString, toBytes<br>
- >>><br>
- >>> cardtype = ATRCardType( toBytes( "3B 16 94 20 02 01 00 00
- 0D" ) )<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>> print toHexString( cardservice.connection.getATR() )<br>
- 3B 16 94 20 02 01 00 00 0D<br>
- >>><br>
- >>> SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]<br>
- >>> DF_TELECOM = [0x7F, 0x10]<br>
- >>> data, sw1, sw2 = cardservice.connection.transmit( SELECT + DF_TELECOM
- )<br>
- >>> print "%x %x" % (sw1, sw2)<br>
- 9f 1a<br>
- >>></font></p>
-<p>To request a card with a know ATR, you must first create an <a href="epydoc/smartcard.CardType.ATRCardType-class.html">ATRCardType</a>
- object with the desired ATR:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- cardtype = ATRCardType( toBytes( "3B 16 94 20 02 01 00 00 0D" ) )<br>
- </font></p>
-<p>And then create a <a href="epydoc/smartcard.CardRequest.CardRequest-class.html">CardRequest</a>
- for this card type. In the sample, we request a time-out of 1 second.</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- </font></p>
-<p>The waitforcard() will either return with a card service or a time-out. The
- card service connection attribute can be used thereafter to transmit APDU commands
- to the card, as with the reader centric approach.</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- cardservice.connection.connect()<br>
- >>> print toHexString( cardservice.connection.getATR() )<br>
- </font></p>
-<p>If necessary, the reader used for the connection can be accessed thru the <a href="epydoc/smartcard.CardConnection.CardConnection-class.html">CardConnection</a>
- object:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- print cardservice.connection.getReader()<br>
- SchlumbergerSema Reflex USB v.2 0</font></p>
-<p>The <a href="epydoc/smartcard.CardType.ATRCardType-class.html">ATRCardType</a>
- also supports masks:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import ATRCardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString, toBytes<br>
- >>><br>
- >>> cardtype = ATRCardType( toBytes( "3B 1<b>5</b> 94 20 02 01
- 00 00 0<b>F</b>" ), toBytes( "00 00 FF FF FF FF FF FF 00" ) )<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>> print toHexString( cardservice.connection.getATR() )<br>
- 3B 1<b>6</b> 94 20 02 01 00 00 0<b>D</b></font></p>
-<p>Other CardTypes are available, and new CardTypes can be created, as described
- below.</p>
-<p><a href="#top">to the top</a></p>
-<h4><a name="anycardrequest"></a>Requesting any card</h4>
-<p>The <a href="epydoc/smartcard.CardType.AnyCardType-class.html">AnyCardType</a>
- is useful for requesting any card in any reader:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import AnyCardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString<br>
- >>><br>
- >>> cardtype = AnyCardType()<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>> print toHexString( cardservice.connection.getATR() )<br>
- 3B 16 94 20 02 01 00 00 0D<br>
- >>> print cardservice.connection.getReader()<br>
- SchlumbergerSema Reflex USB v.2 0</font></p>
-<p><a href="#top">to the top</a></p>
-<h4><a name="customtyperequest"></a>Custom CardTypes</h4>
-<p>Custom CardTypes can be created, e.g. a card type that checks the ATR and the
- historical bytes of the card. To create a custom CardType, deriver your CardType
- class from the the <a href="epydoc/smartcard.CardType.CardType-class.html">CardType</a>
- base class (or any other CardType) and override the <font face="Courier New, Courier, mono" size="2">matches()</font>
- method. For exemple to create a DCCardType that will match cards with the direct
- convention (first byte of ATR to 0x3b):</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import CardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString<br>
- >>><br>
- >>> class DCCardType(CardType):<br>
- ... def matches( self, atr, reader=None ):<br>
- ... return atr[0]==0x3B<br>
- ...<br>
- >>> cardtype = DCCardType()<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>> print toHexString( cardservice.connection.getATR() )<br>
- 3B 16 94 20 02 01 00 00 0D<br>
- >>> print cardservice.connection.getReader()<br>
- SchlumbergerSema Reflex USB v.2 0<br>
- >>></font></p>
-<p>Scripts written with the card-centric approach fixes the problems of the reader-centric
- approach:</p>
-<ul>
- <li>there is no assumption concerning the reader index or reader name; the desired
- card will be located in any reader</li>
- <li>the request will block or time-out if the desired card type is not inserted</li>
- <li>since we request the desired card type, the script is not played on an unknown
- or uncompatible card</li>
-</ul>
-<p>Scripts written with the card-centric approach have however the following drawbacks:</p>
-<ul>
- <li>the script is limited to a specific card type; we have to modify the script
- if we want to execute the script on another card type. For exemple, we have
- to modify the ATR of the card if we are using the ATRCardType. This can be
- partially solved by having a custom CardType that matches several ATRs, though.</li>
-</ul>
-<p><a href="#top">to the top</a></p>
-<h3><a name="protocol"></a>Selecting the card communication protocol</h3>
-<p>Communication parameters are mostly important for the protocol negociation
- between the smart card reader and the card. The main smartcard protocols are
- the T=0 protocol and the T=1 protocol, for byte or block transmission, respectively.
- The required protocol can be specified at card connection or card transmission.
-</p>
-<p> By defaults, the connect() method of the CardConnection object.will try to
- connect using either the T=0 or T=1 protocol. To force a connection protocol,
- you can pass the required protocol to the connect() method.</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import AnyCardType<br>
- >>> from smartcard.CardConnection import CardConnection<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString<br>
- >>><br>
- >>> cardtype = AnyCardType()<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect( CardConnection.T1_protocol )<br>
- >>> print toHexString( cardservice.connection.getATR() )<br>
- 3B 16 94 20 02 01 00 00 0D<br>
- >>> print cardservice.connection.getReader()<br>
- SchlumbergerSema Reflex USB v.2 0</font></p>
-<p><a href="#top"></a>Alternatively, you can specify the required protocol in
- the CardConnection transmit() method:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import AnyCardType<br>
- >>> from smartcard.CardConnection import CardConnection<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString, toBytes<br>
- >>><br>
- >>> cardtype = AnyCardType()<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>><br>
- >>> SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]<br>
- >>> DF_TELECOM = [0x7F, 0x10]<br>
- >>><br>
- >>> apdu = SELECT+DF_TELECOM<br>
- >>> print 'sending ' + toHexString(apdu)<br>
- sending A0 A4 00 00 02 7F 10<br>
- >>> response, sw1, sw2 = cardservice.connection.transmit( apdu, CardConnection.T1_protocol
- )<br>
- >>> print 'response: ', response, ' status words: ', "%x %x"
- % (sw1, sw2)<br>
- response: [] status words: 9f 1a<br>
- >>><br>
- >>> if sw1 == 0x9F:<br>
- ... GET_RESPONSE = [0XA0, 0XC0, 00, 00 ]<br>
- ... apdu = GET_RESPONSE + [sw2]<br>
- ... print 'sending ' + toHexString(apdu)<br>
- ... response, sw1, sw2 = cardservice.connection.transmit(
- apdu )<br>
- ... print 'response: ', toHexString(response), ' status
- words: ', "%x %x" % (sw1, sw2)<br>
- ...<br>
- sending A0 C0 00 00 1A<br>
- response: 00 00 00 00 7F 10 02 00 00 00 00 00 0D 13 00 0A 04 00 83 8A 83 8A
- 00 01 00 00 status words: 90 0<br>
- >>></font></p>
-<h3><a name="objectcentric"></a>The object-centric approach</h3>
-<p>In the object-centric approach, we associate a high-level object with a set
- of smart cards supported by the object. For example we associate a javacard
- loader class with a set of javacard smart cards. We create a request for the
- specific object, and wait until a card supported by the object is inserted.
- Once a card supported by the object is inserted, we perform the required function
- by calling the objec methods.</p>
-<p><i>To be written...</i></p>
-<hr>
-<h2><a name="apdutracing"></a>Tracing APDUs</h2>
-<h3><a name="bruteforcetracing"></a>The brute force</h3>
-<p>A straightforward way of tracing command and response APDUs is to insert print
- statements around the transmit() method calls:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import ATRCardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString, toBytes<br>
- >>><br>
- >>> cardtype = ATRCardType( toBytes( "3B 16 94 20 02 01 00 00
- 0D" ) )<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>><br>
- >>> SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]<br>
- >>> DF_TELECOM = [0x7F, 0x10]<br>
- >>><br>
- >>> apdu = SELECT+DF_TELECOM<br>
- >>> print 'sending ' + toHexString(apdu)<br>
- sending A0 A4 00 00 02 7F 10<br>
- >>> response, sw1, sw2 = cardservice.connection.transmit( apdu )<br>
- >>> print 'response: ', response, ' status words: ', "%x %x"
- % (sw1, sw2)<br>
- response: [] status words: 9f 1a<br>
- >>><br>
- >>> if sw1 == 0x9F:<br>
- ... GET_RESPONSE = [0XA0, 0XC0, 00, 00 ]<br>
- ... apdu = GET_RESPONSE + [sw2]<br>
- ... print 'sending ' + toHexString(apdu)<br>
- ... response, sw1, sw2 = cardservice.connection.transmit(
- apdu )<br>
- ... print 'response: ', toHexString(response), ' status
- words: ', "%x %x" % (sw1, sw2)<br>
- ...<br>
- sending A0 C0 00 00 1A<br>
- response: 00 00 00 00 7F 10 02 00 00 00 00 00 0D 13 00 0A 04 00 83 8A 83 8A
- 00 01 00 00 status words: 90 0<br>
- >>></font></p>
-<p>Scripts written this way are quite difficult to read, because there are more
- tracing statements than actual apdu transmits..</p>
-<p>A small improvement in visibility would be to replace the print instructions
- by functions, e.g.:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import ATRCardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.util import toHexString, toBytes<br>
- >>><br>
- >>> cardtype = ATRCardType( toBytes( "3B 16 94 20 02 01 00 00
- 0D" ) )<br>
- >>> cardrequest = CardRequest( timeout=1, cardType=cardtype )<br>
- >>> cardservice = cardrequest.waitforcard()<br>
- >>><br>
- >>> cardservice.connection.connect()<br>
- >>><br>
- >>> SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]<br>
- >>> DF_TELECOM = [0x7F, 0x10]<br>
- >>><br>
- >>> def trace_command(apdu):<br>
- ... print 'sending ' + toHexString(apdu)<br>
- ...<br>
- >>> def trace_response( response, sw1, sw2 ):<br>
- ... if None==response: response=[]<br>
- ... print 'response: ', toHexString(response), ' status
- words: ', "%x %x" % (sw1, sw2)<br>
- ...<br>
- >>> apdu = SELECT+DF_TELECOM<br>
- >>> trace_command(apdu)<br>
- sending A0 A4 00 00 02 7F 10<br>
- >>> response, sw1, sw2 = cardservice.connection.transmit( apdu )<br>
- >>> trace_response( response, sw1, sw2 )<br>
- response: status words: 9f 1a<br>
- >>><br>
- >>> if sw1 == 0x9F:<br>
- ... GET_RESPONSE = [0XA0, 0XC0, 00, 00 ]<br>
- ... apdu = GET_RESPONSE + [sw2]<br>
- ... trace_command(apdu)<br>
- ... response, sw1, sw2 = cardservice.connection.transmit(
- apdu )<br>
- ... trace_response( response, sw1, sw2 )<br>
- ...<br>
- sending A0 C0 00 00 1A<br>
- response: 00 00 00 00 7F 10 02 00 00 00 00 00 0D 13 00 0A 04 00 83 8A 83 8A
- 00 01 00 00 status words: 90 0<br>
- >>></font></p>
-<p><a href="#top">to the top</a></p>
-<h3><a name="connectionobservers"></a>Using card connection observers to trace
- apdu transmission</h3>
-<p>The prefered solution is to implement a card connection observer, and register
- the observer with the card connection. The card connection will then notify
- the observer when card connection events occur (e.g. connection, disconnection,
- apdu command or apdu response). This is illustrated in the following script:</p>
-<p><font face="Courier New, Courier, mono" size="2" color="#0033FF">>>>
- from smartcard.CardType import AnyCardType<br>
- >>> from smartcard.CardRequest import CardRequest<br>
- >>> from smartcard.CardConnectionObserver import ConsoleCardConnectionObserver<br>
- >>><...
[truncated message content] |