use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect in project open-ecard by ecsec.
the class ChangePinInSALAction method execute.
@Override
public void execute() {
List<ConnectionHandleType> connectedCards = null;
try {
connectedCards = connectCards();
if (connectedCards.isEmpty()) {
// TODO: show no card inserted dialog
}
for (ConnectionHandleType nextCard : connectedCards) {
// pick first card, find pin DID and call didupdate
String didName = null;
try {
didName = getPinDid(nextCard);
} catch (WSException ex) {
LOG.info("Skipping card, because it has no PIN DID.");
continue;
}
DIDUpdate updateReq = new DIDUpdate();
updateReq.setConnectionHandle(nextCard);
updateReq.setDIDName(didName);
DIDUpdateDataType updateData = new PinCompareDIDUpdateDataType();
updateData.setProtocol("urn:oid:1.3.162.15480.3.0.9");
updateReq.setDIDUpdateData(updateData);
dispatcher.safeDeliver(updateReq);
}
} catch (WSException ex) {
} finally {
if (connectedCards != null) {
for (ConnectionHandleType nextHandle : connectedCards) {
CardApplicationDisconnect dr = new CardApplicationDisconnect();
dr.setConnectionHandle(nextHandle);
dr.setAction(ActionType.RESET);
dispatcher.safeDeliver(dr);
}
}
}
}
use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect in project open-ecard by ecsec.
the class TinySALTest method testCardApplicationDisconnect.
/**
* Test of cardApplicationDisconnect method, of class TinySAL.
*/
@Test(enabled = TESTS_ENABLED)
public void testCardApplicationDisconnect() {
System.out.println("cardApplicationDisconnect");
// test normal case
// get esign path
CardApplicationPath cardApplicationPath = new CardApplicationPath();
CardApplicationPathType cardApplicationPathType = new CardApplicationPathType();
cardApplicationPathType.setCardApplication(appIdentifier_ESIGN);
cardApplicationPath.setCardAppPathRequest(cardApplicationPathType);
CardApplicationPathResponse cardApplicationPathResponse = instance.cardApplicationPath(cardApplicationPath);
// connect to esign
CardApplicationConnect cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
CardApplicationConnectResponse result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// disconnect
CardApplicationDisconnect cardApplicationDisconnect = new CardApplicationDisconnect();
cardApplicationDisconnect.setConnectionHandle(result.getConnectionHandle());
instance.cardApplicationDisconnect(cardApplicationDisconnect);
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// test invalid connectionhandle
// connect to esign
cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// disconnect
cardApplicationDisconnect = new CardApplicationDisconnect();
cardApplicationDisconnect.setConnectionHandle(result.getConnectionHandle());
cardApplicationDisconnect.getConnectionHandle().setSlotHandle(new byte[] { 0x0, 0x0, 0x0 });
CardApplicationDisconnectResponse cardApplicationDisconnectResponse = instance.cardApplicationDisconnect(cardApplicationDisconnect);
assertEquals(ECardConstants.Major.ERROR, cardApplicationDisconnectResponse.getResult().getResultMajor());
assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, cardApplicationDisconnectResponse.getResult().getResultMinor());
// test nullpointer
// connect to esign
cardApplicationConnect = new CardApplicationConnect();
cardApplicationConnect.setCardApplicationPath(cardApplicationPathResponse.getCardAppPathResultSet().getCardApplicationPathResult().get(0));
result = instance.cardApplicationConnect(cardApplicationConnect);
assertEquals(appIdentifier_ESIGN, result.getConnectionHandle().getCardApplication());
assertEquals(ECardConstants.Major.OK, result.getResult().getResultMajor());
// disconnect
cardApplicationDisconnect = new CardApplicationDisconnect();
cardApplicationDisconnect.setConnectionHandle(null);
cardApplicationDisconnectResponse = instance.cardApplicationDisconnect(cardApplicationDisconnect);
assertEquals(ECardConstants.Major.ERROR, cardApplicationDisconnectResponse.getResult().getResultMajor());
assertEquals(ECardConstants.Minor.App.INCORRECT_PARM, cardApplicationDisconnectResponse.getResult().getResultMinor());
}
use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect in project open-ecard by ecsec.
the class ChipGateway method sendHello.
public TerminateType sendHello() throws VersionTooOld, ChipGatewayDataError, ConnectionError, InvalidRedirectUrlException, AuthServerException {
try {
byte[] challenge = ValueGenerators.generateRandom(32);
helloReq = new HelloRequestType();
helloReq.setSessionIdentifier(sessionId);
helloReq.setVersion(String.format("%s.%s.%s", AppVersion.getMajor(), AppVersion.getMinor(), AppVersion.getPatch()));
helloReq.setChallenge(challenge);
// send Hello
String helloReqMsg = mapper.writeValueAsString(helloReq);
HelloResponseType helloResp = sendMessageInterruptable(getResource(helloUrl), helloReqMsg, HelloResponseType.class);
processHelloResponse(helloResp);
// send GetCommand
GetCommandType cmdReq = createGetCommandRequest();
String cmdReqMsg = mapper.writeValueAsString(cmdReq);
CommandType cmdResp;
try {
cmdResp = sendMessageInterruptable(getResource(getCommandUrl), cmdReqMsg, CommandType.class);
} catch (ThreadTerminateException ex) {
performProcessCancelled();
throw ex;
}
// send messages to the server as long as there is no termination response
while (cmdResp.getTerminate() == null) {
ListTokensRequestType tokensReq = cmdResp.getListTokensRequest();
ListCertificatesRequestType certReq = cmdResp.getListCertificatesRequest();
SignRequestType signReq = cmdResp.getSignRequest();
if (tokensReq != null) {
cmdResp = processTokensRequest(tokensReq);
} else if (certReq != null) {
cmdResp = processCertificatesRequest(certReq);
} else if (signReq != null) {
cmdResp = processSignRequest(signReq);
} else {
throw new ChipGatewayDataError(token.finalizeErrorAddress(ResultMinor.SERVER_ERROR), INVALID_CHIPGATEWAY_MSG);
}
}
// return the last message (terminate type)
return cmdResp.getTerminate();
} catch (JsonProcessingException ex) {
throw new ChipGatewayDataError(token.finalizeErrorAddress(ResultMinor.CLIENT_ERROR), INVALID_CHIPGATEWAY_MSG, ex);
} finally {
// clear token cache and delete all pins in it
tokenCache.clearPins();
// display GUI if needed
if (showDialogThread != null) {
showDialogThread.start();
}
try {
// in case we are interrupted, terminate is sent in the background, so don't close just yet
if (conn != null && !isInterrupted) {
conn.close();
}
} catch (IOException ex) {
LOG.error("Failed to close connection to server.", ex);
}
// disconnect all slots which have been connected in the process
for (byte[] nextSlot : connectedSlots) {
if (LOG.isDebugEnabled()) {
LOG.debug("Disconnecting card with slotHandle={}.", ByteUtils.toHexString(nextSlot));
}
CardApplicationDisconnect req = new CardApplicationDisconnect();
// req.setAction(ActionType.RESET);
ConnectionHandleType handle = HandlerBuilder.create().setSlotHandle(nextSlot).buildConnectionHandle();
req.setConnectionHandle(handle);
dispatcher.safeDeliver(req);
}
}
}
use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect in project open-ecard by ecsec.
the class CardStateMap method removeSlotHandleEntry.
/**
* Remove the entry reference in slotHandle index. <br>
* This function is needed to update the index in CardApplicationDisconnect.
*
* @param slotHandle SlotHandle for which the entry reference should be deleted.
*/
public synchronized void removeSlotHandleEntry(byte[] slotHandle) {
ConnectionHandleType handle = new ConnectionHandleType();
handle.setSlotHandle(slotHandle);
Set<CardStateEntry> entries = getMatchingEntries(handle);
Iterator<CardStateEntry> it = entries.iterator();
if (it.hasNext()) {
CardStateEntry entry = it.next();
removeMapEntry(handle.getSlotHandle(), slothandleMap, entry);
clearProtocolsForEntry(entry);
}
}
use of iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect in project open-ecard by ecsec.
the class GenericPINAction method updateConnectionHandle.
/**
* Update the connection handle.
* This is necessary after every step because we Disconnect the card with a reset if we have success or not.
*/
private void updateConnectionHandle() {
CardApplicationPath cPath = new CardApplicationPath();
CardApplicationPathType cPathType = new CardApplicationPathType();
cPath.setCardAppPathRequest(cPathType);
CardApplicationPathResponse cPathResp = (CardApplicationPathResponse) dispatcher.safeDeliver(cPath);
List<CardApplicationPathType> cRes = cPathResp.getCardAppPathResultSet().getCardApplicationPathResult();
for (CardApplicationPathType capt : cRes) {
CardApplicationConnect cConn = new CardApplicationConnect();
cConn.setCardApplicationPath(capt);
CardApplicationConnectResponse conRes = (CardApplicationConnectResponse) dispatcher.safeDeliver(cConn);
String cardType = conRes.getConnectionHandle().getRecognitionInfo().getCardType();
ConnectionHandleType cHandleNew = conRes.getConnectionHandle();
if (cardType.equals("http://bsi.bund.de/cif/npa.xml")) {
// ensure same terminal and get the new slothandle
if (cHandleNew.getIFDName().equals(cHandle.getIFDName()) && !Arrays.equals(cHandleNew.getSlotHandle(), slotHandle)) {
cHandle = cHandleNew;
slotHandle = cHandle.getSlotHandle();
break;
// also end if the connection handle found as before than it is still valid
} else if (cHandleNew.getIFDName().equals(cHandle.getIFDName()) && Arrays.equals(cHandleNew.getSlotHandle(), slotHandle)) {
break;
}
} else {
CardApplicationDisconnect disconnect = new CardApplicationDisconnect();
disconnect.setConnectionHandle(conRes.getConnectionHandle());
disconnect.setAction(ActionType.RESET);
dispatcher.safeDeliver(disconnect);
}
}
}
Aggregations