Search in sources :

Example 6 with TransmitResponse

use of iso.std.iso_iec._24727.tech.schema.TransmitResponse in project open-ecard by ecsec.

the class DIDAuthenticateStep method perform.

@Override
public DIDAuthenticateResponse perform(DIDAuthenticate request, Map<String, Object> internalData) {
    DIDAuthenticateResponse response = WSHelper.makeResponse(DIDAuthenticateResponse.class, WSHelper.makeResultOK());
    char[] rawPIN = null;
    try {
        ConnectionHandleType connectionHandle = SALUtils.getConnectionHandle(request);
        String didName = SALUtils.getDIDName(request);
        CardStateEntry cardStateEntry = SALUtils.getCardStateEntry(internalData, connectionHandle);
        PINCompareDIDAuthenticateInputType pinCompareInput = new PINCompareDIDAuthenticateInputType(request.getAuthenticationProtocolData());
        PINCompareDIDAuthenticateOutputType pinCompareOutput = pinCompareInput.getOutputType();
        byte[] cardApplication;
        if (request.getDIDScope() != null && request.getDIDScope().equals(DIDScopeType.GLOBAL)) {
            cardApplication = cardStateEntry.getInfo().getApplicationIdByDidName(request.getDIDName(), request.getDIDScope());
        } else {
            cardApplication = connectionHandle.getCardApplication();
        }
        Assert.securityConditionDID(cardStateEntry, cardApplication, didName, DifferentialIdentityServiceActionName.DID_AUTHENTICATE);
        DIDStructureType didStructure = cardStateEntry.getDIDStructure(didName, cardApplication);
        PINCompareMarkerType pinCompareMarker = new PINCompareMarkerType(didStructure.getDIDMarker());
        byte keyRef = pinCompareMarker.getPINRef().getKeyRef()[0];
        byte[] slotHandle = connectionHandle.getSlotHandle();
        PasswordAttributesType attributes = pinCompareMarker.getPasswordAttributes();
        rawPIN = pinCompareInput.getPIN();
        // delete pin from memory of the structure
        pinCompareInput.setPIN(null);
        byte[] template = new byte[] { 0x00, 0x20, 0x00, keyRef };
        byte[] responseCode;
        // with [ISO7816-4] (Section 7.5.6).
        if (rawPIN == null || rawPIN.length == 0) {
            VerifyUser verify = new VerifyUser();
            verify.setSlotHandle(slotHandle);
            InputUnitType inputUnit = new InputUnitType();
            verify.setInputUnit(inputUnit);
            PinInputType pinInput = new PinInputType();
            inputUnit.setPinInput(pinInput);
            pinInput.setIndex(BigInteger.ZERO);
            pinInput.setPasswordAttributes(attributes);
            verify.setTemplate(template);
            VerifyUserResponse verifyR = (VerifyUserResponse) dispatcher.safeDeliver(verify);
            WSHelper.checkResult(verifyR);
            responseCode = verifyR.getResponse();
        } else {
            Transmit verifyTransmit = PINUtils.buildVerifyTransmit(rawPIN, attributes, template, slotHandle);
            try {
                TransmitResponse transResp = (TransmitResponse) dispatcher.safeDeliver(verifyTransmit);
                WSHelper.checkResult(transResp);
                responseCode = transResp.getOutputAPDU().get(0);
            } finally {
                // blank PIN APDU
                for (InputAPDUInfoType apdu : verifyTransmit.getInputAPDUInfo()) {
                    byte[] rawApdu = apdu.getInputAPDU();
                    if (rawApdu != null) {
                        java.util.Arrays.fill(rawApdu, (byte) 0);
                    }
                }
            }
        }
        CardResponseAPDU verifyResponseAPDU = new CardResponseAPDU(responseCode);
        if (verifyResponseAPDU.isWarningProcessed()) {
            pinCompareOutput.setRetryCounter(new BigInteger(Integer.toString((verifyResponseAPDU.getSW2() & 0x0F))));
        }
        cardStateEntry.addAuthenticated(didName, cardApplication);
        response.setAuthenticationProtocolData(pinCompareOutput.getAuthDataType());
    } catch (ECardException e) {
        LOG.error(e.getMessage(), e);
        response.setResult(e.getResult());
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        LOG.error(e.getMessage(), e);
        response.setResult(WSHelper.makeResult(e));
    } finally {
        if (rawPIN != null) {
            Arrays.fill(rawPIN, ' ');
        }
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType) VerifyUserResponse(iso.std.iso_iec._24727.tech.schema.VerifyUserResponse) PINCompareMarkerType(org.openecard.common.anytype.pin.PINCompareMarkerType) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) PINCompareDIDAuthenticateInputType(org.openecard.common.anytype.pin.PINCompareDIDAuthenticateInputType) ECardException(org.openecard.common.ECardException) ECardException(org.openecard.common.ECardException) DIDAuthenticateResponse(iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse) InputUnitType(iso.std.iso_iec._24727.tech.schema.InputUnitType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) BigInteger(java.math.BigInteger) DIDStructureType(iso.std.iso_iec._24727.tech.schema.DIDStructureType) VerifyUser(iso.std.iso_iec._24727.tech.schema.VerifyUser) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) PINCompareDIDAuthenticateOutputType(org.openecard.common.anytype.pin.PINCompareDIDAuthenticateOutputType) PinInputType(iso.std.iso_iec._24727.tech.schema.PinInputType)

Example 7 with TransmitResponse

use of iso.std.iso_iec._24727.tech.schema.TransmitResponse in project open-ecard by ecsec.

the class CardCommandAPDU method transmit.

/**
 * Transmit the APDU.
 *
 * @param dispatcher Dispatcher
 * @param slotHandle Slot handle
 * @param responses List of positive responses
 * @return Response APDU
 * @throws APDUException
 */
public CardResponseAPDU transmit(Dispatcher dispatcher, byte[] slotHandle, List<byte[]> responses) throws APDUException {
    Transmit t;
    TransmitResponse tr = null;
    try {
        if (responses != null) {
            t = makeTransmit(slotHandle, responses);
        } else {
            t = makeTransmit(slotHandle);
        }
        tr = (TransmitResponse) dispatcher.safeDeliver(t);
        WSHelper.checkResult(tr);
        CardResponseAPDU responseAPDU = new CardResponseAPDU(tr);
        return responseAPDU;
    } catch (WSException ex) {
        throw new APDUException(ex, tr);
    } catch (Exception ex) {
        throw new APDUException(ex);
    }
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) APDUException(org.openecard.common.apdu.exception.APDUException) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) WSException(org.openecard.common.WSHelper.WSException) WSException(org.openecard.common.WSHelper.WSException) IOException(java.io.IOException) APDUException(org.openecard.common.apdu.exception.APDUException)

Example 8 with TransmitResponse

use of iso.std.iso_iec._24727.tech.schema.TransmitResponse in project open-ecard by ecsec.

the class WSHelper method checkResult.

public static <T extends ResponseBaseType> T checkResult(@Nonnull T response) throws WSException {
    Result r = response.getResult();
    if (r.getResultMajor().equals(ECardConstants.Major.ERROR)) {
        if (response instanceof TransmitResponse) {
            TransmitResponse tr = (TransmitResponse) response;
            List<byte[]> rApdus = tr.getOutputAPDU();
            if (rApdus.size() < 1) {
                throw new WSException(r);
            } else {
                byte[] apdu = CardResponseAPDU.getTrailer(rApdus.get(rApdus.size() - 1));
                String msg = CardCommandStatus.getMessage(apdu);
                throw new WSException(msg);
            }
        } else {
            throw new WSException(r);
        }
    }
    return response;
}
Also used : TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 9 with TransmitResponse

use of iso.std.iso_iec._24727.tech.schema.TransmitResponse 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;
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse)

Example 10 with TransmitResponse

use of iso.std.iso_iec._24727.tech.schema.TransmitResponse in project open-ecard by ecsec.

the class CardRecognitionImpl method transmit.

private byte[] transmit(byte[] slotHandle, byte[] input, List<ResponseAPDUType> results) {
    Transmit t = new Transmit();
    t.setSlotHandle(slotHandle);
    InputAPDUInfoType apdu = new InputAPDUInfoType();
    apdu.setInputAPDU(input);
    for (ResponseAPDUType result : results) {
        apdu.getAcceptableStatusCode().add(result.getTrailer());
    }
    t.getInputAPDUInfo().add(apdu);
    TransmitResponse r = (TransmitResponse) env.getDispatcher().safeDeliver(t);
    if (checkTransmitResult(r)) {
        return r.getOutputAPDU().get(0);
    } else {
        return null;
    }
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) ResponseAPDUType(iso.std.iso_iec._24727.tech.schema.ResponseAPDUType)

Aggregations

TransmitResponse (iso.std.iso_iec._24727.tech.schema.TransmitResponse)11 Transmit (iso.std.iso_iec._24727.tech.schema.Transmit)9 InputAPDUInfoType (iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType)7 Result (oasis.names.tc.dss._1_0.core.schema.Result)5 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)4 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)4 Connect (iso.std.iso_iec._24727.tech.schema.Connect)3 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)3 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)3 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)2 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)2 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)2 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)2 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)2 CardApplicationDisconnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse)2 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)2 CardApplicationPathResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse)2 CardApplicationPathType (iso.std.iso_iec._24727.tech.schema.CardApplicationPathType)2