Search in sources :

Example 1 with TransmitResponse

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

the class AbstractTerminal method verifyUser.

public VerifyUserResponse verifyUser(VerifyUser verify) throws SCIOException, IFDException {
    byte[] handle = verify.getSlotHandle();
    // get capabilities
    getCapabilities();
    // check if is possible to perform PinCompare protocol
    List<String> protoList = this.capabilities.getSlotCapability().get(0).getProtocol();
    if (!protoList.contains(ECardConstants.Protocol.PIN_COMPARE)) {
        throw new IFDException("PinCompare protocol is not supported by this IFD.");
    }
    // get values from requested command
    InputUnitType inputUnit = verify.getInputUnit();
    AltVUMessagesType allMsgs = getMessagesOrDefaults(verify.getAltVUMessages());
    BigInteger firstTimeout = verify.getTimeoutUntilFirstKey();
    firstTimeout = (firstTimeout == null) ? BigInteger.valueOf(60000) : firstTimeout;
    BigInteger otherTimeout = verify.getTimeoutAfterFirstKey();
    otherTimeout = (otherTimeout == null) ? BigInteger.valueOf(15000) : otherTimeout;
    final byte[] template = verify.getTemplate();
    VerifyUserResponse response;
    Result result;
    // check which type of authentication to perform
    if (inputUnit.getBiometricInput() != null) {
        // TODO: implement
        String msg = "Biometric authentication not supported by IFD.";
        IFDException ex = new IFDException(ECardConstants.Minor.IFD.IO.UNKNOWN_INPUT_UNIT, msg);
        LOG.warn(ex.getMessage(), ex);
        throw ex;
    } else if (inputUnit.getPinInput() != null) {
        final PinInputType pinInput = inputUnit.getPinInput();
        // we have a sophisticated card reader
        if (terminalInfo.supportsPinCompare()) {
            // create custom pinAction to submit pin to terminal
            NativePinStepAction pinAction = new NativePinStepAction("enter-pin", pinInput, channel, terminalInfo, template);
            // display message instructing user what to do
            UserConsentDescription uc = pinUserConsent("action.changepin.userconsent.pinstep.title", pinAction);
            UserConsentNavigator ucr = gui.obtainNavigator(uc);
            ExecutionEngine exec = new ExecutionEngine(ucr);
            // run gui
            ResultStatus status = exec.process();
            if (status == ResultStatus.CANCEL) {
                String msg = "PIN entry cancelled by user.";
                LOG.warn(msg);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.CANCELLATION_BY_USER, msg);
                response = WSHelper.makeResponse(VerifyUserResponse.class, result);
            } else if (pinAction.exception != null) {
                LOG.warn(pinAction.exception.getMessage(), pinAction.exception);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED, pinAction.exception.getMessage());
                response = WSHelper.makeResponse(VerifyUserResponse.class, result);
            } else {
                // input by user
                byte[] verifyResponse = pinAction.response;
                // evaluate result
                result = checkNativePinVerify(verifyResponse);
                response = WSHelper.makeResponse(VerifyUserResponse.class, result);
                response.setResponse(verifyResponse);
            }
            return response;
        } else if (isVirtual()) {
            // software method
            // get pin, encode and send
            int minLength = pinInput.getPasswordAttributes().getMinLength().intValue();
            int maxLength = pinInput.getPasswordAttributes().getMaxLength().intValue();
            UserConsentDescription uc = pinUserConsent("action.changepin.userconsent.pinstep.title", minLength, maxLength);
            UserConsentNavigator ucr = gui.obtainNavigator(uc);
            ExecutionEngine exec = new ExecutionEngine(ucr);
            ResultStatus status = exec.process();
            if (status == ResultStatus.CANCEL) {
                String msg = "PIN entry cancelled by user.";
                LOG.warn(msg);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.CANCELLATION_BY_USER, msg);
                response = WSHelper.makeResponse(VerifyUserResponse.class, result);
                return response;
            }
            char[] rawPIN = getPinFromUserConsent(exec);
            PasswordAttributesType attributes = pinInput.getPasswordAttributes();
            Transmit verifyTransmit;
            try {
                verifyTransmit = PINUtils.buildVerifyTransmit(rawPIN, attributes, template, handle);
            } catch (UtilException e) {
                String msg = "Failed to create the verifyTransmit message.";
                LOG.error(msg, e);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.UNKNOWN_ERROR, msg);
                response = WSHelper.makeResponse(VerifyUserResponse.class, result);
                return response;
            } finally {
                Arrays.fill(rawPIN, ' ');
            }
            // send to reader
            TransmitResponse transResp;
            try {
                transResp = ifd.transmit(verifyTransmit);
            } finally {
                // blank PIN APDU
                for (InputAPDUInfoType apdu : verifyTransmit.getInputAPDUInfo()) {
                    byte[] rawApdu = apdu.getInputAPDU();
                    if (rawApdu != null) {
                        Arrays.fill(rawApdu, (byte) 0);
                    }
                }
            }
            // produce messages
            if (transResp.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
                if (transResp.getOutputAPDU().isEmpty()) {
                    result = WSHelper.makeResultError(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED, transResp.getResult().getResultMessage().getValue());
                    response = WSHelper.makeResponse(VerifyUserResponse.class, result);
                    return response;
                } else {
                    response = WSHelper.makeResponse(VerifyUserResponse.class, transResp.getResult());
                    response.setResponse(transResp.getOutputAPDU().get(0));
                    // TODO: move this code to the PIN Compare protocol
                    if (response.getResponse() != null) {
                        CardResponseAPDU resApdu = new CardResponseAPDU(response.getResponse());
                        byte[] statusBytes = resApdu.getStatusBytes();
                        boolean isMainStatus = statusBytes[0] == (byte) 0x63;
                        boolean isMinorStatus = (statusBytes[1] & (byte) 0xF0) == (byte) 0xC0;
                        int triesLeft = statusBytes[1] & 0x0F;
                        if (isMainStatus && isMinorStatus && triesLeft > 0) {
                            LOG.info("PIN not entered successful. There are {} tries left.", statusBytes[1] & 0x0F);
                            return verifyUser(verify);
                        }
                    }
                    return response;
                }
            } else {
                response = WSHelper.makeResponse(VerifyUserResponse.class, transResp.getResult());
                response.setResponse(transResp.getOutputAPDU().get(0));
                return response;
            }
        } else {
            IFDException ex = new IFDException("No input unit available to perform PinCompare protocol.");
            LOG.warn(ex.getMessage(), ex);
            throw ex;
        }
    } else {
        String msg = "Unsupported authentication input method requested.";
        IFDException ex = new IFDException(ECardConstants.Minor.IFD.IO.UNKNOWN_INPUT_UNIT, msg);
        LOG.warn(ex.getMessage(), ex);
        throw ex;
    }
}
Also used : Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType) ResultStatus(org.openecard.gui.ResultStatus) AltVUMessagesType(iso.std.iso_iec._24727.tech.schema.AltVUMessagesType) VerifyUserResponse(iso.std.iso_iec._24727.tech.schema.VerifyUserResponse) UtilException(org.openecard.common.util.UtilException) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) UserConsentNavigator(org.openecard.gui.UserConsentNavigator) Result(oasis.names.tc.dss._1_0.core.schema.Result) InputUnitType(iso.std.iso_iec._24727.tech.schema.InputUnitType) ExecutionEngine(org.openecard.gui.executor.ExecutionEngine) UserConsentDescription(org.openecard.gui.definition.UserConsentDescription) BigInteger(java.math.BigInteger) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) PinInputType(iso.std.iso_iec._24727.tech.schema.PinInputType)

Example 2 with TransmitResponse

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

the class IFD method transmit.

@Publish
@Override
public TransmitResponse transmit(Transmit parameters) {
    try {
        TransmitResponse response;
        if (!hasContext()) {
            String msg = "Context not initialized.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(TransmitResponse.class, r);
            return response;
        }
        try {
            byte[] handle = parameters.getSlotHandle();
            SingleThreadChannel ch = cm.getSlaveChannel(handle);
            List<InputAPDUInfoType> apdus = parameters.getInputAPDUInfo();
            // check that the apdus contain sane values
            for (InputAPDUInfoType apdu : apdus) {
                for (byte[] code : apdu.getAcceptableStatusCode()) {
                    if (code.length == 0 || code.length > 2) {
                        String msg = "Invalid accepted status code given.";
                        Result r = WSHelper.makeResultError(ECardConstants.Minor.App.PARM_ERROR, msg);
                        response = WSHelper.makeResponse(TransmitResponse.class, r);
                        return response;
                    }
                }
            }
            // transmit APDUs and stop if an error occurs or a not expected status is hit
            response = WSHelper.makeResponse(TransmitResponse.class, WSHelper.makeResultOK());
            Result result;
            List<byte[]> rapdus = response.getOutputAPDU();
            try {
                for (InputAPDUInfoType capdu : apdus) {
                    byte[] rapdu = ch.transmit(capdu.getInputAPDU(), capdu.getAcceptableStatusCode());
                    rapdus.add(rapdu);
                }
                result = WSHelper.makeResultOK();
            } catch (TransmitException ex) {
                rapdus.add(ex.getResponseAPDU());
                result = ex.getResult();
            } catch (SCIOException ex) {
                String msg = "Error during transmit.";
                LOG.warn(msg, ex);
                result = WSHelper.makeResultUnknownError(msg);
            } catch (IllegalStateException ex) {
                String msg = "Card removed during transmit.";
                LOG.warn(msg, ex);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            } catch (IllegalArgumentException ex) {
                String msg = "Given command contains a MANAGE CHANNEL APDU.";
                LOG.error(msg, ex);
                result = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            }
            response.setResult(result);
            return response;
        } catch (NoSuchChannel | IllegalStateException ex) {
            String msg = "No card with transaction available in the requested terminal.";
            Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, msg);
            response = WSHelper.makeResponse(TransmitResponse.class, r);
            LOG.warn(msg, ex);
            return response;
        }
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
        throwThreadKillException(ex);
        return WSHelper.makeResponse(TransmitResponse.class, WSHelper.makeResult(ex));
    }
}
Also used : SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) NoSuchChannel(org.openecard.ifd.scio.wrapper.NoSuchChannel) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) ThreadTerminateException(org.openecard.common.ThreadTerminateException) SCIOException(org.openecard.common.ifd.scio.SCIOException) ExecutionException(java.util.concurrent.ExecutionException) Result(oasis.names.tc.dss._1_0.core.schema.Result) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) Publish(org.openecard.common.interfaces.Publish)

Example 3 with TransmitResponse

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

the class AndroidMarshaller method parse.

private synchronized Object parse(XmlPullParser parser) throws XmlPullParserException, IOException, ParserConfigurationException, DatatypeConfigurationException {
    if (parser.getName().equals("DestroyChannelResponse")) {
        DestroyChannelResponse destroyChannelResponse = new DestroyChannelResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    destroyChannelResponse.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    destroyChannelResponse.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    destroyChannelResponse.setResult(this.parseResult(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DestroyChannelResponse")));
        return destroyChannelResponse;
    } else if (parser.getName().equals("DestroyChannel")) {
        DestroyChannel destroyChannel = new DestroyChannel();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("SlotHandle")) {
                    destroyChannel.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DestroyChannel")));
        return destroyChannel;
    } else if (parser.getName().equals("EstablishChannelResponse")) {
        EstablishChannelResponse establishChannelResponse = new EstablishChannelResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    establishChannelResponse.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    establishChannelResponse.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    establishChannelResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("AuthenticationProtocolData")) {
                    establishChannelResponse.setAuthenticationProtocolData(this.parseDIDAuthenticationDataType(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("EstablishChannelResponse")));
        return establishChannelResponse;
    } else if (parser.getName().equals("DIDAuthenticate")) {
        DIDAuthenticate didAuthenticate = new DIDAuthenticate();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("DIDName")) {
                    didAuthenticate.setDIDName(parser.nextText());
                } else if (parser.getName().equals("SlotHandle")) {
                    ConnectionHandleType cht = new ConnectionHandleType();
                    cht.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                    didAuthenticate.setConnectionHandle(cht);
                } else if (parser.getName().equals("AuthenticationProtocolData")) {
                    didAuthenticate.setAuthenticationProtocolData(this.parseDIDAuthenticationDataType(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DIDAuthenticate")));
        return didAuthenticate;
    } else if (parser.getName().equals("DIDAuthenticateResponse")) {
        DIDAuthenticateResponse response = new DIDAuthenticateResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    response.setResult(this.parseResult(parser));
                }
                if (parser.getName().equals("AuthenticationProtocolData")) {
                    response.setAuthenticationProtocolData(this.parseDIDAuthenticationDataType(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DIDAuthenticateResponse")));
        return response;
    } else if (parser.getName().equals("StartPAOSResponse")) {
        StartPAOSResponse startPAOSResponse = new StartPAOSResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    startPAOSResponse.setResult(this.parseResult(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("StartPAOSResponse")));
        return startPAOSResponse;
    } else if (parser.getName().equals("InitializeFramework")) {
        InitializeFramework initializeFramework = new InitializeFramework();
        return initializeFramework;
    } else if (parser.getName().equals("Conclusion")) {
        return parseConclusion(parser);
    } else if (parser.getName().equals("WaitResponse")) {
        WaitResponse waitResponse = new WaitResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    waitResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("IFDEvent")) {
                    waitResponse.getIFDEvent().add(parseIFDStatusType(parser, "IFDEvent"));
                } else if (parser.getName().equals("SessionIdentifier")) {
                    waitResponse.setSessionIdentifier(parser.nextText());
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("WaitResponse")));
        return waitResponse;
    } else if (parser.getName().equals("GetStatusResponse")) {
        GetStatusResponse getStatusResponse = new GetStatusResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    getStatusResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("IFDStatus")) {
                    getStatusResponse.getIFDStatus().add(parseIFDStatusType(parser, "IFDStatus"));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("GetStatusResponse")));
        return getStatusResponse;
    } else if (parser.getName().equals("ListIFDs")) {
        ListIFDs listIFDs = new ListIFDs();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ContextHandle")) {
                    listIFDs.setContextHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ListIFDs")));
        return listIFDs;
    } else if (parser.getName().equals("GetIFDCapabilities")) {
        GetIFDCapabilities getIFDCapabilities = new GetIFDCapabilities();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ContextHandle")) {
                    getIFDCapabilities.setContextHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("IFDName")) {
                    getIFDCapabilities.setIFDName(parser.nextText());
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("GetIFDCapabilities")));
        return getIFDCapabilities;
    } else if (parser.getName().equals("GetIFDCapabilitiesResponse")) {
        GetIFDCapabilitiesResponse resp = new GetIFDCapabilitiesResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    resp.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    resp.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    resp.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("GetIFDCapabilitiesResponse")) {
                    resp.setIFDCapabilities((IFDCapabilitiesType) this.parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("GetIFDCapabilitiesResponse")));
        return resp;
    } else if (parser.getName().equals("IFDCapabilitiesType")) {
        IFDCapabilitiesType cap = new IFDCapabilitiesType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("OpticalSignalUnit")) {
                    cap.setOpticalSignalUnit(Boolean.getBoolean(parser.nextText()));
                } else if (parser.getName().equals("AcousticSignalUnit")) {
                    cap.setAcousticSignalUnit(Boolean.getBoolean(parser.nextText()));
                } else if (parser.getName().equals("SlotCapability")) {
                    cap.getSlotCapability().add(parseSlotCapability(parser));
                } else if (parser.getName().equals("DisplayCapability")) {
                    cap.getDisplayCapability().add(parseDisplayCapability(parser));
                } else if (parser.getName().equals("KeyPadCapability")) {
                    cap.getKeyPadCapability().add(parseKeyPadCapability(parser));
                } else if (parser.getName().equals("BioSensorCapability")) {
                    cap.getBioSensorCapability().add(parseBioSensorCapability(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("IFDCapabilitiesType")));
        return cap;
    } else if (parser.getName().equals("BeginTransaction")) {
        BeginTransaction trans = new BeginTransaction();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("SlotHandle")) {
                    trans.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("BeginTransaction")));
        return trans;
    } else if (parser.getName().equals("BeginTransactionResponse")) {
        BeginTransactionResponse response = new BeginTransactionResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    response.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    response.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    response.setResult(this.parseResult(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("BeginTransactionResponse")));
        return response;
    } else if (parser.getName().equals("EndTransaction")) {
        EndTransaction end = new EndTransaction();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("SlotHandle")) {
                    end.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("EndTransaction")));
        return end;
    } else if (parser.getName().equals("EndTransactionResponse")) {
        EndTransactionResponse response = new EndTransactionResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    response.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    response.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    response.setResult(this.parseResult(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("EndTransactionResponse")));
        return response;
    } else if (parser.getName().equals("CardApplicationPath")) {
        CardApplicationPath path = new CardApplicationPath();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("CardAppPathRequest")) {
                    path.setCardAppPathRequest((CardApplicationPathType) parse(parser));
                } else if (parser.getName().equals("Profile")) {
                    path.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    path.setRequestID(parser.nextText());
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardApplicationPath")));
        return path;
    } else if (parser.getName().equals("CardAppPathRequest") || parser.getName().equals("CardApplicationPathResult")) {
        CardApplicationPathType type = new CardApplicationPathType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ChannelHandle")) {
                    type.setChannelHandle((ChannelHandleType) parse(parser));
                } else if (parser.getName().equals("ContextHandle")) {
                    type.setContextHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("IFDName")) {
                    type.setIFDName(parser.nextText());
                } else if (parser.getName().equals("SlotIndex")) {
                    type.setSlotIndex(new BigInteger(parser.nextText()));
                } else if (parser.getName().equals("CardApplication")) {
                    type.setCardApplication(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardAppPathRequest")));
        return type;
    } else if (parser.getName().equals("ChannelHandle")) {
        ChannelHandleType ch = new ChannelHandleType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ProtocolTerminationPoint")) {
                    ch.setProtocolTerminationPoint(parser.nextText());
                } else if (parser.getName().equals("SessionIdentifier")) {
                    ch.setSessionIdentifier(parser.nextText());
                } else if (parser.getName().equals("Binding")) {
                    ch.setBinding(parser.nextText());
                } else if (parser.getName().equals("PathSecurity")) {
                    ch.setPathSecurity((PathSecurityType) parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ChannelHandle")));
        return ch;
    } else if (parser.getName().equals("PathSecurity")) {
        PathSecurityType p = new PathSecurityType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Protocol")) {
                    p.setProtocol(parser.nextText());
                } else if (parser.getName().equals("Parameters")) {
                    // TODO this object is an any type
                    p.setParameters((Object) parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("PathSecurity")));
        return p;
    } else if (parser.getName().equals("CardApplicationPathResponse")) {
        CardApplicationPathResponse resp = new CardApplicationPathResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("CardAppPathResultSet")) {
                    resp.setCardAppPathResultSet((CardApplicationPathResponse.CardAppPathResultSet) parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardApplicationPathResponse")));
        return resp;
    } else if (parser.getName().equals("CardAppPathResultSet")) {
        CardApplicationPathResponse.CardAppPathResultSet result = new CardApplicationPathResponse.CardAppPathResultSet();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("CardApplicationPathResult")) {
                    result.getCardApplicationPathResult().add((CardApplicationPathType) parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardAppPathResultSet")));
        return result;
    } else if (parser.getName().equals("CardApplicationConnect")) {
        CardApplicationConnect result = new CardApplicationConnect();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("CardApplicationPath")) {
                    result.setCardApplicationPath(parseCardApplicationPath(parser));
                } else if (parser.getName().equals("Output")) {
                    result.setOutput((OutputInfoType) parse(parser));
                } else if (parser.getName().equals("ExclusiveUse")) {
                    result.setExclusiveUse(Boolean.getBoolean(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardApplicationConnect")));
        return result;
    } else if (parser.getName().equals("Output")) {
        OutputInfoType result = new OutputInfoType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Timeout")) {
                    result.setTimeout(new BigInteger(parser.nextText()));
                } else if (parser.getName().equals("DisplayIndex")) {
                    result.setDisplayIndex(new BigInteger(parser.nextText()));
                } else if (parser.getName().equals("Message")) {
                    result.setMessage(parser.nextText());
                } else if (parser.getName().equals("AcousticalSignal")) {
                    result.setAcousticalSignal(Boolean.getBoolean(parser.nextText()));
                } else if (parser.getName().equals("OpticalSignal")) {
                    result.setOpticalSignal(Boolean.getBoolean(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("Output")));
        return result;
    } else if (parser.getName().equals("CardApplicationConnectResponse")) {
        CardApplicationConnectResponse result = new CardApplicationConnectResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    result.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    result.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    result.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("ConnectionHandle")) {
                    result.setConnectionHandle((ConnectionHandleType) parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardApplicationConnectResponse")));
        return result;
    } else if (parser.getName().equals("ConnectionHandle")) {
        ConnectionHandleType result = new ConnectionHandleType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ChannelHandle")) {
                    result.setChannelHandle((ChannelHandleType) parse(parser));
                } else if (parser.getName().equals("ContextHandle")) {
                    result.setContextHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("IFDName")) {
                    result.setIFDName(parser.nextText());
                } else if (parser.getName().equals("SlotIndex")) {
                    result.setSlotIndex(new BigInteger(parser.nextText()));
                } else if (parser.getName().equals("CardApplication")) {
                    result.setCardApplication(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("SlotHandle")) {
                    result.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("RecognitionInfo")) {
                    result.setRecognitionInfo((RecognitionInfo) parse(parser));
                } else if (parser.getName().equals("SlotInfo")) {
                    result.setSlotInfo((SlotInfo) parse(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ConnectionHandle")));
        return result;
    } else if (parser.getName().equals("RecognitionInfo")) {
        RecognitionInfo result = new RecognitionInfo();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("CardType")) {
                    result.setCardType(parser.nextText());
                } else if (parser.getName().equals("CardIdentifier")) {
                    result.setCardIdentifier(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("CaptureTime")) {
                // TODO
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("RecognitionInfo")));
        return result;
    } else if (parser.getName().equals("SlotInfo")) {
        SlotInfo result = new SlotInfo();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ProtectedAuthPath")) {
                    result.setProtectedAuthPath(Boolean.getBoolean(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("SlotInfo")));
        return result;
    } else if (parser.getName().equals("CardApplicationDisconnect")) {
        CardApplicationDisconnect result = new CardApplicationDisconnect();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ConnectionHandle")) {
                    result.setConnectionHandle(parseConnectionHandle(parser));
                } else if (parser.getName().equals("Action")) {
                    result.setAction(ActionType.fromValue(parser.nextText()));
                } else if (parser.getName().equals("Profile")) {
                    result.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    result.setRequestID(parser.nextText());
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardApplicationDisconnect")));
        return result;
    } else if (parser.getName().equals("CardApplicationDisconnectResponse")) {
        CardApplicationDisconnectResponse result = new CardApplicationDisconnectResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    result.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    result.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    result.setResult(this.parseResult(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardApplicationDisconnectResponse")));
        return result;
    } else if (parser.getName().equals("GetRecognitionTreeResponse")) {
        GetRecognitionTreeResponse resp = new GetRecognitionTreeResponse();
        RecognitionTree recTree = new RecognitionTree();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    resp.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("CardCall")) {
                    recTree.getCardCall().add(this.parseCardCall(parser));
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if (parser.getName().equals("CardCall")) {
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("GetRecognitionTreeResponse")));
        resp.setRecognitionTree(recTree);
        return resp;
    } else if (parser.getName().equals("EstablishContext")) {
        EstablishContext establishContext = new EstablishContext();
        return establishContext;
    } else if (parser.getName().equals("EstablishContextResponse")) {
        EstablishContextResponse establishContextResponse = new EstablishContextResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    establishContextResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("ContextHandle")) {
                    establishContextResponse.setContextHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("EstablishContextResponse")));
        return establishContextResponse;
    } else if (parser.getName().equals("ListIFDsResponse")) {
        ListIFDsResponse listIFDsResponse = new ListIFDsResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    listIFDsResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("IFDName")) {
                    listIFDsResponse.getIFDName().add(parser.nextText());
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ListIFDsResponse")));
        return listIFDsResponse;
    } else if (parser.getName().equals("ConnectResponse")) {
        ConnectResponse connectResponse = new ConnectResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    connectResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("SlotHandle")) {
                    connectResponse.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("ConnectResponse")));
        return connectResponse;
    } else if (parser.getName().equals("Connect")) {
        Connect c = new Connect();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("IFDName")) {
                    c.setIFDName(parser.nextText());
                } else if (parser.getName().equals("ContextHandle")) {
                    c.setContextHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("Slot")) {
                    c.setSlot(new BigInteger(parser.nextText()));
                }
            // TODO exclusive
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("Connect")));
        return c;
    } else if (parser.getName().equals("Disconnect")) {
        Disconnect d = new Disconnect();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("SlotHandle")) {
                    d.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("Action")) {
                    d.setAction(ActionType.fromValue(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("Disconnect")));
        return d;
    } else if (parser.getName().equals("DisconnectResponse")) {
        DisconnectResponse response = new DisconnectResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Profile")) {
                    response.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    response.setRequestID(parser.nextText());
                } else if (parser.getName().equals("Result")) {
                    response.setResult(this.parseResult(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DisconnectResponse")));
        return response;
    } else if (parser.getName().equals("Transmit")) {
        Transmit t = new Transmit();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("InputAPDUInfo")) {
                    t.getInputAPDUInfo().add(this.parseInputAPDUInfo(parser));
                } else if (parser.getName().equals("SlotHandle")) {
                    t.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("Transmit")));
        return t;
    } else if (parser.getName().equals("TransmitResponse")) {
        TransmitResponse transmitResponse = new TransmitResponse();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("Result")) {
                    transmitResponse.setResult(this.parseResult(parser));
                } else if (parser.getName().equals("OutputAPDU")) {
                    transmitResponse.getOutputAPDU().add(StringUtils.toByteArray(parser.nextText()));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("TransmitResponse")));
        return transmitResponse;
    } else if (parser.getName().equals("CardInfo")) {
        // TODO CardIdentification and CardCapabilities are ignored
        CardInfo cardInfo = new CardInfo();
        ApplicationCapabilitiesType applicationCapabilities = new ApplicationCapabilitiesType();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ObjectIdentifier")) {
                    CardTypeType cardType = new CardTypeType();
                    cardType.setObjectIdentifier(parser.nextText());
                    cardInfo.setCardType(cardType);
                } else if (parser.getName().equals("ImplicitlySelectedApplication")) {
                    try {
                        // TODO iso:Path, see CardInfo_ecard-AT_0-9-0
                        String selectedApplication = parser.nextText();
                        applicationCapabilities.setImplicitlySelectedApplication(StringUtils.toByteArray(selectedApplication));
                    } catch (XmlPullParserException ex) {
                    }
                } else if (parser.getName().equals("CardApplication")) {
                    applicationCapabilities.getCardApplication().add(this.parseCardApplication(parser));
                } else if (parser.getName().equals("CardTypeName")) {
                    InternationalStringType internationalString = new InternationalStringType();
                    String lang = parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang");
                    internationalString.setLang(lang);
                    internationalString.setValue(parser.nextText());
                    cardInfo.getCardType().getCardTypeName().add(internationalString);
                } else if (parser.getName().equals("SpecificationBodyOrIssuer")) {
                    cardInfo.getCardType().setSpecificationBodyOrIssuer(parser.nextText());
                } else if (parser.getName().equals("Status")) {
                    cardInfo.getCardType().setStatus(parser.nextText());
                } else if (parser.getName().equals("Date")) {
                // currently not working; see http://code.google.com/p/android/issues/detail?id=14379
                /*String text = parser.nextText();
			XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(text);
			cardInfo.getCardType().setDate(date);*/
                } else if (parser.getName().equals("Version")) {
                    cardInfo.getCardType().setVersion(this.parseVersion(parser));
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("CardInfo")));
        cardInfo.setApplicationCapabilities(applicationCapabilities);
        return cardInfo;
    } else if (parser.getName().equals("AddonSpecification")) {
        AddonSpecification addonBundleDescription = new AddonSpecification();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("ID")) {
                    addonBundleDescription.setId(parser.nextText());
                } else if (parser.getName().equals("Version")) {
                    addonBundleDescription.setVersion(parser.nextText());
                } else if (parser.getName().equals("License")) {
                    addonBundleDescription.setLicense(parser.nextText());
                } else if (parser.getName().equals("LocalizedName")) {
                    LocalizedString string = new LocalizedString();
                    string.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                    string.setValue(parser.nextText());
                    addonBundleDescription.getLocalizedName().add(string);
                } else if (parser.getName().equals("LocalizedDescription")) {
                    LocalizedString string = new LocalizedString();
                    string.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                    string.setValue(parser.nextText());
                    addonBundleDescription.getLocalizedDescription().add(string);
                } else if (parser.getName().equals("About")) {
                    LocalizedString string = new LocalizedString();
                    string.setLang(parser.getAttributeValue("http://www.w3.org/XML/1998/namespace", "lang"));
                    string.setValue(parser.nextText());
                    addonBundleDescription.getAbout().add(string);
                } else if (parser.getName().equals("Logo")) {
                    addonBundleDescription.setLogo(parser.nextText());
                } else if (parser.getName().equals("ConfigDescription")) {
                    addonBundleDescription.setConfigDescription(parseConfigDescription(parser));
                } else if (parser.getName().equals("BindingActions")) {
                    addonBundleDescription.getBindingActions().addAll(parseBindingActions(parser));
                } else if (parser.getName().equals("ApplicationActions")) {
                    addonBundleDescription.getApplicationActions().addAll(parseApplicationActions(parser));
                } else if (parser.getName().equals("IFDActions")) {
                    addonBundleDescription.getIfdActions().addAll(parseProtocolPluginSpecification(parser, "IFDActions"));
                } else if (parser.getName().equals("SALActions")) {
                    addonBundleDescription.getSalActions().addAll(parseProtocolPluginSpecification(parser, "SALActions"));
                } else {
                    throw new IllegalArgumentException(parser.getName() + " in AddonSpecification is not supported.");
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("AddonSpecification")));
        return addonBundleDescription;
    } else if (parser.getName().equals("EstablishChannel")) {
        EstablishChannel result = new EstablishChannel();
        int eventType;
        do {
            parser.next();
            eventType = parser.getEventType();
            if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("SlotHandle")) {
                    result.setSlotHandle(StringUtils.toByteArray(parser.nextText()));
                } else if (parser.getName().equals("AuthenticationProtocolData")) {
                    result.setAuthenticationProtocolData(parseDIDAuthenticationDataType(parser));
                } else if (parser.getName().equals("Profile")) {
                    result.setProfile(parser.nextText());
                } else if (parser.getName().equals("RequestID")) {
                    result.setRequestID(parser.nextText());
                } else {
                    throw new IOException("Unmarshalling of " + parser.getName() + " in EstablishChannel not supported.");
                }
            }
        } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("EstablishChannel")));
        return result;
    } else {
        throw new IOException("Unmarshalling of " + parser.getName() + " is not yet supported.");
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) InitializeFramework(de.bund.bsi.ecard.api._1.InitializeFramework) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ChannelHandleType(iso.std.iso_iec._24727.tech.schema.ChannelHandleType) LocalizedString(org.openecard.addon.manifest.LocalizedString) GetIFDCapabilities(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilities) BeginTransaction(iso.std.iso_iec._24727.tech.schema.BeginTransaction) PathSecurityType(iso.std.iso_iec._24727.tech.schema.PathSecurityType) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) AddonSpecification(org.openecard.addon.manifest.AddonSpecification) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) EndTransaction(iso.std.iso_iec._24727.tech.schema.EndTransaction) OutputInfoType(iso.std.iso_iec._24727.tech.schema.OutputInfoType) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Connect(iso.std.iso_iec._24727.tech.schema.Connect) CardInfo(iso.std.iso_iec._24727.tech.schema.CardInfo) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) DestroyChannelResponse(iso.std.iso_iec._24727.tech.schema.DestroyChannelResponse) BeginTransactionResponse(iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) BigInteger(java.math.BigInteger) GetIFDCapabilitiesResponse(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) CardTypeType(iso.std.iso_iec._24727.tech.schema.CardTypeType) ConnectResponse(iso.std.iso_iec._24727.tech.schema.ConnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) IFDCapabilitiesType(iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType) StartPAOSResponse(iso.std.iso_iec._24727.tech.schema.StartPAOSResponse) WaitResponse(iso.std.iso_iec._24727.tech.schema.WaitResponse) EndTransactionResponse(iso.std.iso_iec._24727.tech.schema.EndTransactionResponse) LocalizedString(org.openecard.addon.manifest.LocalizedString) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) DisconnectResponse(iso.std.iso_iec._24727.tech.schema.DisconnectResponse) CardApplicationDisconnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) RecognitionTree(iso.std.iso_iec._24727.tech.schema.RecognitionTree) DIDAuthenticate(iso.std.iso_iec._24727.tech.schema.DIDAuthenticate) Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) GetRecognitionTreeResponse(iso.std.iso_iec._24727.tech.schema.GetRecognitionTreeResponse) CardApplicationDisconnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) IOException(java.io.IOException) InternationalStringType(oasis.names.tc.dss._1_0.core.schema.InternationalStringType) DIDAuthenticateResponse(iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) ApplicationCapabilitiesType(iso.std.iso_iec._24727.tech.schema.ApplicationCapabilitiesType) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) SlotInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.SlotInfo)

Example 4 with TransmitResponse

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

the class AndroidMarshaller method marshal.

@Override
public synchronized Document marshal(Object o) throws MarshallingTypeException {
    Document document = documentBuilder.newDocument();
    document.setXmlStandalone(true);
    Element rootElement = null;
    if (o instanceof DestroyChannel) {
        DestroyChannel destroyChannel = (DestroyChannel) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        Element emSlotHandle = createElementIso(document, "SlotHandle");
        emSlotHandle.appendChild(document.createTextNode(ByteUtils.toHexString(destroyChannel.getSlotHandle())));
        rootElement.appendChild(emSlotHandle);
    } else if (o instanceof DestroyChannelResponse) {
        DestroyChannelResponse response = (DestroyChannelResponse) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        if (response.getProfile() != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(response.getProfile()));
            rootElement.appendChild(emProfile);
        }
        if (response.getRequestID() != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(response.getRequestID()));
            rootElement.appendChild(emRequest);
        }
        if (response.getResult() != null) {
            Element emResult = marshalResult(response.getResult(), document);
            rootElement.appendChild(emResult);
        }
    } else if (o instanceof EstablishChannel) {
        EstablishChannel establishChannel = (EstablishChannel) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        Element emSlotHandle = createElementIso(document, "SlotHandle");
        emSlotHandle.appendChild(document.createTextNode(ByteUtils.toHexString(establishChannel.getSlotHandle())));
        rootElement.appendChild(emSlotHandle);
        Element emAuthProtData = createElementIso(document, "AuthenticationProtocolData");
        emAuthProtData.setAttribute("Protocol", establishChannel.getAuthenticationProtocolData().getProtocol());
        for (Element e : establishChannel.getAuthenticationProtocolData().getAny()) {
            Element eClone = createElementIso(document, e.getLocalName());
            eClone.setTextContent(e.getTextContent());
            eClone.setAttribute("xmlns", "urn:iso:std:iso-iec:24727:tech:schema");
            emAuthProtData.appendChild(eClone);
        }
        if (establishChannel.getProfile() != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(establishChannel.getProfile()));
            rootElement.appendChild(emProfile);
        }
        if (establishChannel.getRequestID() != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(establishChannel.getRequestID()));
            rootElement.appendChild(emRequest);
        }
        rootElement.appendChild(emAuthProtData);
    } else if (o instanceof EstablishChannelResponse) {
        EstablishChannelResponse response = (EstablishChannelResponse) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        if (response.getProfile() != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(response.getProfile()));
            rootElement.appendChild(emProfile);
        }
        if (response.getRequestID() != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(response.getRequestID()));
            rootElement.appendChild(emRequest);
        }
        if (response.getResult() != null) {
            Element emResult = marshalResult(response.getResult(), document);
            rootElement.appendChild(emResult);
        }
        if (response.getAuthenticationProtocolData() != null) {
            Element emAuthProtData = createElementIso(document, "AuthenticationProtocolData");
            emAuthProtData.setAttribute("Protocol", response.getAuthenticationProtocolData().getProtocol());
            for (Element e : response.getAuthenticationProtocolData().getAny()) {
                Element eClone = createElementIso(document, e.getLocalName());
                eClone.setTextContent(e.getTextContent());
                eClone.setAttribute("xmlns", "urn:iso:std:iso-iec:24727:tech:schema");
                emAuthProtData.appendChild(eClone);
            }
        }
    } else if (o instanceof DIDAuthenticate) {
        DIDAuthenticate auth = (DIDAuthenticate) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        Element em;
        if (auth.getConnectionHandle() != null) {
            em = marshalConnectionHandle(auth.getConnectionHandle(), document);
            rootElement.appendChild(em);
        }
        if (auth.getDIDScope() != null) {
            em = createElementIso(document, "DIDScope");
            em.appendChild(document.createTextNode(auth.getDIDScope().value()));
            rootElement.appendChild(em);
        }
        if (auth.getDIDName() != null) {
            em = createElementIso(document, "DIDName");
            em.appendChild(document.createTextNode(auth.getDIDName()));
            rootElement.appendChild(em);
        }
        if (auth.getAuthenticationProtocolData() != null) {
            DIDAuthenticationDataType d = auth.getAuthenticationProtocolData();
            em = createElementIso(document, "AuthenticationProtocolData");
            em.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            if (d instanceof EAC1OutputType) {
                em.setAttribute("xsi:type", "iso:EAC1OutputType");
            } else if (d instanceof EAC2OutputType) {
                em.setAttribute("xsi:type", "iso:EAC2OutputType");
            } else if (d instanceof EAC1InputType) {
                em.setAttribute("xsi:type", "iso:EAC1InputType");
            } else if (d instanceof EAC2InputType) {
                em.setAttribute("xsi:type", "iso:EAC2InputType");
            } else {
                String msg = "Marshalling a DIDAuthenticationDataType of " + d.getClass().getName() + " in DIDAuthentication is not supported";
                LOG.error(msg);
                throw new MarshallingTypeException(msg);
            }
            for (Element e : d.getAny()) {
                Element elemCopy = createElementIso(document, e.getLocalName());
                elemCopy.setTextContent(e.getTextContent());
                em.appendChild(elemCopy);
            }
            for (Map.Entry<QName, String> entry : d.getOtherAttributes().entrySet()) {
                em.setAttribute(entry.getKey().getNamespaceURI(), entry.getValue());
            }
            if (d.getProtocol() != null) {
                em.setAttribute("Protocol", d.getProtocol());
            }
            rootElement.appendChild(em);
        }
        if (auth.getSAMConnectionHandle() != null) {
            em = marshalConnectionHandle(auth.getSAMConnectionHandle(), document);
            rootElement.appendChild(em);
        }
        if (auth.getProfile() != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(auth.getProfile()));
            rootElement.appendChild(emProfile);
        }
        if (auth.getRequestID() != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(auth.getRequestID()));
            rootElement.appendChild(emRequest);
        }
    } else if (o instanceof DIDAuthenticateResponse) {
        DIDAuthenticateResponse didAuthenticateResponse = (DIDAuthenticateResponse) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        rootElement.appendChild(marshalResult(didAuthenticateResponse.getResult(), document));
        if (didAuthenticateResponse.getAuthenticationProtocolData() != null) {
            DIDAuthenticationDataType didAuthenticationDataType = didAuthenticateResponse.getAuthenticationProtocolData();
            Element elemEACOutput = createElementIso(document, "AuthenticationProtocolData");
            elemEACOutput.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            if (didAuthenticationDataType instanceof EAC1OutputType) {
                elemEACOutput.setAttribute("xsi:type", "iso:EAC1OutputType");
            } else if (didAuthenticationDataType instanceof EAC2OutputType) {
                elemEACOutput.setAttribute("xsi:type", "iso:EAC2OutputType");
            } else {
                String msg = "Marshalling a DIDAuthenticationDataType of " + didAuthenticationDataType.getClass().getName() + " in DIDAuthentication is not supported";
                throw new MarshallingTypeException(msg);
            }
            for (Element e : didAuthenticationDataType.getAny()) {
                Element elemCopy = createElementIso(document, e.getLocalName());
                elemCopy.setTextContent(e.getTextContent());
                elemEACOutput.appendChild(elemCopy);
            }
            rootElement.appendChild(elemEACOutput);
        }
    // else only the result (with error) is returned
    } else if (o instanceof InitializeFrameworkResponse) {
        InitializeFrameworkResponse initializeFrameworkResponse = (InitializeFrameworkResponse) o;
        rootElement = createElementEcapi(document, o.getClass().getSimpleName());
        rootElement.appendChild(marshalResult(initializeFrameworkResponse.getResult(), document));
        Element emVersion = createElementEcapi(document, "Version");
        Element emMajor = createElementEcapi(document, "Major");
        emMajor.appendChild(document.createTextNode(initializeFrameworkResponse.getVersion().getMajor().toString()));
        emVersion.appendChild(emMajor);
        Element emMinor = createElementEcapi(document, "Minor");
        emMinor.appendChild(document.createTextNode(initializeFrameworkResponse.getVersion().getMinor().toString()));
        emVersion.appendChild(emMinor);
        Element emSubMinor = createElementEcapi(document, "SubMinor");
        emSubMinor.appendChild(document.createTextNode(initializeFrameworkResponse.getVersion().getSubMinor().toString()));
        emVersion.appendChild(emSubMinor);
        rootElement.appendChild(emVersion);
    } else if (o instanceof InternationalStringType) {
        InternationalStringType internationalStringType = (InternationalStringType) o;
        rootElement = marshalInternationStringType(internationalStringType, document, internationalStringType.getClass().getSimpleName());
    } else if (o instanceof Result) {
        Result r = (Result) o;
        rootElement = marshalResult(r, document);
    } else if (o instanceof iso.std.iso_iec._24727.tech.schema.StartPAOS) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        StartPAOS startPAOS = (StartPAOS) o;
        Element em = createElementIso(document, "SessionIdentifier");
        em.appendChild(document.createTextNode(startPAOS.getSessionIdentifier()));
        rootElement.appendChild(em);
        rootElement.appendChild(marshalConnectionHandle(startPAOS.getConnectionHandle().get(0), document));
    } else if (o instanceof TransmitResponse) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        TransmitResponse transmitResponsePOJO = (TransmitResponse) o;
        Element em = marshalResult(transmitResponsePOJO.getResult(), document);
        rootElement.appendChild(em);
        for (int i = 0; i < transmitResponsePOJO.getOutputAPDU().size(); i++) {
            em = createElementIso(document, "OutputAPDU");
            em.appendChild(document.createTextNode(ByteUtils.toHexString(transmitResponsePOJO.getOutputAPDU().get(i))));
            rootElement.appendChild(em);
        }
    } else if (o instanceof EstablishContext) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
    } else if (o instanceof EstablishContextResponse) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        EstablishContextResponse establishContextResponse = (EstablishContextResponse) o;
        Element em = createElementIso(document, "ContextHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(establishContextResponse.getContextHandle())));
        rootElement.appendChild(em);
        em = marshalResult(establishContextResponse.getResult(), document);
        rootElement.appendChild(em);
    } else if (o instanceof GetStatus) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        GetStatus getStatus = (GetStatus) o;
        Element em = createElementIso(document, "ContextHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(getStatus.getContextHandle())));
        rootElement.appendChild(em);
        if (getStatus.getIFDName() != null) {
            em = createElementIso(document, "IFDName");
            em.appendChild(document.createTextNode(getStatus.getIFDName()));
            rootElement.appendChild(em);
        }
    } else if (o instanceof Wait) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        Wait w = (Wait) o;
        Element em = createElementIso(document, "ContextHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(w.getContextHandle())));
        rootElement.appendChild(em);
        if (w.getTimeOut() != null) {
            em = createElementIso(document, "TimeOut");
            em.appendChild(document.createTextNode(w.getTimeOut().toString(16)));
            rootElement.appendChild(em);
        }
        if (w.getCallback() != null) {
            ChannelHandleType callback = w.getCallback();
            em = createElementIso(document, "Callback");
            if (callback.getBinding() != null) {
                Element em2 = createElementIso(document, "Binding");
                em2.appendChild(document.createTextNode(callback.getBinding()));
                em.appendChild(em2);
            }
            if (callback.getSessionIdentifier() != null) {
                Element em2 = createElementIso(document, "SessionIdentifier");
                em2.appendChild(document.createTextNode(callback.getSessionIdentifier()));
                em.appendChild(em2);
            }
            if (callback.getProtocolTerminationPoint() != null) {
                Element em2 = createElementIso(document, "ProtocolTerminationPoint");
                em2.appendChild(document.createTextNode(callback.getProtocolTerminationPoint()));
                em.appendChild(em2);
            }
            if (callback.getPathSecurity() != null) {
                PathSecurityType pathSecurityType = callback.getPathSecurity();
                Element em2 = createElementIso(document, "PathSecurity");
                Element em3 = createElementIso(document, "Protocol");
                em3.appendChild(document.createTextNode(pathSecurityType.getProtocol()));
                em2.appendChild(em3);
                if (pathSecurityType.getParameters() != null) {
                    em3 = createElementIso(document, "Parameters");
                    em3.appendChild(document.createTextNode(pathSecurityType.getParameters().toString()));
                    em2.appendChild(em3);
                }
                em.appendChild(em2);
            }
            rootElement.appendChild(em);
        }
    } else if (o instanceof Connect) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        Connect c = (Connect) o;
        Element em = createElementIso(document, "ContextHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(c.getContextHandle())));
        rootElement.appendChild(em);
        em = createElementIso(document, "IFDName");
        em.appendChild(document.createTextNode(c.getIFDName()));
        rootElement.appendChild(em);
        em = createElementIso(document, "Slot");
        em.appendChild(document.createTextNode(c.getSlot().toString()));
        rootElement.appendChild(em);
        if (c.isExclusive() != null) {
            em = createElementIso(document, "Exclusive");
            em.appendChild(document.createTextNode(c.isExclusive().toString()));
            rootElement.appendChild(em);
        }
    } else if (o instanceof ConnectResponse) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        ConnectResponse cr = (ConnectResponse) o;
        Element em = createElementIso(document, "SlotHandle");
        if (cr.getSlotHandle() != null) {
            em.appendChild(document.createTextNode(ByteUtils.toHexString(cr.getSlotHandle())));
            rootElement.appendChild(em);
        }
        em = marshalResult(cr.getResult(), document);
        rootElement.appendChild(em);
    } else if (o instanceof ListIFDs) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        ListIFDs c = (ListIFDs) o;
        Element em = createElementIso(document, "ContextHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(c.getContextHandle())));
        rootElement.appendChild(em);
    } else if (o instanceof ListIFDsResponse) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        ListIFDsResponse listIFDsResponse = (ListIFDsResponse) o;
        for (String s : listIFDsResponse.getIFDName()) {
            Element em = createElementIso(document, "IFDName");
            em.appendChild(document.createTextNode(s));
            rootElement.appendChild(em);
        }
        Element em = marshalResult(listIFDsResponse.getResult(), document);
        rootElement.appendChild(em);
    } else if (o instanceof Transmit) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        rootElement.setAttribute("xmlns:iso", "urn:iso:std:iso-iec:24727:tech:schema");
        Transmit t = (Transmit) o;
        Element em = createElementIso(document, "SlotHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(t.getSlotHandle())));
        rootElement.appendChild(em);
        for (int i = 0; i < t.getInputAPDUInfo().size(); i++) {
            em = createElementIso(document, "InputAPDUInfo");
            rootElement.appendChild(em);
            Element em2 = createElementIso(document, "InputAPDU");
            em2.appendChild(document.createTextNode(ByteUtils.toHexString(t.getInputAPDUInfo().get(i).getInputAPDU())));
            em.appendChild(em2);
            for (int y = 0; y < t.getInputAPDUInfo().get(i).getAcceptableStatusCode().size(); y++) {
                em2 = createElementIso(document, "AcceptableStatusCode");
                em2.appendChild(document.createTextNode(ByteUtils.toHexString(t.getInputAPDUInfo().get(i).getAcceptableStatusCode().get(y))));
                em.appendChild(em2);
            }
        }
    } else if (o instanceof RecognitionTree) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        RecognitionTree recognitionTree = (RecognitionTree) o;
        for (CardCall c : recognitionTree.getCardCall()) {
            rootElement.appendChild(marshalCardCall(c, document));
        }
    } else if (o instanceof CardCall) {
        CardCall c = (CardCall) o;
        rootElement = (Element) marshalCardCall(c, document);
    } else if (o instanceof Disconnect) {
        Disconnect d = (Disconnect) o;
        rootElement = createElementIso(document, d.getClass().getSimpleName());
        Element em = createElementIso(document, "SlotHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(d.getSlotHandle())));
        rootElement.appendChild(em);
        if (d.getAction() != null) {
            em = createElementIso(document, "Action");
            em.appendChild(document.createTextNode(d.getAction().value()));
        }
    } else if (o instanceof DisconnectResponse) {
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        DisconnectResponse response = (DisconnectResponse) o;
        String profile = response.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = response.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
        Element emResult = marshalResult(response.getResult(), document);
        rootElement.appendChild(emResult);
    } else if (o instanceof GetIFDCapabilities) {
        GetIFDCapabilities getIFDCapabilities = (GetIFDCapabilities) o;
        rootElement = createElementIso(document, o.getClass().getSimpleName());
        Element emContextHandle = createElementIso(document, "ContextHandle");
        emContextHandle.appendChild(document.createTextNode(ByteUtils.toHexString(getIFDCapabilities.getContextHandle())));
        rootElement.appendChild(emContextHandle);
        Element emIFDName = createElementIso(document, "IFDName");
        emIFDName.appendChild(document.createTextNode(getIFDCapabilities.getIFDName()));
        rootElement.appendChild(emIFDName);
    } else if (o instanceof GetIFDCapabilitiesResponse) {
        try {
            GetIFDCapabilitiesResponse response = (GetIFDCapabilitiesResponse) o;
            rootElement = createElementIso(document, o.getClass().getSimpleName());
            String profile = response.getProfile();
            if (profile != null) {
                Element emProfile = createElementIso(document, "Profile");
                emProfile.appendChild(document.createTextNode(profile));
                rootElement.appendChild(emProfile);
            }
            String requestID = response.getRequestID();
            if (requestID != null) {
                Element emRequest = createElementIso(document, "RequestID");
                emRequest.appendChild(document.createElement(requestID));
                rootElement.appendChild(emRequest);
            }
            Element emResult = marshalResult(response.getResult(), document);
            rootElement.appendChild(emResult);
            if (response.getIFDCapabilities() != null) {
                Element emIFDCaps = marshalIFDCapabilities(response.getIFDCapabilities(), document);
                rootElement.appendChild(emIFDCaps);
            }
        } catch (Exception ex) {
            LOG.error(ex.getMessage(), ex);
        }
    } else if (o instanceof TCTokenType) {
        TCTokenType tctoken = (TCTokenType) o;
        rootElement = document.createElement(o.getClass().getSimpleName());
        Element em = document.createElement("ServerAddress");
        em.appendChild(document.createTextNode(tctoken.getServerAddress()));
        rootElement.appendChild(em);
        em = document.createElement("SessionIdentifier");
        em.appendChild(document.createTextNode(tctoken.getSessionIdentifier()));
        rootElement.appendChild(em);
        em = document.createElement("RefreshAddress");
        em.appendChild(document.createTextNode(tctoken.getRefreshAddress()));
        rootElement.appendChild(em);
        // Optional element CommunicationErrorAddress
        String communicationErrorAddress = tctoken.getCommunicationErrorAddress();
        if (communicationErrorAddress != null) {
            em = document.createElement("CommunicationErrorAddress");
            em.appendChild(document.createTextNode(tctoken.getCommunicationErrorAddress()));
            rootElement.appendChild(em);
        }
        em = document.createElement("Binding");
        em.appendChild(document.createTextNode(tctoken.getBinding()));
        rootElement.appendChild(em);
        // Optional element PathSecurity-Protocol
        String pathSecurityProtocol = tctoken.getPathSecurityProtocol();
        if (pathSecurityProtocol != null) {
            em = document.createElement("PathSecurity-Protocol");
            em.appendChild(document.createTextNode(tctoken.getPathSecurityProtocol()));
            rootElement.appendChild(em);
        }
        // Optional element PathSecurity-Parameters
        TCTokenType.PathSecurityParameters pathSecurityParameters = tctoken.getPathSecurityParameters();
        if (pathSecurityParameters != null) {
            em = document.createElement("PSK");
            em.appendChild(document.createTextNode(ByteUtils.toHexString(pathSecurityParameters.getPSK())));
            Element em1 = document.createElement("PathSecurity-Parameters");
            em1.appendChild(em);
            rootElement.appendChild(em1);
        }
    } else if (o instanceof CardApplicationPath) {
        CardApplicationPath p = (CardApplicationPath) o;
        rootElement = createElementIso(document, "CardApplicationPath");
        Element em = createElementIso(document, "CardAppPathRequest");
        String profile = p.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = p.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
        // ChannelHandle
        ChannelHandleType h = p.getCardAppPathRequest().getChannelHandle();
        Element emChild = createElementIso(document, "ChannelHandle");
        em.appendChild(emChild);
        Element emChildOfCH;
        if (h.getProtocolTerminationPoint() != null) {
            emChildOfCH = createElementIso(document, "ProtocolTerminationPoint");
            emChildOfCH.appendChild(document.createTextNode(h.getProtocolTerminationPoint()));
            emChild.appendChild(emChildOfCH);
        }
        if (h.getSessionIdentifier() != null) {
            emChildOfCH = createElementIso(document, "SessionIdentifier");
            emChildOfCH.appendChild(document.createTextNode(h.getSessionIdentifier()));
            emChild.appendChild(emChildOfCH);
        }
        if (h.getBinding() != null) {
            emChildOfCH = createElementIso(document, "Binding");
            emChildOfCH.appendChild(document.createTextNode(h.getBinding()));
            emChild.appendChild(emChildOfCH);
        }
        PathSecurityType ps = h.getPathSecurity();
        if (ps != null) {
            emChildOfCH = createElementIso(document, "PathSecurity");
            Element emChildOfPS = createElementIso(document, "Protocol");
            emChildOfPS.appendChild(document.createTextNode(ps.getProtocol()));
            emChildOfCH.appendChild(emChildOfPS);
            // TODO here any type parsen
            LOG.error("AnyType of CardApplicationPath: " + ps.getParameters().toString());
            emChild.appendChild(emChildOfCH);
        }
        // context handle
        emChild = createElementIso(document, "ContextHandle");
        emChild.appendChild(document.createTextNode(ByteUtils.toHexString(p.getCardAppPathRequest().getContextHandle())));
        em.appendChild(emChild);
        // IFDName
        emChild = createElementIso(document, "IFDName");
        emChild.appendChild(document.createTextNode(p.getCardAppPathRequest().getIFDName()));
        em.appendChild(emChild);
        // SlotIndex
        emChild = createElementIso(document, "SlotIndex");
        emChild.appendChild(document.createTextNode(p.getCardAppPathRequest().getSlotIndex().toString()));
        em.appendChild(emChild);
        // Card Application
        emChild = createElementIso(document, "CardApplication");
        emChild.appendChild(document.createTextNode(ByteUtils.toHexString(p.getCardAppPathRequest().getCardApplication())));
        em.appendChild(emChild);
        rootElement.appendChild(em);
    } else if (o instanceof CardApplicationPathResponse) {
        CardApplicationPathResponse resp = (CardApplicationPathResponse) o;
        rootElement = createElementIso(document, "CardApplicationPathResponse");
        String profile = resp.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = resp.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
        Result result = resp.getResult();
        if (result != null) {
            Element emResult = marshalResult(resp.getResult(), document);
            rootElement.appendChild(emResult);
        }
        Element em = createElementIso(document, "CardAppPathResultSet");
        for (CardApplicationPathType path : resp.getCardAppPathResultSet().getCardApplicationPathResult()) {
            em.appendChild(marshalCardApplicationPathResult(path, document, "CardAppPathRequest"));
        }
        rootElement.appendChild(em);
    } else if (o instanceof BeginTransaction) {
        BeginTransaction t = (BeginTransaction) o;
        rootElement = createElementIso(document, "BeginTransaction");
        Element em = createElementIso(document, "SlotHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(t.getSlotHandle())));
        rootElement.appendChild(em);
    } else if (o instanceof BeginTransactionResponse) {
        BeginTransactionResponse response = (BeginTransactionResponse) o;
        rootElement = createElementIso(document, "BeginTransactionResponse");
        String profile = response.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = response.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
        Element emResult = marshalResult(response.getResult(), document);
        rootElement.appendChild(emResult);
    } else if (o instanceof EndTransaction) {
        EndTransaction end = (EndTransaction) o;
        rootElement = createElementIso(document, "EndTransaction");
        Element em = createElementIso(document, "SlotHandle");
        em.appendChild(document.createTextNode(ByteUtils.toHexString(end.getSlotHandle())));
        rootElement.appendChild(em);
    } else if (o instanceof EndTransactionResponse) {
        EndTransactionResponse response = (EndTransactionResponse) o;
        rootElement = createElementIso(document, "EndTransactionResponse");
        String profile = response.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = response.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
        Element emResult = marshalResult(response.getResult(), document);
        rootElement.appendChild(emResult);
    } else if (o instanceof CardApplicationConnect) {
        CardApplicationConnect c = (CardApplicationConnect) o;
        rootElement = createElementIso(document, "CardApplicationConnect");
        // Card Application Path
        rootElement.appendChild(marshalCardApplicationPathResult(c.getCardApplicationPath(), document, "CardApplicationPath"));
        Element em;
        if (c.getOutput() != null) {
            em = createElementIso(document, "Output");
            em.appendChild(marshalOutput(c.getOutput(), document));
            rootElement.appendChild(em);
        }
        // Exclusive Use
        if (c.isExclusiveUse() != null) {
            em = createElementIso(document, "ExclusiveUse");
            em.appendChild(document.createTextNode(Boolean.toString(c.isExclusiveUse())));
            rootElement.appendChild(em);
        }
    } else if (o instanceof CardApplicationConnectResponse) {
        CardApplicationConnectResponse resp = (CardApplicationConnectResponse) o;
        rootElement = createElementIso(document, "CardApplicationConnectResponse");
        appendResponseValues(resp.getProfile(), resp.getRequestID(), resp.getResult(), rootElement, document);
        ConnectionHandleType ch = resp.getConnectionHandle();
        if (ch != null) {
            Element em = marshalConnectionHandle(ch, document);
            rootElement.appendChild(em);
        }
    } else if (o instanceof CardApplicationDisconnect) {
        CardApplicationDisconnect c = (CardApplicationDisconnect) o;
        rootElement = createElementIso(document, "CardApplicationDisconnect");
        if (c.getConnectionHandle() != null) {
            rootElement.appendChild(marshalConnectionHandle(c.getConnectionHandle(), document));
        }
        if (c.getAction() != null) {
            Element em = createElementIso(document, "Action");
            em.appendChild(document.createTextNode(c.getAction().value()));
            rootElement.appendChild(em);
        }
        String profile = c.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = c.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
    } else if (o instanceof CardApplicationDisconnectResponse) {
        CardApplicationDisconnectResponse response = (CardApplicationDisconnectResponse) o;
        rootElement = createElementIso(document, "CardApplicationDisconnectResponse");
        String profile = response.getProfile();
        if (profile != null) {
            Element emProfile = createElementIso(document, "Profile");
            emProfile.appendChild(document.createTextNode(profile));
            rootElement.appendChild(emProfile);
        }
        String requestID = response.getRequestID();
        if (requestID != null) {
            Element emRequest = createElementIso(document, "RequestID");
            emRequest.appendChild(document.createElement(requestID));
            rootElement.appendChild(emRequest);
        }
        if (response.getResult() != null) {
            Element emResult = marshalResult(response.getResult(), document);
            rootElement.appendChild(emResult);
        }
    } else {
        throw new IllegalArgumentException("Cannot marshal " + o.getClass().getSimpleName());
    }
    document.appendChild(rootElement);
    return document;
}
Also used : TCTokenType(generated.TCTokenType) ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) MarshallingTypeException(org.openecard.ws.marshal.MarshallingTypeException) LocalizedString(org.openecard.addon.manifest.LocalizedString) ChannelHandleType(iso.std.iso_iec._24727.tech.schema.ChannelHandleType) Document(org.w3c.dom.Document) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) StreamResult(javax.xml.transform.stream.StreamResult) Result(oasis.names.tc.dss._1_0.core.schema.Result) GetIFDCapabilities(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilities) BeginTransaction(iso.std.iso_iec._24727.tech.schema.BeginTransaction) PathSecurityType(iso.std.iso_iec._24727.tech.schema.PathSecurityType) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus) EndTransaction(iso.std.iso_iec._24727.tech.schema.EndTransaction) CardApplicationPathResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationPathResponse) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) CardApplicationConnect(iso.std.iso_iec._24727.tech.schema.CardApplicationConnect) Connect(iso.std.iso_iec._24727.tech.schema.Connect) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) DestroyChannelResponse(iso.std.iso_iec._24727.tech.schema.DestroyChannelResponse) BeginTransactionResponse(iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) EAC2InputType(iso.std.iso_iec._24727.tech.schema.EAC2InputType) GetIFDCapabilitiesResponse(iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse) Wait(iso.std.iso_iec._24727.tech.schema.Wait) Map(java.util.Map) EAC2OutputType(iso.std.iso_iec._24727.tech.schema.EAC2OutputType) ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) ConnectResponse(iso.std.iso_iec._24727.tech.schema.ConnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) EndTransactionResponse(iso.std.iso_iec._24727.tech.schema.EndTransactionResponse) EAC1OutputType(iso.std.iso_iec._24727.tech.schema.EAC1OutputType) CardApplicationPathType(iso.std.iso_iec._24727.tech.schema.CardApplicationPathType) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) Disconnect(iso.std.iso_iec._24727.tech.schema.Disconnect) CardApplicationDisconnect(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect) DisconnectResponse(iso.std.iso_iec._24727.tech.schema.DisconnectResponse) CardApplicationDisconnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) EAC1InputType(iso.std.iso_iec._24727.tech.schema.EAC1InputType) RecognitionTree(iso.std.iso_iec._24727.tech.schema.RecognitionTree) DIDAuthenticate(iso.std.iso_iec._24727.tech.schema.DIDAuthenticate) Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) QName(javax.xml.namespace.QName) CardApplicationDisconnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnectResponse) CardApplicationConnectResponse(iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse) InternationalStringType(oasis.names.tc.dss._1_0.core.schema.InternationalStringType) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) MarshallingTypeException(org.openecard.ws.marshal.MarshallingTypeException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) RuntimeCryptoException(org.openecard.bouncycastle.crypto.RuntimeCryptoException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SOAPException(org.openecard.ws.soap.SOAPException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DIDAuthenticateResponse(iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse) CardApplicationPath(iso.std.iso_iec._24727.tech.schema.CardApplicationPath) InitializeFrameworkResponse(de.bund.bsi.ecard.api._1.InitializeFrameworkResponse) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse) CardCall(iso.std.iso_iec._24727.tech.schema.CardCall)

Example 5 with TransmitResponse

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

the class PACEStep method perform.

@Override
public DIDAuthenticateResponse perform(DIDAuthenticate request, Map<String, Object> internalData) {
    // get context to save values in
    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    DIDAuthenticate didAuthenticate = request;
    DIDAuthenticateResponse response = new DIDAuthenticateResponse();
    ConnectionHandleType conHandle = (ConnectionHandleType) dynCtx.get(TR03112Keys.CONNECTION_HANDLE);
    try {
        ObjectSchemaValidator valid = (ObjectSchemaValidator) dynCtx.getPromise(EACProtocol.SCHEMA_VALIDATOR).deref();
        boolean messageValid = valid.validateObject(request);
        if (!messageValid) {
            String msg = "Validation of the EAC1InputType message failed.";
            LOG.error(msg);
            dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
            response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM, msg));
            return response;
        }
    } catch (ObjectValidatorException ex) {
        String msg = "Validation of the EAC1InputType message failed due to invalid input data.";
        LOG.error(msg, ex);
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg));
        return response;
    } catch (InterruptedException ex) {
        String msg = "Thread interrupted while waiting for schema validator instance.";
        LOG.error(msg, ex);
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg));
        return response;
    }
    if (!ByteUtils.compare(conHandle.getSlotHandle(), didAuthenticate.getConnectionHandle().getSlotHandle())) {
        String msg = "Invalid connection handle given in DIDAuthenticate message.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.SAL.UNKNOWN_HANDLE, msg);
        response.setResult(r);
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
        return response;
    }
    byte[] slotHandle = conHandle.getSlotHandle();
    dynCtx.put(EACProtocol.SLOT_HANDLE, slotHandle);
    dynCtx.put(EACProtocol.DISPATCHER, dispatcher);
    try {
        EAC1InputType eac1Input = new EAC1InputType(didAuthenticate.getAuthenticationProtocolData());
        EAC1OutputType eac1Output = eac1Input.getOutputType();
        AuthenticatedAuxiliaryData aad = new AuthenticatedAuxiliaryData(eac1Input.getAuthenticatedAuxiliaryData());
        byte pinID = PasswordID.valueOf(didAuthenticate.getDIDName()).getByte();
        final String passwordType = PasswordID.parse(pinID).getString();
        // determine PACE capabilities of the terminal
        boolean nativePace = genericPACESupport(conHandle);
        dynCtx.put(EACProtocol.IS_NATIVE_PACE, nativePace);
        // Certificate chain
        CardVerifiableCertificateChain certChain = new CardVerifiableCertificateChain(eac1Input.getCertificates());
        byte[] rawCertificateDescription = eac1Input.getCertificateDescription();
        CertificateDescription certDescription = CertificateDescription.getInstance(rawCertificateDescription);
        // put CertificateDescription into DynamicContext which is needed for later checks
        dynCtx.put(TR03112Keys.ESERVICE_CERTIFICATE_DESC, certDescription);
        // according to BSI-INSTANCE_KEY-7 we MUST perform some checks immediately after receiving the eService cert
        Result activationChecksResult = performChecks(certDescription, dynCtx);
        if (!ECardConstants.Major.OK.equals(activationChecksResult.getResultMajor())) {
            response.setResult(activationChecksResult);
            dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
            return response;
        }
        CHAT requiredCHAT = new CHAT(eac1Input.getRequiredCHAT());
        CHAT optionalCHAT = new CHAT(eac1Input.getOptionalCHAT());
        // get the PACEMarker
        CardStateEntry cardState = (CardStateEntry) internalData.get(EACConstants.IDATA_CARD_STATE_ENTRY);
        PACEMarkerType paceMarker = getPaceMarker(cardState, passwordType);
        dynCtx.put(EACProtocol.PACE_MARKER, paceMarker);
        // Verify that the certificate description matches the terminal certificate
        CardVerifiableCertificate taCert = certChain.getTerminalCertificate();
        CardVerifiableCertificateVerifier.verify(taCert, certDescription);
        // Verify that the required CHAT matches the terminal certificate's CHAT
        CHAT taCHAT = taCert.getCHAT();
        // an other role.
        if (taCHAT.getRole() != CHAT.Role.AUTHENTICATION_TERMINAL) {
            String msg = "Unsupported terminal type in Terminal Certificate referenced. Refernced terminal type is " + taCHAT.getRole().toString() + ".";
            response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM, msg));
            dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
            return response;
        }
        CHATVerifier.verfiy(taCHAT, requiredCHAT);
        // remove overlapping values from optional chat
        optionalCHAT.restrictAccessRights(taCHAT);
        // Prepare data in DIDAuthenticate for GUI
        final EACData eacData = new EACData();
        eacData.didRequest = didAuthenticate;
        eacData.certificate = certChain.getTerminalCertificate();
        eacData.certificateDescription = certDescription;
        eacData.rawCertificateDescription = rawCertificateDescription;
        eacData.transactionInfo = eac1Input.getTransactionInfo();
        eacData.requiredCHAT = requiredCHAT;
        eacData.optionalCHAT = optionalCHAT;
        eacData.selectedCHAT = requiredCHAT;
        eacData.aad = aad;
        eacData.pinID = pinID;
        eacData.passwordType = passwordType;
        dynCtx.put(EACProtocol.EAC_DATA, eacData);
        // get initial pin status
        InputAPDUInfoType input = new InputAPDUInfoType();
        input.setInputAPDU(new byte[] { (byte) 0x00, (byte) 0x22, (byte) 0xC1, (byte) 0xA4, (byte) 0x0F, (byte) 0x80, (byte) 0x0A, (byte) 0x04, (byte) 0x00, (byte) 0x7F, (byte) 0x00, (byte) 0x07, (byte) 0x02, (byte) 0x02, (byte) 0x04, (byte) 0x02, (byte) 0x02, (byte) 0x83, (byte) 0x01, (byte) 0x03 });
        input.getAcceptableStatusCode().addAll(EacPinStatus.getCodes());
        Transmit transmit = new Transmit();
        transmit.setSlotHandle(slotHandle);
        transmit.getInputAPDUInfo().add(input);
        TransmitResponse pinCheckResponse = (TransmitResponse) dispatcher.safeDeliver(transmit);
        WSHelper.checkResult(pinCheckResponse);
        byte[] output = pinCheckResponse.getOutputAPDU().get(0);
        CardResponseAPDU outputApdu = new CardResponseAPDU(output);
        byte[] status = outputApdu.getStatusBytes();
        dynCtx.put(EACProtocol.PIN_STATUS, EacPinStatus.fromCode(status));
        // define GUI depending on the PIN status
        final UserConsentDescription uc = new UserConsentDescription(LANG.translationForKey(TITLE));
        final CardMonitor cardMon;
        uc.setDialogType("EAC");
        // create GUI and init executor
        cardMon = new CardMonitor();
        CardRemovedFilter filter = new CardRemovedFilter(conHandle.getIFDName(), conHandle.getSlotIndex());
        eventDispatcher.add(cardMon, filter);
        CVCStep cvcStep = new CVCStep(eacData);
        cvcStep.setBackgroundTask(cardMon);
        CVCStepAction cvcStepAction = new CVCStepAction(cvcStep);
        cvcStep.setAction(cvcStepAction);
        uc.getSteps().add(cvcStep);
        uc.getSteps().add(CHATStep.createDummy());
        uc.getSteps().add(PINStep.createDummy(passwordType));
        ProcessingStep procStep = new ProcessingStep();
        ProcessingStepAction procStepAction = new ProcessingStepAction(procStep);
        procStep.setAction(procStepAction);
        uc.getSteps().add(procStep);
        Thread guiThread = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    // get context here because it is thread local
                    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
                    if (!uc.getSteps().isEmpty()) {
                        UserConsentNavigator navigator = gui.obtainNavigator(uc);
                        dynCtx.put(TR03112Keys.OPEN_USER_CONSENT_NAVIGATOR, navigator);
                        ExecutionEngine exec = new ExecutionEngine(navigator);
                        ResultStatus guiResult = exec.process();
                        dynCtx.put(EACProtocol.GUI_RESULT, guiResult);
                        if (guiResult == ResultStatus.CANCEL) {
                            Promise<Object> pPaceSuccessful = dynCtx.getPromise(EACProtocol.PACE_EXCEPTION);
                            if (!pPaceSuccessful.isDelivered()) {
                                pPaceSuccessful.deliver(WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER, "User canceled the PACE dialog.")));
                            }
                        }
                    }
                } finally {
                    if (cardMon != null) {
                        eventDispatcher.del(cardMon);
                    }
                }
            }
        }, "EAC-GUI");
        guiThread.start();
        // wait for PACE to finish
        Promise<Object> pPaceException = dynCtx.getPromise(EACProtocol.PACE_EXCEPTION);
        Object pPaceError = pPaceException.deref();
        if (pPaceError != null) {
            if (pPaceError instanceof WSHelper.WSException) {
                response.setResult(((WSHelper.WSException) pPaceError).getResult());
                return response;
            } else if (pPaceError instanceof DispatcherException | pPaceError instanceof InvocationTargetException) {
                String msg = "Internal error while PACE authentication.";
                Result r = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg);
                response.setResult(r);
                return response;
            } else {
                String msg = "Unknown error while PACE authentication.";
                Result r = WSHelper.makeResultError(ECardConstants.Minor.App.UNKNOWN_ERROR, msg);
                response.setResult(r);
                return response;
            }
        }
        // get challenge from card
        TerminalAuthentication ta = new TerminalAuthentication(dispatcher, slotHandle);
        byte[] challenge = ta.getChallenge();
        // prepare DIDAuthenticationResponse
        DIDAuthenticationDataType data = eacData.paceResponse.getAuthenticationProtocolData();
        AuthDataMap paceOutputMap = new AuthDataMap(data);
        // int retryCounter = Integer.valueOf(paceOutputMap.getContentAsString(PACEOutputType.RETRY_COUNTER));
        byte[] efCardAccess = paceOutputMap.getContentAsBytes(PACEOutputType.EF_CARD_ACCESS);
        byte[] currentCAR = paceOutputMap.getContentAsBytes(PACEOutputType.CURRENT_CAR);
        byte[] previousCAR = paceOutputMap.getContentAsBytes(PACEOutputType.PREVIOUS_CAR);
        byte[] idpicc = paceOutputMap.getContentAsBytes(PACEOutputType.ID_PICC);
        // Store SecurityInfos
        SecurityInfos securityInfos = SecurityInfos.getInstance(efCardAccess);
        internalData.put(EACConstants.IDATA_SECURITY_INFOS, securityInfos);
        // Store additional data
        internalData.put(EACConstants.IDATA_AUTHENTICATED_AUXILIARY_DATA, aad);
        internalData.put(EACConstants.IDATA_CERTIFICATES, certChain);
        internalData.put(EACConstants.IDATA_CURRENT_CAR, currentCAR);
        internalData.put(EACConstants.IDATA_PREVIOUS_CAR, previousCAR);
        internalData.put(EACConstants.IDATA_CHALLENGE, challenge);
        // Create response
        // eac1Output.setRetryCounter(retryCounter);
        eac1Output.setCHAT(eacData.selectedCHAT.toByteArray());
        eac1Output.setCurrentCAR(currentCAR);
        eac1Output.setPreviousCAR(previousCAR);
        eac1Output.setEFCardAccess(efCardAccess);
        eac1Output.setIDPICC(idpicc);
        eac1Output.setChallenge(challenge);
        response.setResult(WSHelper.makeResultOK());
        response.setAuthenticationProtocolData(eac1Output.getAuthDataType());
    } catch (CertificateException ex) {
        LOG.error(ex.getMessage(), ex);
        String msg = ex.getMessage();
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.EAC.DOC_VALID_FAILED, msg));
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
    } catch (WSHelper.WSException e) {
        LOG.error(e.getMessage(), e);
        response.setResult(e.getResult());
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
    } catch (ElementParsingException ex) {
        LOG.error(ex.getMessage(), ex);
        response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM, ex.getMessage()));
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
        dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
    }
    return response;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) PACEMarkerType(org.openecard.sal.protocol.eac.anytype.PACEMarkerType) ProcessingStepAction(org.openecard.sal.protocol.eac.gui.ProcessingStepAction) CertificateException(java.security.cert.CertificateException) CardMonitor(org.openecard.sal.protocol.eac.gui.CardMonitor) UserConsentNavigator(org.openecard.gui.UserConsentNavigator) Result(oasis.names.tc.dss._1_0.core.schema.Result) ObjectValidatorException(org.openecard.common.interfaces.ObjectValidatorException) ObjectSchemaValidator(org.openecard.common.interfaces.ObjectSchemaValidator) UserConsentDescription(org.openecard.gui.definition.UserConsentDescription) DispatcherException(org.openecard.common.interfaces.DispatcherException) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) InvocationTargetException(java.lang.reflect.InvocationTargetException) Promise(org.openecard.common.util.Promise) ExecutionEngine(org.openecard.gui.executor.ExecutionEngine) AuthenticatedAuxiliaryData(org.openecard.crypto.common.asn1.eac.AuthenticatedAuxiliaryData) CardVerifiableCertificate(org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate) AuthDataMap(org.openecard.common.anytype.AuthDataMap) CVCStepAction(org.openecard.sal.protocol.eac.gui.CVCStepAction) DynamicContext(org.openecard.common.DynamicContext) CardRemovedFilter(org.openecard.sal.protocol.eac.gui.CardRemovedFilter) CardStateEntry(org.openecard.common.sal.state.CardStateEntry) CVCStep(org.openecard.sal.protocol.eac.gui.CVCStep) CHAT(org.openecard.crypto.common.asn1.cvc.CHAT) InputAPDUInfoType(iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType) ElementParsingException(org.openecard.sal.protocol.eac.anytype.ElementParsingException) EAC1OutputType(org.openecard.sal.protocol.eac.anytype.EAC1OutputType) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) CardVerifiableCertificateChain(org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificateChain) EAC1InputType(org.openecard.sal.protocol.eac.anytype.EAC1InputType) WSHelper(org.openecard.common.WSHelper) DIDAuthenticate(iso.std.iso_iec._24727.tech.schema.DIDAuthenticate) Transmit(iso.std.iso_iec._24727.tech.schema.Transmit) ResultStatus(org.openecard.gui.ResultStatus) SecurityInfos(org.openecard.crypto.common.asn1.eac.SecurityInfos) CertificateDescription(org.openecard.crypto.common.asn1.cvc.CertificateDescription) ProcessingStep(org.openecard.sal.protocol.eac.gui.ProcessingStep) DispatcherException(org.openecard.common.interfaces.DispatcherException) ObjectValidatorException(org.openecard.common.interfaces.ObjectValidatorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ElementParsingException(org.openecard.sal.protocol.eac.anytype.ElementParsingException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) DIDAuthenticateResponse(iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse) TransmitResponse(iso.std.iso_iec._24727.tech.schema.TransmitResponse)

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