Search in sources :

Example 1 with BufferEntry

use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.

the class CopyAction method bufferSelectedEntry.

private BufferEntry bufferSelectedEntry() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        String alias = kseFrame.getSelectedEntryAlias();
        if (alias == null) {
            return null;
        }
        BufferEntry bufferEntry = null;
        KeyStore keyStore = currentState.getKeyStore();
        if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
            Password password = getEntryPassword(alias, currentState);
            if (password == null) {
                return null;
            }
            Key key = keyStore.getKey(alias, password.toCharArray());
            if (key instanceof PrivateKey) {
                JOptionPane.showMessageDialog(frame, res.getString("CopyAction.NoCopyKeyEntryWithPrivateKey.message"), res.getString("CopyAction.Copy.Title"), JOptionPane.WARNING_MESSAGE);
                return null;
            }
            bufferEntry = new KeyBufferEntry(alias, false, key, password);
        } else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
            Certificate certificate = keyStore.getCertificate(alias);
            bufferEntry = new TrustedCertificateBufferEntry(alias, false, certificate);
        } else if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
            Password password = getEntryPassword(alias, currentState);
            if (password == null) {
                return null;
            }
            PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
            Certificate[] certificateChain = keyStore.getCertificateChain(alias);
            bufferEntry = new KeyPairBufferEntry(alias, false, privateKey, password, certificateChain);
        }
        return bufferEntry;
    } catch (Exception ex) {
        DError.displayError(frame, ex);
        return null;
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) KeyStore(java.security.KeyStore) KeyBufferEntry(org.kse.utilities.buffer.KeyBufferEntry) KeyPairBufferEntry(org.kse.utilities.buffer.KeyPairBufferEntry) TrustedCertificateBufferEntry(org.kse.utilities.buffer.TrustedCertificateBufferEntry) BufferEntry(org.kse.utilities.buffer.BufferEntry) KeyPairBufferEntry(org.kse.utilities.buffer.KeyPairBufferEntry) KeyBufferEntry(org.kse.utilities.buffer.KeyBufferEntry) TrustedCertificateBufferEntry(org.kse.utilities.buffer.TrustedCertificateBufferEntry) Key(java.security.Key) PrivateKey(java.security.PrivateKey) Password(org.kse.crypto.Password) Certificate(java.security.cert.Certificate)

Example 2 with BufferEntry

use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.

the class CutAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    BufferEntry bufferEntry = bufferSelectedEntry();
    if (bufferEntry != null) {
        Buffer.populate(bufferEntry);
        kseFrame.updateControls(true);
    }
}
Also used : TrustedCertificateBufferEntry(org.kse.utilities.buffer.TrustedCertificateBufferEntry) BufferEntry(org.kse.utilities.buffer.BufferEntry) KeyPairBufferEntry(org.kse.utilities.buffer.KeyPairBufferEntry) KeyBufferEntry(org.kse.utilities.buffer.KeyBufferEntry)

Example 3 with BufferEntry

use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.

the class CopyAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    BufferEntry bufferEntry = bufferSelectedEntry();
    if (bufferEntry != null) {
        Buffer.populate(bufferEntry);
        kseFrame.updateControls(false);
    }
}
Also used : TrustedCertificateBufferEntry(org.kse.utilities.buffer.TrustedCertificateBufferEntry) BufferEntry(org.kse.utilities.buffer.BufferEntry) KeyPairBufferEntry(org.kse.utilities.buffer.KeyPairBufferEntry) KeyBufferEntry(org.kse.utilities.buffer.KeyBufferEntry)

Example 4 with BufferEntry

use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.

the class CutAction method bufferSelectedEntry.

private BufferEntry bufferSelectedEntry() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        String alias = kseFrame.getSelectedEntryAlias();
        if (alias == null) {
            return null;
        }
        BufferEntry bufferEntry = null;
        KeyStore keyStore = currentState.getKeyStore();
        if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
            Password password = getEntryPassword(alias, currentState);
            if (password == null) {
                return null;
            }
            Key key = keyStore.getKey(alias, password.toCharArray());
            if (key instanceof PrivateKey) {
                JOptionPane.showMessageDialog(frame, res.getString("CutAction.NoCutKeyEntryWithPrivateKey.message"), res.getString("CutAction.Cut.Title"), JOptionPane.WARNING_MESSAGE);
                return null;
            }
            bufferEntry = new KeyBufferEntry(alias, true, key, password);
        } else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
            Certificate certificate = keyStore.getCertificate(alias);
            bufferEntry = new TrustedCertificateBufferEntry(alias, true, certificate);
        } else if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
            Password password = getEntryPassword(alias, currentState);
            if (password == null) {
                return null;
            }
            PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
            Certificate[] certificateChain = keyStore.getCertificateChain(alias);
            bufferEntry = new KeyPairBufferEntry(alias, true, privateKey, password, certificateChain);
        }
        KeyStoreState newState = currentState.createBasisForNextState(this);
        keyStore = newState.getKeyStore();
        keyStore.deleteEntry(alias);
        newState.removeEntryPassword(alias);
        currentState.append(newState);
        return bufferEntry;
    } catch (Exception ex) {
        DError.displayError(frame, ex);
        return null;
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) KeyStore(java.security.KeyStore) KeyBufferEntry(org.kse.utilities.buffer.KeyBufferEntry) KeyPairBufferEntry(org.kse.utilities.buffer.KeyPairBufferEntry) TrustedCertificateBufferEntry(org.kse.utilities.buffer.TrustedCertificateBufferEntry) BufferEntry(org.kse.utilities.buffer.BufferEntry) KeyPairBufferEntry(org.kse.utilities.buffer.KeyPairBufferEntry) KeyBufferEntry(org.kse.utilities.buffer.KeyBufferEntry) TrustedCertificateBufferEntry(org.kse.utilities.buffer.TrustedCertificateBufferEntry) Key(java.security.Key) PrivateKey(java.security.PrivateKey) Password(org.kse.crypto.Password) Certificate(java.security.cert.Certificate)

Aggregations

BufferEntry (org.kse.utilities.buffer.BufferEntry)4 KeyBufferEntry (org.kse.utilities.buffer.KeyBufferEntry)4 KeyPairBufferEntry (org.kse.utilities.buffer.KeyPairBufferEntry)4 TrustedCertificateBufferEntry (org.kse.utilities.buffer.TrustedCertificateBufferEntry)4 Key (java.security.Key)2 KeyStore (java.security.KeyStore)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 Password (org.kse.crypto.Password)2 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)2 KeyStoreState (org.kse.utilities.history.KeyStoreState)2