use of org.openecard.common.sal.protocol.exception.ProtocolException 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.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.
the class TerminalAuthentication method externalAuthentication.
/**
* Performs an External Authentication.
* Sends an External Authentication APDU. (Protocol step 4)
* See BSI-TR-03110, version 2.10, part 3, B.11.7.
*
* @param terminalSignature Terminal signature
* @throws ProtocolException
*/
public void externalAuthentication(byte[] terminalSignature) throws ProtocolException {
try {
CardCommandAPDU externalAuthentication = new ExternalAuthentication(terminalSignature);
externalAuthentication.transmit(dispatcher, slotHandle);
} catch (APDUException e) {
throw new ProtocolException(e.getResult());
}
}
use of org.openecard.common.sal.protocol.exception.ProtocolException in project open-ecard by ecsec.
the class TerminalAuthentication method getChallenge.
/**
* Gets a challenge from the PICC.
* Sends a Get Challenge APDU. (Protocol step 3)
* See BSI-TR-03110, version 2.10, part 3, B.11.6.
*
* @return Challenge
* @throws ProtocolException
*/
public byte[] getChallenge() throws ProtocolException {
try {
CardCommandAPDU getChallenge = new GetChallenge();
CardResponseAPDU response = getChallenge.transmit(dispatcher, slotHandle);
return response.getData();
} catch (APDUException e) {
throw new ProtocolException(e.getResult());
}
}
Aggregations