use of org.openecard.common.ifd.scio.SCIOTerminal in project open-ecard by ecsec.
the class IFD method getIFDCapabilities.
@Override
public GetIFDCapabilitiesResponse getIFDCapabilities(GetIFDCapabilities parameters) {
GetIFDCapabilitiesResponse response;
// you thought of a different IFD obviously
if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
String msg = "Invalid context handle specified.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, r);
return response;
}
try {
TerminalInfo info;
String ifdName = parameters.getIFDName();
try {
SingleThreadChannel channel = cm.openMasterChannel(ifdName);
info = new TerminalInfo(cm, channel);
} catch (NoSuchTerminal ex) {
// continue without a channel
SCIOTerminal term = cm.getTerminals().getTerminal(ifdName);
info = new TerminalInfo(cm, term);
}
IFDCapabilitiesType cap = new IFDCapabilitiesType();
// slot capability
SlotCapabilityType slotCap = info.getSlotCapability();
cap.getSlotCapability().add(slotCap);
// ask protocol factory which types it supports
List<String> protocols = slotCap.getProtocol();
for (String proto : protocolFactories.protocols()) {
if (!protocols.contains(proto)) {
protocols.add(proto);
}
}
// TODO: PIN Compare should be a part of establishChannel and thus just appear in the software protocol list
if (!protocols.contains(ECardConstants.Protocol.PIN_COMPARE)) {
protocols.add(ECardConstants.Protocol.PIN_COMPARE);
}
// display capability
DisplayCapabilityType dispCap = info.getDisplayCapability();
if (dispCap != null) {
cap.getDisplayCapability().add(dispCap);
}
// keypad capability
KeyPadCapabilityType keyCap = info.getKeypadCapability();
if (keyCap != null) {
cap.getKeyPadCapability().add(keyCap);
}
// biosensor capability
BioSensorCapabilityType bioCap = info.getBiosensorCapability();
if (bioCap != null) {
cap.getBioSensorCapability().add(bioCap);
}
// acoustic and optical elements
cap.setOpticalSignalUnit(info.isOpticalSignal());
cap.setAcousticSignalUnit(info.isAcousticSignal());
// prepare response
response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, WSHelper.makeResultOK());
response.setIFDCapabilities(cap);
return response;
} catch (NullPointerException | NoSuchTerminal ex) {
String msg = String.format("Requested terminal not found.");
LOG.warn(msg, ex);
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.Terminal.UNKNOWN_IFD, msg);
response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, r);
return response;
} catch (SCIOException ex) {
String msg = String.format("Failed to request status from terminal.");
// use debug when card has been removed, as this happens all the time
SCIOErrorCode code = ex.getCode();
if (!(code == SCIOErrorCode.SCARD_E_NO_SMARTCARD || code == SCIOErrorCode.SCARD_W_REMOVED_CARD)) {
LOG.warn(msg, ex);
} else {
LOG.debug(msg, ex);
}
Result r = WSHelper.makeResultUnknownError(msg);
response = WSHelper.makeResponse(GetIFDCapabilitiesResponse.class, r);
return response;
}
}
use of org.openecard.common.ifd.scio.SCIOTerminal in project open-ecard by ecsec.
the class IFD method listIFDs.
@Override
public ListIFDsResponse listIFDs(ListIFDs parameters) {
ListIFDsResponse response;
if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
String msg = "Invalid context handle specified.";
Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
response = WSHelper.makeResponse(ListIFDsResponse.class, r);
return response;
} else {
try {
List<SCIOTerminal> terminals = cm.getTerminals().list();
ArrayList<String> ifds = new ArrayList<>(terminals.size());
for (SCIOTerminal next : terminals) {
ifds.add(next.getName());
}
response = WSHelper.makeResponse(ListIFDsResponse.class, WSHelper.makeResultOK());
response.getIFDName().addAll(ifds);
return response;
} catch (SCIOException ex) {
LOG.warn(ex.getMessage(), ex);
Result r = WSHelper.makeResultUnknownError(ex.getMessage());
response = WSHelper.makeResponse(ListIFDsResponse.class, r);
return response;
}
}
}
use of org.openecard.common.ifd.scio.SCIOTerminal in project open-ecard by ecsec.
the class ChannelManager method openMasterChannel.
public synchronized SingleThreadChannel openMasterChannel(@Nonnull String ifdName) throws NoSuchTerminal, SCIOException {
if (baseChannels.containsKey(ifdName)) {
LOG.warn("Terminal '" + ifdName + "' is already connected.");
return baseChannels.get(ifdName);
}
SCIOTerminal t = getTerminals().getTerminal(ifdName);
SingleThreadChannel ch = new SingleThreadChannel(t);
baseChannels.put(ifdName, ch);
ifdNameToHandles.put(ifdName, new TreeSet<>(new ByteArrayComparator()));
return ch;
}
use of org.openecard.common.ifd.scio.SCIOTerminal 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 org.openecard.common.ifd.scio.SCIOTerminal in project open-ecard by ecsec.
the class SingleThreadChannel method reconnect.
@Override
public void reconnect() throws SCIOException {
if (channel.isBasicChannel()) {
SCIOCard card = channel.getCard();
SCIOTerminal term = card.getTerminal();
channel.close();
card.disconnect(true);
card = connectCard(term);
channel = card.getBasicChannel();
removeSecureMessaging();
} else {
throw new RuntimeException("Reconnect called on logical channel.");
}
}
Aggregations