Uploaded image for project: 'Commons Daemon'
  1. Commons Daemon
  2. DAEMON-389

JnaPCSCException when using jnasmartcardio

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Not A Bug
    • None
    • None
    • Jsvc
    • MacOS Sierra 10.12.4

       

    Description

      The following code works properly when running the JAR directly in console. The connection to the smart card reader works fine and the card info is printer on screen.

      public static void main(String[] args) throws CardException, GPException, NoSuchAlgorithmException {
      		GlobalPlatform gp;
      		Card card;
      		CardTerminal terminal = TerminalManager.getTheReader(null);
      		card = terminal.connect("*");
      		card.beginExclusive();
      		gp = new GlobalPlatform(card.getBasicChannel());
      		gp.select(null);
      		byte[] info = gp.getCPLC();
      		String cardInfo = HexUtils.encodeHexString_imp(info);
      		card.disconnect(true);
      		System.out.println("Hexa Card Info: " + cardInfo);
      	}
      

      However, when using JSVC to launch the JAR as a daemon, I get a JnaPCSCException (SCardEstablishContext got response 0x8010001d (SCARD_E_NO_SERVICE: The Smart card resource manager is not running.)

      The full code is:

      package com.st.simple.card.client;
      
      import java.security.NoSuchAlgorithmException;
      
      import javax.smartcardio.Card;
      import javax.smartcardio.CardException;
      import javax.smartcardio.CardTerminal;
      
      import org.apache.commons.daemon.Daemon;
      import org.apache.commons.daemon.DaemonContext;
      import org.apache.commons.daemon.DaemonInitException;
      
      import apdu4j.HexUtils;
      import apdu4j.TerminalManager;
      import pro.javacard.gp.GPException;
      import pro.javacard.gp.GlobalPlatform;
      
      
      
      public class Client implements Daemon {
      	
      	public static void main(String[] args) throws CardException, GPException, NoSuchAlgorithmException {
      		GlobalPlatform gp;
      		Card card;
      		CardTerminal terminal = TerminalManager.getTheReader(null);
      		card = terminal.connect("*");
      		card.beginExclusive();
      		gp = new GlobalPlatform(card.getBasicChannel());
      		gp.select(null);
      		byte[] info = gp.getCPLC();
      		String cardInfo = HexUtils.encodeHexString_imp(info);
      		card.disconnect(true);
      		System.out.println("Hexa Card Info: " + cardInfo);
      	}
      
      	@Override
      	public void destroy() {
      		// TODO Auto-generated method stub
      		
      	}
      
      	@Override
      	public void init(DaemonContext arg0) throws DaemonInitException, Exception {
      		// TODO Auto-generated method stub
      	}
      
      	@Override
      	public void start() throws Exception {
      		// TODO Auto-generated method stub
      		main(null);
      	}
      
      	@Override
      	public void stop() throws Exception {
      		// TODO Auto-generated method stub
      		
      	}
      
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            qprotex Miguel Febres
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: