use of org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType in project open-ecard by ecsec.
the class ChipAuthenticationStep method perform.
@Override
public DIDAuthenticateResponse perform(DIDAuthenticate didAuthenticate, Map<String, Object> internalData) {
DIDAuthenticateResponse response = new DIDAuthenticateResponse();
byte[] slotHandle = didAuthenticate.getConnectionHandle().getSlotHandle();
DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
try {
ObjectSchemaValidator valid = (ObjectSchemaValidator) dynCtx.getPromise(EACProtocol.SCHEMA_VALIDATOR).deref();
boolean messageValid = valid.validateObject(didAuthenticate);
if (!messageValid) {
String msg = "Validation of the EACAdditionalInputType message failed.";
logger.error(msg);
dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM, msg));
return response;
}
} catch (ObjectValidatorException ex) {
String msg = "Validation of the EACAdditionalInputType message failed due to invalid input data.";
logger.error(msg, ex);
dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg));
return response;
} catch (InterruptedException ex) {
String msg = "Thread interrupted while waiting for schema validator instance.";
logger.error(msg, ex);
dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg));
return response;
}
try {
EACAdditionalInputType eacAdditionalInput = new EACAdditionalInputType(didAuthenticate.getAuthenticationProtocolData());
EAC2OutputType eac2Output = eacAdditionalInput.getOutputType();
TerminalAuthentication ta = new TerminalAuthentication(dispatcher, slotHandle);
ChipAuthentication ca = new ChipAuthentication(dispatcher, slotHandle);
// save signature, it is needed in the authentication step
byte[] signature = eacAdditionalInput.getSignature();
internalData.put(EACConstants.IDATA_SIGNATURE, signature);
// perform TA and CA authentication
AuthenticationHelper auth = new AuthenticationHelper(ta, ca);
eac2Output = auth.performAuth(eac2Output, internalData);
response.setResult(WSHelper.makeResultOK());
response.setAuthenticationProtocolData(eac2Output.getAuthDataType());
} catch (ParserConfigurationException | ProtocolException | TLVException e) {
logger.error(e.getMessage(), e);
response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
dynCtx.put(EACProtocol.AUTHENTICATION_FAILED, true);
}
Promise<Object> p = (Promise<Object>) dynCtx.getPromise(TR03112Keys.PROCESSING_CANCELLATION);
if (p.derefNonblocking() == null) {
// authentication finished, notify GUI
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, true);
return response;
} else {
// authentication finished, notify GUI
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
response = new DIDAuthenticateResponse();
String msg = "Authentication canceled by the user.";
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.CANCELLATION_BY_USER, msg));
return response;
}
}
Aggregations