Hi all.

I'm trying to access a Gemplus GemPC430 USB reader from Java using
OpenCard FrameWork (OCF), configurated in my Windows 2000 Professional
PC. But I'm having problems.

The installation steps found in:
http://www.gemplus.fr/techno/opencard/faqs/install-faq-qna.html#q1.0.2
were ok, and I can successfully "load" the libraries from a Java program
(see attachments), compile it and execute.

Also attached goes my "opencard.properties" file and the output of the
execution of the java program.

I can't figure out what is the problem. Can anyone help me with this?

Many thanks in advance to all.

______________________________________________
Arturo Garc�a Mart�n - [EMAIL PROTECTED]
eSolutions Consultant - eBusiness Architect
BURKE, Software y Servicios - +34.91.571.55.50
http://www.burke.es/ <http://www.burke.es/>


import opencard.core.service.*;
import opencard.core.terminal.*;
import opencard.core.util.*;
import opencard.opt.signature.*;
import opencard.opt.security.*;
import opencard.opt.iso.fs.*;
import java.util.*;

/**
  * OpenCard Framework (OCF) code for a smart card that is inserted already
  * or just the next one being inserted. Followed by the generation (if needed)
  * and smart card storage of a public/private key pair.
  *
  * Written by: Tammy M. Blaser
  * Date: August 12, 2002
  **/
public class OCFGenKey {
	private static final boolean _VIES_PROPS_ = false;
	private static final String NAME = "GemPlus GemPC430 USB Reader";
	public static String separator = System.getProperty("file.separator");
	private static final String OCPROPDIR = "C:" + separator + "Gemplus" + separator + "GemXpresso.rad3" + separator + "conf";
	private static final String JAVAHOMEDIR = "C:" + separator + "jdk1.2.2" + separator + "jre";
	private SmartCard sc = null;
	// Constructor
	public OCFGenKey(SmartCard sc) throws CardServiceException, ClassNotFoundException {
		this.sc = sc;
		// Instanciate file CardServices
		System.out.println("\n===============\nCreating KeyGenerationCardService...\n");
		try {
			KeyGenerationCardService kgcs = null;
			kgcs = (KeyGenerationCardService)
					  sc.getCardService(KeyGenerationCardService.class, true);
			// create the key references for the keys to be generated
			// REMINDER: See if private and public key reference formats compatible with CORBASec HSS
			CardFilePath path = new CardFilePath(":3F00:C110");
			PrivateKeyFile privKey = new PrivateKeyFile(path,0);
			PublicKeyFile pubKey = new PublicKeyFile(path,1);
			kgcs.generateKeyPair(privKey, pubKey, 512, "RSA");
			// read the public key from the card
			java.security.PublicKey rsaPublic = kgcs.readPublicKey(pubKey, "RSA");
		} catch (java.security.InvalidKeyException ike) {
			System.out.println ("InvalidKeyException: ");
			System.out.println (ike.getMessage () );
			ike.printStackTrace();
		} catch (CardServiceException cse) {
			System.out.println ("CardServiceException: ");
			System.out.println (cse.getMessage () );
			cse.printStackTrace();
		} catch (CardTerminalException cte) {
			System.out.println ("CardTerminalException: ");
			System.out.println (cte.getMessage () );
			cte.printStackTrace();
		}
	}
	public static void viewProperties( java.util.Properties p ) {
		java.util.Enumeration enum = p.propertyNames();
		while ( enum.hasMoreElements() ) {
			String clave = (String) enum.nextElement();
			String valor = System.getProperty(clave);
			System.out.println("Property: ["+clave+"], valor: ["+valor+"]");
		}
	}
	public static void main (String [] args) {
		System.out.println ("--------------------------------------------------------------------------");
		System.out.println ("Start use case: " + NAME);
		try {
			// set needed properties
			/*
			System.setProperty("user.dir", OCPROPDIR);
			System.setProperty("java.home", JAVAHOMEDIR);
			*/
			java.util.Properties p = System.getProperties();
			if ( _VIES_PROPS_ ) viewProperties( p );
			System.out.println( "user.dir: " + System.getProperty("user.dir") );
			System.out.println( "java.home: " + System.getProperty("java.home") );
			System.out.println ("Getting the environment.");
			SmartCard.start ();
			System.out.println ("Requesting the card.");
			CardRequest cr = new CardRequest (CardRequest.ANYCARD,null,null);
			// Wait for smart card insertion
			System.out.println ("Wait for smart card insertion.");
			SmartCard card = SmartCard.waitForCard(cr);
			System.out.println ("If card found...");
			if (card != null) {
				System.out.println ("got a SmartCard object!\n");
			} else System.out.println ("did not get a SmartCard object!\n");
			// Start KeyGenerationCardService and generate PKA Keys on the smart card
			OCFGenKey ocfgk = new OCFGenKey(card);
			SmartCard.shutdown ();
		} catch (OpenCardPropertyLoadingException plfe) {
			System.out.println ( "OpenCardPropertyLoadingException: " );
			System.out.println ( plfe.getMessage () );
			plfe.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			System.out.println ( "ClassNotFoundException: " );
			System.out.println ( cnfe.getMessage () );
			cnfe.printStackTrace();
		} catch (CardServiceException cse) {
			System.out.println ( "CardServiceException: " );
			System.out.println ( cse.getMessage () );
			cse.printStackTrace();
		} catch (CardTerminalException cte) {
			System.out.println ( "CardTerminalException: " );
			System.out.println ( cte.getMessage () );
			cte.printStackTrace();
			CardTerminal ct = cte.getCardTerminal();
			int errorSlot = cte.getSlot();
			System.out.println( "OCF isStarted: "+SmartCard.isStarted() );
			System.out.println( "CardTerminal.errorSlot: "+errorSlot );
			if ( ct!=null ) {
				Properties props = ct.features();
				int slots = ct.getSlots();
				System.out.println("CardTerminal.name: "+props.get("name"));
				System.out.println("CardTerminal.type: "+props.get("type"));
				System.out.println("CardTerminal.address: "+props.get("address"));
				System.out.println("CardTerminal.slots: "+props.get("slots"));
				for ( int slot=0; slot<slots; slot++ ) {
					try {
						System.out.println("CardTerminal info: CardID["+slot+"]: "+ct.getCardID(slot));
						System.out.println("CardTerminal info: CardPresent["+slot+"]: "+ct.isCardPresent(slot));
						System.out.println("CardTerminal info: SlotChannelAvailable["+slot+"]: "+ct.isSlotChannelAvailable(slot));
					} catch (CardTerminalException ctein) {
					}
				}
			} else {
				System.out.println("No CardTerminal.");
			}
		} finally {
		}
		System.out.println ("");
		System.out.println ("Finished use case: " + NAME);
		System.out.println ("-----------------------------------------------------------------------------");
	} // main
} // OCFGenKey.java
// end of OCFGenKey.java

---------- Ejecutar Java StandAlone ----------
--------------------------------------------------------------------------
Start use case: GemPlus GemPC430 USB Reader
user.dir: C:\temp\OCF
java.home: C:\java\jre
Getting the environment.
[DEBUG    ] opencard.core.service.SmartCard.getRegistryEntry
--- message   tag OpenCard.terminals = 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory|My_GCR_430|GemPC430|SHARED 
com.gemplus.opencard.terminal.GemplusCardTerminalFactory|My_GCR_410|GCR410|COM1 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory 
--- thread    Thread[main,5,main]
--- source    class opencard.core.service.SmartCard

[DEBUG    ] 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory.Pcsc10CardTerminalFactory
--- message   connect to PCSC 1.0 resource manager
--- thread    Thread[main,5,main]
--- source    com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory@19189e1

[DEBUG    ] 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory.Pcsc10CardTerminalFactory
--- message   Driver initialized
--- thread    Thread[main,5,main]
--- source    com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory@19189e1

[DEBUG    ] 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory.Pcsc10CardTerminalFactory
--- message   get reader list from PC/SC
--- thread    Thread[main,5,main]
--- source    com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory@19189e1

[DEBUG    ] opencard.core.terminal.CardTerminal.<init>
--- message   (Gemplus GemPC430 0, PCSC10, )
--- thread    Thread[main,5,main]
--- source    class opencard.core.terminal.CardTerminal

[DEBUG    ] com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminal.Pcsc10CardTerminal
--- message   connect to PCSC 1.0 resource manager
--- thread    Thread[main,5,main]
--- source    com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminal@1befab0
+ name    Gemplus GemPC430 0
+ type    PCSC10
+ addr    

[ERROR    ] com.ibm.opencard.terminal.pcsc10.OCFPCSC1.OCFPCSC1.SCardEstablishContext
--- message   PCSC Exception in method SCardEstablishContext: PC/SC Error 
SCardEstablishContext
return code = 8010001d

--- thread    Thread[main,5,main]
--- source    com.ibm.opencard.terminal.pcsc10.OCFPCSC1@13c5982

CardTerminalException: 
Pcsc10CardTerminal: PCSC Exception in method SCardEstablishContext: PC/SC Error 
SCardEstablishContext
return code = 8010001d

opencard.core.terminal.CardTerminalException: Pcsc10CardTerminal: PCSC Exception in 
method SCardEstablishContext: PC/SC Error SCardEstablishContext
return code = 8010001d

        at 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminal.translatePcscException(Pcsc10CardTerminal.java:502)
        at 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminal.<init>(Pcsc10CardTerminal.java:127)
        at 
com.ibm.opencard.terminal.pcsc10.Pcsc10CardTerminalFactory.createCardTerminals(Pcsc10CardTerminalFactory.java:82)
        at 
opencard.core.service.SmartCard.handleTerminalFactoryEntries(SmartCard.java:432)
        at 
opencard.core.service.SmartCard.configureTerminalRegistry(SmartCard.java:261)
        at opencard.core.service.SmartCard.start(SmartCard.java:534)
        at OCFGenKey.main(OCFGenKey.java:77)
OCF isStarted: false
CardTerminal.errorSlot: 0
CardTerminal.name: Gemplus GemPC430 0
CardTerminal.type: PCSC10
CardTerminal.address: 
CardTerminal.slots: 0

Finished use case: GemPlus GemPC430 USB Reader
-----------------------------------------------------------------------------
Normal Termination
Output completed (1 sec consumed).

Attachment: opencard.properties
Description: Binary data

Reply via email to