@RequestMapping(value = "/finalize", method = RequestMethod.GET)
@ResponseBody
public Response finalizeExchange(@RequestBody(required = true) FinalizeDHRequest finalizeDHRequest) {
if (finalizeDHRequest.getKeyExchangeSessionId() == null || !keyExchangeSessions.containsKey(finalizeDHRequest.getKeyExchangeSessionId())) {
return new ErrorResponse("Invalid keyExchangeSessionId.");
}
DHAgreementModel dhAgreementModel = keyExchangeSessions.get(finalizeDHRequest.getKeyExchangeSessionId());
try {
byte[] secretKey = dhAlgorithm.generateSecret(dhAgreementModel.get_a(), finalizeDHRequest.getPublicB());
secretKeys.put(finalizeDHRequest.getKeyExchangeSessionId(), secretKey);
keyExchangeSessions.remove(finalizeDHRequest.getKeyExchangeSessionId());
return new DefaultResponse();
} catch (CreatingDHAgreementException e) {
return new ErrorResponse(e.getMessage());
}
}