OS X Yosemite bug: PC/SC functions crash after a fork(2)

This is part of the series: "OS X Yosemite and smart cards: known bugs".

All (?) PC/SC functions

SCardxx() do not work on Yosemite if executed in a son process of the one that has executed SCardEstablishContext().

This happen if SCardEstablishContext() is exected and then the process is forked. The PC/SC functions used in the son using the hContext received by the SCardEstablishContext() in the parent process will crash.

I verified this behaviour only with SCardListReaders() and SCardConnect(). I would not be surprised if it is the case for all PC/SC functions (except SCardEstablishContext() of course).

Using a PC/SC context in a son process after a fork(2) may not be supported by the PC/SC API. The support of such a use case has changed in the official pcsc-lite. The current version (pcsc-lite 1.8.13) will support it but be sure to not use the PC/SC handle in the parent process if you want to use it in the son process (or you will have problems).
In the case of Yosemite the PC/SC function will even crash instead of returning an error code.

See also

Apple bug report #19374107 "PC/SC functions crash after a fork(2)".

"com.apple.pcsc Crashes in SCardDisconnect / transact / libdispatch / fork resource handling code" https://smartcardservices.macosforge.org/trac/ticket/141.

"OpenVPN Crashes in OpenSC pcsc_disconnect on OSX 10.10 Yosemite" https://github.com/OpenSC/OpenSC/issues/333.

Sample code

#include <stdio.h>
#include <unistd.h>
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#endif

int main(int argc, const char * argv[]) {
 SCARDCONTEXT hContext;
 DWORD err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardEstablishedContext: 0x%08x\n",err);
  return -1;
 }

 pid_t pid = fork();
 printf("%s:%d %d\n", __FILE__, __LINE__, pid);
 if (0 == pid)
 {
  /* son process */
  printf("Before\n");
  DWORD cchReaders = 0;
  err = SCardListReaders(hContext, "SCard$AllReaders", NULL, &cchReaders);
  if (err != 0) {
   printf("ScardListReaders: 0x%08x\n",err);
   return -1;
  }
  printf("Has not crashed: %X\n", err);
 }
 else
 {
  /* give some time to the son */
  sleep(1);
 }

 SCardReleaseContext(hContext);

 return 0;
}


Result (on Yosemite)

$ CFLAGS="-framework PCSC" make main
cc -framework PCSC    main.c   -o main

$ ./main
main.c:19 8236
main.c:19 0
Before

I could not generate a crash dump or a backtrace using lldb.
You can see that the line "Has not crashed: xx" is NOT displayed. The function SCardListReaders() has crashed and has not returned.

I can reproduce the problem and generate a crash dump using the pcsc-lite unitary test SCard_fork.py. This is less easy to use since you have to install the PC/SC Python wrapper pyscard first.

The crash dump is then:
Process:               Python [8270]
Path:                  /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               2.7.6 (2.7.6)
Code Type:             X86-64 (Native)
Parent Process:        Python [8268]
Responsible:           Terminal [450]
User ID:               501

PlugIn Path:             /Library/Python/2.7/site-packages/smartcard/scard/_scard.so
PlugIn Identifier:       _scard.so
PlugIn Version:          ??? (0)

Date/Time:             2015-01-05 15:54:21.335 +0100
OS Version:            Mac OS X 10.10.1 (14B25)
Report Version:        11
Anonymous UUID:        7FE6A9DE-5002-1B38-88FE-227046540C73

Sleep/Wake UUID:       99799303-CF96-4849-9024-4B487D8B2393

Time Awake Since Boot: 7600 seconds
Time Since Wake:       3600 seconds

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000110

VM Regions Near 0x110:
--> 
    __TEXT                 000000010837b000-000000010837c000 [    4K] r-x/rwx SM=COW  /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python

Application Specific Information:
crashed on child side of fork pre-exec

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libdispatch.dylib      0x00007fff8ddae5d2 _dispatch_queue_wakeup_with_qos_slow + 525
1   libdispatch.dylib      0x00007fff8ddae5f8 _dispatch_queue_wakeup_with_qos_slow + 563
2   libdispatch.dylib      0x00007fff8dda3cfc _dispatch_mach_msg_send + 1690
3   libdispatch.dylib      0x00007fff8dda35e4 dispatch_mach_send + 326
4   libxpc.dylib           0x00007fff887048b1 _xpc_connection_send_message_with_reply_f + 125
5   libxpc.dylib           0x00007fff887047c2 xpc_connection_send_message_with_reply_sync + 185
6   com.apple.pcsc         0x00000001086fec5b transact + 604
7   com.apple.pcsc         0x00000001086ffe73 SCardListReaders + 140
8   _scard.so              0x00000001086ec6a5 _wrap_SCardListReaders + 181 (scard_wrap.c:3401)
9   org.python.python      0x0000000108407180 PyEval_EvalFrameEx + 12778
10  org.python.python      0x0000000108403d62 PyEval_EvalCodeEx + 1413
11  org.python.python      0x000000010840a57d 0x108380000 + 566653
12  org.python.python      0x00000001084073e3 PyEval_EvalFrameEx + 13389
13  org.python.python      0x0000000108403d62 PyEval_EvalCodeEx + 1413
14  org.python.python      0x00000001084037d7 PyEval_EvalCode + 54
15  org.python.python      0x00000001084237bd 0x108380000 + 669629
16  org.python.python      0x0000000108423860 PyRun_FileExFlags + 133
17  org.python.python      0x00000001084233fd PyRun_SimpleFileExFlags + 769
18  org.python.python      0x0000000108434b23 Py_Main + 3051
19  libdyld.dylib          0x00007fff8ca555c9 start + 1

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x00007f97b2517a50  rcx: 0x0000000000000100  rdx: 0x0000000000000001
  rdi: 0x00007f97b244f620  rsi: 0x0000000000000001  rbp: 0x00007fff57883990  rsp: 0x00007fff57883960
   r8: 0x0000000000000006   r9: 0x00000000fffff000  r10: 0x00007fff7584b244  r11: 0x0000000000000206
  r12: 0x0000000000000001  r13: 0x00007f97b244f620  r14: 0x0000000000001000  r15: 0x00007fff76583bc0
  rip: 0x00007fff8ddae5d2  rfl: 0x0000000000010206  cr2: 0x0000000000000110
  
Logical CPU:     1
Error Code:      0x00000006
Trap Number:     14

Expected result (on Debian)

$ CFLAGS=`pkg-config --cflags libpcsclite` LDFLAGS=`pkg-config --libs libpcsclite` make main
cc -pthread -I/usr/include/PCSC    -lpcsclite    main.c   -o main

$ ./main
main.c:19 2274
main.c:19 0
Before
Has not crashed: 0

Here the line "Has not crashed: 0" is displayed and SCardListReaders() returned SCARD_S_SUCCESS.

Known workaround

Do not share a PC/SC context between a father process and its sons. It is a dangerous use the of PC/SC API. In the case of Yosemite it will even make your application crash.

Update, 4 April 2015

A reader signals that the Mac OS X behaviour is normal according to fork(2) manpage.

CAVEATS
There are limits to what you can do in the child process. To be totally safe you should restrict yourself to only executing async-signal safe operations until such time as one of the exec functions is called. All APIs, including global data symbols, in any framework or library should be assumed to be unsafe after a fork() unless explicitly documented to be safe or async-signal safe. If you need to use these frameworks in the child process, you must exec. In this situation it is reasonable to exec yourself.

Mavericks

Maybe it is an expected behaviour. But it is a regression compared to Mavericks (Mac OS X 10.9).

On Mavericks the output is:
$ ./main
a.c:19 2297
a.c:19 0
Before
Has not crashed: 0

Update, 14 November 2015

Answer from Apple to my bug report:
Please know this is intended behavior. Please review the CAVEATS section in the fork() manpage.

To clarify: It is intended that the results are undefined & unsupported for using Darwin APIs beyond the POSIX standard in a forked child of a parent process that had also used Darwin APIs beyond the POSIX standard. In such cases we try to at least make the crash report contain a clear indication that the program attempted such unsupported behavior. In this case the crash doesn’t have any such indication; for that we apologize.

OpenSC-devel mailing list statistics for 2014

Statistics for previous years 2011, 2012 and 2013 are available.

Evolution

The OpenSC-devel mailing list number of messages is stable compared to last year.

Year Total number of messages Progression
2011 3214
2012 626 -80 %
2013 317 -49 %
2014 335 +6 %

As last year, the top poster is Douglas E Engert. Now that he is retired he has even more time to post on the OpenSC mailing list :-). His progression is +41% of messages.

I moved from the 2nd position to the 10th position with -63% of messages.



Statistics from 7.1.2014 to 23.12.2014
for opensc-devel@lists.sourceforge.net



People who have written most messages:

   Author   Msg   Percent 
1 deengert@gmail.com 58 17.31 %
2 andreas.schwier.ml@cardcontact.de 25 7.46 %
3 anders.rundgren.net@gmail.com 21 6.27 %
4 martin@martinpaljak.net 19 5.67 %
5 dwmw2@infradead.org 18 5.37 %
6 bill.c.roberts@gmail.com 16 4.78 %
7 morgner@informatik.hu-berlin.de 16 4.78 %
8 viktor.tarasov@gmail.com 13 3.88 %
9 roberto@resolutions.it 13 3.88 %
10 ludovic.rousseau@gmail.com 12 3.58 %
11 shaun.schutte@tis.bz.it 9 2.69 %
12 J.Witvliet@mindef.nl 6 1.79 %
13 ndk.clanbo@gmail.com 5 1.49 %
14 muzio.francesco@clear-elettronica.it 5 1.49 %
15 n.mavrogiannopoulos@gmail.com 5 1.49 %
16 helpcrypto@gmail.com 5 1.49 %
17 deengert@anl.gov 4 1.19 %
18 nsara_57@hotmail.com 4 1.19 %
19 lturek@enovacom.fr 3 0.90 %
20 munoz0raul@gmail.com 3 0.90 %
21 leonardo.schenkel@gmail.com 3 0.90 %
22 Erik.Schick@taskit.de 3 0.90 %
23 sanaullah82@gmail.com 3 0.90 %
24 dirkx@webweaving.org 3 0.90 %
25 tristan.timmermans@ubiqu.nl 3 0.90 %
26 nmav@gnutls.org 3 0.90 %
27 ribalkin@gmail.com 2 0.60 %
28 maxxer@ufficyo.com 2 0.60 %
29 erik.g.bostrom@gmail.com 2 0.60 %
30 ondrej.mikle@nic.cz 2 0.60 %
  other 49 14.63 %

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

   Author   KBytes 
1 wendlandphilip@gmail.com 5357.8
2 deengert@gmail.com 908.3
3 bill.c.roberts@gmail.com 331.6
4 andreas.schwier.ml@cardcontact.de 219.7
5 dwmw2@infradead.org 141.2
6 anders.rundgren.net@gmail.com 125.8
7 martin@martinpaljak.net 110.6
8 morgner@informatik.hu-berlin.de 104.2
9 viktor.tarasov@gmail.com 99.5
10 dirkx@webweaving.org 99.4
11 roberto@resolutions.it 87.9
12 ludovic.rousseau@gmail.com 72.9
13 J.Witvliet@mindef.nl 67.6
14 shaun.schutte@tis.bz.it 52.0
15 eric@kuroneko.ca 47.5
16 n.mavrogiannopoulos@gmail.com 46.2
17 ndk.clanbo@gmail.com 39.4
18 nmav@gnutls.org 37.4
19 helpcrypto@gmail.com 36.4
20 nsara_57@hotmail.com 34.5
21 muzio.francesco@clear-elettronica.it 32.4
22 tristan.timmermans@ubiqu.nl 27.2
23 munoz0raul@gmail.com 24.1
24 lturek@enovacom.fr 23.1
25 deengert@anl.gov 22.8
26 marjan.stankovic@gmail.com 22.3
27 Erik.Schick@taskit.de 22.2
28 alon.barlev@gmail.com 20.2
29 jblaine@kickflop.net 17.6
30 leonardo.schenkel@gmail.com 16.2

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

   Author   bytes 
1 wendlandphilip@gmail.com 2743179
2 eric@kuroneko.ca 48636
3 dirkx@webweaving.org 33930
4 marjan.stankovic@gmail.com 22835
5 bill.c.roberts@gmail.com 21224
6 jblaine@kickflop.net 18003
7 deengert@gmail.com 16035
8 etienne.cordonnier@theobroma-systems.com 13715
9 nmav@gnutls.org 12759
10 J.Witvliet@mindef.nl 11542
11 pstew@chromium.org 11174
12 loniux.mail@gmail.com 10495
13 alon.barlev@gmail.com 10358
14 n.mavrogiannopoulos@gmail.com 9467
15 tristan.timmermans@ubiqu.nl 9289
16 andreas.schwier.ml@cardcontact.de 8997
17 nsara_57@hotmail.com 8819
18 thican@thican.net 8533
19 munoz0raul@gmail.com 8214
20 ndk.clanbo@gmail.com 8066
21 dwdopensc@drdykstra.us 8040
22 dwmw2@infradead.org 8033
23 Johannes.Becker@hrz.uni-giessen.de 8014
24 jaroslav.imrich@gmail.com 7983
25 lturek@enovacom.fr 7877
26 viktor.tarasov@gmail.com 7839
27 Erik.Schick@taskit.de 7583
28 vlastimil.pavicek@centrum.cz 7541
29 mmartynas@gmail.com 7485
30 helpcrypto@gmail.com 7460

Table showing the most successful subjects:

   Subject   Msg   Percent 
1 [Opensc-devel] OpenSC Internet Explorer
18 5.37 %
2 [Opensc-devel] Repeated login issues with Yubikey NEO
11 3.28 %
3 [Opensc-devel] CKR_ARGUMENTS_BAD
10 2.99 %
4 [Opensc-devel] Why do PIV key and cert labels not match?
10 2.99 %
5 [Opensc-devel] [OpenSC] openssl req -engine pkcs11 fails with
9 2.69 %
6 [Opensc-devel] Safran Morpho YpsID S3
9 2.69 %
7 [Opensc-devel] Jenkins
9 2.69 %
8 [Opensc-devel] PINPAD quirks
7 2.09 %
9 [Opensc-devel] ACOS5 smart cards support
6 1.79 %
10 [Opensc-devel] Format of extracted ECC public keys
6 1.79 %
11 [Opensc-devel] using MyEID without a PIN
6 1.79 %
12 [Opensc-devel] PKCS#11 usability improvements
6 1.79 %
13 [Opensc-devel] Minidriver still marked experimental
5 1.49 %
14 [Opensc-devel] Adding support for AES General Auth
5 1.49 %
15 [Opensc-devel] "fatal: could not initialize dst: crypto
5 1.49 %
16 [Opensc-devel] Support of French Professional Health Card CPS3
4 1.19 %
17 [Opensc-devel] reader & card that can sign files and accept
4 1.19 %
18 [Opensc-devel] Problem with generating keys on SmartCard HSM
4 1.19 %
19 [Opensc-devel] Request for object 5C017E in PIV
4 1.19 %
20 [Opensc-devel] Smart Cards vs. TEEs
4 1.19 %
21 [Opensc-devel] The TPM is dead, long live the TEE!
4 1.19 %
22 [Opensc-devel] Is openct dead?
4 1.19 %
23 [Opensc-devel] building 0.14
4 1.19 %
24 [Opensc-devel] Discussion about OpenSC broken PKCS#11 compliance
4 1.19 %
25 [Opensc-devel] Smartcard-HSM sleeping?
4 1.19 %
26 [Opensc-devel] PKCS#11, ECC and OpenSSL
4 1.19 %
27 [Opensc-devel] The RSA division joins Google's U2F
3 0.90 %
28 [Opensc-devel] minidriver setup
3 0.90 %
29 [Opensc-devel] Fixed ALL compiler warnings
3 0.90 %
30 [Opensc-devel] PIV cards and Mobile Devices
3 0.90 %
  other 157 46.87 %

Most used email clients:

   Mailer   Msg   Percent 
1 Mozilla/5.x 171 51.04 %
2 (unknown) 111 33.13 %
3 Evolution 3.12.8 (3.12.8-1.fc21)
13 3.88 %
4 obfuscated
9 2.69 %
5 Mutt 6 1.79 %
6 Evolution 3.12.7 (3.12.7-1.fc21)
6 1.79 %
7 Apple Mail (2.1874)
3 0.90 %
8 Apple Mail (2.1878.2)
2 0.60 %
9 Apple Mail (2.1985.3)
2 0.60 %
10 K-9 Mail for Android
2 0.60 %
11 Zimbra 8.0.6_GA_5922 (ZimbraWebClient - GC33 (Linux)/8.0.6_GA_5922)
1 0.30 %
12 Zimbra 8.0.6_GA_5922 (ZimbraWebClient - GC34 (Linux)/8.0.6_GA_5922)
1 0.30 %
13 Gnus/5.130006 (Ma Gnus v0.6) Emacs/23.4 (berkeley-unix)
1 0.30 %
14 Centrum Email 5.3
1 0.30 %
15 YahooMailWebService/0.8.185.657
1 0.30 %
16 KMail 1 0.30 %
17 Apple Mail (2.1973.6)
1 0.30 %
18 Microsoft Outlook 15.0
1 0.30 %
19 Evolution 3.12.7-1
1 0.30 %
  other 1 0.30 %

Table of maximal quoting:

   Author   Percent 
1 ebr.ghasemi@gmail.com 62.29 %
2 frederic.vandevelde@paradigmo.com 55.75 %
3 florian.bruckner@3kraft.com 54.19 %
4 opensc@secure-edge.com 46.42 %
5 adam@digitalpirate.ca 45.28 %
6 deengert@anl.gov 42.41 %
7 Andrea.Cremaschi@midainformatica.it 39.68 %
8 andre.tampubolon@ciptasrigatilestari.co.id 38.02 %
9 marjan.stankovic@gmail.com 34.74 %
10 muzio.francesco@clear-elettronica.it 30.15 %
11 shaun.schutte@tis.bz.it 29.57 %
12 lholzheid@bihl-wiedemann.de 29.36 %
13 viktor.tarasov@gmail.com 27.86 %
14 helpcrypto@gmail.com 26.97 %
15 alexandre.aufrere@opentrust.com 25.92 %
16 ndk.clanbo@gmail.com 22.41 %
17 sanaullah82@gmail.com 22.28 %
18 morgner@informatik.hu-berlin.de 21.03 %
19 earl@baugh.org 20.37 %
20 andreas.schwier.ml@cardcontact.de 19.39 %
21 jaroslav.imrich@gmail.com 19.24 %
22 J.Witvliet@mindef.nl 18.52 %
23 ludovic.rousseau@gmail.com 17.92 %
24 erik.g.bostrom@gmail.com 17.74 %
25 tristan.timmermans@ubiqu.nl 15.72 %
26 aivaraslaimikis@gmail.com 15.64 %
27 lturek@enovacom.fr 14.32 %
28 martin@martinpaljak.net 13.32 %
29 n.mavrogiannopoulos@gmail.com 11.93 %
30 dwmw2@infradead.org 11.08 %
  average 5.66 %

Graph showing number of messages written during hours of day:

msgs
5
|
4
|
0
|
0
|
2
|
3
|
4
|
10
|
24
|
17
|
21
|
30
|
16
|
20
|
21
|
24
|
27
|
30
|
12
|
15
|
17
|
14
|
8
|
9
|
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

Warning: 2 message(s) not counted.


Graph showing number of messages written during days of month:

msgs
7
|
6
|
16
|
19
|
11
|
11
|
14
|
7
|
5
|
27
|
8
|
3
|
9
|
22
|
5
|
10
|
10
|
7
|
13
|
12
|
6
|
9
|
14
|
10
|
9
|
11
|
9
|
16
|
16
|
8
|
3
|
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

Warning: 2 message(s) not counted.


Graph showing number of messages written during days of week:

msgs
69
|
49
|
57
|
69
|
53
|
11
|
25
|

Mon Tue Wed Thu Fri Sat Sun

Warning: 2 message(s) not counted.


Maximal quoting:

Author : frederic.vandevelde@paradigmo.com
Subject : [Opensc-devel] using MyEID without a PIN

Date : Fri, 6 Jun 2014 14:32:24 +0200

Quote ratio: 70.50% / 20823 bytes

Longest message:

Author : wendlandphilip@gmail.com
Subject : [Opensc-devel] Format of extracted ECC public keys
Date : Thu, 25 Sep 2014 17:43:22 +0200
Size : 5481666 bytes

Most successful subject:

Subject : [Opensc-devel] OpenSC Internet Explorer
No. of msgs: 18
Total size : 145598 bytes

Final summary:

Total number of messages: 335
Total number of different authors: 70
Total number of different subjects: 138
Total size of messages (w/o headers): 9292267 bytes
Average size of a message: 27738 bytes


Input file last updated: Sun Jan 4 18:09:51 2015
Generated by MailListStat v1.3

MUSCLE mailing list statistics for 2014

Happy new year 2014!

As I did in 2009, 2010, 2011, 2012 and 2013 I propose some statistics of the MUSCLE mailing list usage.

The list at muscle@lists.musclecard.com failed in May 2014. I moved the users to a new list pcsclite-muscle@lists.alioth.debian.org in June 2014. The number in the table bellow for 2014 is the the addition of both lists.

Evolution


Year Total number of messages Progression
2009 603
2010 718 +19 %
2011 999 +39 %
2012 207 -79 %
2013 198 -4 %
2014 194 -2 %

The number of messages is stable on the last 3 years. I guess that is a good sign.

Day of work


msgs 29
|
21
|
26
|
32
|
21
|
4
|
4
|

Mon Tue Wed Thu Fri Sat Sun

This table shows that the activity is concentrated during work days. The email activity on Saturday and Sunday is very low. This is an evolution compared to previous years.

Maybe it is a sign that participants of the MUSCLE mailing list are using the PC/SC and smart card layers for there paid work and that it is less a hobby than previously.





Statistics from 6.1.2014 to 24.4.2014
for muscle@lists.musclecard.com



People who have written most messages:


 Author   Msg   Percent
1 ludovic.rousseau@gmail.com 17 30.36 %
2 martin@martinpaljak.net 7 12.50 %
3 wully@bluewin.ch 6 10.71 %
4 tommaso.cucinotta@sssup.it 4 7.14 %
5 gdt@ir.bbn.com 3 5.36 %
6 nmav@redhat.com 2 3.57 %
7 josealf@rocketmail.com 2 3.57 %
8 adam.miartus@gmail.com 2 3.57 %
9 gavin.williams@weareact.com 2 3.57 %
10 00cpxxx@gmail.com 1 1.79 %
11 mstjohns@comcast.net 1 1.79 %
12 sfhacker@hotmail.com 1 1.79 %
13 sebastien@lorquet.fr 1 1.79 %
14 Patrick.Rotsaert@intoit.be 1 1.79 %
15 rentorbuy@yahoo.com 1 1.79 %
16 muscle-bounces@lists.musclecard.com 1 1.79 %
17 andreas.schwier@cardcontact.de 1 1.79 %
18 crack.nyse@gmail.com 1 1.79 %
19 nicholas@nikom.net 1 1.79 %
20 p.s.vanderheide@gmail.com 1 1.79 %
other 0 0.00 %

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


 Author   KBytes
1 ludovic.rousseau@gmail.com 91.6
2 rentorbuy@yahoo.com 54.8
3 tommaso.cucinotta@sssup.it 38.7
4 adam.miartus@gmail.com 37.1
5 gdt@ir.bbn.com 34.7
6 nicholas@nikom.net 32.8
7 wully@bluewin.ch 23.4
8 martin@martinpaljak.net 23.0
9 nmav@redhat.com 21.1
10 sfhacker@hotmail.com 7.3
11 andreas.schwier@cardcontact.de 7.1
12 gavin.williams@weareact.com 7.1
13 crack.nyse@gmail.com 6.7
14 muscle-bounces@lists.musclecard.com 6.6
15 josealf@rocketmail.com 5.9
16 sebastien@lorquet.fr 5.5
17 p.s.vanderheide@gmail.com 5.5
18 00cpxxx@gmail.com 5.3
19 mstjohns@comcast.net 4.9
20 Patrick.Rotsaert@intoit.be 1.2

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


 Author   bytes
1 rentorbuy@yahoo.com 56082
2 nicholas@nikom.net 33616
3 adam.miartus@gmail.com 19019
4 gdt@ir.bbn.com 11845
5 nmav@redhat.com 10826
6 tommaso.cucinotta@sssup.it 9895
7 sfhacker@hotmail.com 7514
8 andreas.schwier@cardcontact.de 7300
9 crack.nyse@gmail.com 6839
10 muscle-bounces@lists.musclecard.com 6745
11 sebastien@lorquet.fr 5675
12 p.s.vanderheide@gmail.com 5660
13 ludovic.rousseau@gmail.com 5518
14 00cpxxx@gmail.com 5405
15 mstjohns@comcast.net 5055
16 wully@bluewin.ch 4001
17 gavin.williams@weareact.com 3621
18 martin@martinpaljak.net 3371
19 josealf@rocketmail.com 3008
20 Patrick.Rotsaert@intoit.be 1203

Table showing the most successful subjects:


 Subject   Msg   Percent
1 [Muscle] Cyberflex 5 8.93 %
2 [Muscle] PC/SC lite for Windows 3 5.36 %
3 [Muscle] using polkit 3 5.36 %
4 [Muscle] Help with HID OminKey 5427 CK USB Card Reader 3 5.36 %
5 [Muscle] New version of libccid: 1.4.15 3 5.36 %
6 [Muscle] pscd and usbip 3 5.36 %
7 [Muscle] HID vericlass vp3500 reader stops reading cards after a 3 5.36 %
8 [Muscle] OSX installer of the CCID driver 2 3.57 %
9 [Muscle] once again: eGate 32k and MUSCLE 2 3.57 %
10 [Muscle] pkcs11 and MuscleCard 2 3.57 %
11 [Muscle] Cyberflex versus Cryptoflex? 2 3.57 %
12 [Muscle] PCSCD: Smart card readers stop responding after being 2 3.57 %
13 [Muscle] New version of libccid: 1.4.16 2 3.57 %
14 [Muscle] access to SmartTerminal XX44 2 3.57 %
15 [Muscle] Pam_pkcs11 ca_dir not working 2 3.57 %
16 Patch for readers based on a Realtek chip on OSX 1 1.79 %
17 [Muscle] Gemalto Prox-DU EEPROM modification for Android Host Card 1 1.79 %
18 New version of libccid: 1.4.15 1 1.79 %
19 New version of pcsc-lite: 1.8.11 1 1.79 %
20 [Muscle] eGate 32k and MUSCLE 1 1.79 %
21 [Muscle] USB problem with ACR1222L reader 1 1.79 %
22 [Muscle] Musclecard 1 1.79 %
23 [Muscle] Fwd: Card Inserted/Removed when holding card near reader 1 1.79 %
24 [Muscle] Fwd: Card Inserted/Removed when holding card near 1 1.79 %
25 [Muscle] problem accessing smartcard 1 1.79 %
26 [Muscle] Attempting to build PCSC-Lite 1.8.11 RPM for Centos 6 1 1.79 %
27 [Muscle] SmartTerminal XX44 on Linux redirected to Windows Terminal 1 1.79 %
28 [Muscle] PCSCD: Smart card readers stop responding after being plugged and unplugged multiple times... 1 1.79 %
29 [Muscle] OpenSerialByName() Change card movement notification 1 1.79 %
30 [Muscle] Get Attribute support 1 1.79 %
other 2 3.57 %

Most used email clients:


 Mailer   Msg   Percent
1 (unknown) 34 60.71 %
2 Mozilla/5.x 13 23.21 %
3 Gnus/5.130006 (Ma Gnus v0.6) Emacs/23.4 (berkeley-unix) 3 5.36 %
4 YahooMailWebService/0.8.181.645 2 3.57 %
5 YahooMailWebService/0.8.174.629 1 1.79 %
6 iPad Mail (11B554a) 1 1.79 %
7 YahooMailWebService/0.8.177.636 1 1.79 %
8 Open-Xchange Mailer v7.4.2-Rev18 1 1.79 %
other 0 0.00 %

Table of maximal quoting:


 Author   Percent
1 Patrick.Rotsaert@intoit.be 50.49 %
2 sebastien@lorquet.fr 32.16 %
3 martin@martinpaljak.net 22.25 %
4 josealf@rocketmail.com 18.96 %
5 nicholas@nikom.net 16.14 %
6 gavin.williams@weareact.com 15.44 %
7 wully@bluewin.ch 15.30 %
8 ludovic.rousseau@gmail.com 12.80 %
9 nmav@redhat.com 12.25 %
10 rentorbuy@yahoo.com 9.95 %
11 gdt@ir.bbn.com 9.09 %
12 andreas.schwier@cardcontact.de 7.33 %
13 muscle-bounces@lists.musclecard.com 6.26 %
14 mstjohns@comcast.net 4.22 %
15 adam.miartus@gmail.com 3.48 %
16 tommaso.cucinotta@sssup.it 3.12 %
17 crack.nyse@gmail.com 2.38 %
18 00cpxxx@gmail.com 1.35 %
19 sfhacker@hotmail.com 0.00 %
20 p.s.vanderheide@gmail.com 0.00 %
average 11.31 %

Graph showing number of messages written during hours of day:


msgs 1
|
0
|
0
|
0
|
0
|
0
|
3
|
0
|
2
|
4
|
6
|
3
|
4
|
5
|
3
|
4
|
4
|
4
|
3
|
2
|
6
|
0
|
2
|
0
|
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 1
|
3
|
0
|
1
|
1
|
4
|
3
|
0
|
0
|
5
|
1
|
2
|
2
|
2
|
3
|
1
|
2
|
2
|
1
|
1
|
0
|
1
|
2
|
7
|
4
|
1
|
2
|
3
|
0
|
0
|
0
|
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

Warning: 1 message(s) not counted.


Graph showing number of messages written during days of week:


msgs 13
|
8
|
7
|
10
|
9
|
7
|
2
|

Mon Tue Wed Thu Fri Sat Sun

Maximal quoting:


Author : martin@martinpaljak.net
Subject : [Muscle] New version of libccid: 1.4.16

Date : Mon, 24 Mar 2014 12:59:00 +0000

Quote ratio: 66.45% / 4077 bytes

Longest message:


Author : rentorbuy@yahoo.com
Subject : [Muscle] SmartTerminal XX44 on Linux redirected to Windows Terminal
Date : Thu, 20 Mar 2014 06:12:02 -0700 (PDT)
Size : 62282 bytes

Most successful subject:


Subject : [Muscle] Cyberflex
No. of msgs: 5
Total size : 32612 bytes

Final summary:


Total number of messages: 56
Total number of different authors: 20
Total number of different subjects: 32
Total size of messages (w/o headers): 485490 bytes
Average size of a message: 8669 bytes



Statistics from 3.1.2014 to 18.12.2014
for pcsclite-muscle@lists.alioth.debian.org



People who have written most messages:


 Author   Msg   Percent
1 ludovic.rousseau@gmail.com 42 30.43 %
2 helpcrypto@gmail.com 8 5.80 %
3 nmav@redhat.com 8 5.80 %
4 stefani@seibold.net 6 4.35 %
5 dwmw2@infradead.org 6 4.35 %
6 sbrabec@suse.cz 5 3.62 %
7 umberto.rustichelli@gt50.org 4 2.90 %
8 alexander.may@hjp-consulting.com 4 2.90 %
9 martin@martinpaljak.net 4 2.90 %
10 godfreyhkchung@gmail.com 4 2.90 %
11 dirkx@webweaving.org 3 2.17 %
12 Pcsclite-muscle 3 2.17 %
13 Daniel.Abson@ecebs.com 3 2.17 %
14 sebastien@lorquet.fr 3 2.17 %
15 Laurent.DeBuyst@fedasil.be 2 1.45 %
16 ignacio.casal@nice-software.com 2 1.45 %
17 gdm23@iragan.org 2 1.45 %
18 santiago.gimeno@gmail.com 2 1.45 %
19 morgner@informatik.hu-berlin.de 2 1.45 %
20 hendrik.donner@gmx.de 2 1.45 %
21 michael@stroeder.com 2 1.45 %
22 russell+muscle@stuart.id.au 2 1.45 %
23 nboullis@debian.org 2 1.45 %
24 chris.j.arges@canonical.com 1 0.72 %
25 ludovic.rousseau@free.fr 1 0.72 %
26 johannes.kapune@gmx.de 1 0.72 %
27 cocodidouf@gmail.com 1 0.72 %
28 Maximilian.Stein@secunet.com 1 0.72 %
29 maximilian.stein@secunet.com 1 0.72 %
30 00cpxxx@gmail.com 1 0.72 %
other 10 7.25 %

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


 Author   KBytes
1 ludovic.rousseau@gmail.com 283.8
2 stefani@seibold.net 54.1
3 gdm23@iragan.org 49.9
4 helpcrypto@gmail.com 35.8
5 morgner@informatik.hu-berlin.de 34.2
6 sebastien@lorquet.fr 30.6
7 godfreyhkchung@gmail.com 28.8
8 nmav@redhat.com 24.3
9 sbrabec@suse.cz 21.7
10 martin@martinpaljak.net 19.5
11 dirkx@webweaving.org 18.8
12 santiago.gimeno@gmail.com 17.0
13 fdimitriou@tmm-software.com 16.0
14 ignacio.casal@nice-software.com 13.9
15 umberto.rustichelli@gt50.org 13.7
16 Daniel.Abson@ecebs.com 12.8
17 alexander.may@hjp-consulting.com 12.4
18 russell+muscle@stuart.id.au 10.6
19 dwmw2@infradead.org 9.6
20 jan@jvales.net 8.2
21 Pcsclite-muscle 8.0
22 cocodidouf@gmail.com 7.8
23 Laurent.DeBuyst@fedasil.be 7.5
24 michael@stroeder.com 7.3
25 hendrik.donner@gmx.de 7.2
26 hans-martin.haase@ecsec.de 5.7
27 hean01@cendio.se 5.6
28 ludovic.rousseau@free.fr 5.6
29 00cpxxx@gmail.com 5.5
30 Tom.Arnautovic@neardesk.com 4.6

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


 Author   bytes
1 gdm23@iragan.org 25559
2 morgner@informatik.hu-berlin.de 17532
3 fdimitriou@tmm-software.com 16367
4 sebastien@lorquet.fr 10440
5 stefani@seibold.net 9229
6 santiago.gimeno@gmail.com 8721
7 jan@jvales.net 8406
8 cocodidouf@gmail.com 7955
9 godfreyhkchung@gmail.com 7375
10 ignacio.casal@nice-software.com 7110
11 ludovic.rousseau@gmail.com 6920
12 dirkx@webweaving.org 6406
13 hans-martin.haase@ecsec.de 5868
14 hean01@cendio.se 5758
15 ludovic.rousseau@free.fr 5694
16 00cpxxx@gmail.com 5671
17 russell+muscle@stuart.id.au 5426
18 martin@martinpaljak.net 4993
19 Tom.Arnautovic@neardesk.com 4723
20 helpcrypto@gmail.com 4578
21 sbrabec@suse.cz 4443
22 Daniel.Abson@ecebs.com 4384
23 Laurent.DeBuyst@fedasil.be 3840
24 michael@stroeder.com 3728
25 hendrik.donner@gmx.de 3666
26 umberto.rustichelli@gt50.org 3518
27 alexander.may@hjp-consulting.com 3168
28 nmav@redhat.com 3115
29 Pcsclite-muscle 2745
30 tom.arnautovic@neardesk.com 2732

Table showing the most successful subjects:


 Subject   Msg   Percent
1 [Pcsclite-muscle] [PATCH] pcsc-lite & polkit: allow auth_admin 10 7.25 %
2 [Pcsclite-muscle] HELP! Any experience on smart card chip 8 5.80 %
3 [Pcsclite-muscle] Client code review request 6 4.35 %
4 [Pcsclite-muscle] Dump reader utility 5 3.62 %
5 [Pcsclite-muscle] Registering virtual readers 5 3.62 %
6 [Pcsclite-muscle] About SHARED/EXCLUSIVE and starvation Was: 4 2.90 %
7 [Pcsclite-muscle] New version of pcsc-lite: 1.8.12 4 2.90 %
8 [Pcsclite-muscle] Dynamically disable/enable specific card 4 2.90 %
9 [Pcsclite-muscle] OMNIKEY AG 3121 USB not working with libccid 3 2.17 %
10 [Pcsclite-muscle] Fix libudev hotplug 3 2.17 %
11 [Pcsclite-muscle] PySCard: unofficial version 1.6.16 available 3 2.17 %
12 [Pcsclite-muscle] Portable way to detect when a smart card is 3 2.17 %
13 [Pcsclite-muscle] Issue with SCardGetStatusChange() and timeout 3 2.17 %
14 [Pcsclite-muscle] Not enough reader entries on CentOS 7.0 with 3 2.17 %
15 [Pcsclite-muscle] SCardTransmit error with ISO-14443A tag 3 2.17 %
16 [Pcsclite-muscle] ccid_usb.c error handling 3 2.17 %
17 [PATCH V3] revamp libudev hotplug 3 2.17 %
18 [Pcsclite-muscle] [PATCH V3] revamp libudev hotplug 3 2.17 %
19 [Pcsclite-muscle] An alternate Python library for PC/SC Lite 3 2.17 %
20 [Pcsclite-muscle] CCID Download 2 1.45 %
21 [Pcsclite-muscle] Driver development 2 1.45 %
22 [Pcsclite-muscle] SCardGetStatusChange() fails after ~10 card insertions 2 1.45 %
23 [Pcsclite-muscle] [PATCH] Fix invalid pthread_mutex_unlock in 2 1.45 %
24 [Pcsclite-muscle] Changes to pcscd for XSpice support 2 1.45 %
25 [Pcsclite-muscle] pcsc-lite and polkit rules in openSUSE 13.2 2 1.45 %
26 [Pcsclite-muscle] Problem using a "GnuPG card V2" smartcard 2 1.45 %
27 [Pcsclite-muscle] Problem using a "GnuPG card V2" smartcard with 2 1.45 %
28 [Pcsclite-muscle] acsccid 1.1.0 Released 2 1.45 %
29 [Pcsclite-muscle] Patch for readers based on a Realtek chip on OSX 1 0.72 %
30 Issue with Alcor Micro AU9540 1 0.72 %
other 39 28.26 %

Most used email clients:


 Mailer   Msg   Percent
1 (unknown) 77 55.80 %
2 Mozilla/5.x 32 23.19 %
3 Evolution 3.12.4 4 2.90 %
4 Microsoft Outlook 15.0 4 2.90 %
5 Apple Mail (2.1974.6) 3 2.17 %
6 Evolution 3.12.7 (3.12.7-1.fc21) 3 2.17 %
7 Evolution 3.12.8 (3.12.8-1.fc21) 3 2.17 %
8 Lotus Notes Release 8.5 2 1.45 %
9 Zimbra 8.0.6_GA_5922 (ZimbraWebClient - FF31 (Linux)/8.0.6_GA_5922) 2 1.45 %
10 Mutt 2 1.45 %
11 Evolution 3.12.3 1 0.72 %
12 Claws Mail 3.10.1 (GTK+ 2.24.22; x86_64-redhat-linux-gnu) 1 0.72 %
13 Microsoft Office Outlook 11 1 0.72 %
14 Evolution 3.12.7 1 0.72 %
15 Evolution 3.4.4-3 1 0.72 %
other 1 0.72 %

Table of maximal quoting:


 Author   Percent
1 Maximilian.Stein@secunet.com 68.74 %
2 maximilian.stein@secunet.com 55.11 %
3 nboullis@debian.org 51.75 %
4 00cpxxx@gmail.com 50.60 %
5 mark.kohler@proteinsimple.com 48.56 %
6 johannes.kapune@gmx.de 42.66 %
7 dwmw2@infradead.org 40.43 %
8 chris.j.arges@canonical.com 40.15 %
9 sebastien@lorquet.fr 34.64 %
10 martin@martinpaljak.net 32.89 %
11 Tom.Arnautovic@neardesk.com 28.20 %
12 tom.arnautovic@neardesk.com 25.37 %
13 alexander.may@hjp-consulting.com 23.13 %
14 umberto.rustichelli@gt50.org 21.44 %
15 morgner@informatik.hu-berlin.de 20.97 %
16 igor@igormedeiros.com.br 18.40 %
17 russell+muscle@stuart.id.au 17.12 %
18 sbrabec@suse.cz 16.25 %
19 nmav@redhat.com 15.43 %
20 helpcrypto@gmail.com 15.24 %
21 michael@stroeder.com 14.85 %
22 cocodidouf@gmail.com 14.70 %
23 ignacio.casal@nice-software.com 14.51 %
24 Laurent.DeBuyst@fedasil.be 14.14 %
25 andreas.schwier@cardcontact.de 13.41 %
26 Daniel.Abson@ecebs.com 13.31 %
27 jan@jvales.net 9.76 %
28 stefani@seibold.net 9.66 %
29 ludovic.rousseau@gmail.com 8.58 %
30 hendrik.donner@gmx.de 6.90 %
average 14.32 %

Graph showing number of messages written during hours of day:


msgs 2
|
0
|
0
|
1
|
0
|
1
|
0
|
2
|
3
|
15
|
17
|
11
|
6
|
8
|
15
|
13
|
8
|
8
|
10
|
3
|
2
|
4
|
7
|
1
|
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

Warning: 1 message(s) not counted.


Graph showing number of messages written during days of month:


msgs 2
|
5
|
3
|
8
|
6
|
7
|
7
|
15
|
3
|
2
|
1
|
5
|
4
|
4
|
6
|
8
|
16
|
3
|
3
|
4
|
0
|
2
|
2
|
3
|
5
|
3
|
0
|
4
|
1
|
3
|
2
|
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

Warning: 1 message(s) not counted.


Graph showing number of messages written during days of week:


msgs 29
|
21
|
26
|
32
|
21
|
4
|
4
|

Mon Tue Wed Thu Fri Sat Sun

Warning: 1 message(s) not counted.


Maximal quoting:


Author : ludovic.rousseau@gmail.com
Subject : [PATCH V3] revamp libudev hotplug

Date : Thu, 6 Nov 2014 15:26:27 +0100

Quote ratio: 75.26% / 3994 bytes

Longest message:


Author : gdm23@iragan.org
Subject : [Pcsclite-muscle] [PATCH] Fix invalid pthread_mutex_unlock in
Date : Thu, 02 Oct 2014 12:11:41 +0200
Size : 46384 bytes

Most successful subject:


Subject : [Pcsclite-muscle] [PATCH] pcsc-lite & polkit: allow auth_admin
No. of msgs: 10
Total size : 51232 bytes

Final summary:


Total number of messages: 138
Total number of different authors: 39
Total number of different subjects: 68
Total size of messages (w/o headers): 949045 bytes
Average size of a message: 6877 bytes



Input file last updated: Sun Jan 4 16:22:33 2015 Generated by MailListStat v1.3

Great OpenPGP smart card article (in French)

gouttegd published a very good article about the configuration and use of an OpenPGP smart card. The article is "“OpenPGP card“, une application cryptographique pour carte à puce" and is written in French (sorry).

Sommaire

OS X Yosemite bug: SCardStatus returns SCARD_E_INSUFFICIENT_BUFFER

This is part of the series: "OS X Yosemite and smart cards: known bugs".

SCardStatus returns SCARD_E_INSUFFICIENT_BUFFER

SCardStatus() does not correctly report the reader name length. The terminating NUL character of the reader name is not counted. So a second call to SCardStatus() using the size returned by the first SCardStatus() call will fail with 0x80100008 (that is SCARD_E_INSUFFICIENT_BUFFER).

It is a really stupid bug and very easy to fix for Apple.

See also

"Problem with SCardStatus on MAC OS X 10.10 (Yosemite)" at https://smartcardservices.macosforge.org/trac/ticket/140.

Apple bug report #19306215 "PC/SC SCardStatus returns SCARD_E_INSUFFICIENT_BUFFER". Closed by Apple, 9th January 2015, as a duplicated of #18890042.

Sample code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#endif

int main(int argc, const char * argv[]) {
 SCARDCONTEXT hContext;
 LPSTR mszReaders;
 DWORD err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardEstablishedContext: 0x%08x\n",err);
  return -1;
 }

 DWORD cchReaders = 0;
 err = SCardListReaders(hContext, "SCard$AllReaders", NULL, &cchReaders);
 if (err != 0) {
  printf("ScardListReaders: 0x%08x\n",err);
  return -1;
 }
 mszReaders = calloc(cchReaders, sizeof(char));
 if (!mszReaders) {
  printf("calloc\n");
  return -1;
 }
 err = SCardListReaders(hContext,"SCard$AllReaders", mszReaders, &cchReaders);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardListReaders: 0x%08x\n",err);
  return -1;
 }
 printf("Reader: %s\n", mszReaders);

 SCARDHANDLE hCard;
 DWORD dwActiveProtocol;
 err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardConnect: 0x%08x\n",err);
  return -1;
 }

 /* 1st SCardStatus call to get the reader name length */
 char name[100];
 DWORD len;
 err = SCardStatus(hCard, NULL, &len, NULL, NULL, NULL, NULL);
 if (err != SCARD_S_SUCCESS) {
  printf("SCardStatus: 0x%08x\n",err);
  return -1;
 }
 printf("reader name length: %d\n", len);
 //len += 1;

 /* 2nd SCardStatus call to get the reader name value */
 err = SCardStatus(hCard, name, &len, NULL, NULL, NULL, NULL);
 if (err != SCARD_S_SUCCESS) {
  printf("SCardStatus: 0x%08x\n",err);
  return -1;
 }
 printf("Reader name: %s (%ld)\n", name, strlen(name));

 SCardDisconnect(hCard, SCARD_LEAVE_CARD);
 SCardReleaseContext(hContext);

 return 0;
}

Result (on Yosemite)

$ CFLAGS="-framework PCSC" make main
cc -framework PCSC    main.c   -o main

$ ./main
Reader: Gemalto PC Twin Reader
reader name length: 22
SCardStatus: 0x80100008

If I uncomment the line: len += 1; I get:
$ ./main
Reader: Gemalto PC Twin Reader
reader name length: 22
Reader name: Gemalto PC Twin Reader (22)

Note that the reader length returned by the first SCardStatus() call is identical to the value returned by strlen(name). And strlen() does NOT includes the terminating NUL character.

Expected result (on Debian)

$ CFLAGS=`pkg-config --cflags libpcsclite` LDFLAGS=`pkg-config --libs libpcsclite` make main
cc -pthread -I/usr/include/PCSC    -lpcsclite    main.c   -o main

$ ./main
Reader: Gemalto PC Twin Reader 00 00
reader length: 29
Reader name: Gemalto PC Twin Reader 00 00 (28)

Note that the length returned by the first SCardStatus() call is strlen(name) + 1.

Known workaround

Add 1 to the reader length returned by SCardStatus().

Update

This bug is now fixed in Mac OS X Yosemite 10.10.2.

OS X Yosemite bug: SCardStatus() after a card reset

This is part of the series: "OS X Yosemite and smart cards: known bugs".

SCardStatus() after a card reset

SCardStatus() does not corectly detect card reset any more on OS X 10.10 Yosemite.

If a card has been reseted using another PC/SC context then SCardStatus() will not fail with 0x80100068 (for SCARD_W_RESET_CARD) as before but will succeed instead.
The problem will be detected later by, for example, the next SCardTransmit() returning SCARD_W_RESET_CARD.

The problem is similar to the one described in OS X Yosemite bug: SCardBeginTransaction() after a card reset.

What is strange is that SCardTransmit() erroneously returns SCARD_W_RESET_CARD after a SCardReconnect(..., SCARD_RESET_CARD, ...) (see OS X Yosemite bug: SCardReconnect) but SCardStatus() do not return SCARD_W_RESET_CARD in the same case. The card reset (or not) state is managed in a "funny" way inside PC/SC on Yosemite.

See also

Apple bug report #19264087 "PC/SC function SCardStatus() fails to fail after a card reset"
#19264087 closed as a duplicate of #18689292.

Sample code

#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#endif

int main(int argc, const char * argv[]) {
 SCARDCONTEXT hContext;
 LPSTR mszReaders;
 DWORD err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardEstablishedContext: 0x%08x\n",err);
  return -1;
 }

 DWORD cchReaders = 0;
 err = SCardListReaders(hContext, "SCard$AllReaders", NULL, &cchReaders);
 if (err != 0) {
  printf("ScardListReaders: 0x%08x\n",err);
  return -1;
 }
 mszReaders = calloc(cchReaders, sizeof(char));
 if (!mszReaders) {
  printf("calloc\n");
  return -1;
 }
 err = SCardListReaders(hContext,"SCard$AllReaders", mszReaders, &cchReaders);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardListReaders: 0x%08x\n",err);
  return -1;
 }
 printf("Reader: %s\n", mszReaders);

 SCARDHANDLE hCard;
 DWORD dwActiveProtocol;
 err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardConnect: 0x%08x\n",err);
  return -1;
 }

 /* create a second PC/SC handle and reset the card */
 SCARDHANDLE hCard2;
 err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard2, &dwActiveProtocol);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardConnect: 0x%08x\n",err);
  return -1;
 }
 err = SCardDisconnect(hCard2, SCARD_RESET_CARD);
 if (err != SCARD_S_SUCCESS) {
  printf("SCardDisconnect: 0x%08x\n",err);
 }

 /* SCardStatus should fail with SCARD_W_RESET_CARD */
 char name[100];
 DWORD len = sizeof name;
 DWORD dwState, dwProtocol;
 unsigned char atr[MAX_ATR_SIZE];
 DWORD atr_len = sizeof atr;
 err = SCardStatus(hCard, name, &len, &dwState, &dwProtocol, atr, &atr_len);
 if (err != SCARD_S_SUCCESS) {
  printf("SCardStatus: 0x%08x\n",err);
  return -1;
 }
 SCardDisconnect(hCard, SCARD_LEAVE_CARD);
 SCardReleaseContext(hContext);

 return 0;
}

Result (on Yosemite)

$ CFLAGS="-framework PCSC" make main
cc -framework PCSC    main.c   -o main

An error 0x80100068 (for SCARD_W_RESET_CARD) is expected here.
$ ./main 
Reader: Gemalto PC Twin Reader

Expected result (on Debian)

$ CFLAGS=`pkg-config --cflags libpcsclite` LDFLAGS=`pkg-config --libs libpcsclite` make main
cc -pthread -I/usr/include/PCSC    -lpcsclite    main.c   -o main

$ ./main
Reader: Gemalto PC Twin Reader 00 00
SCardStatus: 0x80100068

Known workaround

None known.

Modify your code to check for  SCARD_W_RESET_CARD returned by SCardTransmit() even after a successful SCardStatus().

Update

This bug is now fixed in Mac OS X Yosemite 10.10.2.

OS X Yosemite bug: SCardBeginTransaction() after a card reset

This is part of the series: "OS X Yosemite and smart cards: known bugs".

SCardBeginTransaction() after a card reset

SCardBeginTransaction() does not corectly detect card reset any more on OS X 10.10 Yosemite.

If a card has been reseted using another PC/SC context then SCardBeginTransaction() will not fail with 0x80100068 (for SCARD_W_RESET_CARD) as before but will succeed instead.
The problem will be detected later by, for example, the next SCardTransmit() returning SCARD_W_RESET_CARD.

The goal of a PC/SC transaction was to guarantee that you have an exclusive and successful access to the card. This mechanism is broken on Yosemite.

See also

Apple bug report #19263926 "PC/SC SCardBeginTransaction() fails after a card reset"
#19263926 closed as a duplicate of #18689292.

Sample code

#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#endif

int main(int argc, const char * argv[]) {
 SCARDCONTEXT hContext;
 LPSTR mszReaders;
 DWORD err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardEstablishedContext: 0x%08x\n",err);
  return -1;
 }

 DWORD cchReaders = 0;
 err = SCardListReaders(hContext, "SCard$AllReaders", NULL, &cchReaders);
 if (err != 0) {
  printf("ScardListReaders: 0x%08x\n",err);
  return -1;
 }
 mszReaders = calloc(cchReaders, sizeof(char));
 if (!mszReaders) {
  printf("calloc\n");
  return -1;
 }
 err = SCardListReaders(hContext,"SCard$AllReaders", mszReaders, &cchReaders);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardListReaders: 0x%08x\n",err);
  return -1;
 }
 printf("Reader: %s\n", mszReaders);

 SCARDHANDLE hCard;
 DWORD dwActiveProtocol;
 err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardConnect: 0x%08x\n",err);
  return -1;
 }

 /* create a second PC/SC handle and reset the card */
 SCARDHANDLE hCard2;
 err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard2, &dwActiveProtocol);
 if (err != SCARD_S_SUCCESS) {
  printf("ScardConnect: 0x%08x\n",err);
  return -1;
 }
 err = SCardDisconnect(hCard2, SCARD_RESET_CARD);
 if (err != SCARD_S_SUCCESS) {
  printf("SCardReconnect: 0x%08x\n",err);
 }

 /* SCardBeginTransaction should fail with SCARD_W_RESET_CARD */
 err = SCardBeginTransaction(hCard);
 if (err != SCARD_S_SUCCESS) {
  printf("SCardBeginTransaction: 0x%08x\n",err);
  return -1;
 }
 SCardDisconnect(hCard, SCARD_LEAVE_CARD);
 SCardReleaseContext(hContext);

 return 0;
}

Result (on Yosemite)

$ CFLAGS="-framework PCSC" make main
cc -framework PCSC    main.c   -o main

An error 0x80100068 (for SCARD_W_RESET_CARD) is expected here.
$ ./main 
Reader: Gemalto PC Twin Reader

Expected result (on Debian)

$ CFLAGS=`pkg-config --cflags libpcsclite` LDFLAGS=`pkg-config --libs libpcsclite` make main
cc -pthread -I/usr/include/PCSC    -lpcsclite    main.c   -o main

$ ./main 
Reader: Gemalto PC Twin Reader 00 00
SCardBeginTransaction: 0x80100068

Known workaround

None known.

Modify your code to check for  SCARD_W_RESET_CARD returned by SCardTransmit() even inside a PC/SC transaction.

Update

This bug is now fixed in Mac OS X Yosemite 10.10.2.

OS X Yosemite bug: SCardReconnect

This is part of the series: "OS X Yosemite and smart cards: known bugs".

SCardReconnect

SCardReconnect() has a bad side effect on Yosemite.
After a SCardReconnect(..., SCARD_RESET_CARD, ...) the next SCardTransmit() will fail with the error code 0x80100068 that is SCARD_W_RESET_CARD.

This should not happen since SCardReconnect() should reconnect (sic) to the card after the card has been reseted.

See also

"[OSX 10.10] After connect and SCardReconnect, SCardTransmit raises card reset" https://smartcardservices.macosforge.org/trac/ticket/136

Apple bug report #19262854 "PC/SC function SCardReconnect does not work as expected". Closed by Apple, 6th January 2015, as a duplicated of #18689292.

Sample code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#endif

int main(int argc, const char * argv[]) {
    SCARDCONTEXT hContext;
    LPSTR mszReaders;
    DWORD err = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
    if (err != SCARD_S_SUCCESS) {
        printf("ScardEstablishedContext: 0x%08x\n",err);
        return -1;
    }

    DWORD cchReaders = 0;
    err = SCardListReaders(hContext, "SCard$AllReaders", NULL, &cchReaders);
    if (err != 0) {
        printf("ScardListReaders: 0x%08x\n",err);
        return -1;
    }
    mszReaders = calloc(cchReaders, sizeof(char));
    if (!mszReaders) {
        printf("calloc\n");
        return -1;
    }
    err = SCardListReaders(hContext,"SCard$AllReaders", mszReaders, &cchReaders);
    if (err != SCARD_S_SUCCESS) {
        printf("ScardListReaders: 0x%08x\n",err);
        return -1;
    }
    printf("Reader: %s\n", mszReaders);

    SCARDHANDLE hCard;
    DWORD dwActiveProtocol;
    err = SCardConnect(hContext, mszReaders, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol);
    if (err != SCARD_S_SUCCESS) {
        printf("ScardConnect: 0x%08x\n",err);
        return -1;
    }

    unsigned char cmd[] = {0, 0, 0, 0};
    unsigned char resp[255];
    DWORD resp_len = sizeof resp;
    SCARD_IO_REQUEST * pci;

    err = SCardReconnect(hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_RESET_CARD, &dwActiveProtocol);
    if (err != SCARD_S_SUCCESS) {
        printf("SCardReconnect: 0x%08x\n",err);
    }

    if (SCARD_PROTOCOL_T0 == dwActiveProtocol)
        pci = SCARD_PCI_T0;
    else
        pci = SCARD_PCI_T1;
    err = SCardTransmit(hCard, pci, cmd, sizeof cmd, pci, resp, &resp_len);
    if (err != SCARD_S_SUCCESS) {
        printf("SCardTransmit: 0x%08x\n",err);
    }
    SCardDisconnect(hCard, SCARD_LEAVE_CARD);
    SCardReleaseContext(hContext);

    return 0;
}


Result (on Yosemite)

$ CFLAGS="-framework PCSC" make main
cc -framework PCSC    main.c   -o main

$ ./main 
Reader: Gemalto PC Twin Reader
SCardTransmit: 0x80100068

Expected result (on Debian)

$ CFLAGS=`pkg-config --cflags libpcsclite` LDFLAGS=`pkg-config --libs libpcsclite` make main
cc -pthread -I/usr/include/PCSC    -lpcsclite    main.c   -o main
main.c: In function ‘main’:
main.c:57:7: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]
main.c:59:7: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]

No error expected:
$ ./main 
Reader: Gemalto PC Twin Reader 00 00

Known workaround

You can add an second call to SCardReconnect(..., SCARD_LEAVE_CARD, ...) after the first one to force a card reconnection.

Or you can replace the bogus SCardReconnect() by the sequence:
SCardDisconnect(..., SCARD_RESET_CARD);
SCardConnect(...);

I could not find an elegant way to write a macro to automate the code change. The problem is that SCardConnect() needs parameters (PC/SC context and reader name) that are not available from the SCardReconnect() call.

Update

This bug is now fixed in Mac OS X Yosemite 10.10.2.

Feitian bR301 driver for iOS now Free Software

Bluetooth reader

Feitian sells the bR301 smart card reader. This reader uses Blutooth to communicate with a host. The idea is to be able to "connect" the reader to a smart phone (iOS and Android).

The reader can also be connected using a USB cable. In that case the reader is a normal CCID reader and is already listed by my CCID driver in the "Should work but untested by me" list.


Software Development Kit (SDK)

The SDK (containing the reader drivers) is not directly available from Feitian web site. But you can get it from a reseller web site at http://cartesapuce-discount.com/en/smart-card-reader-usb/74-lecteur-de-cartes-a-puce-usb-cardman-3121.html. The SDK URL is http://download.ftsafe.com/files/reade/bR301_UB_V2.19_20141008.zip.

After I had a look inside the SDK I discovered that the iOS driver bR301_UB_V2.19_20141008/SDK/iOS/Library/NON-PCSC API/lib/libiRockey301_ccid_debug_NPCSC_V1.29.0.a is in fact a derivated work from my CCID driver.

It is perfectly fine to modify my CCID driver and provide a derivated work. The only condition is to respect the GNU LGPL v2.1+ license used by my CCID driver. This was not the case with the Feitian driver.

Free Software version

After some email exchanges with Feitian to explain the situation they decided to release their iOS driver under the same license as my CCID driver: the GNU LGPL v2.1+ license. The Feitian iOS driver is hosted at github: https://github.com/entersafe/bR301_iOS.

Conclusion

I am happy the issue ended that way.
  • The license of my CCID driver is respected by this Feitian driver
  • One more Free Software smart card reader driver is available for users

PySCard 1.6.16 released

As explained in "PySCard: unofficial version 1.6.16 available" the PySCard software was no more actively maintained. After discussing with Jean-Daniel Aussel, previous maintainer, I got the admin rights to manage the sourceforge project. I was already an active code contributor since 2007.


Release 1.6.16

I just released a new official pyscard version 1.6.16.

Changes:
1.6.16 (December 2014)
  • added support for windows 64bit amd64 (Jean-Daniel Aussel)
  • support python "new" classes (derive classes from object) (Ludovic Rousseau from chrysn feature request ID 3110077)
  • fixed Reader.__eq__() (Ludovic Rousseau from Bernard Paulus bug ID 3418113)
  • fixed extended APDU transmit buffer too short by 2 (Jean-Daniel Aussel from bugs ID 2914636 and 3106761)
  • make Card and Reader objects hashable (Jean-Daniel Aussel from Hans-Peter Jansen feature request and patch)
  • convert the user guide to python-Sphinx

Documentation in Sphinx

I also changed the project web pages to use Sphinx (Python document generator) and generate a nice and modern user's guide from ReStructured text instead of manually edited HTML pages.

The API documentation is still using epydoc. Maybe I will switch it to Sphinx if I find the time and motivation. Help appreciated.

Provided software

The source code archive pyscard-1.6.16.tar.gz is of course provided.

I also provide a binary installer pyscard-1.6.16.macosx-10.9-x86_64.tar.gz for Mac OS X 10.9 and Python 2.7.

I do not use Windows so no installer is provided for this platform. Help appreciated.

Debian packages and Ubuntu packages are already provided in Debian and Ubuntu. The other GNU distribution should also provide packages but I have not checked.