use of javax.smartcardio.CardTerminal in project jdk8u_jdk by JetBrains.
the class TestControl 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);
byte[] data = new byte[] { 2 };
try {
byte[] resp = card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, data);
System.out.println("Firmware: " + toString(resp));
throw new Exception();
} catch (CardException e) {
// we currently don't know of any control commands that work with
// our readers. call the function just to make sure we don't crash
// or throw the wrong exception
System.out.println("OK: " + e);
e.printStackTrace(System.out);
}
try {
card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, null);
} catch (NullPointerException e) {
System.out.println("OK: " + e);
}
// disconnect
card.disconnect(true);
System.out.println("OK.");
}
use of javax.smartcardio.CardTerminal in project jdk8u_jdk by JetBrains.
the class TestDefault method main.
public static void main(String[] args) throws Exception {
TerminalFactory factory = TerminalFactory.getDefault();
System.out.println("Type: " + factory.getType());
List<CardTerminal> terminals = factory.terminals().list();
if (terminals.isEmpty()) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println("Terminals: " + terminals);
System.out.println("OK.");
}
use of javax.smartcardio.CardTerminal in project jdk8u_jdk by JetBrains.
the class TestMultiplePresent method main.
public static void main(String[] args) throws Exception {
Utils.setLibrary(args);
TerminalFactory factory = Utils.getTerminalFactory(null);
if (factory == null) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println(factory);
CardTerminals terminals = factory.terminals();
List<CardTerminal> list = terminals.list();
System.out.println("Terminals: " + list);
boolean multipleReaders = true;
if (list.size() < 2) {
if (list.isEmpty()) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println("Only one reader present, using simplified test");
multipleReaders = false;
}
while (true) {
boolean present = false;
for (CardTerminal terminal : list) {
present |= terminal.isCardPresent();
}
if (present == false) {
break;
}
System.out.println("*** Remove all cards!");
Thread.sleep(1000);
}
System.out.println("OK");
List<CardTerminal> result;
result = terminals.list(CARD_PRESENT);
if (result.size() != 0) {
throw new Exception("List not empty: " + result);
}
if (terminals.waitForChange(1000)) {
throw new Exception("no timeout");
}
if (terminals.waitForChange(1000)) {
throw new Exception("no timeout");
}
result = terminals.list(CARD_PRESENT);
if (result.size() != 0) {
throw new Exception("List not empty: " + result);
}
System.out.println("*** Insert card!");
terminals.waitForChange();
result = terminals.list(CARD_INSERTION);
System.out.println(result);
if (result.size() != 1) {
throw new Exception("no card present");
}
CardTerminal t1 = result.get(0);
result = terminals.list(CARD_INSERTION);
System.out.println(result);
if ((result.size() != 1) || (result.get(0) != t1)) {
throw new Exception("no card present");
}
if (terminals.list(CARD_REMOVAL).size() != 0) {
throw new Exception("List not empty: " + result);
}
if (terminals.list(CARD_REMOVAL).size() != 0) {
throw new Exception("List not empty: " + result);
}
if (terminals.waitForChange(1000)) {
throw new Exception("no timeout");
}
if (terminals.list(CARD_REMOVAL).size() != 0) {
throw new Exception("List not empty: " + result);
}
if (multipleReaders) {
System.out.println("*** Insert card into other reader!");
terminals.waitForChange();
result = terminals.list(CARD_INSERTION);
System.out.println(result);
if (result.size() != 1) {
throw new Exception("no card present");
}
CardTerminal t2 = result.get(0);
if (t1.getName().equals(t2.getName())) {
throw new Exception("same terminal");
}
System.out.println("*** Remove card from 2nd reader!");
terminals.waitForChange();
if (terminals.list(CARD_INSERTION).size() != 0) {
throw new Exception("List not empty: " + result);
}
result = terminals.list(CARD_REMOVAL);
if ((result.size() != 1) || (result.get(0) != t2)) {
throw new Exception("no or wrong terminal");
}
}
System.out.println("*** Remove card from 1st reader!");
terminals.waitForChange();
if (terminals.list(CARD_INSERTION).size() != 0) {
throw new Exception("List not empty: " + result);
}
result = terminals.list(CARD_REMOVAL);
if ((result.size() != 1) || (result.get(0) != t1)) {
throw new Exception("no or wrong terminal");
}
System.out.println("OK.");
}
use of javax.smartcardio.CardTerminal in project jmulticard by ctt-gob-es.
the class SmartcardIoConnection method getTerminals.
/**
* {@inheritDoc}
*/
@Override
public long[] getTerminals(final boolean onlyWithCardPresent) throws ApduConnectionException {
final List<CardTerminal> terminales;
try {
terminales = TerminalFactory.getDefault().terminals().list();
} catch (final CardException e) {
// $NON-NLS-1$
LOGGER.warning("No se ha podido recuperar la lista de lectores del sistema: " + e);
return new long[0];
}
try {
// Listamos los indices de los lectores que correspondan segun si tienen o no tarjeta insertada
final ArrayList<Long> idsTerminales = new ArrayList<>(terminales.size());
for (int idx = 0; idx < terminales.size(); idx++) {
if (onlyWithCardPresent) {
if (terminales.get(idx).isCardPresent()) {
idsTerminales.add(Long.valueOf(idx));
}
} else {
idsTerminales.add(Long.valueOf(idx));
}
}
final long[] ids = new long[idsTerminales.size()];
for (int i = 0; i < ids.length; i++) {
ids[i] = idsTerminales.get(i).longValue();
}
return ids;
} catch (final Exception ex) {
throw new ApduConnectionException(// $NON-NLS-1$
"Error recuperando la lista de lectores de tarjetas del sistema: " + ex, // $NON-NLS-1$
ex);
}
}
use of javax.smartcardio.CardTerminal in project open-ecard by ecsec.
the class PCSCTest method connect.
private void connect() {
try {
// File libPcscLite = new File("/usr/lib/libpcsclite.so.1");
// if (libPcscLite.exists()) {
// System.setProperty("sun.security.smartcardio.library", libPcscLite.getAbsolutePath());
// }
TerminalFactory t = TerminalFactory.getInstance("PC/SCs", null);
// TerminalFactory t = TerminalFactory.getDefault();
CardTerminals c = t.terminals();
logger.info("Card terminals: {}", c.list().size());
List terminals = c.list();
if (terminals.isEmpty()) {
logger.info("No presend cards!");
} else {
for (int i = 0; i < terminals.size(); i++) {
CardTerminal ct = (CardTerminal) terminals.get(i);
if (ct.isCardPresent()) {
Card card = ct.connect("*");
connection = card.getBasicChannel();
logger.info("Card found at card terminal " + i + ": ", card.toString());
}
}
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
Aggregations