1 package org.eparapher.rcp.wizards;
2
3 import java.security.KeyStore;
4 import java.security.cert.X509Certificate;
5
6 import org.eclipse.jface.viewers.IStructuredSelection;
7 import org.eclipse.jface.wizard.Wizard;
8 import org.eclipse.ui.INewWizard;
9 import org.eclipse.ui.IWorkbench;
10 import org.eclipse.ui.IWorkbenchWindow;
11 import org.eparapher.core.crypto.keystore.EPKeystoreUtils;
12 import org.eparapher.rcp.tools.RCPGUI;
13
14
15 public class ExportKeysCertificatesWizard extends Wizard implements INewWizard {
16
17
18 private IWorkbenchWindow window;
19
20 KeysAndFormatWizardPage one;
21 PinOrPassphraseWizardPage newSecret;
22
23 private X509Certificate userCert = null;
24
25 private String[] selected_aliases;
26
27 public ExportKeysCertificatesWizard(String[] mselected_aliases) {
28 super();
29 setNeedsProgressMonitor(true);
30 setWindowTitle("Keys and certificates export ");
31 selected_aliases = mselected_aliases;
32 }
33
34 public void addPages() {
35
36 one = new KeysAndFormatWizardPage();
37
38 newSecret = new PinOrPassphraseWizardPage(true,false,"");
39 addPage(one);
40 addPage(newSecret);
41 newSecret.setPageComplete(true);
42 }
43
44 public boolean performFinish() {
45 if (one.isPrivateKeyExported()) {
46
47 KeyStore exportedks = EPKeystoreUtils.initNewKeystore( one.getKeystoreType(), newSecret.getSecret());
48 if (!EPKeystoreUtils.exportUserKSPKAndCerts(selected_aliases, exportedks, newSecret.getSecret(),one.isPrivateKeyPassword()))
49 RCPGUI.infoMessage("Export Keys/Certificates", "Error while copying keystores");
50 else if (!EPKeystoreUtils.saveKeystore( exportedks, one.getKeystoreFile(), newSecret.getSecret() ))
51 RCPGUI.infoMessage("Export Keys/Certificates", "Error while saving exported keystores");
52 } else
53 if (!EPKeystoreUtils.exportUserKSCerts(selected_aliases, one.getKeystoreFile()))
54 RCPGUI.infoMessage("Export Keys/Certificates", "Error while exporting certificates");
55 return true;
56 }
57
58 public void init(IWorkbench workbench, IStructuredSelection selection) {
59 window = workbench.getActiveWorkbenchWindow();
60 }
61
62 }