*/
public ActionForward exportPrivate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String sel = ((ShowKeyStoreForm) form).getSelectedItem();
KeyStore systemClientStore = ((ShowKeyStoreForm) form).getSelectedKeyStore().getKeyStore();
FileDownloadPageInterceptListener l = (FileDownloadPageInterceptListener) CoreUtil.getPageInterceptListenerById(request
.getSession(), "fileDownload");
if (l == null) {
l = new FileDownloadPageInterceptListener();
CoreUtil.addPageInterceptListener(request.getSession(), l);
}
File clientCertFile = new File(CoreUtil.getTempDownloadDirectory(getSessionInfo(request)), sel + ".p12");
FileOutputStream out = new FileOutputStream(clientCertFile);
char[] password = ((ShowKeyStoreForm) form).getSelectedKeyStore().getKeyStorePassword().toCharArray();
if (systemClientStore.isKeyEntry(sel)){
PrivateKey keypair = ((ShowKeyStoreForm) form).getSelectedKeyStore().getPrivateKey(sel,
password);
KeyStore userStore = KeyStore.getInstance("PKCS12", "BC");
userStore.load(null, null);
userStore.setKeyEntry(sel, keypair, ((ShowKeyStoreForm) form).getPassword().toCharArray(), ((ShowKeyStoreForm) form).getSelectedKeyStore().getCertificateChain(sel));
userStore.store(out, ((ShowKeyStoreForm) form).getPassword().toCharArray());
out.close();
}
l.addDownload(new CSRDownload(clientCertFile, clientCertFile.getName(), "application/octet-stream", mapping.findForward("success"),
"exportPrivateKey.message", "keystore", sel));
return mapping.findForward("success");