Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8066657

javax.smartcardio does not parallelize card-reader access

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 7u65, 9
    • security-libs

      FULL PRODUCT VERSION :
      # java -version
      java version "1.7.0_65"
      Java(TM) SE Runtime Environment (build 1.7.0_65-b33)
      Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux B0196067 2.6.32-431.5.1.el6.x86_64 #1 SMP Fri Jan 10 14:46:43 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      # lsusb|grep Omni
      Bus 002 Device 007: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 008: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 009: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 010: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 011: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 012: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 013: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 014: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 015: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 016: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 017: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 018: ID 076b:3821 OmniKey AG CardMan 3821
      Bus 002 Device 019: ID 076b:3821 OmniKey AG CardMan 3821

      A DESCRIPTION OF THE PROBLEM :
      javax.smartcardio does not parallelize card-reader access
      if TerminalFactory.getDefault() is invoked ESTABLISH_CONTEXT of pcsc-subsystem is only called once. Even if multiple threaded TerminalFactory.getDefault() invocations are done ESTABLISH_CONTEXT of pcsc-subsystem is not called another time.
      Thus card-reader access is serialized instead of parallelized.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      write program that threads multiple card-reader-accesses with minimum 2 threads and maxmimum as many threads as you have card-readers. Do a card-reader-list per thread, maybe each thread lists one respective reader (e.g. source-code)
      pcsc-debug-log of two-fold-threaded run:

      Nov 28 14:32:23 localhost pcscd: winscard_msg_srv.c:239:SHMProcessEventsServer() Common channel packet arrival
      Nov 28 14:32:23 localhost pcscd: winscard_msg_srv.c:248:SHMProcessEventsServer() SHMProcessCommonChannelRequest detects: 10
      Nov 28 14:32:23 localhost pcscd: pcscdaemon.c:147:SVCServiceRunLoop() A new context thread creation is requested: 10
      Nov 28 14:32:23 localhost pcscd: winscard_svc.c:133:ContextThread() Thread is started: 10
      Nov 28 14:32:23 localhost pcscd: winscard_msg_srv.c:317:SHMProcessEventsContext() command CMD_VERSION received by client 10
      Nov 28 14:32:23 localhost pcscd: winscard_svc.c:189:ContextThread() Client is protocol version 3:0
      Nov 28 14:32:23 localhost pcscd: winscard_msg_srv.c:317:SHMProcessEventsContext() command ESTABLISH_CONTEXT received by client 10
      Nov 28 14:32:23 localhost pcscd: winscard.c:242:SCardEstablishContext() Establishing Context: 17000443
      Nov 28 14:32:24 localhost pcscd: winscard_msg_srv.c:306:SHMProcessEventsContext() Client has disappeared: 10
      Nov 28 14:32:24 localhost pcscd: winscard_svc.c:146:ContextThread() Client die: 10
      Nov 28 14:32:24 localhost pcscd: winscard.c:253:SCardReleaseContext() Releasing Context: 17000443




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      multiple contexts opened to pcsc-subsystem, as a mutlithreaded C-program would do.
      ACTUAL -
      only one context is established to pcsc-subsystem

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      PcscTest.java

      ListSmartcardReaders[] listSmartcardReaders = new ListSmartcardReaders[numThreads];

      // thread-Objekte erstellen
      for(thread=0;thread<numThreads;thread++) {
      listSmartcardReaders[thread] = new ListSmartcardReaders(thread);
      }

      // threads starten
      for(thread=0;thread<numThreads;thread++) {
      listSmartcardReaders[thread].start();
      }

      ListSmartCardReaders.java

      public void run() {
      try {
      listCounted();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      public int listCounted() {
      /* we use the default TerminalFactory */
      TerminalFactory factory = TerminalFactory.getDefault();

      try {
      /* We can have multiple terminals on one System, so we get a list */
      List<CardTerminal> terminals = factory.terminals().list();
      return terminals.size();

      } catch (CardException e) {
      e.printStackTrace();
      } catch (Exception e) {
      e.printStackTrace();
      }
      return 0;
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      none available

            rpallath Rajendrakumar Pallath
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: