Commit 6fac7641 authored by Tobias Wich's avatar Tobias Wich
Browse files

Return actual error cause in PACE and EAC parts instead of unknown error

parent a517483b
...@@ -111,7 +111,11 @@ public class PAOSTask implements Callable<StartPAOSResponse> { ...@@ -111,7 +111,11 @@ public class PAOSTask implements Callable<StartPAOSResponse> {
sp.getSupportedDIDProtocols().addAll(supportedDIDs); sp.getSupportedDIDProtocols().addAll(supportedDIDs);
return p.sendStartPAOS(sp); return p.sendStartPAOS(sp);
} finally { } finally {
TCTokenHandler.disconnectHandle(dispatcher, connectionHandle); try {
TCTokenHandler.disconnectHandle(dispatcher, connectionHandle);
} catch (Exception ex) {
LOG.warn("Error disconnecting finished handle.", ex);
}
} }
} }
......
...@@ -375,6 +375,7 @@ public class TCTokenHandler { ...@@ -375,6 +375,7 @@ public class TCTokenHandler {
break; break;
} }
LOG.debug("Processing InnerException.", innerException);
if (innerException instanceof WSException) { if (innerException instanceof WSException) {
WSException ex = (WSException) innerException; WSException ex = (WSException) innerException;
errorMsg = createResponseFromWsEx(ex, response); errorMsg = createResponseFromWsEx(ex, response);
...@@ -397,6 +398,14 @@ public class TCTokenHandler { ...@@ -397,6 +398,14 @@ public class TCTokenHandler {
response.setAdditionalResultMinor(ECardConstants.Minor.App.UNKNOWN_ERROR); response.setAdditionalResultMinor(ECardConstants.Minor.App.UNKNOWN_ERROR);
} }
String paosAdditionalMinor = w.getAdditionalResultMinor();
if (paosAdditionalMinor != null) {
LOG.debug("Replacing minor from inner exception with minor from PAOSException.");
LOG.debug("InnerException minor: {}", response.getAuxResultData().get(AuxDataKeys.MINOR_PROCESS_RESULT));
LOG.debug("PAOSException minor: {}", paosAdditionalMinor);
response.setAdditionalResultMinor(paosAdditionalMinor);
}
showErrorMessage(errorMsg); showErrorMessage(errorMsg);
try { try {
......
...@@ -30,9 +30,9 @@ import org.openecard.addon.sal.FunctionType; ...@@ -30,9 +30,9 @@ import org.openecard.addon.sal.FunctionType;
import org.openecard.addon.sal.ProtocolStep; import org.openecard.addon.sal.ProtocolStep;
import org.openecard.binding.tctoken.TR03112Keys; import org.openecard.binding.tctoken.TR03112Keys;
import org.openecard.common.DynamicContext; import org.openecard.common.DynamicContext;
import org.openecard.common.ECardException;
import org.openecard.common.WSHelper; import org.openecard.common.WSHelper;
import org.openecard.common.interfaces.Dispatcher; import org.openecard.common.interfaces.Dispatcher;
import org.openecard.common.sal.protocol.exception.ProtocolException;
import org.openecard.common.tlv.TLVException; import org.openecard.common.tlv.TLVException;
import org.openecard.sal.protocol.eac.anytype.EAC2OutputType; import org.openecard.sal.protocol.eac.anytype.EAC2OutputType;
import org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType; import org.openecard.sal.protocol.eac.anytype.EACAdditionalInputType;
...@@ -92,7 +92,11 @@ public class ChipAuthenticationStep implements ProtocolStep<DIDAuthenticate, DID ...@@ -92,7 +92,11 @@ public class ChipAuthenticationStep implements ProtocolStep<DIDAuthenticate, DID
eac2Output = auth.performAuth(eac2Output, internalData); eac2Output = auth.performAuth(eac2Output, internalData);
response.setAuthenticationProtocolData(eac2Output.getAuthDataType()); response.setAuthenticationProtocolData(eac2Output.getAuthDataType());
} catch (ParserConfigurationException | ProtocolException | TLVException e) { } catch (ECardException e) {
LOG.error(e.getMessage(), e);
response.setResult(e.getResult());
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
} catch (ParserConfigurationException | TLVException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
response.setResult(WSHelper.makeResultUnknownError(e.getMessage())); response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false); dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
......
...@@ -46,6 +46,7 @@ import org.openecard.binding.tctoken.TR03112Keys; ...@@ -46,6 +46,7 @@ import org.openecard.binding.tctoken.TR03112Keys;
import org.bouncycastle.tls.TlsServerCertificate; import org.bouncycastle.tls.TlsServerCertificate;
import org.openecard.common.DynamicContext; import org.openecard.common.DynamicContext;
import org.openecard.common.ECardConstants; import org.openecard.common.ECardConstants;
import org.openecard.common.ECardException;
import org.openecard.common.I18n; import org.openecard.common.I18n;
import org.openecard.common.ThreadTerminateException; import org.openecard.common.ThreadTerminateException;
import org.openecard.common.WSHelper; import org.openecard.common.WSHelper;
...@@ -392,7 +393,7 @@ public class PACEStep implements ProtocolStep<DIDAuthenticate, DIDAuthenticateRe ...@@ -392,7 +393,7 @@ public class PACEStep implements ProtocolStep<DIDAuthenticate, DIDAuthenticateRe
String msg = ex.getMessage(); String msg = ex.getMessage();
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.EAC.DOC_VALID_FAILED, msg)); response.setResult(WSHelper.makeResultError(ECardConstants.Minor.SAL.EAC.DOC_VALID_FAILED, msg));
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false); dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
} catch (WSHelper.WSException e) { } catch (ECardException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
response.setResult(e.getResult()); response.setResult(e.getResult());
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false); dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
......
...@@ -30,6 +30,7 @@ import org.openecard.addon.sal.ProtocolStep; ...@@ -30,6 +30,7 @@ import org.openecard.addon.sal.ProtocolStep;
import org.openecard.binding.tctoken.TR03112Keys; import org.openecard.binding.tctoken.TR03112Keys;
import org.openecard.common.DynamicContext; import org.openecard.common.DynamicContext;
import org.openecard.common.ECardConstants; import org.openecard.common.ECardConstants;
import org.openecard.common.ECardException;
import org.openecard.common.WSHelper; import org.openecard.common.WSHelper;
import org.openecard.common.interfaces.Dispatcher; import org.openecard.common.interfaces.Dispatcher;
import org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate; import org.openecard.crypto.common.asn1.cvc.CardVerifiableCertificate;
...@@ -136,6 +137,10 @@ public class TerminalAuthenticationStep implements ProtocolStep<DIDAuthenticate, ...@@ -136,6 +137,10 @@ public class TerminalAuthenticationStep implements ProtocolStep<DIDAuthenticate,
} }
response.setAuthenticationProtocolData(eac2Output.getAuthDataType()); response.setAuthenticationProtocolData(eac2Output.getAuthDataType());
} catch (ECardException e) {
LOG.error(e.getMessage(), e);
response.setResult(e.getResult());
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
} catch (Exception e) { } catch (Exception e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
response.setResult(WSHelper.makeResultUnknownError(e.getMessage())); response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
......
...@@ -329,6 +329,7 @@ public class PAOS { ...@@ -329,6 +329,7 @@ public class PAOS {
DefaultConnectionReuseStrategy reuse = new DefaultConnectionReuseStrategy(); DefaultConnectionReuseStrategy reuse = new DefaultConnectionReuseStrategy();
boolean connectionDropped = false; boolean connectionDropped = false;
ResponseBaseType lastResponse = null; ResponseBaseType lastResponse = null;
String firstOecMinorError = null;
try { try {
// loop and send makes a computer happy // loop and send makes a computer happy
...@@ -344,6 +345,16 @@ public class PAOS { ...@@ -344,6 +345,16 @@ public class PAOS {
// save the last message we sent to the eID-Server. // save the last message we sent to the eID-Server.
if (msg instanceof ResponseBaseType) { if (msg instanceof ResponseBaseType) {
lastResponse = (ResponseBaseType) msg; lastResponse = (ResponseBaseType) msg;
// save first minor code if there is one returned from our stack
if (firstOecMinorError == null) {
Result r = lastResponse.getResult();
if (r != null) {
String minor = r.getResultMinor();
if (minor != null) {
firstOecMinorError = minor;
}
}
}
} }
// prepare request // prepare request
String resource = tlsHandler.getResource(); String resource = tlsHandler.getResource();
...@@ -451,7 +462,11 @@ public class PAOS { ...@@ -451,7 +462,11 @@ public class PAOS {
} catch (TransformerException ex) { } catch (TransformerException ex) {
throw new DispatcherException(ex); throw new DispatcherException(ex);
} catch (WSException ex) { } catch (WSException ex) {
throw new PAOSException(ex); PAOSException newEx = new PAOSException(ex);
if (firstOecMinorError != null) {
newEx.setAdditionalResultMinor(firstOecMinorError);
}
throw newEx;
} finally { } finally {
try { try {
if (conn != null) { if (conn != null) {
......
...@@ -38,6 +38,8 @@ public class PAOSException extends I18nException { ...@@ -38,6 +38,8 @@ public class PAOSException extends I18nException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final I18n lang = I18n.getTranslation("tr03112"); private static final I18n lang = I18n.getTranslation("tr03112");
private String additionalResultMinor;
/** /**
* Creates an instance and initializes the exception with a cause. * Creates an instance and initializes the exception with a cause.
* *
...@@ -78,4 +80,12 @@ public class PAOSException extends I18nException { ...@@ -78,4 +80,12 @@ public class PAOSException extends I18nException {
super(lang, key, cause, params); super(lang, key, cause, params);
} }
public void setAdditionalResultMinor(String additionalResultMinor) {
this.additionalResultMinor = additionalResultMinor;
}
public String getAdditionalResultMinor() {
return additionalResultMinor;
}
} }
...@@ -25,6 +25,7 @@ package org.openecard.ifd.protocol.pace; ...@@ -25,6 +25,7 @@ package org.openecard.ifd.protocol.pace;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.List; import java.util.List;
import org.openecard.common.ECardConstants; import org.openecard.common.ECardConstants;
import org.openecard.common.WSHelper;
import org.openecard.common.apdu.GeneralAuthenticate; import org.openecard.common.apdu.GeneralAuthenticate;
import org.openecard.common.apdu.common.CardCommandAPDU; import org.openecard.common.apdu.common.CardCommandAPDU;
import org.openecard.common.apdu.common.CardResponseAPDU; import org.openecard.common.apdu.common.CardResponseAPDU;
...@@ -135,7 +136,7 @@ public class PACEImplementation { ...@@ -135,7 +136,7 @@ public class PACEImplementation {
if (e.getCause() instanceof Exception) { if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause(); throw (Exception) e.getCause();
} else { } else {
throw new ProtocolException(ECardConstants.Minor.IFD.UNKNOWN_ERROR, e.getMessage()); throw new ProtocolException(e.getResultMinor(), e.getMessage());
} }
} }
......
...@@ -26,6 +26,7 @@ import iso.std.iso_iec._24727.tech.schema.EstablishChannel; ...@@ -26,6 +26,7 @@ import iso.std.iso_iec._24727.tech.schema.EstablishChannel;
import iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse; import iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.openecard.common.ECardConstants; import org.openecard.common.ECardConstants;
import org.openecard.common.ECardException;
import org.openecard.common.WSHelper; import org.openecard.common.WSHelper;
import org.openecard.common.apdu.common.CardResponseAPDU; import org.openecard.common.apdu.common.CardResponseAPDU;
import org.openecard.common.apdu.utils.CardUtils; import org.openecard.common.apdu.utils.CardUtils;
...@@ -121,7 +122,7 @@ public class PACEProtocol implements Protocol { ...@@ -121,7 +122,7 @@ public class PACEProtocol implements Protocol {
response.setResult(WSHelper.makeResultError( response.setResult(WSHelper.makeResultError(
ECardConstants.Minor.IFD.IO.UNKNOWN_PIN_FORMAT, ECardConstants.Minor.IFD.IO.UNKNOWN_PIN_FORMAT,
"Cannot encode the PIN in " + PACEConstants.PIN_CHARSET + " charset.")); "Cannot encode the PIN in " + PACEConstants.PIN_CHARSET + " charset."));
} catch (ProtocolException ex) { } catch (ECardException ex) {
logger.error(ex.getMessage(), ex); logger.error(ex.getMessage(), ex);
response.setResult(WSHelper.makeResult(ex)); response.setResult(WSHelper.makeResult(ex));
} catch (Throwable ex) { } catch (Throwable ex) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment