Search in sources :

Example 1 with TokenInfoType

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;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) ArrayList(java.util.ArrayList)

Example 2 with TokenInfoType

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;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ArrayList(java.util.ArrayList) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus)

Example 3 with TokenInfoType

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;
}
Also used : WSHelper(org.openecard.common.WSHelper) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException) GetCommandType(org.openecard.ws.chipgateway.GetCommandType)

Example 4 with TokenInfoType

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.");
}
Also used : ListTokensResponseType(org.openecard.ws.chipgateway.ListTokensResponseType) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) BigInteger(java.math.BigInteger) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with TokenInfoType

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);
}
Also used : ByteComparator(org.openecard.common.util.ByteComparator) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList)

Aggregations

TokenInfoType (org.openecard.ws.chipgateway.TokenInfoType)10 ArrayList (java.util.ArrayList)8 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)3 WSHelper (org.openecard.common.WSHelper)2 GetStatus (iso.std.iso_iec._24727.tech.schema.GetStatus)1 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)1 IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)1 SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)1 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 TreeSet (java.util.TreeSet)1 TimeoutException (java.util.concurrent.TimeoutException)1 ByteComparator (org.openecard.common.util.ByteComparator)1 UnsupportedAlgorithmException (org.openecard.crypto.common.UnsupportedAlgorithmException)1 GetCommandType (org.openecard.ws.chipgateway.GetCommandType)1 ListTokensResponseType (org.openecard.ws.chipgateway.ListTokensResponseType)1