Important!

Blog moved to https://blog.apdu.fr/

I moved my blog from https://ludovicrousseau.blogspot.com/ to https://blog.apdu.fr/ . Why? I wanted to move away from Blogger (owne...

Thursday, January 27, 2011

PCSC API spy, another way

In a previous post "PCSC API spy for GNU systems" I described the use of ltrace to trace the PC/SC API calls with the arguments.

ltrace limitations

ltrace can only trace calls made by the program itself. It does not work in two common cases in the smart card world:

library loading at run time


If the libpcsclite.so.1 library is loaded at run time using dlopen() then ltrace can't be used.

For example OpenSC now uses dlopen to load libpcsclite.so.1.

library used by another library


A PKCS#11 library using a smart card will be linked to libpcsclite.so.1. You may have your program traced by ltrace directly linked to the PKCS#11 library (to avoid the previous limitation). In this case ltrace will only be able to trace calls to the PKCS#11 library but not calls from the PKCS#11 library to the libpcsclite.so.1 library.

Usefulness of ltrace?


With these 2 limitations the use of ltrace is very limited. It works well for a test program doing direct winscard calls. But it is useless for a PKCS#11 library.

Internal tracing feature


So the idea is to do the tracing inside the PC/SC library itself.

Profiling


I already had a profiling feature on the client side. This offer the possibility to log every PC/SC calls and the time in each call. It is useful to know where time is spent in the application and to detect some application bugs (like less SCardReleaseContext() calls than SCardEstablishContext() calls).

Profiling is activated by defining DO_PROFILE in PCSC/src/winscard_clnt.c and recompiling + reinstalling libpcsclite.so.1.

I wrote a Perl script to generate a report from the traces.

Example trace file generated by the pcsc/src/testpcscd "sample":

Start a new profile
SCardEstablishContext 169
SCardIsValidContext 1
SCardIsValidContext 0
SCardListReaderGroups 1
SCardFreeMemory 1
SCardListReaders 26
SCardListReaders 26
SCardGetStatusChange 24
SCardConnect 15766
SCardTransmit 2952
SCardControl 1902
SCardGetAttrib 133
SCardFreeMemory 0
SCardGetAttrib 66
SCardFreeMemory 1
SCardGetAttrib 94
SCardGetAttrib 103
SCardGetAttrib 36
SCardSetAttrib 41
SCardStatus 171
SCardFreeMemory 1
SCardFreeMemory 0
SCardReconnect 112890
SCardDisconnect 90827
SCardFreeMemory 1
SCardReleaseContext 170


Example result:

(6) SCardFreeMemory: 4 µs
(5) SCardGetAttrib: 432 µs
(2) SCardIsValidContext: 1 µs
(2) SCardListReaders: 52 µs
(1) SCardDisconnect: 90827 µs
(1) SCardTransmit: 2952 µs
(1) SCardGetStatusChange: 24 µs
(1) SCardStatus: 171 µs
(1) SCardReconnect: 112890 µs
(1) SCardConnect: 15766 µs
(1) SCardEstablishContext: 169 µs
(1) SCardControl: 1902 µs
(1) SCardSetAttrib: 41 µs
(1) SCardListReaderGroups: 1 µs
(1) SCardReleaseContext: 170 µs
total: 225402 µs

Percentages:
50.08%: SCardReconnect
40.30%: SCardDisconnect
6.99%: SCardConnect
1.31%: SCardTransmit
0.84%: SCardControl
0.19%: SCardGetAttrib
0.08%: SCardStatus
0.08%: SCardReleaseContext
0.07%: SCardEstablishContext
0.02%: SCardListReaders
0.02%: SCardSetAttrib
0.01%: SCardGetStatusChange
0.00%: SCardFreeMemory
0.00%: SCardIsValidContext
0.00%: SCardListReaderGroups


In the first list WinSCard calls are sorted by number of occurrence with the total time of execution.
In the second list the WinSCard calls are sorted by percentage of total time used.

Tracing


The profiling feature is fine but does not give the parameters used in the calls.
So I added a tracing feature.

Tracing is activated by defining DO_TRACE in PCSC/src/winscard_clnt.c and recompiling + reinstalling libpcsclite.so.1.

Example trace file generated by the pcsc/src/testpcscd "sample":


< [7FFF70121CA0] SCardEstablishContext 2, 0x0, 0x0
> [7FFF70121CA0] SCardEstablishContext 16997142
< [7FFF70121CA0] SCardIsValidContext 16997142
> [7FFF70121CA0] SCardIsValidContext
< [7FFF70121CA0] SCardIsValidContext 16997143
> [7FFF70121CA0] SCardIsValidContext
< [7FFF70121CA0] SCardListReaders 16997142
> [7FFF70121CA0] SCardListReaders 26
< [7FFF70121CA0] SCardListReaders 16997142
> [7FFF70121CA0] SCardListReaders 26
< [7FFF70121CA0] SCardGetStatusChange 16997142 -1 1
< [7FFF70121CA0] SCardGetStatusChange [0] Gemalto GemPC Twin 00 00 10 0
> [7FFF70121CA0] SCardGetStatusChange [0] Gemalto GemPC Twin 00 00 10 22
< [7FFF70121CA0] SCardConnect 16997142 Gemalto GemPC Twin 00 00 2 3
> [7FFF70121CA0] SCardConnect 1
< [7FFF70121CA0] SCardDisconnect 71159 2
> [7FFF70121CA0] SCardDisconnect
< [7FFF70121CA0] SCardReleaseContext 16997142
> [7FFF70121CA0] SCardReleaseContext


< lines are IN arguments
> lines are OUT arguments

The value within [] is the thread identification.

You should look at the source code to know what are the other data.

Not all the function are covered by the tracing feature. For example SCardTransmit has not tracing facility. But it is easy to get the arguments on the pcscd side using --debug --foreground --apdu.

Conclusion


ltrace is a nice tool but not usable for tracing libraries using PC/SC.

pcsc-lite profiling is nice but does not give the parameters used.

pcsc-lite tracing is an answer to the problem.

Of course profiling and tracing in libpcsclite are DISABLED by default and should be disabled in a deployed system. They are help tools for a developer.


Flattr this

Wednesday, January 5, 2011

MUSCLE mailing list statistics for 2010

As I did for 2009 here is the statistics from the MUSCLE mailing list for 2010.


Again I am the mail poster number one :-)

Statistics from 1.1.2010 to 29.12.2010
for muscle@lists.musclecard.com



People who have written most messages:

 Author  Msg  Percent 
1ludovic.rousseau@gmail.com21329.67 %
2squalyl@gmail.com476.55 %
3martin@paljak.pri.ee425.85 %
4drasko.draskovic@gmail.com263.62 %
5deengert@anl.gov253.48 %
6aj@dungeon.inka.de182.51 %
7acptsys@gmail.com172.37 %
8mstjohns@comcast.net141.95 %
9fundu_1999@yahoo.com131.81 %
10vtanna1@gmail.com121.67 %
11brocean@gmail.com111.53 %
12nsayer@kfu.com101.39 %
13tkoeppen.nospam@googlemail.com81.11 %
14nicholas.cole@gmail.com81.11 %
15kalev@smartlink.ee81.11 %
16roger.brown@snapper.co.nz81.11 %
17dr.claudia.neumann@gmx.de70.97 %
18Ivar.Nilsson@kapsch.net70.97 %
19jmpoure@gooze.eu70.97 %
20max.vozeler@lsexperts.de60.84 %
21linuxprocess@free.fr60.84 %
22valerie.fenwick@oracle.com60.84 %
23marcelmancini@hotmail.com60.84 %
24han.hartgers@gmail.com50.70 %
25kreinholz@gmail.com50.70 %
26baran.murat@gmail.com50.70 %
27pakorodri@gmail.com50.70 %
28lcstyle@hotmail.com40.56 %
29hugomc.silva@gmail.com40.56 %
30caruso.ray@gmail.com40.56 %
other16122.42 %

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

 Author  KBytes 
1ludovic.rousseau@gmail.com177.1
2squalyl@gmail.com155.8
3deengert@anl.gov79.8
4vtanna1@gmail.com57.2
5marcelmancini@hotmail.com51.9
6sasha.garcya@gmail.com47.2
7kreinholz@gmail.com42.6
8lcstyle@hotmail.com42.5
9dr.claudia.neumann@gmx.de40.5
10han.hartgers@gmail.com40.1
11pakorodri@gmail.com36.2
12forest@alittletooquiet.net34.2
13drasko.draskovic@gmail.com31.5
14praveenya.g@gmail.com30.7
15martin@paljak.pri.ee28.2
16Paul.Klissner@sun.com24.8
17mstjohns@comcast.net24.7
18caruso.ray@gmail.com24.6
19amustelier@tecatel.com21.4
20Michael.Bender@sun.com20.0
21tkoeppen.nospam@googlemail.com19.5
22aj@dungeon.inka.de18.6
23mbrown@dsci.com18.5
24amiad.salton@gmail.com17.9
25Ivar.Nilsson@kapsch.net17.6
26fundu_1999@yahoo.com16.9
27roger.brown@snapper.co.nz16.5
28global@codekab.com16.1
29acptsys@gmail.com15.8
30Geert.VanMuylem@be.zetes.com15.1

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

 Author  bytes 
1alessandro.vincelli@wedjaa.net14998
2sasha.garcya@gmail.com12094
3forest@alittletooquiet.net11684
4alexej.muehlberg@nxp.com11247
5lcstyle@hotmail.com10875
6Michael.Bender@sun.com10246
7mbrown@dsci.com9452
8marcelmancini@hotmail.com8860
9kreinholz@gmail.com8729
10Paul.Klissner@sun.com8479
11han.hartgers@gmail.com8211
12praveenya.g@gmail.com7857
13Geert.VanMuylem@be.zetes.com7745
14pakorodri@gmail.com7407
15B.Thomas@astronautics.com7105
16bcymet@cbnco.com7011
17franz.trierweiler.ingenieur@gmail.com6379
18caruso.ray@gmail.com6309
19bogusemail98230@yahoo.com6299
20dr.claudia.neumann@gmx.de5918
21anujakarthikeyan@gmail.com5918
22jlucg_ml@mac.com5892
23amustelier@tecatel.com5475
24nzl@me.com4974
25vtanna1@gmail.com4882
26sschwab@hidglobal.com4724
27amiad.salton@gmail.com4588
28global@codekab.com4122
29nastasi@alternativeoutput.it3829
30natarajsn@gmail.com3720

Table showing the most successful subjects:

 Subject  Msg  Percent 
1[Muscle] Re: Open readers and iso7816 question314.32 %
2[Muscle] new BETA versions of pcsc-lite and libccid223.06 %
3[Muscle] T=0 Case 2 response length192.65 %
4[Muscle] 64bit portability and header tidy up172.37 %
5[Muscle] [PATCH] more idiomatic sysconfdir usage152.09 %
6[Muscle] Questions about musclecard131.81 %
7[Muscle] PCSC on ARM121.67 %
8[Muscle] Problem communication with pcscd.121.67 %
9[Muscle] Accessing Smart Card Unique ID (newbee)111.53 %
10[Muscle] German Health Insurance Card (Krankenversichertenkarte111.53 %
11[Muscle] Problem with gemalto USB Shell Token V2 on OS X101.39 %
12[Muscle] Loaded latest pcsc-lite 1.5.5, getting seg fault and 91.25 %
13[Muscle] Re: Muscle Digest, Vol 76, Issue 991.25 %
14[Muscle] Status of the Muscle applet91.25 %
15[Muscle] pcsc-lite 1.5.5 problem81.11 %
16[Muscle] powerup problem and timed out problem with mac osx 81.11 %
17[Muscle] SCARD_E_SHARING_VIOLATION information81.11 %
18[Muscle] Re: "Card absent or mute" on MacOS 10.6.381.11 %
19[Muscle] pcsc freeze my computer81.11 %
20[Muscle] Problem with "precise biometrics 250 MC reader"81.11 %
21[Muscle] SmartCard/PCSC-lite developer information81.11 %
22[Muscle] Open Port 200000 Failed70.97 %
23[Muscle] [PATCH] Quirk for BCM5880/5881 GetSlotStatus70.97 %
24[Muscle] GDM with smartcard70.97 %
25[Muscle] ACR122U10270.97 %
26[opensc-devel] pcscd access rights limitation and scard group70.97 %
27[Muscle] pcsc-lite, ccid: Precise MC 200 problems with T=170.97 %
28[Muscle] Problem with pcsc-lite 1.6.570.97 %
29[Muscle] Bug with bit4id smart card reader and the Italian70.97 %
30[Muscle] Re: pcscd: Error: "Client failed to authenticate" on 60.84 %
other40055.71 %

Most used email clients:

 Mailer  Msg  Percent 
1(unknown)48467.41 %
2Mozilla/5.x456.27 %
3KMail324.46 %
4Apple Mail (2.1077)233.20 %
5Apple Mail (2.1078)141.95 %
6QUALCOMM Windows Eudora131.81 %
7Thunderbird 2.0.0.23 (Windows/20090812)121.67 %
8Apple Mail (2.1081)101.39 %
9YahooMailRC/459 YahooMailWebService/0.8.105.27995070.97 %
10Thunderbird 2.0.0.24 (Windows/20100228)60.84 %
11Apple Mail (2.1082)60.84 %
12Evolution 2.30.3 60.84 %
13Mutt60.84 %
14Zimbra 5.0 (ZimbraWebClient - FF3.050.70 %
15Evolution 2.28.1 50.70 %
16YahooMailRC/397.8 YahooMailWebService/0.8.104.27445740.56 %
17Microsoft-MacOutlook/14.0.0.10082540.56 %
18SquirrelMail/1.4.1930.42 %
19Zarafa 6.30.5-1765830.42 %
20YahooMailRC/240.3 YahooMailWebService/0.8.100.26096420.28 %
21Thunderbird 2.0.0.22 (X11/20090605)20.28 %
22Thunderbird 2.0.0.23 (X11/20090817)20.28 %
23iPhone Mail (7E18)20.28 %
24Thunderbird 2.0.0.22 (X11/20090625)20.28 %
25Apple Mail (2.936)20.28 %
26Microsoft Office Outlook 1120.28 %
27Evolution 2.30.220.28 %
28Microsoft Office Outlook 12.020.28 %
29Zimbra 5.0 (ZimbraWebClient - FF3.0 (Win)/5.0.15_GA_2815.UBUNTU8_64)10.14 %
30SquirrelMail/1.4.9a10.14 %
other101.39 %

Table of maximal quoting:

 Author  Percent 
1alon.barlev@gmail.com79.80 %
2mrv@c3po.es74.18 %
3acptsys@gmail.com65.14 %
4brocean@gmail.com63.17 %
5martin@aqbanking.de62.37 %
6jianjiaosun@gmail.com61.15 %
7gregor.dschung@itwm.fraunhofer.de60.79 %
8stef.hoeben@zetes.com58.35 %
9mailman@hanez.org57.45 %
10Paul.Klissner@sun.com50.84 %
11kevredon@mail.tsaitgaist.info50.35 %
12andreas.schwier@cardcontact.de48.46 %
13ludovic.rousseau@gmail.com47.98 %
14martin@paljak.pri.ee47.58 %
15deengert@anl.gov47.16 %
16Michael.Bender@sun.com43.92 %
17zealcook@gmail.com43.44 %
18anujakarthikeyan@gmail.com42.93 %
19mstjohns@comcast.net41.78 %
20Todd.Denniston@tsb.cranrdte.navy.mil40.03 %
21caruso.ray@gmail.com39.05 %
22ilgicioglu@gmail.com38.58 %
23squalyl@gmail.com37.24 %
24puneet.maillist@gmail.com36.96 %
25hugomc.silva@gmail.com36.87 %
26jonas.gulle@gmail.com36.02 %
27martin@martinpaljak.net33.90 %
28info@linsoft.de32.75 %
29vdsrst@gmail.com30.47 %
30drasko.draskovic@gmail.com30.30 %
average30.79 %

Graph showing number of messages written during hours of day:

msgs14
|
8
|
1
|
0
|
4
|
3
|
5
|
12
|
37
|
62
|
48
|
62
|
34
|
54
|
50
|
49
|
62
|
42
|
36
|
23
|
29
|
42
|
27
|
14
|
hour 01234567891011121314151617181920212223

Graph showing number of messages written during days of month:

msgs25
|
37
|
22
|
28
|
33
|
30
|
27
|
34
|
25
|
32
|
23
|
8
|
15
|
30
|
43
|
21
|
12
|
7
|
16
|
11
|
23
|
28
|
31
|
10
|
13
|
4
|
22
|
22
|
40
|
37
|
9
|
day 12345678910111213141516171819202122232425262728293031

Graph showing number of messages written during days of week:

msgs91
|
139
|
126
|
133
|
100
|
71
|
58
|

MonTueWedThuFriSatSun

Maximal quoting:

Author : deengert@anl.gov
Subject : [Muscle] new BETA versions of pcsc-lite and libccid
Date : Thu, 11 Feb 2010 14:08:52 -0600
Quote ratio: 95.44% / 17763 bytes

Longest message:

Author : sasha.garcya@gmail.com
Subject : [Muscle] pcsc freeze my computer
Date : Thu, 28 Oct 2010 13:49:13 +0200
Size : 41721 bytes

Most successful subject:

Subject : [Muscle] Re: Open readers and iso7816 question
No. of msgs: 31
Total size : 108549 bytes

Final summary:

Total number of messages: 718
Total number of different authors: 116
Total number of different subjects: 227
Total size of messages (w/o headers): 2271592 bytes
Average size of a message: 3163 bytes


Input file last updated: Wed Jan 5 15:02:38 2011Generated by MailListStat v1.3



Flattr this