Search in sources :

Example 1 with DragTrustedCertificateEntry

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;
    }
}
Also used : DragKeyPairEntry(org.kse.gui.dnd.DragKeyPairEntry) KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) KeyStoreType(org.kse.crypto.keystore.KeyStoreType) DragTrustedCertificateEntry(org.kse.gui.dnd.DragTrustedCertificateEntry) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) CryptoException(org.kse.crypto.CryptoException) Password(org.kse.crypto.Password) Certificate(java.security.cert.Certificate)

Aggregations

GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 PrivateKey (java.security.PrivateKey)1 Certificate (java.security.cert.Certificate)1 CryptoException (org.kse.crypto.CryptoException)1 Password (org.kse.crypto.Password)1 KeyStoreType (org.kse.crypto.keystore.KeyStoreType)1 DragKeyPairEntry (org.kse.gui.dnd.DragKeyPairEntry)1 DragTrustedCertificateEntry (org.kse.gui.dnd.DragTrustedCertificateEntry)1 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)1 KeyStoreState (org.kse.utilities.history.KeyStoreState)1