use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DSignJar method okPressed.
private void okPressed() {
String inputJar = jtfInputJar.getText().trim();
if (inputJar.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DSignJar.InputJarRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
File inputJarFile = new File(inputJar);
if (!inputJarFile.isFile()) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DSignJar.InputJarNotFile.message"), inputJarFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
JarFile jarFile = null;
try {
jarFile = new JarFile(inputJarFile);
} catch (IOException ex) {
String problemStr = MessageFormat.format(res.getString("DSignJar.NoOpenJar.Problem"), inputJarFile.getName());
String[] causes = new String[] { res.getString("DSignJar.NotJar.Cause"), res.getString("DSignJar.CorruptedJar.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(this, res.getString("DSignJar.ProblemOpeningJar.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return;
} finally {
IOUtils.closeQuietly(jarFile);
}
boolean signDirectly = jcbSignDirectly.isSelected();
File outputJarFile;
if (signDirectly) {
outputJarFile = inputJarFile;
} else {
String outputJar = jtfOutputJar.getText().trim();
if (outputJar.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DSignJar.OutputJarRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
outputJarFile = new File(outputJar);
}
String signatureName = jtfSignatureName.getText().trim();
if (signatureName.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DSignJar.ValReqSignatureName.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
if (!verifySignatureName(signatureName)) {
JOptionPane.showMessageDialog(this, res.getString("DSignJar.ValJarSignatureName.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
if (!signDirectly && outputJarFile.isFile()) {
String message = MessageFormat.format(res.getString("DSignJar.OverWriteOutputJarFile.message"), outputJarFile);
int selected = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
try {
if (JarSigner.hasSignature(new File(inputJar), signatureName)) {
String message = MessageFormat.format(res.getString("DSignJar.SignatureOverwrite.message"), signatureName);
int selected = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
} catch (IOException ex) {
DError.displayError(this, ex);
return;
}
if (jcbAddTimestamp.isSelected() && jcbTimestampServerUrl.getSelectedItem().toString().isEmpty()) {
JOptionPane.showMessageDialog(this, res.getString("DSignJar.EmptyTimestampUrl.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
this.inputJarFile = inputJarFile;
this.outputJarFile = outputJarFile;
this.signatureName = signatureName;
signatureType = (SignatureType) jcbSignatureAlgorithm.getSelectedItem();
digestType = (DigestType) jcbDigestAlgorithm.getSelectedItem();
if (jcbAddTimestamp.isSelected()) {
tsaUrl = jcbTimestampServerUrl.getSelectedItem().toString();
}
closeDialog();
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DOpenPkcs11KeyStore method okPressed.
private void okPressed() {
final String selectedLib = ((String) jtfP11Library.getSelectedItem()).trim();
try {
if (jrbUseExisting.isSelected()) {
String providerName = (String) jcbPkcs11Provider.getSelectedItem();
selectedProvider = Security.getProvider(providerName);
if (selectedProvider == null) {
JOptionPane.showMessageDialog(this, res.getString("DOpenPkcs11KeyStore.providerNotInstalled.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
}
} else {
if (selectedLib.isEmpty()) {
JOptionPane.showMessageDialog(this, res.getString("DOpenPkcs11KeyStore.noLibSelected.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
String pkcs11ConfigSettings = "name = Slot" + jspSlotListIndex.getValue() + "\n" + "library = " + selectedLib + "\n" + "slotListIndex = " + jspSlotListIndex.getValue() + "";
ByteArrayInputStream confStream = new ByteArrayInputStream(pkcs11ConfigSettings.getBytes());
// instantiate the provider
Provider p11Provider = null;
if (JavaVersion.getJreVersion().isAtLeast(JavaVersion.JRE_VERSION_9)) {
p11Provider = Security.getProvider("SunPKCS11");
// add marker ("--") for inline config
pkcs11ConfigSettings = "--" + pkcs11ConfigSettings;
// p11Provider.configure(pkcs11ConfigSettings);
Method method = Provider.class.getMethod("configure", String.class);
p11Provider = (Provider) method.invoke(p11Provider, pkcs11ConfigSettings);
} else {
Class<?> cl = Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor<?> cons = cl.getConstructor(InputStream.class);
p11Provider = (Provider) cons.newInstance(confStream);
}
Security.addProvider(p11Provider);
selectedProvider = p11Provider;
// save library in preferences
applicationSettings.addP11Lib(selectedLib);
}
closeDialog();
} catch (final Exception e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (DOpenPkcs11KeyStore.this.isShowing()) {
String problemStr = MessageFormat.format(res.getString("DOpenPkcs11KeyStore.ProblemLoadingProvider.Problem"), selectedLib);
String[] causes = new String[] { res.getString("DOpenPkcs11KeyStore.NotPkcs11Lib.Cause"), res.getString("DOpenPkcs11KeyStore.32with64bit.Cause"), res.getString("DOpenPkcs11KeyStore.64bitBeforeJRE8.Cause"), res.getString("DOpenPkcs11KeyStore.WrongConfiguration.Cause") };
Problem problem = new Problem(problemStr, causes, e);
DProblem dProblem = new DProblem(DOpenPkcs11KeyStore.this, res.getString("DOpenPkcs11KeyStore.ProblemLoadingProvider.Title"), problem);
dProblem.setLocationRelativeTo(DOpenPkcs11KeyStore.this);
dProblem.setVisible(true);
}
}
});
}
}
Aggregations