Search in sources :

Example 21 with Password

use of org.kse.crypto.Password in project keystore-explorer by kaikramer.

the class SetPasswordAction method setKeyStorePassword.

/**
 * Set the active KeyStore's password.
 *
 * @return True if successful
 * @throws CryptoException
 *             If problem occurred
 */
protected boolean setKeyStorePassword() throws CryptoException {
    KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
    KeyStoreState currentState = history.getCurrentState();
    KeyStoreState newState = currentState.createBasisForNextState(this);
    Password password = getNewKeyStorePassword();
    if (password == null) {
        return false;
    }
    newState.setPassword(password);
    currentState.append(newState);
    kseFrame.updateControls(true);
    return true;
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) Password(org.kse.crypto.Password)

Example 22 with Password

use of org.kse.crypto.Password in project keystore-explorer by kaikramer.

the class OpenCaCertificatesAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    File caCertificatesFile = applicationSettings.getCaCertificatesFile();
    if (caCertificatesFile.isFile()) {
        openKeyStore(caCertificatesFile, AuthorityCertificates.CACERTS_DEFAULT_PWD);
        return;
    }
    int selected = JOptionPane.showConfirmDialog(frame, res.getString("OpenCaCertificatesAction.NoCaCertificatesKeyStoreCreate.message"), res.getString("OpenCaCertificatesAction.OpenCaCertificatesKeyStore.Title"), JOptionPane.YES_NO_OPTION);
    if (selected != JOptionPane.YES_OPTION) {
        return;
    }
    try {
        DNewKeyStoreType dNewKeyStoreType = new DNewKeyStoreType(frame);
        dNewKeyStoreType.setLocationRelativeTo(frame);
        dNewKeyStoreType.setVisible(true);
        KeyStoreType keyStoreType = dNewKeyStoreType.getKeyStoreType();
        if (keyStoreType == null) {
            return;
        }
        Password password = getNewKeyStorePassword();
        if (password == null) {
            return;
        }
        KeyStore caCertificatesKeyStore = KeyStoreUtil.create(keyStoreType);
        KeyStoreUtil.save(caCertificatesKeyStore, caCertificatesFile, password);
        kseFrame.addKeyStore(caCertificatesKeyStore, caCertificatesFile, password);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : DNewKeyStoreType(org.kse.gui.dialogs.DNewKeyStoreType) KeyStoreType(org.kse.crypto.keystore.KeyStoreType) DNewKeyStoreType(org.kse.gui.dialogs.DNewKeyStoreType) File(java.io.File) KeyStore(java.security.KeyStore) Password(org.kse.crypto.Password)

Example 23 with Password

use of org.kse.crypto.Password in project keystore-explorer by kaikramer.

the class KeyStoreState method createBasisForNextState.

/**
 * Create the basis for the next state based on this one. Makes a copy of
 * the current state excluding its position in the history.
 *
 * @param action
 *            The action responsible for the creation of the next state
 * @return Next state
 * @throws CryptoException
 *             If underlying KeyStore could not be copied
 */
public KeyStoreState createBasisForNextState(HistoryAction action) throws CryptoException {
    KeyStoreState copy = new KeyStoreState();
    copy.history = this.history;
    copy.keyStore = KeyStoreUtil.copy(this.keyStore);
    if (this.password != null) {
        // Copy as may be cleared
        copy.password = new Password(this.password);
    }
    HashMap<String, Password> keyPairPasswordsCopy = new HashMap<String, Password>();
    for (String alias : entryPasswords.keySet()) {
        keyPairPasswordsCopy.put(alias, new Password(entryPasswords.get(alias)));
    }
    copy.entryPasswords = keyPairPasswordsCopy;
    copy.action = action;
    return copy;
}
Also used : HashMap(java.util.HashMap) Password(org.kse.crypto.Password)

Example 24 with Password

use of org.kse.crypto.Password in project keystore-explorer by kaikramer.

the class DImportKeyPairPkcs8 method loadPrivateKey.

private PrivateKey loadPrivateKey() {
    String privateKeyPath = jtfPrivateKeyPath.getText().trim();
    if (privateKeyPath.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs8.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    }
    File privateKeyFile = new File(privateKeyPath);
    try {
        PrivateKey privateKey = null;
        if (!jcbEncrypted.isSelected()) {
            privateKey = Pkcs8Util.load(new FileInputStream(privateKeyFile));
        } else {
            Password password = new Password(jpfPassword.getPassword());
            privateKey = Pkcs8Util.loadEncrypted(new FileInputStream(privateKeyFile), password);
        }
        return privateKey;
    } catch (PrivateKeyEncryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(true);
        return null;
    } catch (PrivateKeyUnencryptedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        jcbEncrypted.setSelected(false);
        return null;
    } catch (PrivateKeyPbeNotSupportedException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (Exception ex) {
        Problem problem = createLoadPkcs8Problem(ex, privateKeyFile);
        DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs8.ProblemLoadingPkcs8.Title"), problem);
        dProblem.setLocationRelativeTo(this);
        dProblem.setVisible(true);
        return null;
    }
}
Also used : PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) File(java.io.File) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) DProblem(org.kse.gui.error.DProblem) Password(org.kse.crypto.Password)

Example 25 with Password

use of org.kse.crypto.Password in project keystore-explorer by kaikramer.

the class DExportKeyPair method exportPressed.

private void exportPressed() {
    Password firstPassword;
    if (jpfPassword instanceof JPasswordQualityField) {
        char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
        if (firstPasswordChars == null) {
            JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.MinimumPasswordQualityNotMet.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        firstPassword = new Password(firstPasswordChars);
    } else {
        firstPassword = new Password(((JPasswordField) jpfPassword).getPassword());
    }
    Password confirmPassword = new Password(jpfConfirmPassword.getPassword());
    if (firstPassword.equals(confirmPassword)) {
        exportPassword = firstPassword;
    } else {
        JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.PasswordsNoMatch.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    String exportFileStr = jtfExportFile.getText().trim();
    if (exportFileStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.ExportFileRequired.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File exportFile = new File(exportFileStr);
    if (exportFile.isFile()) {
        String message = MessageFormat.format(res.getString("DExportKeyPair.OverWriteExportFile.message"), exportFile);
        int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportKeyPair.Simple.Title"), JOptionPane.YES_NO_OPTION);
        if (selected != JOptionPane.YES_OPTION) {
            return;
        }
    }
    this.exportFile = exportFile;
    exportSelected = true;
    closeDialog();
}
Also used : JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) JPasswordField(javax.swing.JPasswordField) File(java.io.File) Password(org.kse.crypto.Password)

Aggregations

Password (org.kse.crypto.Password)60 KeyStore (java.security.KeyStore)35 KeyStoreState (org.kse.utilities.history.KeyStoreState)32 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)31 PrivateKey (java.security.PrivateKey)24 File (java.io.File)23 FileNotFoundException (java.io.FileNotFoundException)16 Key (java.security.Key)15 X509Certificate (java.security.cert.X509Certificate)15 Certificate (java.security.cert.Certificate)13 KeyStoreType (org.kse.crypto.keystore.KeyStoreType)12 CryptoException (org.kse.crypto.CryptoException)9 DProblem (org.kse.gui.error.DProblem)9 Problem (org.kse.gui.error.Problem)9 DGetAlias (org.kse.gui.dialogs.DGetAlias)8 DGetNewPassword (org.kse.gui.password.DGetNewPassword)8 JPasswordField (javax.swing.JPasswordField)6 DViewPrivateKey (org.kse.gui.dialogs.DViewPrivateKey)6 DGetPassword (org.kse.gui.password.DGetPassword)6 FileInputStream (java.io.FileInputStream)5