use of org.kse.gui.dnd.DragTrustedCertificateEntry in project keystore-explorer by kaikramer.
the class KseFrame method dragSelectedEntry.
/**
* Get a the selected entry as a drag entry for DnD.
*
* @return Drag entry or null if entry could not be dragged
*/
public DragEntry dragSelectedEntry() {
try {
KeyStoreHistory history = getActiveKeyStoreHistory();
if (history == null) {
// No KeyStore to drag from
return null;
}
KeyStoreState currentState = history.getCurrentState();
KeyStore keyStore = currentState.getKeyStore();
String alias = getSelectedEntryAlias();
KeyStoreType type = KeyStoreType.resolveJce(keyStore.getType());
if (alias == null) {
// No selected entry to drag
return null;
}
if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
JOptionPane.showMessageDialog(frame, res.getString("KseFrame.NoDragKeyEntry.message"), KSE.getApplicationName(), JOptionPane.WARNING_MESSAGE);
return null;
}
if (KeyStoreUtil.isKeyPairEntry(alias, keyStore) && type.hasExportablePrivateKeys()) {
// Otherwise entry must already be unlocked to get password
Password password = currentState.getEntryPassword(alias);
if (password == null && type.hasEntryPasswords()) {
JOptionPane.showMessageDialog(frame, res.getString("KseFrame.NoDragLockedKeyPairEntry.message"), KSE.getApplicationName(), JOptionPane.WARNING_MESSAGE);
return null;
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificateChain = keyStore.getCertificateChain(alias);
return new DragKeyPairEntry(alias, privateKey, password, certificateChain);
} else {
Certificate trustedCertificate = keyStore.getCertificate(alias);
return new DragTrustedCertificateEntry(alias, trustedCertificate);
}
} catch (Exception ex) {
DError.displayError(frame, ex);
return null;
}
}
Aggregations