use of org.openecard.ws.chipgateway.TokenInfoType in project open-ecard by ecsec.
the class ListTokens method convertHandles.
private ArrayList<TokenInfoType> convertHandles(List<ConnectionHandleType> handles) {
ArrayList<TokenInfoType> result = new ArrayList<>();
for (ConnectionHandleType next : handles) {
ConnectionHandleType.RecognitionInfo rec = next.getRecognitionInfo();
// create token type and copy available information about it
TokenInfoType ti = new TokenInfoType();
org.openecard.ws.chipgateway.ConnectionHandleType h = new org.openecard.ws.chipgateway.ConnectionHandleType();
h.setSlotHandle(next.getSlotHandle());
h.setCardType(rec.getCardType());
ti.setConnectionHandle(h);
ConnectionHandleType.SlotInfo si = next.getSlotInfo();
if (si != null) {
ti.setHasProtectedAuthPath(si.isProtectedAuthPath());
}
if (determineTokenFeatures(ti)) {
// only add this token if there are no errors
result.add(ti);
}
}
return result;
}
use of org.openecard.ws.chipgateway.TokenInfoType 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 org.openecard.ws.chipgateway.TokenInfoType in project open-ecard by ecsec.
the class ChipGateway method createGetCommandRequest.
private GetCommandType createGetCommandRequest() {
GetCommandType cmd = new GetCommandType();
cmd.setSessionIdentifier(sessionId);
// add token info
try {
ListTokens helper = new ListTokens(Collections.EMPTY_LIST, addonCtx);
List<TokenInfoType> matchedTokens = helper.findTokens();
cmd.getTokenInfo().addAll(matchedTokens);
} catch (UnsupportedAlgorithmException ex) {
throw new RuntimeException("Unexpected error in empty token filter.", ex);
} catch (WSHelper.WSException ex) {
LOG.error("Error requesting initial list of tokens.");
}
return cmd;
}
use of org.openecard.ws.chipgateway.TokenInfoType in project open-ecard by ecsec.
the class ChipGateway method waitForTokens.
private ListTokensResponseType waitForTokens(ListTokensRequestType tokensReq) throws UnsupportedAlgorithmException, WSHelper.WSException, InterruptedException, TimeoutException {
BigInteger waitSecondsBig = tokensReq.getMaxWaitSeconds();
long waitMillis = getWaitMillis(waitSecondsBig);
Date startTime = new Date();
ListTokens helper = new ListTokens(tokensReq.getTokenInfo(), addonCtx);
do {
// build list of matching tokens
List<TokenInfoType> matchedTokens = helper.findTokens();
// save handles of connected cards
connectedSlots.addAll(helper.getConnectedSlots());
// return if tokens have been found or no specific set of tokens has been requested
if (!matchedTokens.isEmpty() || tokensReq.getTokenInfo().isEmpty()) {
ListTokensResponseType tokensResp = new ListTokensResponseType();
tokensResp.setSessionIdentifier(sessionId);
tokensResp.setResult(ChipGatewayStatusCodes.OK);
tokensResp.getTokenInfo().addAll(matchedTokens);
return tokensResp;
}
// TODO: use real wait mechanism on the SAL implementation
Thread.sleep(1000);
} while ((new Date().getTime() - startTime.getTime()) < waitMillis);
throw new TimeoutException("Waiting for ListTokens timed out.");
}
use of org.openecard.ws.chipgateway.TokenInfoType in project open-ecard by ecsec.
the class ListTokens method removeDuplicates.
private List<TokenInfoType> removeDuplicates(List<TokenInfoType> resultHandles) {
// use set with compare function to remove duplicates
TreeSet<TokenInfoType> result = new TreeSet<>(new Comparator<TokenInfoType>() {
private final ByteComparator cmp = new ByteComparator();
@Override
public int compare(TokenInfoType o1, TokenInfoType o2) {
return cmp.compare(o1.getConnectionHandle().getSlotHandle(), o2.getConnectionHandle().getSlotHandle());
}
});
result.addAll(resultHandles);
return new ArrayList<>(result);
}
Aggregations