use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.
the class IfdEventManager method initialize.
public synchronized void initialize() {
threadPool = Executors.newCachedThreadPool(new ThreadFactory() {
private final AtomicInteger num = new AtomicInteger(0);
private final ThreadGroup group = new ThreadGroup("IFD Event Manager");
@Override
public Thread newThread(Runnable r) {
String name = String.format("IFD Watcher %d", num.getAndIncrement());
Thread t = new Thread(group, r, name);
t.setDaemon(false);
return t;
}
});
// start watcher thread
try {
watcher = threadPool.submit(new IfdEventRunner(env, this, builder, cm, ctx));
} catch (WSException ex) {
throw new RuntimeException("Failed to request initial status from IFD.");
}
}
use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.
the class IfdEventRunner method ifdStatus.
@Nonnull
private List<IFDStatusType> ifdStatus() throws WSException {
LOG.debug("Requesting terminal names.");
ListIFDs listReq = new ListIFDs();
listReq.setContextHandle(ctxHandle);
ListIFDsResponse ifds = env.getIFD().listIFDs(listReq);
WSHelper.checkResult(ifds);
LOG.debug("Requesting status for all terminals found.");
ArrayList<IFDStatusType> result = new ArrayList<>();
for (String ifd : ifds.getIFDName()) {
GetStatus status = new GetStatus();
status.setContextHandle(ctxHandle);
status.setIFDName(ifd);
GetStatusResponse statusResponse = env.getIFD().getStatus(status);
try {
WSHelper.checkResult(statusResponse);
result.addAll(statusResponse.getIFDStatus());
} catch (WSException ex) {
String msg = "Failed to request status from terminal, assuming no card present.";
LOG.error(msg, ex);
IFDStatusType is = new IFDStatusType();
is.setIFDName(ifd);
result.add(is);
}
}
return result;
}
use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.
the class TCTokenHandler method processBinding.
/**
* Performs the actual PAOS procedure.
* Connects the given card, establishes the HTTP channel and talks to the server. Afterwards disconnects the card.
*
* @param token The TCToken containing the connection parameters.
* @param connectionHandle The handle of the card that will be used.
* @return A TCTokenResponse indicating success or failure.
* @throws DispatcherException If there was a problem dispatching a request from the server.
* @throws PAOSException If there was a transport error.
*/
private TCTokenResponse processBinding(TCTokenRequest tokenRequest, @Nullable ConnectionHandleType connectionHandle) throws PAOSException, DispatcherException {
TCToken token = tokenRequest.getTCToken();
try {
TCTokenResponse response = new TCTokenResponse();
response.setTCToken(token);
response.setResult(WSHelper.makeResultOK());
String binding = token.getBinding();
switch(binding) {
case "urn:liberty:paos:2006-08":
{
// send StartPAOS
connectionHandle = ensureHandleIsUsable(connectionHandle);
List<String> supportedDIDs = getSupportedDIDs();
PAOSTask task = new PAOSTask(dispatcher, connectionHandle, supportedDIDs, tokenRequest, gui, evManager);
FutureTask<StartPAOSResponse> paosTask = new FutureTask<>(task);
Thread paosThread = new Thread(paosTask, "PAOS");
paosThread.start();
if (!tokenRequest.isTokenFromObject()) {
// wait for computation to finish
waitForTask(paosTask);
}
response.setBindingTask(paosTask);
break;
}
case "urn:ietf:rfc:2616":
{
// no actual binding, just connect via tls and authenticate the user with that connection
connectionHandle = ensureHandleIsUsable(connectionHandle);
HttpGetTask task = new HttpGetTask(dispatcher, connectionHandle, tokenRequest);
FutureTask<StartPAOSResponse> tlsTask = new FutureTask<>(task);
Thread tlsThread = new Thread(tlsTask, "TLS Auth");
tlsThread.start();
waitForTask(tlsTask);
response.setBindingTask(tlsTask);
break;
}
default:
// unknown binding
throw new RuntimeException("Unsupported binding in TCToken.");
}
return response;
} catch (WSException ex) {
String msg = "Failed to connect to card.";
LOG.error(msg, ex);
throw new DispatcherException(msg, ex);
}
}
use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.
the class PINStepAction method perform.
@Override
public StepActionResult perform(Map<String, ExecutionResults> oldResults, StepResult result) {
if (retryCounter == 2) {
try {
EstablishChannelResponse response = performPACEWithCAN(oldResults);
if (response == null) {
LOG.debug("The CAN does not meet the format requirements.");
step.setStatus(EacPinStatus.RC1);
return new StepActionResult(StepActionResultStatus.REPEAT);
}
if (response.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
if (response.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.AUTHENTICATION_FAILED)) {
LOG.error("Failed to authenticate with the given CAN.");
step.setStatus(EacPinStatus.RC1);
return new StepActionResult(StepActionResultStatus.REPEAT);
} else {
WSHelper.checkResult(response);
}
}
} catch (WSException ex) {
// This is for PIN Pad Readers in case the user pressed the cancel button on the reader.
if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.CANCELLATION_BY_USER)) {
LOG.error("User canceled the authentication manually.", ex);
ctx.put(EACProtocol.PACE_EXCEPTION, ex);
return new StepActionResult(StepActionResultStatus.CANCEL);
}
// for people which think they have to remove the card in the process
if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE)) {
LOG.error("The SlotHandle was invalid so probably the user removed the card or an reset occurred.", ex);
ctx.put(EACProtocol.PACE_EXCEPTION, ex);
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(lang.translationForKey(ERROR_TITLE), langPin.translationForKey(ERROR_CARD_REMOVED)));
}
}
}
try {
EstablishChannelResponse establishChannelResponse = performPACEWithPIN(oldResults);
if (establishChannelResponse.getResult().getResultMajor().equals(ECardConstants.Major.ERROR)) {
if (establishChannelResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORD_ERROR)) {
// increase counters and the related displays
retryCounter++;
step.updateAttemptsDisplay(3 - retryCounter);
// repeat the step
LOG.info("Wrong PIN entered, trying again (try number {}).", retryCounter);
this.step.setStatus(EacPinStatus.RC2);
return new StepActionResult(StepActionResultStatus.REPEAT);
} else if (establishChannelResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORD_SUSPENDED)) {
// increase counters and the related displays
retryCounter++;
step.updateAttemptsDisplay(3 - retryCounter);
LOG.info("Wrong PIN entered, trying again (try number {}).", retryCounter);
step.setStatus(EacPinStatus.RC1);
if (capturePin) {
step.addCANEntry();
} else {
step.addNativeCANNotice();
}
return new StepActionResult(StepActionResultStatus.REPEAT);
} else if (establishChannelResponse.getResult().getResultMinor().equals(ECardConstants.Minor.IFD.PASSWORD_BLOCKED)) {
LOG.warn("Wrong PIN entered. The PIN is blocked.");
ctx.put(EACProtocol.PIN_BLOCKED_STATUS, EacPinStatus.BLOCKED);
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(lang.translationForKey("step_error_title_blocked", pin), lang.translationForKey("step_error_pin_blocked", pin, pin, puk, pin), WSHelper.createException(establishChannelResponse.getResult())));
} else {
WSHelper.checkResult(establishChannelResponse);
}
}
eacData.paceResponse = establishChannelResponse;
// PACE completed successfully, proceed with next step
ctx.put(EACProtocol.PACE_EXCEPTION, null);
return new StepActionResult(StepActionResultStatus.NEXT);
} catch (WSException ex) {
// This is for PIN Pad Readers in case the user pressed the cancel button on the reader.
if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.CANCELLATION_BY_USER)) {
LOG.error("User canceled the authentication manually.", ex);
ctx.put(EACProtocol.PACE_EXCEPTION, ex);
return new StepActionResult(StepActionResultStatus.CANCEL);
}
// for people which think they have to remove the card in the process
if (ex.getResultMinor().equals(ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE)) {
LOG.error("The SlotHandle was invalid so probably the user removed the card or an reset occurred.", ex);
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(lang.translationForKey(ERROR_TITLE), langPin.translationForKey(ERROR_CARD_REMOVED), ex));
}
// repeat the step
LOG.error("An unknown error occured while trying to verify the PIN.");
return new StepActionResult(StepActionResultStatus.REPEAT, new ErrorStep(langPin.translationForKey(ERROR_TITLE), langPin.translationForKey(ERROR_UNKNOWN), ex));
}
}
use of org.openecard.common.WSHelper.WSException in project open-ecard by ecsec.
the class CardCommandAPDU method transmit.
/**
* Transmit the APDU.
*
* @param dispatcher Dispatcher
* @param slotHandle Slot handle
* @param responses List of positive responses
* @return Response APDU
* @throws APDUException
*/
public CardResponseAPDU transmit(Dispatcher dispatcher, byte[] slotHandle, List<byte[]> responses) throws APDUException {
Transmit t;
TransmitResponse tr = null;
try {
if (responses != null) {
t = makeTransmit(slotHandle, responses);
} else {
t = makeTransmit(slotHandle);
}
tr = (TransmitResponse) dispatcher.safeDeliver(t);
WSHelper.checkResult(tr);
CardResponseAPDU responseAPDU = new CardResponseAPDU(tr);
return responseAPDU;
} catch (WSException ex) {
throw new APDUException(ex, tr);
} catch (Exception ex) {
throw new APDUException(ex);
}
}
Aggregations