Search in sources :

Example 1 with PinCompareMarkerType

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

the class CIFCreator method createPinDID.

private DIDInfoType createPinDID() throws WSMarshallerException {
    LOG.debug("Creating PinCompare DID object.");
    DIDInfoType di = new DIDInfoType();
    // create differential identity
    DifferentialIdentityType did = new DifferentialIdentityType();
    di.setDifferentialIdentity(did);
    String didName = PIN_NAME;
    did.setDIDName(didName);
    did.setDIDProtocol("urn:oid:1.3.162.15480.3.0.9");
    did.setDIDScope(DIDScopeType.GLOBAL);
    // create pin compare marker
    PinMarkerBuilder markerBuilder = new PinMarkerBuilder();
    KeyRefType kr = new KeyRefType();
    // value is irrelevant
    kr.setKeyRef(new byte[] { 0x01 });
    markerBuilder.setPinRef(kr);
    try {
        PasswordAttributesType pw = new PasswordAttributesType();
        MwToken tok = session.getSlot().getTokenInfo();
        long minPinLen = tok.getUlMinPinLen();
        long maxPinLen = tok.getUlMinPinLen();
        pw.setMinLength(BigInteger.valueOf(minPinLen));
        pw.setMaxLength(BigInteger.valueOf(maxPinLen));
        markerBuilder.setPwAttributes(pw);
    } catch (CryptokiException | NullPointerException ex) {
        LOG.warn("Unable to read min and max PIN length from middleware.");
    }
    // wrap pin compare marker and add to parent
    PinCompareMarkerType marker = markerBuilder.build();
    DIDMarkerType markerWrapper = new DIDMarkerType();
    markerWrapper.setPinCompareMarker(marker);
    did.setDIDMarker(markerWrapper);
    // create acl
    AccessControlListType acl = new AccessControlListType();
    di.setDIDACL(acl);
    List<AccessRuleType> rules = acl.getAccessRule();
    rules.add(createRuleTrue(AuthorizationServiceActionName.ACL_LIST));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_LIST));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_GET));
    rules.add(createRuleTrue(DifferentialIdentityServiceActionName.DID_AUTHENTICATE));
    return di;
}
Also used : KeyRefType(iso.std.iso_iec._24727.tech.schema.KeyRefType) PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType) AccessControlListType(iso.std.iso_iec._24727.tech.schema.AccessControlListType) PinMarkerBuilder(org.openecard.mdlw.sal.didfactory.PinMarkerBuilder) DIDMarkerType(iso.std.iso_iec._24727.tech.schema.DIDMarkerType) DifferentialIdentityType(iso.std.iso_iec._24727.tech.schema.DifferentialIdentityType) PinCompareMarkerType(iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType) DIDInfoType(iso.std.iso_iec._24727.tech.schema.DIDInfoType) CryptokiException(org.openecard.mdlw.sal.exceptions.CryptokiException) AccessRuleType(iso.std.iso_iec._24727.tech.schema.AccessRuleType)

Example 2 with PinCompareMarkerType

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

the class PinMarkerBuilder method build.

public PinCompareMarkerType build() {
    PinCompareMarkerType marker = new PinCompareMarkerType();
    marker.setProtocol(PROTOCOL);
    if (pinRef != null) {
        try {
            JAXBElement<KeyRefType> e;
            e = new JAXBElement<>(new QName(ISONS, "PinRef"), KeyRefType.class, pinRef);
            Document d = m.marshal(e);
            marker.getAny().add(d.getDocumentElement());
        } catch (MarshallingTypeException ex) {
            LOG.error("Failed to marshal PinRef element.", ex);
        }
    }
    if (pinValue != null) {
        try {
            JAXBElement<String> e;
            e = new JAXBElement<>(new QName(ISONS, "PinValue"), String.class, pinValue);
            Document d = m.marshal(e);
            marker.getAny().add(d.getDocumentElement());
        } catch (MarshallingTypeException ex) {
            LOG.error("Failed to marshal PinValue element.", ex);
        }
    }
    if (pwAttributes != null) {
        try {
            JAXBElement<PasswordAttributesType> e;
            e = new JAXBElement(new QName(ISONS, "PasswordAttributes"), PasswordAttributesType.class, pinRef);
            Document d = m.marshal(e);
            marker.getAny().add(d.getDocumentElement());
        } catch (MarshallingTypeException ex) {
            LOG.error("Failed to marshal PasswordAttributes element.", ex);
        }
    }
    return marker;
}
Also used : KeyRefType(iso.std.iso_iec._24727.tech.schema.KeyRefType) MarshallingTypeException(org.openecard.ws.marshal.MarshallingTypeException) PinCompareMarkerType(iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType) PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Document(org.w3c.dom.Document)

Example 3 with PinCompareMarkerType

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

the class AndroidMarshaller method parseDIDMarkerType.

private DIDMarkerType parseDIDMarkerType(XmlPullParser parser) throws XmlPullParserException, IOException {
    DIDMarkerType didMarker = new DIDMarkerType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("PACEMarker")) {
                didMarker.setPACEMarker((PACEMarkerType) this.parseMarker(parser, PACEMarkerType.class));
            } else if (parser.getName().equals("TAMarker")) {
                didMarker.setTAMarker((TAMarkerType) this.parseMarker(parser, TAMarkerType.class));
            } else if (parser.getName().equals("CAMarker")) {
                didMarker.setCAMarker((CAMarkerType) this.parseMarker(parser, CAMarkerType.class));
            } else if (parser.getName().equals("RIMarker")) {
                didMarker.setRIMarker((RIMarkerType) this.parseMarker(parser, RIMarkerType.class));
            } else if (parser.getName().equals("CryptoMarker")) {
                didMarker.setCryptoMarker((CryptoMarkerType) this.parseMarker(parser, CryptoMarkerType.class));
            } else if (parser.getName().equals("PinCompareMarker")) {
                didMarker.setPinCompareMarker((PinCompareMarkerType) this.parseMarker(parser, PinCompareMarkerType.class));
            } else if (parser.getName().equals("RSAAuthMarker")) {
                didMarker.setRSAAuthMarker((RSAAuthMarkerType) this.parseMarker(parser, RSAAuthMarkerType.class));
            } else if (parser.getName().equals("MutualAuthMarker")) {
                didMarker.setMutualAuthMarker((MutualAuthMarkerType) this.parseMarker(parser, MutualAuthMarkerType.class));
            } else if (parser.getName().equals("EACMarker")) {
                didMarker.setEACMarker((EACMarkerType) this.parseMarker(parser, EACMarkerType.class));
            } else {
                LOG.error(parser.getName() + " not yet implemented");
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("DIDMarker")));
    return didMarker;
}
Also used : DIDMarkerType(iso.std.iso_iec._24727.tech.schema.DIDMarkerType) RIMarkerType(iso.std.iso_iec._24727.tech.schema.RIMarkerType) PinCompareMarkerType(iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType) MutualAuthMarkerType(iso.std.iso_iec._24727.tech.schema.MutualAuthMarkerType) TAMarkerType(iso.std.iso_iec._24727.tech.schema.TAMarkerType)

Example 4 with PinCompareMarkerType

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

the class DIDAuthenticateStep method perform.

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

Example 5 with PinCompareMarkerType

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

the class PinCompareMarkerTypeTest method testPinCompareMarkerType.

/**
 * Simple test for PinCompareMarkerType. After getting the PinCompareMarker for the PIN.home DID in the the root
 * application we check if the get-methods return the expected values.
 *
 * @throws Exception when something in this test went unexpectedly wrong
 */
@Test
public void testPinCompareMarkerType() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(PinCompareMarkerType.class);
    Unmarshaller um = ctx.createUnmarshaller();
    InputStream res = getClass().getResourceAsStream("/anytype/pin/egk_pin_home_marker.xml");
    JAXBElement<PinCompareMarkerType> elem = um.unmarshal(new StreamSource(res), PinCompareMarkerType.class);
    PINCompareMarkerType pinCompareMarker = new PINCompareMarkerType(elem.getValue());
    assertEquals(pinCompareMarker.getPINRef().getKeyRef(), new byte[] { 0x02 });
    assertNull(pinCompareMarker.getPINValue());
    assertEquals(pinCompareMarker.getPasswordAttributes().getMaxLength(), new BigInteger("8"));
    assertEquals(pinCompareMarker.getProtocol(), ECardConstants.Protocol.PIN_COMPARE);
}
Also used : PinCompareMarkerType(iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) BigInteger(java.math.BigInteger) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.testng.annotations.Test)

Aggregations

PinCompareMarkerType (iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType)5 PasswordAttributesType (iso.std.iso_iec._24727.tech.schema.PasswordAttributesType)3 PINCompareMarkerType (org.openecard.common.anytype.pin.PINCompareMarkerType)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)2 DIDMarkerType (iso.std.iso_iec._24727.tech.schema.DIDMarkerType)2 DIDStructureType (iso.std.iso_iec._24727.tech.schema.DIDStructureType)2 KeyRefType (iso.std.iso_iec._24727.tech.schema.KeyRefType)2 BigInteger (java.math.BigInteger)2 ECardException (org.openecard.common.ECardException)2 PINCompareDIDAuthenticateInputType (org.openecard.common.anytype.pin.PINCompareDIDAuthenticateInputType)2 PINCompareDIDAuthenticateOutputType (org.openecard.common.anytype.pin.PINCompareDIDAuthenticateOutputType)2 CardStateEntry (org.openecard.common.sal.state.CardStateEntry)2 CryptokiException (org.openecard.mdlw.sal.exceptions.CryptokiException)2 Test (org.testng.annotations.Test)2 AccessControlListType (iso.std.iso_iec._24727.tech.schema.AccessControlListType)1 AccessRuleType (iso.std.iso_iec._24727.tech.schema.AccessRuleType)1 CardApplicationConnect (iso.std.iso_iec._24727.tech.schema.CardApplicationConnect)1 CardApplicationConnectResponse (iso.std.iso_iec._24727.tech.schema.CardApplicationConnectResponse)1 CardApplicationPath (iso.std.iso_iec._24727.tech.schema.CardApplicationPath)1