MUSCLE mailing list statistics

In my serie about statistics, I generated statistics from the MUSCLE mailing list using the MailListStat software.

I can't easily extract the mails previous to 2005 for technical reasons. 2005 is when I subscribed to the list using my @gmail.com email.

I is interesting to see emails of people in the top 30 that are not present at all in statistics from 2009 or 2010.



Statistics from 3.2.2005 to 15.10.2010



People who have written most messages:

 Author   Msg   Percent 
1 ludovic.rousseau@gmail.com 979 18.16 %
2 widerstand@t-online.de 419 7.77 %
3 home_pw@msn.com 158 2.93 %
4 mstjohns@comcast.net 79 1.47 %
5 muscle@dseven.org 74 1.37 %
6 squalyl@gmail.com 74 1.37 %
7 deengert@anl.gov 74 1.37 %
8 martin@paljak.pri.ee 74 1.37 %
9 pmartin@snakecard.com 71 1.32 %
10 aj@dungeon.inka.de 68 1.26 %
11 Todd.Denniston@ssa.crane.navy.mil 63 1.17 %
12 Michael.Bender@sun.com 61 1.13 %
13 shawn-muscle@willden.org 59 1.09 %
14 s.ferey@wanadoo.fr 58 1.08 %
15 tmiller@mitre.org 52 0.96 %
16 corcoran@musclecard.com 49 0.91 %
17 alon.barlev@gmail.com 47 0.87 %
18 gelgey@vintela.com 46 0.85 %
19 ltorro@certisign.com.br 43 0.80 %
20 amandaortega@gmail.com 42 0.78 %
21 cucinotta@sssup.it 42 0.78 %
22 martin.paljak@gmail.com 40 0.74 %
23 pwt@iosis.co.uk 40 0.74 %
24 mfribeiro@gmail.com 38 0.70 %
25 Dejan.Gambin@pula.hr 37 0.69 %
26 goister@gmail.com 36 0.67 %
27 mistamaila@gmail.com 35 0.65 %
28 corcoran@identityalliance.com 31 0.57 %
29 countzero@sapo.pt 30 0.56 %
30 towergeebulk@gmail.com 29 0.54 %
other 2444 45.33 %

Best authors, by total size of their messages (w/o quoting):

 Author   KBytes 
1 ludovic.rousseau@gmail.com 607.0
2 home_pw@msn.com 467.4
3 widerstand@t-online.de 321.7
4 tmiller@mitre.org 288.7
5 squalyl@gmail.com 249.9
6 amandaortega@gmail.com 197.9
7 wnugent@abcsinc.com 161.0
8 Wei.Hu@quest.com 145.4
9 towergeebulk@gmail.com 144.7
10 gelgey@vintela.com 134.0
11 deengert@anl.gov 128.9
12 Naveen@worldsmart.com.au 128.7
13 mfribeiro@gmail.com 127.0
14 ltorro@certisign.com.br 117.4
15 Dseven@Dseven.ORG 114.4
16 daniel@benoy.name 108.7
17 Michael.Bender@sun.com 104.4
18 mstjohns@comcast.net 101.9
19 jackie17youth@yahoo.com 92.6
20 aj@dungeon.inka.de 91.9
21 pmartin@snakecard.com 90.8
22 sguthery@mobile-mind.com 89.2
23 kammicazze@hotmail.com 78.1
24 shawn-muscle@willden.org 77.7
25 ccmartin@ust.hk 77.2
26 muscle@dseven.org 73.9
27 s.ferey@wanadoo.fr 73.8
28 bjohnson@jatdi.mil 73.6
29 martin@paljak.pri.ee 70.3
30 Paul.Klissner@sun.com 66.2

Best authors, by average size of their message (w/o quoting):

 Author   bytes 
1 Dseven@Dseven.ORG 29285
2 euvieru@gmail.com 19127
3 wnugent@abcsinc.com 16489
4 dkeller@pid-llc.com 13612
5 thomas.harning@identityalliance.com 13054
6 blargity@gmail.com 12414
7 forest@alittletooquiet.net 11684
8 lcstyle@hotmail.com 10875
9 David.MacKenzie@kirtland.af.mil 10813
10 y.leplard@dhimyotis.com 10693
11 marco.matarazzo@manilamatic.it 10620
12 daniel@benoy.name 10117
13 mpapet@sci-s.com 10088
14 benny@benny.de 9684
15 lfuente@it.uc3m.es 9675
16 gt-dev@gthomas.homelinux.org 9651
17 mbrown@dsci.com 9452
18 Wei.Hu@quest.com 9306
19 hamish@prodigi.ch 8929
20 sudheervemana@gmail.com 8915
21 marcelmancini@hotmail.com 8860
22 DZShen@Winbond.com.tw 8678
23 paulaaa1234@hotmail.com 8588
24 KGUNGL@de.ibm.com 8500
25 jesus.garcia@worldnet21.com 8422
26 han.hartgers@gmail.com 8211
27 rvermer@skynet.be 8162
28 ccmartin@ust.hk 7909
29 albertoparis@hotmail.com 7763
30 Geert.VanMuylem@be.zetes.com 7745

Table showing the most successful subjects:

 Subject   Msg   Percent 
1 [Muscle] new pcsc-lite and CCID driver: test needed 35 0.65 %
2 [Muscle] Cyberflex e-gate 32k install error 6A80 32 0.59 %
3 [Muscle] Re: Open readers and iso7816 question 31 0.57 %
4 [Muscle] Would like to find ideal err const to return in pcsc-lite 29 0.54 %
5 [Muscle] Help with XCardII 29 0.54 %
6 [Muscle] muscle getChallenge, versus GP 2 way authentication 24 0.45 %
7 [Muscle] NIST Services 23 0.43 %
8 [Muscle] Installing MuscleCard on JCOP41 v2.2 23 0.43 %
9 [Muscle] Impossible to crypt using MuscleTool 23 0.43 %
10 [Muscle] new BETA versions of pcsc-lite and libccid 22 0.41 %
11 [Muscle] libmusclecard configure error. 21 0.39 %
12 [Muscle] pcsclite-1.2.9beta7 and GemPC430 crash on Fedora 4 20 0.37 %
13 [Muscle] SLED10 SCR331 20 0.37 %
14 [Muscle] FC6 and pkcs11_inspect 20 0.37 %
15 [Muscle] Current state of HAL-support? 20 0.37 %
16 [Muscle] pkcslite and libmusclecard on solaris box 19 0.35 %
17 [Muscle] CardEdge applet (MCardApplet) version to review 19 0.35 %
18 [Muscle] SCLOGON 0.1 Smart Card event daemon for GNU/Linux 19 0.35 %
19 [Muscle] Restricting reader/card access by user account 19 0.35 %
20 [Muscle] T=0 Case 2 response length 19 0.35 %
21 [Muscle] problem installing pycsc 18 0.33 %
22 [Muscle] CAC/PKCS11 Help 18 0.33 %
23 [Muscle] CAC card and Linux fedora core 5 18 0.33 %
24 [Muscle] PS/SC segfault on ACS ACR30U card reader 18 0.33 %
25 [Muscle] activcard usb v2.0 firmware upgrade to scr3xx 18 0.33 %
26 [Muscle] Problem generating Muscle Card Applet 0.9.11 18 0.33 %
27 [Muscle] GlobalPlatform keys 18 0.33 %
28 [Muscle] Protecting a PIN with keyed hashing? 17 0.32 %
29 [Muscle] 64bit portability and header tidy up 17 0.32 %
30 [Muscle] Remote connections to pcsc 16 0.30 %
other 4749 88.07 %

Most used email clients:

 Mailer   Msg   Percent 
1 (unknown) 2413 44.75 %
2 Mozilla Thunderbird 1.0 (Windows/20041206) 341 6.32 %
3 KMail 253 4.69 %
4 Mozilla/5.x 189 3.51 %
5 Mutt 126 2.34 %
6 QUALCOMM Windows Eudora 109 2.02 %
7 Microsoft Outlook Express 6.x 83 1.54 %
8 Microsoft Office Outlook, Build 11.0.6353 46 0.85 %
9 Thunderbird 1.5.0.2 (Windows/20060308) 42 0.78 %
10 Lotus Notes Release 6.5 41 0.76 %
11 Mozilla Thunderbird 1.0.2 (X11/20050322) 39 0.72 %
12 Thunderbird 1.5 (X11/20060112) 38 0.70 %
13 Apple Mail (2.1077) 37 0.69 %
14 Thunderbird 2.0.0.21 (Windows/20090302) 33 0.61 %
15 Thunderbird 2.0.0.9 (Windows/20071031) 31 0.57 %
16 Microsoft Outlook IMO 29 0.54 %
17 Internet Messaging Program (IMP) H3 (5.0-cvs) 27 0.50 %
18 Mozilla Thunderbird 0.8 (X11/20040913) 26 0.48 %
19 Mozilla Thunderbird 1.0 (X11/20041206) 25 0.46 %
20 Apple Mail (2.752.2) 24 0.45 %
21 Thunderbird 2.0.0.23 (Windows/20090812) 23 0.43 %
22 Apple Mail (2.746.2) 21 0.39 %
23 Mozilla Thunderbird 1.0.8-1.1.fc4 (X11/20060501) 20 0.37 %
24 Mozilla Thunderbird 0.8 (Windows/20040913) 19 0.35 %
25 Thunderbird 1.5.0.5 (X11/20060728) 19 0.35 %
26 Coremail Webmail Server Version XT_Ux_snapshot build 19 0.35 %
27 Apple Mail (2.728) 18 0.33 %
28 Mozilla Thunderbird 1.0.2 (X11/20050602) 18 0.33 %
29 Mozilla Thunderbird 1.0.6 (Windows/20050716) 18 0.33 %
30 Thunderbird 2.0.0.12 (Windows/20080213) 18 0.33 %
other 1247 23.13 %

Table of maximal quoting:

 Author   Percent 
1 guillaume.rablat@c-s.fr 90.98 %
2 Dejan.Gambin@pula.hr 85.56 %
3 Hoeben.S@zetes.com 82.18 %
4 cameron.durham@gte.net 80.80 %
5 Mahadev.Karadigudda@sun.com 78.34 %
6 lippold@gmail.com 76.65 %
7 no.1@online.de 76.14 %
8 widerstand@t-online.de 75.87 %
9 simrid@hotmail.com 74.84 %
10 matheus.oliveira@gmail.com 74.22 %
11 fschiava@libero.it 74.15 %
12 lamo@ccs.ru 74.04 %
13 diego.laborero@macroseguridad.net 73.00 %
14 christiancatalano@interfree.it 72.49 %
15 petcoradipewjepknu@jbohm.dk 71.99 %
16 andre.puschmann@stud.tu-ilmenau.de 70.71 %
17 esunilkumare@yahoo.co.in 70.16 %
18 andreas.schwier@cardcontact.de 69.88 %
19 lxgbrian@yahoo.com.cn 68.81 %
20 lars@primekey.se 68.07 %
21 nlarsch@gmx.net 67.80 %
22 musclecard@fcse.co.uk 67.27 %
23 cristiano.agosti@gmail.com 66.64 %
24 dejan.gambin@pula.hr 65.55 %
25 storm.richard@gmail.com 65.31 %
26 miro@space-comm.com 65.29 %
27 acptsys@gmail.com 65.14 %
28 gold4639@yahoo.com 64.77 %
29 vskytta@gmail.com 63.95 %
30 ameetbharti@gmail.com 63.71 %
average 35.08 %

Graph showing number of messages written during hours of day:

msgs 138
|
78
|
59
|
56
|
37
|
38
|
48
|
112
|
296
|
422
|
393
|
434
|
277
|
339
|
383
|
419
|
374
|
287
|
247
|
160
|
173
|
235
|
198
|
189
|
hour 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

Graph showing number of messages written during days of month:

msgs 174
|
143
|
172
|
164
|
137
|
153
|
185
|
193
|
163
|
207
|
168
|
131
|
120
|
189
|
213
|
176
|
205
|
145
|
235
|
164
|
196
|
180
|
193
|
176
|
199
|
151
|
198
|
192
|
196
|
178
|
96
|
day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Graph showing number of messages written during days of week:

msgs 857
|
1022
|
1035
|
967
|
831
|
330
|
337
|

Mon Tue Wed Thu Fri Sat Sun

Warning: 13 message(s) not counted.


Maximal quoting:

Author : widerstand@t-online.de
Subject : [Muscle] Installing MuscleCard on JCOP41 v2.2
Date : Mon, 10 Apr 2006 20:29:22 +0200
Quote ratio: 99.29% / 33835 bytes

Longest message:

Author : Dseven@Dseven.ORG
Subject : visibility problems (Re: [Muscle] New pcsc-lite 1.2.9-beta10
Date : Wed, 15 Mar 2006 16:23:35 -0800
Size : 113891 bytes

Most successful subject:

Subject : [Muscle] new pcsc-lite and CCID driver: test needed
No. of msgs: 35
Total size : 40711 bytes

Final summary:

Total number of messages: 5392
Total number of different authors: 643
Total number of different subjects: 1776
Total size of messages (w/o headers): 15999403 bytes
Average size of a message: 2967 bytes


Input file last updated: Sat Oct 16 14:23:39 2010 Generated by MailListStat v1.3

IFDHandler version 1 support removed from pcsc-lite

In revision 5321 (October 2010) I removed the support of the IFD Handler API version 1. The IFD Handler API the is API used to communicate between pcscd and reader driver. The API v3 is documented here.

The version 1 of the API is very old and I never saw a reader driver using it. Even when I started using pcsc-lite and writing drivers the version 2 was already in place.

Motivation


I removed this API for two reasons:
  1. This API is not used and is dead code inside pcscd.
  2. This API do not return the ATR on card power on but using IFD_Set_Capabilities()/IFD_Get_Capabilities() and IFDStatusICC() had a special case for that.

With this v1 API removal I can simplify the prototype of IFDStatusICC() and remove 2 parameters from:

LONG IFDStatusICC(READER_CONTEXT * rContext, PDWORD pdwStatus,
PUCHAR pucAtr, PDWORD pdwAtrLen)

to:

LONG IFDStatusICC(READER_CONTEXT * rContext, PDWORD pdwStatus)


This also simplifies the internal pcscd code using IFDStatusICC() since the code just wants to know if a card is present or not, but not need to know the ATR.

Consideration


Note that I already removed the API prototype from ifdhandler.h in revision 4472 in October 2009. And no one complained since then. So the version 1 API may really be unused.

Result


51 lines of code added. 335 lines of code removed. Gain: 284 lines of code removed.

Subversion statistics for CCID driver (libccid) at September 2010

I used the tool statsvn to generate nice graphics about the subversion activity of the CCID driver (libccid) project.

The full report is available here. We will just reuse some graphics and discuss them.

Developers


The project is now 7 years old. I am the only developer on the project. It is a one man project. This can be problematic because the bus factor is quite low.

Source code


The total number of line of "code" is still growing at a constant rate.



With a closer look it appears that not every thing is source code. A large part of the content comes from the readers/ directory.

The readers/ contains the CCID description (the reader capabilities) of CCID readers. The data is also available in the big matrix.



The readers/ directory is the biggest part of the repository.



In the src/ directory the file sizes are visible using the repomap tool. You will get display like this:



Conclusion


It always nice to stand back and look at a big picture on a project you are involved.

You can also have different graphics from the libccid project at ohloh.net site.

For example ohloh.net estimates the cost of the project at 2 man.year for a total of 89,000 US$. The 2 man.year estimation is very reasonable. Over the 7 years of the project that is an average of one or two days per week.

Subversion statistics for pcsc-lite at September 2010

I used the tool statsvn to generate nice graphics about the subversion activity of the pcsc-lite project.

The full report is available here. We will just reuse some graphics and discuss them.

Developers


The project is now 10 years old. The old versions were hosted in a CVS repository on David Corcoran computer. The access was slow. In 2003 the project moved to the Debian forge at https://alioth.debian.org/projects/pcsclite/.

9 developpers committed patches to the project.

Author Author Id Changes Lines of Code Lines per Change
Totals 3897 (100.0%) 155334 (100.0%) 39.8
rousseau rousseau 3183 (81.7%) 86878 (55.9%) 27.2
corcoran corcoran 339 (8.7%) 63138 (40.6%) 186.2
aet-guest aet-guest 227 (5.8%) 2696 (1.7%) 11.8
sauveron-guest sauveron-guest 110 (2.8%) 1918 (1.2%) 17.4
corcoran-guest corcoran-guest 25 (0.6%) 528 (0.3%) 21.1
cprados cprados 4 (0.1%) 91 (0.1%) 22.7
giraud giraud 7 (0.2%) 83 (0.1%) 11.8
phuang phuang 1 (0.0%) 1 (0.0%) 1.0
mikeg mikeg 1 (0.0%) 1 (0.0%) 1.0

A large part of the code was written by David Corcoran. Even if David has not committed any thing since 2004 he is the author of 40% of lines of code.



Since 2004 I am the only one to commit changes in the subversion repository. I receive some patches from other people but they do not have write access to the subversion repository so the commits appear as mine.

Source code




The number of lines in the project is slowly growing. The main features are present since the beginning. What I do is mainly debug and optimization.



As expected a large part of the "code" is located in the src/ directory.

You can use a live source code explorer at repomap to display things like:


Conclusion


It always nice to stand back and look at a big picture on a project you are involved.

You can also have different graphics from the pcsc-lite project at ohloh.net site.

pcscd auto start

The problem


pcsc-lite is composed of two parts:
  1. a daemon pcscd
  2. The daemon job is to access/send commands to the readers, through reader drivers.
  3. a library libpcsclite.so.1
  4. The library provides the PC/SC API to the application to talk to the pcscd daemon using an internal protocol.

Traditionally the daemon is started when the system starts and is running until the system is shut down.

Using the dependencies relation of packages in modern distributions you may install a package that, in some cases, uses PC/SC and then is linked with libpcsclite and then pcscd is also installed and running all the time for nothing.

The solution


The idea is to start pcscd only when needed. It is possible since the first PC/SC call is always SCardEstablishContext(). So SCardEstablishContext() must check if pcscd is already running and launch it if not.

The implementation details


pcscd exit


It is also possible to exit pcscd when no more client is using it. This is possible since the last PC/SC call is always SCardReleaseContext().

When all the contexts open with SCardEstablishContext() have been closed by SCardReleaseContext() it is possible to exit pcscd. To avoid restarting pcscd just after exiting it, pcscd exits only after 60 seconds of inactivity. It is configurable using:
#define TIME_BEFORE_SUICIDE 60

Reader devices access rights


By default (on GNU/Linux) USB devices are accessible (for write accesses) by root processes only. If pcscd is started during the system start up the process is executed as root so has the correct permissions to access the USB devices. But if now pcscd is started by a process of a normal user it will be started with the access rights of this normal user.

pcscd then needs to gain extra access rights. This is the perfect use of the suid/sgid mechanism. In pcsc-lite 1.6.x (with x < 5) the file /usr/sbin/pcscd was suid root. So the process was running as root. It does work but programs running as root are always "suspicious" for a security aware administrator. And it is even more important if the program is suid root, as it was the case.

To be conform to the principle of least privilege a better approach has been implemented. The access rights of the devices are changed to be accessible in read and write to a process in the group "pcscd", and pcscd is now a sgid program in the group "pcscd". So when pcscd is started by a normal user it will gain access to files in the group "pcscd".

The group "pcscd" should be used only by pcsc-lite so only pcscd has access to smart card readers. The pcscd process has only gained the minimum rights needed to do its job (instead of gaining root access).

udev rule


To change the access rights of a USB devices the solution on a GNU/Linux system is to write a udev rule file.

The CCID driver provides such a udev rule file.

The main part of the file is:
# If not adding the device, go away
ACTION!="add", GOTO="pcscd_ccid_rules_end"
SUBSYSTEM!="usb", GOTO="pcscd_ccid_rules_end"
ENV{DEVTYPE}!="usb_device", GOTO="pcscd_ccid_rules_end"

# generic CCID device
ATTRS{bInterfaceClass}=="0b", RUN+="/bin/chgrp pcscd $root/$parent"

# All done
LABEL="pcscd_ccid_rules_end"

If a device has an interface with the field bInterfaceClass set to 0x0b (11 in decimal) then it is a CCID device according to the CCID specification. In that case run the command chgrp to set the group to pcscd to the parent device.

udev has a GROUP= action to change the group of a device but it looks like I can't use that. The rule matches a field of an interface but GROUP= works when matching a device (the parent of an interface).

Reader driver impacts


The reader drivers have to provide a udev rule to change the group ownership of the device supported by the driver. If they do not the devices will not be accessible unless pcscd is run as root (as before).

For example the ifd-gempc driver will have to provide a udev rule for the 3 USB devices supported.

Something like:
# udev rules to set the access rights of GemPC smart card readers
# so they can be used by pcscd

# If not adding the device, go away
ACTION!="add", GOTO="pcscd_ifd_gempc_rules_end"
SUBSYSTEM!="usb", GOTO="pcscd_ifd_gempc_rules_end"

# GemPC 430, 432 & 435 USB readers
ATTRS{idVendor}=="08e6", ATTRS{idProduct}=="0430", GROUP="pcscd"
ATTRS{idVendor}=="08e6", ATTRS{idProduct}=="0432", GROUP="pcscd"
ATTRS{idVendor}=="08e6", ATTRS{idProduct}=="0435", GROUP="pcscd"

# All done
LABEL="pcscd_ifd_gempc_rules_end"

The file is easy to generate since you just have to reuse the information from the Info.plist file of the driver.

The rule file for the CCID driver is a bit different since I used the fact that CCID devices all have the same USB class (bInterfaceClass).

Security aspects


Possible security vulnerability in pcscd


I know no security vulnerability in pcscd. But pcscd is not immune. See pcsc-lite security advisory CVE-2010-0407 for example.

If a new security vulnerability in pcscd is found the impact will be much lower now that pcscd run as a simple user in group "pcscd". An attacker would not gain root access.

Multi user systems


What will happen on a system with users A and B that both want to use PC/SC?

Suppose A starts a PC/SC program and then starts the pcscd daemon. pcscd will run as user A with the group set to pcscd.

Then B starts a PC/SC program. pcscd is already running so it will not be restarted.

B could try to inject code in the pcscd process and run the code with the access rights of A. This should not be possible. See the previous chapter about possible vulnerability in pcscd.

User A could run pcscd in debug mode (using the --debug and --apdu option of pcscd) and see all the PC/SC commands and APDU used by the application run by B. Such APDU could contain the pincode of B for example. This attack is not possible. pcscd contains a check to disable the --apdu option if it has been launched using the sgid mechanism.

Conclusion


The auto start mechanism introduced in pcsc-lite 1.6.0 allows to limit the number of running processes (when a smart card is not used).

The sgid mechanism introduced in pcsc-lite 1.6.5 greatly limits the security implication by just using a special group instead of running pcscd as root.

RAM and CPU improvements in pcsc-lite 1.6.x

Between pcsc-lite 1.5.x and pcsc-lite 1.6.x I improved many aspects regarding resources consumption: CPU and memory.

System used


For the measures I used an embedded Linux on an ARM9 CPU. This is a typical embedded system. The relative gains are comparable on a desktop PC even if the numbers are different.

The CCID driver is the standard one with support of 159 readers. Only this driver is installed.

Note that pcscd is compiled to use libusb instead of the default libhal. The targeted system does not have libhal available. So the libusb-1.0 code is shared between pcscd and libccid.

CPU consumption


Start up time


From 13193049 µs (13 s) to 258262 µs (0.3 s) ⇒ factor x51 or 5008%

pcsc-lite 1.5.x (and previous versions) used a complexity exponential with the number of readers supported in a Info.plist file.

pcsc-lite 1.6.x now has a complexity linear with the number of readers supported in a Info.plist file.

No more polling


In previous versions the sources of polling were:
  • SCardGetStatusChange

    This function is used by an application to detect card events or readers events. In the previous implementation the client library libpcsclite regularly asked the daemon the list of connected readers and card status.

  • Reader hotplug

    If libusb is used by pcsc-lite the USB bus is scanned every 1 second. It is no more the case with libhal.

  • Card events

    The card status is asked by pcscd to the card driver every 200ms. If the driver supports TAG_IFD_POLLING_THREAD then it is no more the case. My CCID driver supports this feature.

In version 1.6.x no polling is done by pcsc-lite. So if nothing happens with the reader(s) then the CPU activity of pcsc-lite is 0%.

RAM consumption of pcscd


Global


Numbers are from the VSZ field from ps(1)

With no reader connected:
From 1516 kB to 976 kB ⇒ gain 36% or 540 kB

With one reader connected:
From 1688 kB to 1180 kB ⇒ gain 30% or 508 kB

text


From 76 kB to 88 kB ⇒ loss 15%
The code has grow. Mainly because of the use of a list management library.

heap


With no reader connected:
From 624 kB to 84 kB ⇒ gain 86% or 540 kB

With one reader connected:
From 652 kB to 132 kB ⇒; gain 80% or 520 kB

RAM consumption with optimization for embedded systems


As described in a previous article "pcsc-lite for limited (embedded) systems" it is possible to limit the RAM consumption by disabling features.

--enable-embedded


Both pcsc-lite and libccid supports the --enable-embedded flag.

Global consumption with one reader connected and compared to version 1.6.x:
From 1180 kB to 1152 kB ⇒ gain 2% or 28 kB

--enable-embedded and --disable-serial


Compared to the previous case:
From 1152 kB to 1144 kB ⇒ gain 1% or 8 kB

Compared to the normal case:
From 1180 kB to 1144 kB ⇒ gain 3% or 36 kB

RAM consumption repartition


The graphic bellow gives the repartition (sorted by size) of RAM used by the different parts of a running pcscd with a CCID reader connected.



If I separate the different libraries used from pcscd + libpcsclite + heap + stack we have:



The code I have an impact on (pcsc-lite and libccid) is only 34% of the total RAM consumed. So any further improvement will be rather limited.

But the libraries uClibc, libpthread, libgcc and libdl may also be used by other applications and be present only once in memory and shared. So the real RAM consumption is more complex than shown in the graphics.

RAM consumption of libpcsclite.so


Measures are done using the testpcsc sample program.

libpcsclite text


Without --enable-embedded:
From 36 kB to 32 kB ⇒ gain 11% or 4 kB

With --enable-embedded:
From 36 kB to 24 kB ⇒ gain 33% or 12 kB

libpcsclite data


The communication between pcscd and libpcsclite do not use a shared memory segment any more. So the pcscd.pub RAM mapped file is no more used and 64 kB of RAM are saved.

Conclusion


The start up speed has greatly been improved. This is even more important now that we can start pcscd automatically when needed from libpcsclite.

The use of lists instead of static arrays has decreased the RAM consumed in normal cases and allowed to use much more contexts.

PCSC sample in Ada

Here is the PCSC sample in Ada language I promised in PC/SC sample in different languages.

Installation


The PCSC/Ada project is hosted at http://www.nongnu.org/pcscada.

PCSC/Ada is available as package in Debian testing/unstable and Ubuntu
10.04.

Debian squeeze (testing at time of writing this article)


To install the PCSC/Ada development package type:
$ sudo apt-get install libpcscada1-dev

Debian Lenny (stable)


If you use Debian stable (Lenny), an unofficial backport is also
available from codelabs.ch. To install the backport package, perform the
following steps:

Add this line to /etc/apt/sources.list:

deb http://www.codelabs.ch/debian lenny-backports main contrib non-free

Then, execute the following commands:
$ sudo apt-get update
$ sudo apt-get install debian-codelabs-archive-keyring
$ sudo apt-get update

To install the PCSC/Ada development package type:
$ sudo apt-get install libpcscada1-dev

If you want to compile PCSC/Ada from source, see the distributed README
file for details.

API


The API documentation is available online at
http://www.nongnu.org/pcscada/api/index.html.


Source code


Makefile


all: ada_sample

ada_sample:
 @gnatmake -p -Ppcscada_sample

clean:
 @rm -rf obj

pcscada_sample.gpr


with "pcscada";

project PCSCAda_Sample is

   for Object_Dir use "obj";
   for Source_Dirs use (".");
   for Main use ("ada_sample.adb");

   Compiler_Switches := ("-gnaty3aAbcdefhiIklnprStuxM80o",
                         "-gnatVa",
                         "-gnat05",
                         "-gnatwal",
                         "-gnatf",
                         "-fstack-check",
                         "-gnato",
                         "-g");

   package Compiler is
      for Default_Switches ("ada") use Compiler_Switches;
   end Compiler;

   package Binder is
      for Default_Switches ("ada") use ("-E");
   end Binder;

end PCSCAda_Sample;


ada_sample.adb


with Ada.Text_IO;

with PCSC.SCard.Utils;

use PCSC;

procedure Ada_Sample is

   package SCU renames SCard.Utils;

   My_Context : SCard.Context;
   First_Card : SCard.Card;
   Readers    : SCard.Reader_ID_Set;
   Recv_PCI   : SCard.IO_Request;
   Recv_Len   : Natural := 0;

   APDU_Select  : constant SCard.Byte_Set :=
     (16#00#, 16#A4#, 16#04#, 16#00#, 16#0A#,
      16#A0#, 16#00#, 16#00#, 16#00#, 16#62#,
      16#03#, 16#01#, 16#0C#, 16#06#, 16#01#);
   APDU_Command : constant SCard.Byte_Set :=
     (16#00#, 16#00#, 16#00#, 16#00#);

begin

   --  Establish context

   SCard.Establish_Context (Context => My_Context,
                            Scope   => SCard.Scope_System);

   --  List readers

   Readers := SCard.List_Readers (Context => My_Context);
   Ada.Text_IO.Put_Line ("Readers found:");
   SCU.For_Every_Reader (Readers => Readers,
                         Call    => SCU.Print_ReaderID'Access);

   --  Connect with the card in first reader

   SCard.Connect (Context => My_Context,
                  Card    => First_Card,
                  Reader  => Readers.First_Item,
                  Mode    => SCard.Share_Shared);

   --  Send APDUs

   Send_Select_Applet_APDU :
   declare
      Recv_Buffer : SCard.Byte_Set (1 .. 128);
   begin
      SCard.Transmit (Card        => First_Card,
                      Send_Buffer => APDU_Select,
                      Recv_Pci    => Recv_PCI,
                      Recv_Buffer => Recv_Buffer,
                      Recv_Len    => Recv_Len);
      Ada.Text_IO.Put_Line
        ("Select applet: " & SCU.To_Hex_String
         (Given => Recv_Buffer,
          Len   => 2 * Recv_Len));
   end Send_Select_Applet_APDU;

   Send_Command_APDU :
   declare
      Recv_Buffer : SCard.Byte_Set (1 .. 32);
   begin
      SCard.Transmit (Card        => First_Card,
                      Send_Buffer => APDU_Command,
                      Recv_Pci    => Recv_PCI,
                      Recv_Buffer => Recv_Buffer,
                      Recv_Len    => Recv_Len);
      Ada.Text_IO.Put_Line
        ("Command      : "
         & SCU.To_String (Given => Recv_Buffer (1 .. Recv_Len)));
   end Send_Command_APDU;

   --  Disconnect the card

   SCard.Disconnect (Card   => First_Card,
                     Action => SCard.Unpower_Card);

   --  Release context

   SCard.Release_Context (Context => My_Context);

exception
   when others =>
      Ada.Text_IO.Put_Line ("OOPS - got an exception:");
      if SCard.Is_Valid (Context => My_Context) then
         SCard.Release_Context (Context => My_Context);
      end if;

      raise;
end Ada_Sample;

Compilation


Just type make.

$ make
object directory "/home/rousseau/blog/pcscada_sample/obj" created
gcc-4.4 -c -gnaty3aAbcdefhiIklnprStuxM80o -gnatVa -gnat05 -gnatwal -gnatf -fstack-check -gnato -g -I- -gnatA /home/rousseau/blog/pcscada_sample/ada_sample.adb
gnatbind -shared -E -I- -x /home/rousseau/blog/pcscada_sample/obj/ada_sample.ali
gnatlink /home/rousseau/blog/pcscada_sample/obj/ada_sample.ali -shared-libgcc -L/usr/lib -lpcscada -o /home/rousseau/blog/pcscada_sample/obj/ada_sample

The generated binary is ./obj/ada_sample.

Output


$ ./obj/ada_sample 
Readers found:
Gemalto GemPC Twin 00 00
Select applet: 9000
Command      : Hello world!�

Conclusion


I do not use Ada myself so I can't really say more. This wrapper should do the job if you do use Ada.

Thanks a lot to Reto Buerki, the author of the Ada wrapper, for writing the sample code for me.

How to help my projects?

I am now a member of flattr.com. Go see the web site if you do not know flattr yet.

The idea is to give money to the people doing things you like. So if you like this blog or my smart card project you can say so by clicking the flattr icon
on the right just above my picture.

Thanks

pcsc-lite 1.6.x breaks some programs at compilation

Minor API change


pcsc-lite 1.6.x makes the compilation of some badly written programs to fail. Badly written programs include my owns: pcsc-tools and pcsc-perl.

SCARD_READERSTATE_A


Windows uses two versions for the SCARD_READERSTATE structure:
  • SCARD_READERSTATE_W

    If UNICODE is defined and the szReader field is a LPCWSTR using wide characters
  • SCARD_READERSTATE_A

    If UNICODE is not define and the szReader field is a LPCSTR using normal characters

Since Unix uses UTF-8 instead of UTF-16 we do not need those stupid wide characters. Every string (ASCII or Unicode or what ever encoding) is a char [].

The problem is that the Windows winscard API only uses SCARD_READERSTATE externally and programs should never use SCARD_READERSTATE_W or SCARD_READERSTATE_A.

pcsc-lite 1.6.2 removed the definition of SCARD_READERSTATE_A PSCARD_READERSTATE_A and LPSCARD_READERSTATE_A types

LPSCARD_READERSTATE


This type was missing and has been added in pcsc-lite 1.6.3. pcsc-lite up to 1.6.1 defined LPSCARD_READERSTATE_A instead and we have seen why it was a bad idea.


SCARD_W_INSERTED_CARD


The SCARD_W_INSERTED_CARD error code was specific to pcsc-lite and was never used. I removed its declaration.

If your code uses it just remove the line.

No ABI change


Only the compilation of some programs will fail. The execution should not fail. The ABI (Application Binary Interface) has not changed.

ATR not (yet) in my database

If you are using my online ATR parsing I presented in Parsing an ATR you may have used an ATR of a card I do not know. You then get a:

Possibly identified card: UNKNOWN

Now a new "Enter the card description" link is added to allow you to file a card description. The form looks like:



Remarks


  • To avoid spam and abuse you first have to login using a google account.
  • The design is really minimalistic (I am not a web designer). If you have ideas to improve the look-n-feel just contact me.
  • I still have to manually edit a file to add your ATR. So do not be impatient and do not resubmit the same ATR.