use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairOpenSsl method loadPrivateKey.
private PrivateKey loadPrivateKey() {
String privateKeyPath = jtfPrivateKeyPath.getText().trim();
if (privateKeyPath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairOpenSsl.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File privateKeyFile = new File(privateKeyPath);
try {
PrivateKey privateKey = null;
if (!jcbEncrypted.isSelected()) {
privateKey = OpenSslPvkUtil.load(new FileInputStream(privateKeyFile));
} else {
Password password = new Password(jpfPassword.getPassword());
privateKey = OpenSslPvkUtil.loadEncrypted(new FileInputStream(privateKeyFile), password);
}
return privateKey;
} catch (PrivateKeyEncryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(true);
return null;
} catch (PrivateKeyUnencryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(false);
return null;
} catch (PrivateKeyPbeNotSupportedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadOpenSslProblem(ex, privateKeyFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairOpenSsl.ProblemLoadingOpenSsl.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairPkcs12 method loadKeyPair.
private Keypair loadKeyPair() {
String pkcs12Path = jtfPkcs12Path.getText().trim();
if (pkcs12Path.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs12.KeyPairRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File pkcs12File = new File(pkcs12Path);
try {
Password pkcs12Password = new Password(jpfPassword.getPassword());
KeyStore pkcs12 = KeyStoreUtil.load(pkcs12File, pkcs12Password, KeyStoreType.PKCS12);
// Find a key pair in the PKCS #12 KeyStore
PrivateKey privKey = null;
ArrayList<Certificate> certsList = new ArrayList<Certificate>();
// Look for key pair entries first
for (Enumeration<?> aliases = pkcs12.aliases(); aliases.hasMoreElements(); ) {
String alias = (String) aliases.nextElement();
if (pkcs12.isKeyEntry(alias)) {
privKey = (PrivateKey) pkcs12.getKey(alias, pkcs12Password.toCharArray());
Certificate[] certs = pkcs12.getCertificateChain(alias);
if ((certs != null) && (certs.length > 0)) {
Collections.addAll(certsList, certs);
break;
}
}
}
// entries
if ((privKey == null) || (certsList.size() == 0)) {
for (Enumeration<?> aliases = pkcs12.aliases(); aliases.hasMoreElements(); ) {
String alias = (String) aliases.nextElement();
certsList.add(pkcs12.getCertificate(alias));
}
}
if ((privKey == null) || (certsList.size() == 0)) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs12.NoKeyPairPkcs12File.message"), pkcs12File.getName()), getTitle(), JOptionPane.INFORMATION_MESSAGE);
return null;
}
X509Certificate[] certs = X509CertUtil.convertCertificates(certsList.toArray(new Certificate[certsList.size()]));
return new Keypair(privKey, certs);
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs12.NoReadFile.message"), pkcs12File), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadPkcs12Problem(ex, pkcs12File);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs12.ProblemLoadingPkcs12.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairPkcs8 method loadCertificates.
private X509Certificate[] loadCertificates() {
String certificatePath = jtfCertificatePath.getText().trim();
if (certificatePath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs8.CertificateRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File certificateFile = new File(certificatePath);
try {
X509Certificate[] certs = X509CertUtil.loadCertificates(new FileInputStream(certificateFile));
if (certs.length == 0) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoCertsFound.message"), certificateFile), getTitle(), JOptionPane.WARNING_MESSAGE);
}
return certs;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoReadFile.message"), certificateFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadCertsProblem(ex, certificateFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs8.ProblemLoadingCerts.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairPvk method loadPrivateKey.
private PrivateKey loadPrivateKey() {
String privateKeyPath = jtfPrivateKeyPath.getText().trim();
if (privateKeyPath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPvk.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File privateKeyFile = new File(privateKeyPath);
try {
PrivateKey privateKey = null;
if (!jcbEncrypted.isSelected()) {
privateKey = MsPvkUtil.load(new FileInputStream(privateKeyFile));
} else {
Password password = new Password(jpfPassword.getPassword());
privateKey = MsPvkUtil.loadEncrypted(new FileInputStream(privateKeyFile), password);
}
return privateKey;
} catch (PrivateKeyEncryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(true);
return null;
} catch (PrivateKeyUnencryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(false);
return null;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadPvkProblem(ex, privateKeyFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPvk.ProblemLoadingPvk.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairPvk method loadCertificates.
private X509Certificate[] loadCertificates() {
String certificatePath = jtfCertificatePath.getText().trim();
if (certificatePath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPvk.CertificateRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File certificateFile = new File(certificatePath);
try {
X509Certificate[] certs = X509CertUtil.loadCertificates(new FileInputStream(certificateFile));
if (certs.length == 0) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.NoCertsFound.message"), certificateFile), getTitle(), JOptionPane.WARNING_MESSAGE);
}
return certs;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPvk.NoReadFile.message"), certificateFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadCertsProblem(ex, certificateFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPvk.ProblemLoadingCerts.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
Aggregations