use of org.openecard.crypto.common.sal.did.NoSuchDid in project open-ecard by ecsec.
the class ChipGateway method processSignRequest.
private CommandType processSignRequest(final SignRequestType signReq) throws ConnectionError, JsonProcessingException, InvalidRedirectUrlException, ChipGatewayDataError {
// check if we have been interrupted
checkProcessCancelled();
BigInteger waitSecondsBig = signReq.getMaxWaitSeconds();
long waitMillis = getWaitMillis(waitSecondsBig);
// run the actual stuff in the background, so we can wait and terminate if needed
FutureTask<SignResponseType> action = new FutureTask<>(new Callable<SignResponseType>() {
@Override
public SignResponseType call() throws Exception {
SignResponseType signResp = new SignResponseType();
signResp.setSessionIdentifier(sessionId);
byte[] slotHandle = signReq.getSlotHandle();
String didName = signReq.getDIDName();
char[] pin = null;
try {
pin = getPin(signReq.getPIN());
Signer signer = new Signer(tokenCache, slotHandle, didName, pin);
byte[] signature = signer.sign(signReq.getMessage());
signResp.setSignature(signature);
signResp.setResult(ChipGatewayStatusCodes.OK);
return signResp;
} finally {
if (pin != null) {
Arrays.fill(pin, ' ');
}
}
}
});
Thread t = new Thread(action, "SignRequest-Task-" + TASK_THREAD_NUM.getAndIncrement());
t.setDaemon(true);
t.start();
SignResponseType signResp = new SignResponseType();
signResp.setSessionIdentifier(sessionId);
try {
// wait for thread to finish
signResp = action.get(waitMillis, TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
LOG.info("Background task took longer than the timeout value permitted.", ex);
// cancel task
action.cancel(true);
// wait for task to finish, so the SC stack can not get confused
try {
t.join();
signResp.setResult(ChipGatewayStatusCodes.TIMEOUT);
} catch (InterruptedException ignore) {
// send stop message
signResp.setResult(ChipGatewayStatusCodes.STOPPED);
}
} catch (ExecutionException ex) {
LOG.error("Background task produced an exception.", ex);
Throwable cause = ex.getCause();
if (cause instanceof RemotePinException) {
LOG.error("Error getting encrypted PIN.", cause);
signResp.setResult(ChipGatewayStatusCodes.INCORRECT_PARAMETER);
} else if (cause instanceof ParameterInvalid) {
LOG.error("Error while processing the certificate filter parameters.", cause);
signResp.setResult(ChipGatewayStatusCodes.INCORRECT_PARAMETER);
} else if (cause instanceof SlotHandleInvalid) {
LOG.error("No token for the given slot handle found.", cause);
signResp.setResult(ChipGatewayStatusCodes.UNKNOWN_SLOT);
} else if (cause instanceof NoSuchDid) {
LOG.error("DID does not exist.", cause);
signResp.setResult(ChipGatewayStatusCodes.UNKNOWN_DID);
} else if (cause instanceof PinBlocked) {
LOG.error("PIN is blocked.", ex);
signResp.setResult(ChipGatewayStatusCodes.PIN_BLOCKED);
} else if (cause instanceof SecurityConditionUnsatisfiable) {
LOG.error("DID can not be authenticated.", cause);
signResp.setResult(ChipGatewayStatusCodes.SECURITY_NOT_SATISFIED);
} else if (cause instanceof WSHelper.WSException) {
LOG.error("Unknown error.", cause);
signResp.setResult(ChipGatewayStatusCodes.OTHER);
} else if (cause instanceof ThreadTerminateException) {
LOG.error("Chipgateway process interrupted.", cause);
signResp.setResult(ChipGatewayStatusCodes.STOPPED);
} else {
LOG.error("Unknown error during sign operation.", cause);
signResp.setResult(ChipGatewayStatusCodes.OTHER);
}
} catch (InterruptedException ex) {
String msg = "Interrupted while waiting for background task.";
if (LOG.isDebugEnabled()) {
LOG.debug(msg, ex);
} else {
LOG.info(msg);
}
// cancel task
action.cancel(true);
// send stop message
signResp.setResult(ChipGatewayStatusCodes.STOPPED);
}
return sendMessageInterruptableAndCheckTermination(getResource(signUrl), signResp);
}
Aggregations