Search in sources :

Example 21 with DIDAuthenticationDataType

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

the class PUKStepAction method perform.

@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
    if (result.isBack()) {
        return new StepActionResult(StepActionResultStatus.BACK);
    }
    DIDAuthenticationDataType paceInput = new DIDAuthenticationDataType();
    paceInput.setProtocol(ECardConstants.Protocol.PACE);
    AuthDataMap tmp;
    try {
        tmp = new AuthDataMap(paceInput);
    } catch (ParserConfigurationException ex) {
        LOG.error("Failed to read empty Protocol data.", ex);
        return new StepActionResult(StepActionResultStatus.CANCEL);
    }
    AuthDataResponse paceInputMap = tmp.createResponse(paceInput);
    if (capturePin) {
        ExecutionResults executionResults = oldResults.get(getStepID());
        if (!verifyUserInput(executionResults)) {
            // TODO inform user that something with his input is wrong
            return new StepActionResult(StepActionResultStatus.REPEAT);
        } else {
            paceInputMap.addElement(PACEInputType.PIN, puk);
        }
    }
    paceInputMap.addElement(PACEInputType.PIN_ID, PIN_ID_PUK);
    // perform PACE by sending an EstablishChannel
    EstablishChannel establishChannel = new EstablishChannel();
    establishChannel.setSlotHandle(slotHandle);
    establishChannel.setAuthenticationProtocolData(paceInputMap.getResponse());
    establishChannel.getAuthenticationProtocolData().setProtocol(ECardConstants.Protocol.PACE);
    try {
        EstablishChannelResponse establishChannelResponse = (EstablishChannelResponse) dispatcher.safeDeliver(establishChannel);
        WSHelper.checkResult(establishChannelResponse);
        // pace was successfully performed, so get to the next step
        return new StepActionResult(StepActionResultStatus.NEXT);
    } catch (WSException ex) {
        LOG.info("Wrong PUK entered, trying again");
        // TODO update the step to inform the user that he entered the puk wrong
        return new StepActionResult(StepActionResultStatus.REPEAT);
    } finally {
        DestroyChannel destroyChannel = new DestroyChannel();
        destroyChannel.setSlotHandle(slotHandle);
        dispatcher.safeDeliver(destroyChannel);
    }
}
Also used : EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) DestroyChannel(iso.std.iso_iec._24727.tech.schema.DestroyChannel) AuthDataMap(org.openecard.common.anytype.AuthDataMap) ExecutionResults(org.openecard.gui.executor.ExecutionResults) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) WSException(org.openecard.common.WSHelper.WSException) AuthDataResponse(org.openecard.common.anytype.AuthDataResponse) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StepActionResult(org.openecard.gui.executor.StepActionResult)

Example 22 with DIDAuthenticationDataType

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

the class SchemaValidationTest method testDIDAuth.

@Test
public void testDIDAuth() throws JAXBException, SAXException, IOException, ObjectValidatorException, ParserConfigurationException {
    JAXBSchemaValidator validator;
    JAXBContext jc = JAXBContext.newInstance(DIDAuthenticate.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    InputStream dataStream = FileUtils.resolveResourceAsStream(SchemaValidationTest.class, "DIDAuthenticate.xml");
    DIDAuthenticate didAuth = (DIDAuthenticate) unmarshaller.unmarshal(dataStream);
    validator = JAXBSchemaValidator.load(didAuth.getClass(), "ISO24727-Protocols.xsd");
    Assert.assertEquals(validator.validateObject(didAuth), true);
    dataStream = FileUtils.resolveResourceAsStream(SchemaValidationTest.class, "DIDAuthenticate.xml");
    DIDAuthenticate didAuth2 = (DIDAuthenticate) unmarshaller.unmarshal(dataStream);
    DIDAuthenticationDataType authData = didAuth2.getAuthenticationProtocolData();
    DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFac.newDocumentBuilder();
    Document d = docBuilder.newDocument();
    Element sigElem = d.createElementNS("urn:iso:std:iso-iec:24727:tech:schema", "Signature");
    sigElem.setTextContent("1254786930AAD4A8");
    authData.getAny().add(sigElem);
    didAuth2.setAuthenticationProtocolData(authData);
    validator = JAXBSchemaValidator.load(didAuth2.getClass(), "ISO24727-Protocols.xsd");
    Assert.assertEquals(validator.validateObject(didAuth2), false);
}
Also used : DIDAuthenticate(iso.std.iso_iec._24727.tech.schema.DIDAuthenticate) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) DIDAuthenticationDataType(iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Document(org.w3c.dom.Document) Test(org.testng.annotations.Test)

Aggregations

DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)18 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)10 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)10 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)9 AuthDataMap (org.openecard.common.anytype.AuthDataMap)9 Document (org.w3c.dom.Document)9 Element (org.w3c.dom.Element)9 Result (oasis.names.tc.dss._1_0.core.schema.Result)8 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)8 ExecutionResults (org.openecard.gui.executor.ExecutionResults)8 DocumentBuilder (javax.xml.parsers.DocumentBuilder)7 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)7 Test (org.testng.annotations.Test)7 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)5 InternationalStringType (oasis.names.tc.dss._1_0.core.schema.InternationalStringType)5 PasswordField (org.openecard.gui.definition.PasswordField)5 DIDAuthenticate (iso.std.iso_iec._24727.tech.schema.DIDAuthenticate)4 EAC2OutputType (iso.std.iso_iec._24727.tech.schema.EAC2OutputType)4 ECardException (org.openecard.common.ECardException)3