Search in sources :

Example 51 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class KeyPairCertificateChainDetailsAction method showCertificateSelectedEntry.

/**
 * Show the certificate details of the selected KeyStore entry.
 */
public void showCertificateSelectedEntry() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStore keyStore = history.getCurrentState().getKeyStore();
        String alias = kseFrame.getSelectedEntryAlias();
        X509Certificate[] certs = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
        DViewCertificate dViewCertificate = new DViewCertificate(frame, MessageFormat.format(res.getString("KeyPairCertificateChainDetailsAction.CertDetailsEntry.Title"), alias), certs, kseFrame, DViewCertificate.EXPORT);
        dViewCertificate.setLocationRelativeTo(frame);
        dViewCertificate.setVisible(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) DViewCertificate(org.kse.gui.dialogs.DViewCertificate) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Example 52 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class KeyPairPublicKeyDetailsAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        KeyStore keyStore = currentState.getKeyStore();
        String alias = kseFrame.getSelectedEntryAlias();
        PublicKey pubKey = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)))[0].getPublicKey();
        DViewPublicKey dViewPublicKey = new DViewPublicKey(frame, MessageFormat.format(res.getString("KeyPairPublicKeyDetailsAction.PubKeyDetailsEntry.Title"), alias), pubKey);
        dViewPublicKey.setLocationRelativeTo(frame);
        dViewPublicKey.setVisible(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) DViewPublicKey(org.kse.gui.dialogs.DViewPublicKey) PublicKey(java.security.PublicKey) DViewPublicKey(org.kse.gui.dialogs.DViewPublicKey) KeyStore(java.security.KeyStore)

Example 53 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class DeleteKeyPairAction method deleteSelectedEntry.

/**
 * Let the user delete the selected KeyStore entry.
 */
public void deleteSelectedEntry() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        KeyStoreState newState = currentState.createBasisForNextState(this);
        KeyStore keyStore = newState.getKeyStore();
        String alias = kseFrame.getSelectedEntryAlias();
        String message = MessageFormat.format(res.getString("DeleteKeyPairAction.ConfirmDelete.message"), alias);
        int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("DeleteKeyPairAction.DeleteEntry.Title"), JOptionPane.YES_NO_OPTION);
        if (selected != JOptionPane.YES_OPTION) {
            return;
        }
        keyStore.deleteEntry(alias);
        newState.removeEntryPassword(alias);
        currentState.append(newState);
        kseFrame.updateControls(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) KeyStore(java.security.KeyStore)

Example 54 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class ExportKeyPairAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    File exportFile = null;
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        String alias = kseFrame.getSelectedEntryAlias();
        Password password = getEntryPassword(alias, currentState);
        if (password == null) {
            return;
        }
        KeyStore keyStore = currentState.getKeyStore();
        PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
        Certificate[] certificates = keyStore.getCertificateChain(alias);
        DExportKeyPair dExportKeyPair = new DExportKeyPair(frame, alias, applicationSettings.getPasswordQualityConfig());
        dExportKeyPair.setLocationRelativeTo(frame);
        dExportKeyPair.setVisible(true);
        if (!dExportKeyPair.exportSelected()) {
            return;
        }
        exportFile = dExportKeyPair.getExportFile();
        Password exportPassword = dExportKeyPair.getExportPassword();
        KeyStore pkcs12 = KeyStoreUtil.create(KeyStoreType.PKCS12);
        certificates = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certificates));
        pkcs12.setKeyEntry(alias, privateKey, exportPassword.toCharArray(), certificates);
        KeyStoreUtil.save(pkcs12, exportFile, exportPassword);
        JOptionPane.showMessageDialog(frame, res.getString("ExportKeyPairAction.ExportKeyPairSuccessful.message"), res.getString("ExportKeyPairAction.ExportKeyPair.Title"), JOptionPane.INFORMATION_MESSAGE);
    } catch (FileNotFoundException ex) {
        String message = MessageFormat.format(res.getString("ExportKeyPairAction.NoWriteFile.message"), exportFile);
        JOptionPane.showMessageDialog(frame, message, res.getString("ExportKeyPairAction.ExportKeyPair.Title"), JOptionPane.WARNING_MESSAGE);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) DExportKeyPair(org.kse.gui.dialogs.importexport.DExportKeyPair) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) KeyStore(java.security.KeyStore) FileNotFoundException(java.io.FileNotFoundException) Password(org.kse.crypto.Password) Certificate(java.security.cert.Certificate)

Example 55 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class ExportKeyPairCertificateChainAction method getCertificateChain.

private X509Certificate[] getCertificateChain(String alias) throws CryptoException {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStore keyStore = history.getCurrentState().getKeyStore();
        X509Certificate[] certChain = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
        return certChain;
    } catch (KeyStoreException ex) {
        String message = MessageFormat.format(res.getString("ExportKeyPairCertificateChainAction.NoAccessEntry.message"), alias);
        throw new CryptoException(message, ex);
    }
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Aggregations

KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)60 KeyStore (java.security.KeyStore)45 KeyStoreState (org.kse.utilities.history.KeyStoreState)41 Password (org.kse.crypto.Password)31 X509Certificate (java.security.cert.X509Certificate)21 PrivateKey (java.security.PrivateKey)17 Certificate (java.security.cert.Certificate)13 Key (java.security.Key)12 CryptoException (org.kse.crypto.CryptoException)11 KeyStoreType (org.kse.crypto.keystore.KeyStoreType)11 DGetAlias (org.kse.gui.dialogs.DGetAlias)10 KeyStoreException (java.security.KeyStoreException)9 File (java.io.File)7 GeneralSecurityException (java.security.GeneralSecurityException)6 DViewCertificate (org.kse.gui.dialogs.DViewCertificate)6 DGetNewPassword (org.kse.gui.password.DGetNewPassword)6 FileNotFoundException (java.io.FileNotFoundException)5 PublicKey (java.security.PublicKey)5 Provider (java.security.Provider)4 ArrayList (java.util.ArrayList)3