use of org.openecard.common.DynamicContext in project open-ecard by ecsec.
the class CVCStepAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (result.isBack()) {
// no going back to the initialization step
return new StepActionResult(StepActionResultStatus.REPEAT);
}
DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
EACData eacData = (EACData) ctx.get(EACProtocol.EAC_DATA);
CHATStep chatStep = new CHATStep(eacData);
chatStep.setBackgroundTask(bTask);
StepAction chatAction = new CHATStepAction(eacData, chatStep);
chatStep.setAction(chatAction);
return new StepActionResult(StepActionResultStatus.NEXT, chatStep);
}
use of org.openecard.common.DynamicContext 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;
}
}
use of org.openecard.common.DynamicContext in project open-ecard by ecsec.
the class EACProtocol method init.
@Override
public void init(Context ctx) throws ActionInitializationException {
DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
dynCtx.putPromise(SCHEMA_VALIDATOR, new FuturePromise<>(new Callable<ObjectSchemaValidator>() {
@Override
public ObjectSchemaValidator call() throws Exception {
boolean noValid = Boolean.valueOf(OpenecardProperties.getProperty("legacy.ignore_ns"));
ObjectSchemaValidator v;
if (!noValid) {
v = JAXBSchemaValidator.load(DIDAuthenticate.class, "ISO24727-Protocols.xsd");
} else {
// always valid
v = new ObjectSchemaValidator() {
@Override
public boolean validateObject(Object obj) throws ObjectValidatorException {
return true;
}
};
}
return v;
}
}));
addOrderStep(new PACEStep(ctx.getDispatcher(), ctx.getUserConsent(), ctx.getEventDispatcher()));
addOrderStep(new TerminalAuthenticationStep(ctx.getDispatcher()));
addOrderStep(new ChipAuthenticationStep(ctx.getDispatcher()));
}
use of org.openecard.common.DynamicContext in project open-ecard by ecsec.
the class CHATStepAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (result.isOK()) {
processResult(oldResults);
DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
boolean nativePace = (boolean) ctx.get(EACProtocol.IS_NATIVE_PACE);
PACEMarkerType paceMarker = (PACEMarkerType) ctx.get(EACProtocol.PACE_MARKER);
EacPinStatus status = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
byte[] slotHandle = (byte[]) ctx.get(EACProtocol.SLOT_HANDLE);
Dispatcher dispatcher = (Dispatcher) ctx.get(EACProtocol.DISPATCHER);
Step pinStep;
assert (status != null);
switch(status) {
case BLOCKED:
ctx.put(EACProtocol.PIN_BLOCKED_STATUS, status);
pinStep = new ErrorStep(LANG.translationForKey("step_error_title_blocked", PIN), LANG.translationForKey("step_error_pin_blocked", PIN, PIN, PUK, PIN), WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.PASSWORD_BLOCKED, "Password blocked.")));
break;
case DEACTIVATED:
ctx.put(EACProtocol.PIN_BLOCKED_STATUS, status);
pinStep = new ErrorStep(LANG.translationForKey("step_error_title_deactivated"), LANG.translationForKey("step_error_pin_deactivated"), WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.PASSWORD_SUSPENDED, "Card deactivated.")));
break;
default:
pinStep = new PINStep(eacData, !nativePace, paceMarker, status);
pinStep.setBackgroundTask(bTask);
StepAction pinAction = new PINStepAction(eacData, !nativePace, slotHandle, dispatcher, (PINStep) pinStep, status);
pinStep.setAction(pinAction);
}
return new StepActionResult(StepActionResultStatus.NEXT, pinStep);
} else {
// cancel can not happen, so only back is left to be handled
return new StepActionResult(StepActionResultStatus.BACK);
}
}
use of org.openecard.common.DynamicContext in project open-ecard by ecsec.
the class CardMonitor method call.
@Override
public StepActionResult call() throws Exception {
try {
logger.debug("Waiting for card to be removed.");
cardRemoved.deref();
logger.debug("Card has been removed.");
String title = langPin.translationForKey(ERROR_TITLE);
String desc = langPin.translationForKey(ERROR_CARD_REMOVED);
ErrorStep replacement = new ErrorStep(title, desc);
DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
dynCtx.put(EACProtocol.PACE_EXCEPTION, WSHelper.createException(WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE, "Card has been removed.")));
return new StepActionResult(StepActionResultStatus.REPEAT, replacement);
} catch (InterruptedException ex) {
logger.debug("Card has not been removed.");
// terminate the current thread
throw ex;
}
}
Aggregations