use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DViewPrivateKey method pemEncodingPressed.
private void pemEncodingPressed() {
try {
DViewPem dViewCsrPem = new DViewPem(this, res.getString("DViewPrivateKey.Pem.Title"), privateKey);
dViewCsrPem.setLocationRelativeTo(this);
dViewCsrPem.setVisible(true);
} catch (CryptoException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DGenerateKeyPairCert method generateCertificate.
private boolean generateCertificate() {
Date validityStart = jdtValidityStart.getDateTime();
Date validityEnd = jdtValidityEnd.getDateTime();
String serialNumberStr = jtfSerialNumber.getText().trim();
if (serialNumberStr.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.ValReqSerialNumber.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
BigInteger serialNumber;
try {
serialNumber = new BigInteger(serialNumberStr);
if (serialNumber.compareTo(BigInteger.ONE) < 0) {
JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.SerialNumberNonZero.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.SerialNumberNotInteger.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
X500Name x500Name = jdnName.getDistinguishedName();
if (x500Name == null || x500Name.toString().isEmpty()) {
JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.NameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
try {
SignatureType signatureType = ((SignatureType) jcbSignatureAlgorithm.getSelectedItem());
X509CertificateGenerator generator;
if (jrbVersion1.isSelected()) {
generator = new X509CertificateGenerator(VERSION1);
} else {
generator = new X509CertificateGenerator(VERSION3);
}
// self-signed or signed by other key pair?
if (issuerPrivateKey == null) {
certificate = generator.generateSelfSigned(x500Name, validityStart, validityEnd, keyPair.getPublic(), keyPair.getPrivate(), signatureType, serialNumber, extensions, provider);
} else {
certificate = generator.generate(x500Name, X500NameUtils.x500PrincipalToX500Name(issuerCert.getSubjectX500Principal()), validityStart, validityEnd, keyPair.getPublic(), issuerPrivateKey, signatureType, serialNumber, extensions, provider);
}
} catch (CryptoException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(getParent());
dError.setVisible(true);
closeDialog();
}
return true;
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class KseFrame method updateControls.
/**
* Update the frame's controls dependent on the state of its open and active
* KeyStores.
*
* @param keyStoreContentsChanged
* Have the active KeyStore's contents changed?
*/
public void updateControls(boolean keyStoreContentsChanged) {
KeyStoreHistory history = getActiveKeyStoreHistory();
if (history == null) {
updateControlsNoKeyStoresOpen();
return;
}
KeyStoreState currentState = history.getCurrentState();
// Reload KeyStore in table if it has changed
if (keyStoreContentsChanged) {
try {
String selectedAlias = getSelectedEntryAlias();
((KeyStoreTableModel) getActiveKeyStoreTable().getModel()).load(history);
// Loading the model loses the selected entry - preserve it
if (selectedAlias != null) {
setSelectedEntryByAlias(selectedAlias);
}
} catch (GeneralSecurityException ex) {
DError.displayError(frame, ex);
} catch (CryptoException ex) {
DError.displayError(frame, ex);
}
}
// Can save if active KeyStore has not been saved
if (!currentState.isSavedState()) {
saveAction.setEnabled(true);
} else {
saveAction.setEnabled(false);
}
// Can save all if any KeyStore has been changed since saved
boolean saveAll = false;
for (int i = 0; i < histories.size(); i++) {
KeyStoreHistory h = histories.get(i);
if (!h.getCurrentState().isSavedState()) {
// Yes - can Save All
saveAll = true;
break;
}
}
saveAllAction.setEnabled(saveAll);
// Can close
closeAction.setEnabled(true);
closeAllAction.setEnabled(true);
// Can close others?
if (jkstpKeyStores.getTabCount() > 1) {
closeOthersAction.setEnabled(true);
} else {
closeOthersAction.setEnabled(false);
}
KeyStore keyStore = currentState.getKeyStore();
KeyStoreType type = KeyStoreType.resolveJce(keyStore.getType());
// Can Save As
if (type.isFileBased()) {
saveAsAction.setEnabled(true);
}
// May be able to undo/redo
updateUndoRedoControls(currentState);
// May be able to cut/copy/paste
if (type.isFileBased()) {
updateCutCopyPasteControls();
}
// Can use tools on
generateKeyPairAction.setEnabled(true);
generateSecretKeyAction.setEnabled(type.supportsKeyEntries());
importTrustedCertificateAction.setEnabled(true);
importKeyPairAction.setEnabled(true);
propertiesAction.setEnabled(true);
if (type.isFileBased()) {
setPasswordAction.setEnabled(true);
}
// Show default status bar display
setDefaultStatusBarText();
// Passwords, and therefore unlocking, are not relevant for PKCS #12 or KeyStores that are not file-based
if (!type.hasEntryPasswords() || !type.isFileBased()) {
unlockKeyPairAction.setEnabled(false);
setKeyPairPasswordAction.setEnabled(false);
unlockKeyAction.setEnabled(false);
setKeyPasswordAction.setEnabled(false);
} else {
unlockKeyPairAction.setEnabled(true);
setKeyPairPasswordAction.setEnabled(true);
unlockKeyAction.setEnabled(true);
setKeyPasswordAction.setEnabled(true);
}
// Special restrictions for MSCAPI and PKCS#11 type
if (type == KeyStoreType.MS_CAPI_PERSONAL || type == KeyStoreType.PKCS11) {
keyPairPrivateKeyDetailsAction.setEnabled(false);
keyDetailsAction.setEnabled(false);
renameKeyAction.setEnabled(false);
renameKeyPairAction.setEnabled(false);
renameTrustedCertificateAction.setEnabled(false);
exportKeyPairAction.setEnabled(false);
exportKeyPairPrivateKeyAction.setEnabled(false);
jmKeyPairEditCertChain.setEnabled(false);
appendToCertificateChainAction.setEnabled(false);
removeFromCertificateChainAction.setEnabled(false);
// "UnsupportedOperationException" ...
jmKeyPairImportCaReply.setEnabled(false);
} else {
keyPairPrivateKeyDetailsAction.setEnabled(true);
keyDetailsAction.setEnabled(true);
renameKeyAction.setEnabled(true);
renameKeyPairAction.setEnabled(true);
renameTrustedCertificateAction.setEnabled(true);
exportKeyPairAction.setEnabled(true);
exportKeyPairPrivateKeyAction.setEnabled(true);
jmKeyPairEditCertChain.setEnabled(true);
appendToCertificateChainAction.setEnabled(true);
removeFromCertificateChainAction.setEnabled(true);
jmKeyPairImportCaReply.setEnabled(true);
}
// KeyStore type menu items
if (type.isFileBased()) {
jmChangeType.setEnabled(true);
if (type == JKS) {
jrbmiChangeTypeJks.setSelected(true);
jrbmiKeyStoreChangeTypeJks.setSelected(true);
} else if (type == JCEKS) {
jrbmiChangeTypeJceks.setSelected(true);
jrbmiKeyStoreChangeTypeJceks.setSelected(true);
} else if (type == PKCS12) {
jrbmiChangeTypePkcs12.setSelected(true);
jrbmiKeyStoreChangeTypePkcs12.setSelected(true);
} else if (type == BKS_V1) {
jrbmiChangeTypeBksV1.setSelected(true);
jrbmiKeyStoreChangeTypeBksV1.setSelected(true);
} else if (type == BKS) {
jrbmiChangeTypeBks.setSelected(true);
jrbmiKeyStoreChangeTypeBks.setSelected(true);
} else {
jrbmiChangeTypeUber.setSelected(true);
jrbmiKeyStoreChangeTypeUber.setSelected(true);
}
} else {
jmKeyStoreChangeType.setEnabled(false);
}
// Show KeyStores tabbed pane
frame.getContentPane().remove(jQuickStart);
frame.getContentPane().add(jkstpKeyStores, BorderLayout.CENTER);
updateKeyStoreTabsText();
updateApplicationTitle();
frame.repaint();
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class X509CertUtil method loadCRL.
/**
* Load a CRL from the specified stream.
*
* @param is
* Stream to load CRL from
* @return The CRL
* @throws CryptoException
* Problem encountered while loading the CRL
*/
public static X509CRL loadCRL(InputStream is) throws CryptoException {
try {
CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE);
X509CRL crl = (X509CRL) cf.generateCRL(is);
return crl;
} catch (CertificateException ex) {
throw new CryptoException(res.getString("NoLoadCrl.exception.message"), ex);
} catch (CRLException ex) {
throw new CryptoException(res.getString("NoLoadCrl.exception.message"), ex);
} finally {
IOUtils.closeQuietly(is);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class X509CertUtil method getCertsEncodedPkiPath.
/**
* PKI Path encode a number of certificates.
*
* @return The encoding
* @param certs
* The certificates
* @throws CryptoException
* If there was a problem encoding the certificates
*/
public static byte[] getCertsEncodedPkiPath(X509Certificate[] certs) throws CryptoException {
try {
ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();
Collections.addAll(encodedCerts, certs);
CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
CertPath cp = cf.generateCertPath(encodedCerts);
return cp.getEncoded(PKI_PATH_ENCODING);
} catch (CertificateException | NoSuchProviderException e) {
throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
}
}
Aggregations