use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class ListTokens method getUnknownCards.
private List<TokenInfoType> getUnknownCards(List<ConnectionHandleType> knownHandles) {
ArrayList<TokenInfoType> result = new ArrayList<>();
List<byte[]> ifdCtxs = ctx.getIfdCtx();
for (byte[] ifdCtx : ifdCtxs) {
try {
// get all IFD names
GetStatus gs = new GetStatus();
gs.setContextHandle(ifdCtx);
GetStatusResponse gsr = (GetStatusResponse) dispatcher.safeDeliver(gs);
WSHelper.checkResult(gsr);
for (IFDStatusType istatus : gsr.getIFDStatus()) {
for (SlotStatusType sstatus : istatus.getSlotStatus()) // check if name is already in the list of known cards
if (sstatus.isCardAvailable() && !isInHandleList(istatus.getIFDName(), knownHandles)) {
TokenInfoType ti = new TokenInfoType();
org.openecard.ws.chipgateway.ConnectionHandleType conHandle;
conHandle = new org.openecard.ws.chipgateway.ConnectionHandleType();
conHandle.setCardType(ECardConstants.UNKNOWN_CARD);
ti.setConnectionHandle(conHandle);
// add to handle list
result.add(ti);
}
}
} catch (WSHelper.WSException ex) {
LOG.warn("Failed to retrieve status info from IFD. Skipping unknown card entries.");
}
}
return result;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class GenericCryptographyProtocolTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
env = new ClientEnv();
Dispatcher d = new MessageDispatcher(env);
env.setDispatcher(d);
ifd = new IFD();
ifd.setGUI(new SwingUserConsent(new SwingDialogWrapper()));
env.setIFD(ifd);
states = new CardStateMap();
EstablishContextResponse ecr = env.getIFD().establishContext(new EstablishContext());
final CardRecognitionImpl cr = new CardRecognitionImpl(env);
ListIFDs listIFDs = new ListIFDs();
CIFProvider cp = new CIFProvider() {
@Override
public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
return cr.getCardInfo(cardType);
}
@Override
public boolean needsRecognition(byte[] atr) {
return true;
}
@Override
public CardInfoType getCardInfo(String cardType) throws RuntimeException {
return cr.getCardInfo(cardType);
}
@Override
public InputStream getCardImage(String cardType) {
return cr.getCardImage(cardType);
}
};
env.setCIFProvider(cp);
listIFDs.setContextHandle(ecr.getContextHandle());
ListIFDsResponse listIFDsResponse = ifd.listIFDs(listIFDs);
RecognitionInfo recognitionInfo = cr.recognizeCard(ecr.getContextHandle(), listIFDsResponse.getIFDName().get(0), BigInteger.ZERO);
SALStateCallback salCallback = new SALStateCallback(env, states);
ConnectionHandleType connectionHandleType = new ConnectionHandleType();
connectionHandleType.setContextHandle(ecr.getContextHandle());
connectionHandleType.setRecognitionInfo(recognitionInfo);
connectionHandleType.setIFDName(listIFDsResponse.getIFDName().get(0));
connectionHandleType.setSlotIndex(new BigInteger("0"));
salCallback.signalEvent(EventType.CARD_RECOGNIZED, new IfdEventObject(connectionHandleType));
instance = new TinySAL(env, states);
env.setSAL(instance);
// init AddonManager
UserConsent uc = new SwingUserConsent(new SwingDialogWrapper());
AddonManager manager = new AddonManager(env, uc, states, null);
instance.setAddonManager(manager);
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class AbstractPINAction method connectToRootApplication.
/**
* Connect to the root application of the card specified with a connection handle using a empty CardApplicationPath
* and afterwards a CardApplicationConnect.
*
* @param cHandle
* The connection handle for the card to connect to root application.
* @return The updated connection handle (now including a SlotHandle) or null if connecting went wrong.
*/
protected ConnectionHandleType connectToRootApplication(ConnectionHandleType cHandle) {
// Perform a CardApplicationPath and CardApplicationConnect to connect to the card application
CardApplicationPath cardApplicationPath = new CardApplicationPath();
cardApplicationPath.setCardAppPathRequest(cHandle);
CardApplicationPathResponse cardApplicationPathResponse = (CardApplicationPathResponse) dispatcher.safeDeliver(cardApplicationPath);
// Check CardApplicationPathResponse
try {
WSHelper.checkResult(cardApplicationPathResponse);
} catch (WSException ex) {
LOG.error("CardApplicationPath failed.", ex);
return null;
}
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse cardApplicationConnectResponse = (CardApplicationConnectResponse) dispatcher.safeDeliver(cardApplicationConnect);
// Check CardApplicationConnectResponse
try {
WSHelper.checkResult(cardApplicationConnectResponse);
} catch (WSException ex) {
LOG.error("CardApplicationConnect failed.", ex);
return null;
}
// Update ConnectionHandle. It now includes a SlotHandle.
cHandle = cardApplicationConnectResponse.getConnectionHandle();
return cHandle;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class AbstractPINAction method recognizeState.
/**
* Recognize the PIN state of the card given through the connection handle.
*
* @param cHandle The connection handle for the card for which the pin state should be recognized.
* @return The recognized State (may be {@code RecognizedState.UNKNOWN}).
*/
protected RecognizedState recognizeState(ConnectionHandleType cHandle) {
Transmit t = new Transmit();
t.setSlotHandle(cHandle.getSlotHandle());
InputAPDUInfoType inputAPDU = new InputAPDUInfoType();
inputAPDU.setInputAPDU(RECOGNIZE_APDU);
t.getInputAPDUInfo().add(inputAPDU);
TransmitResponse response = (TransmitResponse) dispatcher.safeDeliver(t);
byte[] responseAPDU = response.getOutputAPDU().get(0);
RecognizedState state;
if (ByteUtils.compare(RESPONSE_RC3, responseAPDU)) {
state = RecognizedState.PIN_activated_RC3;
} else if (ByteUtils.compare(RESPONSE_DEACTIVATED, responseAPDU)) {
state = RecognizedState.PIN_deactivated;
} else if (ByteUtils.compare(RESPONSE_RC2, responseAPDU)) {
state = RecognizedState.PIN_activated_RC2;
} else if (ByteUtils.compare(RESPONSE_SUSPENDED, responseAPDU)) {
state = RecognizedState.PIN_suspended;
} else if (ByteUtils.compare(RESPONSE_BLOCKED, responseAPDU)) {
state = RecognizedState.PIN_blocked;
} else {
LOG.error("Unhandled response to the PIN state recognition APDU: {}\n");
state = RecognizedState.UNKNOWN;
}
LOG.info("State of the PIN: {}.", state);
return state;
}
use of iso.std.iso_iec._24727.tech.schema.ConnectionHandleType in project open-ecard by ecsec.
the class AbstractPINAction method genericPACESupport.
/**
* Check if the selected card reader supports PACE.
* In that case, the reader is a standard or comfort reader.
*
* @param connectionHandle Handle describing the IFD and reader.
* @return true when card reader supports genericPACE, false otherwise.
* @throws WSException In case request for the terminal capabilities returned an error.
*/
protected boolean genericPACESupport(ConnectionHandleType connectionHandle) throws WSException {
// Request terminal capabilities
GetIFDCapabilities capabilitiesRequest = new GetIFDCapabilities();
capabilitiesRequest.setContextHandle(connectionHandle.getContextHandle());
capabilitiesRequest.setIFDName(connectionHandle.getIFDName());
GetIFDCapabilitiesResponse capabilitiesResponse = (GetIFDCapabilitiesResponse) dispatcher.safeDeliver(capabilitiesRequest);
WSHelper.checkResult(capabilitiesResponse);
if (capabilitiesResponse.getIFDCapabilities() != null) {
List<SlotCapabilityType> capabilities = capabilitiesResponse.getIFDCapabilities().getSlotCapability();
// Check all capabilities for generic PACE
final String genericPACE = PACECapabilities.PACECapability.GenericPACE.getProtocol();
for (SlotCapabilityType capability : capabilities) {
if (capability.getIndex().equals(connectionHandle.getSlotIndex())) {
for (String protocol : capability.getProtocol()) {
if (protocol.equals(genericPACE)) {
return true;
}
}
}
}
}
// No PACE capability found
return false;
}
Aggregations