Search in sources :

Example 6 with PasswordAttributesType

use of iso.std.iso_iec._24727.tech.schema.PasswordAttributesType 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 7 with PasswordAttributesType

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

the class GenericPINAction method create.

private static PasswordAttributesType create(boolean needsPadding, PasswordTypeType pwdType, int minLen, int storedLen, int maxLen) {
    PasswordAttributesType r = new PasswordAttributesType();
    r.setMinLength(BigInteger.valueOf(minLen));
    r.setStoredLength(BigInteger.valueOf(storedLen));
    r.setPwdType(pwdType);
    if (needsPadding) {
        r.getPwdFlags().add("needs-padding");
    }
    r.setMaxLength(BigInteger.valueOf(maxLen));
    return r;
}
Also used : PasswordAttributesType(iso.std.iso_iec._24727.tech.schema.PasswordAttributesType)

Example 8 with PasswordAttributesType

use of iso.std.iso_iec._24727.tech.schema.PasswordAttributesType 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 9 with PasswordAttributesType

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

the class PINUtils method encodePin.

public static byte[] encodePin(char[] rawPin, PasswordAttributesType attributes) throws UtilException {
    // extract attributes
    PasswordTypeType pwdType = attributes.getPwdType();
    int minLen = attributes.getMinLength().intValue();
    int maxLen = (attributes.getMaxLength() == null) ? 0 : attributes.getMaxLength().intValue();
    int storedLen = attributes.getStoredLength().intValue();
    boolean needsPadding = needsPadding(attributes);
    // check if padding is inferred
    byte padChar = getPadChar(attributes, needsPadding);
    // helper variables
    String encoding = "UTF-8";
    try {
        switch(pwdType) {
            case ASCII_NUMERIC:
                encoding = "US-ASCII";
            case UTF_8:
                byte[] textPin = encodeTextPin(encoding, rawPin, minLen, storedLen, maxLen, needsPadding, padChar);
                return textPin;
            case ISO_9564_1:
            case BCD:
            case HALF_NIBBLE_BCD:
                byte[] bcdPin = encodeBcdPin(pwdType, rawPin, minLen, storedLen, maxLen, needsPadding, padChar);
                return bcdPin;
            default:
                String msg = "Unsupported PIN encoding requested.";
                UtilException ex = new UtilException(ECardConstants.Minor.IFD.IO.UNKNOWN_PIN_FORMAT, msg);
                LOG.error(ex.getMessage(), ex);
                throw ex;
        }
    } catch (UnsupportedEncodingException ex) {
        throw new UtilException(ex);
    } catch (IOException ex) {
        throw new UtilException(ex);
    }
}
Also used : PasswordTypeType(iso.std.iso_iec._24727.tech.schema.PasswordTypeType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 10 with PasswordAttributesType

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

the class PINUtils method createPinMask.

public static byte[] createPinMask(PasswordAttributesType attributes) throws UtilException {
    // extract attributes
    PasswordTypeType pwdType = attributes.getPwdType();
    int minLen = attributes.getMinLength().intValue();
    int maxLen = (attributes.getMaxLength() == null) ? 0 : attributes.getMaxLength().intValue();
    int storedLen = attributes.getStoredLength().intValue();
    boolean needsPadding = needsPadding(attributes);
    // opt out if needs-padding is not on
    if (!needsPadding) {
        return new byte[0];
    }
    byte padChar = getPadChar(attributes, needsPadding);
    if (storedLen <= 0) {
        throw new UtilException("PIN mask can only be created when storage size is known.");
    }
    // they are all the same except half nibble which
    if (HALF_NIBBLE_BCD == pwdType) {
        padChar = (byte) (padChar | 0xF0);
    }
    byte[] mask = new byte[storedLen];
    Arrays.fill(mask, padChar);
    // iso needs a sligth correction
    if (ISO_9564_1 == pwdType) {
        mask[0] = 0x20;
    }
    return mask;
}
Also used : PasswordTypeType(iso.std.iso_iec._24727.tech.schema.PasswordTypeType)

Aggregations

PasswordAttributesType (iso.std.iso_iec._24727.tech.schema.PasswordAttributesType)17 Test (org.testng.annotations.Test)7 ControlIFD (iso.std.iso_iec._24727.tech.schema.ControlIFD)3 InputAPDUInfoType (iso.std.iso_iec._24727.tech.schema.InputAPDUInfoType)3 Transmit (iso.std.iso_iec._24727.tech.schema.Transmit)3 ControlIFDResponse (iso.std.iso_iec._24727.tech.schema.ControlIFDResponse)2 InputUnitType (iso.std.iso_iec._24727.tech.schema.InputUnitType)2 KeyRefType (iso.std.iso_iec._24727.tech.schema.KeyRefType)2 PasswordTypeType (iso.std.iso_iec._24727.tech.schema.PasswordTypeType)2 PinCompareMarkerType (iso.std.iso_iec._24727.tech.schema.PinCompareMarkerType)2 PinInputType (iso.std.iso_iec._24727.tech.schema.PinInputType)2 TransmitResponse (iso.std.iso_iec._24727.tech.schema.TransmitResponse)2 VerifyUserResponse (iso.std.iso_iec._24727.tech.schema.VerifyUserResponse)2 BigInteger (java.math.BigInteger)2 CardResponseAPDU (org.openecard.common.apdu.common.CardResponseAPDU)2 PCSCPinModify (org.openecard.ifd.scio.reader.PCSCPinModify)2 PCSCPinVerify (org.openecard.ifd.scio.reader.PCSCPinVerify)2 AccessControlListType (iso.std.iso_iec._24727.tech.schema.AccessControlListType)1 AccessRuleType (iso.std.iso_iec._24727.tech.schema.AccessRuleType)1 AltVUMessagesType (iso.std.iso_iec._24727.tech.schema.AltVUMessagesType)1