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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations