use of javax.smartcardio.CardTerminal in project jdk8u_jdk by JetBrains.
the class TestDirect method main.
public static void main(String[] args) throws Exception {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
List<CardTerminal> cardTerminals = terminalFactory.terminals().list();
if (cardTerminals.isEmpty()) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println("Terminals: " + cardTerminals);
CardTerminal cardTerminal = cardTerminals.get(0);
Card card = cardTerminal.connect("DIRECT");
card.disconnect(true);
System.out.println("OK.");
}
use of javax.smartcardio.CardTerminal in project jdk8u_jdk by JetBrains.
the class TestExclusive method main.
public static void main(String[] args) throws Exception {
CardTerminal terminal = getTerminal(args);
if (terminal == null) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
// establish a connection with the card
Card card = terminal.connect("T=0");
System.out.println("card: " + card);
Thread thread = new Thread(new OtherThread(card));
thread.setDaemon(true);
thread.start();
card.beginExclusive();
exclusive = true;
Thread.sleep(1000);
System.out.println("=1=resuming...");
CardChannel channel = card.getBasicChannel();
System.out.println("=1=Transmitting...");
transmitTestCommand(channel);
System.out.println("=1=OK");
try {
card.beginExclusive();
} catch (CardException e) {
System.out.println("=1=OK: " + e);
}
card.endExclusive();
try {
card.endExclusive();
} catch (IllegalStateException e) {
System.out.println("=1=OK: " + e);
}
exclusive = false;
Thread.sleep(1000);
// disconnect
card.disconnect(true);
if (!otherOK) {
throw new Exception("Secondary thread failed");
}
System.out.println("=1=OK.");
}
use of javax.smartcardio.CardTerminal in project jmulticard by ctt-gob-es.
the class SmartcardIoConnection method open.
/**
* {@inheritDoc}
*/
@Override
public void open() throws ApduConnectionException {
// Desactivamos las respuestas automaticas para evitar los problemas con el canal seguro
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("sun.security.smartcardio.t0GetResponse", "false");
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("sun.security.smartcardio.t1GetResponse", "false");
if (isExclusiveUse() && isOpen()) {
throw new ApduConnectionOpenedInExclusiveModeException();
}
final List<CardTerminal> terminales;
try {
terminales = TerminalFactory.getDefault().terminals().list();
} catch (final Exception e) {
throw new NoReadersFoundException(// $NON-NLS-1$
"No se han podido listar los lectores del sistema: " + e, // $NON-NLS-1$
e);
}
try {
if (terminales.size() < 1) {
throw new NoReadersFoundException();
}
if (this.terminalNumber == -1) {
final long[] cadsWithCard = getTerminals(true);
if (cadsWithCard.length > 0) {
this.terminalNumber = (int) cadsWithCard[0];
} else {
throw new ApduConnectionException(// $NON-NLS-1$
"En el sistema no hay ningun terminal con tarjeta insertada");
}
}
if (terminales.size() <= this.terminalNumber) {
throw new ApduConnectionException(// $NON-NLS-1$
"No se detecto el lector de tarjetas numero " + Integer.toString(this.terminalNumber));
}
this.card = terminales.get(this.terminalNumber).connect(this.protocol.toString());
} catch (final javax.smartcardio.CardNotPresentException e) {
throw new CardNotPresentException(e);
} catch (final CardException e) {
throw new ApduConnectionException(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido abrir la conexion con el lector de tarjetas numero " + Integer.toString(this.terminalNumber) + ": " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
if (this.exclusive) {
try {
this.card.beginExclusive();
} catch (final CardException e) {
throw new ApduConnectionException(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido abrir la conexion exclusiva con el lector de tarjetas numero " + Integer.toString(this.terminalNumber) + ": " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
}
this.canal = this.card.getBasicChannel();
}
use of javax.smartcardio.CardTerminal in project open-ecard by ecsec.
the class PCSCTerminals method list.
public List<SCIOTerminal> list(State state, boolean firstTry) throws SCIOException {
LOG.trace("Entering list().");
try {
CardTerminals.State scState = convertState(state);
// get terminals with the specified state from the SmartcardIO
List<CardTerminal> scList = terminals.list(scState);
ArrayList<SCIOTerminal> list = convertTerminals(scList);
LOG.trace("Leaving list().");
return Collections.unmodifiableList(list);
} catch (CardException ex) {
SCIOErrorCode code = getCode(ex);
if (code == SCIOErrorCode.SCARD_E_NO_READERS_AVAILABLE) {
LOG.debug("No reader available exception.");
return Collections.emptyList();
} else if (code == SCIOErrorCode.SCARD_E_NO_SERVICE || code == SCIOErrorCode.SCARD_E_SERVICE_STOPPED) {
if (firstTry) {
LOG.debug("No service available exception, reloading PCSC and trying again.");
reloadFactory();
return list(state, false);
} else {
LOG.debug("No service available exception, returning empty list.");
return Collections.emptyList();
}
}
String msg = "Failed to retrieve list from terminals instance.";
LOG.error(msg, ex);
throw new SCIOException(msg, code, ex);
}
}
use of javax.smartcardio.CardTerminal in project jdk8u_jdk by JetBrains.
the class TestConnectAgain method main.
public static void main(String[] args) throws Exception {
CardTerminal terminal = getTerminal(args);
if (terminal == null) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
Card card = terminal.connect("T=0");
CardChannel channel = card.getBasicChannel();
transmitTestCommand(channel);
Card card2 = terminal.connect("*");
if (card != card2) {
throw new Exception("Different card object");
}
card2 = terminal.connect("T=0");
if (card != card2) {
throw new Exception("Different card object");
}
System.out.println("Remove card!");
terminal.waitForCardAbsent(0);
try {
transmitTestCommand(channel);
throw new Exception();
} catch (CardException e) {
System.out.println("OK: " + e);
}
System.out.println("Insert card!");
terminal.waitForCardPresent(0);
try {
transmitTestCommand(channel);
throw new Exception();
} catch (IllegalStateException e) {
System.out.println("OK: " + e);
}
card = terminal.connect("*");
if (card == card2) {
throw new Exception("Old card object");
}
try {
transmitTestCommand(channel);
throw new Exception();
} catch (IllegalStateException e) {
System.out.println("OK: " + e);
}
channel = card.getBasicChannel();
transmitTestCommand(channel);
card2 = terminal.connect("*");
if (card != card2) {
throw new Exception("Different card object");
}
// disconnect
card.disconnect(true);
System.out.println("OK.");
}
Aggregations