Search in sources :

Example 1 with PasswordTypeType

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

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

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

Example 4 with PasswordTypeType

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

the class PINTest method create.

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

Example 5 with PasswordTypeType

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

the class PINStepAction 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)

Aggregations

PasswordAttributesType (iso.std.iso_iec._24727.tech.schema.PasswordAttributesType)3 PasswordTypeType (iso.std.iso_iec._24727.tech.schema.PasswordTypeType)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1