use of org.openecard.ws.chipgateway.HelloRequestType 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 org.openecard.ws.chipgateway.HelloRequestType in project open-ecard by ecsec.
the class MessageTest method testHelloRequest.
@Test
public void testHelloRequest() throws JsonProcessingException, IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JaxbAnnotationModule());
HelloRequestType req = new HelloRequestType();
req.setSessionIdentifier("1234abcd");
req.setChallenge(new byte[] { 0, 1, 2, 3 });
req.setVersion("1.2.3");
String result = mapper.writeValueAsString(req);
HelloRequestType req1 = mapper.readValue(result, HelloRequestType.class);
// load reference
String inputRef = "{\"Challenge\" : \"00010203\", \"Version\" : \"1.2.3\", \"SessionIdentifier\" : \"1234abcd\"}";
HelloRequestType reference = mapper.readValue(inputRef, HelloRequestType.class);
Assert.assertEquals(reference.getSessionIdentifier(), req1.getSessionIdentifier());
Assert.assertEquals(reference.getChallenge(), req1.getChallenge());
Assert.assertEquals(reference.getVersion(), req1.getVersion());
}
Aggregations