Search in sources :

Example 46 with Password

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

the class KeyStoreExplorerAction method getNewKeyStorePassword.

/**
 * Get a new KeyStore password.
 *
 * @return The new KeyStore password, or null if none entered by the user
 */
protected Password getNewKeyStorePassword() {
    DGetNewPassword dGetNewPassword = new DGetNewPassword(frame, res.getString("KeyStoreExplorerAction.SetKeyStorePassword.Title"), ApplicationSettings.getInstance().getPasswordQualityConfig());
    dGetNewPassword.setLocationRelativeTo(frame);
    dGetNewPassword.setVisible(true);
    Password password = dGetNewPassword.getPassword();
    return password;
}
Also used : DGetNewPassword(org.kse.gui.password.DGetNewPassword) DGetNewPassword(org.kse.gui.password.DGetNewPassword) DGetPassword(org.kse.gui.password.DGetPassword) Password(org.kse.crypto.Password)

Example 47 with Password

use of org.kse.crypto.Password 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 48 with Password

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

the class RenameKeyPairAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        String alias = kseFrame.getSelectedEntryAlias();
        Password password = getEntryPassword(alias, currentState);
        if (password == null) {
            return;
        }
        KeyStoreState newState = currentState.createBasisForNextState(this);
        KeyStore keyStore = newState.getKeyStore();
        Key privateKey = keyStore.getKey(alias, password.toCharArray());
        Certificate[] certs = keyStore.getCertificateChain(alias);
        certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certs));
        DGetAlias dGetAlias = new DGetAlias(frame, res.getString("RenameKeyPairAction.NewEntryAlias.Title"), alias);
        dGetAlias.setLocationRelativeTo(frame);
        dGetAlias.setVisible(true);
        String newAlias = dGetAlias.getAlias();
        if (newAlias == null) {
            return;
        }
        if (newAlias.equalsIgnoreCase(alias)) {
            JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("RenameKeyPairAction.RenameAliasIdentical.message"), alias), res.getString("RenameKeyPairAction.RenameEntry.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (keyStore.containsAlias(newAlias)) {
            String message = MessageFormat.format(res.getString("RenameKeyPairAction.OverWriteEntry.message"), newAlias);
            int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("RenameKeyPairAction.RenameEntry.Title"), JOptionPane.YES_NO_OPTION);
            if (selected != JOptionPane.YES_OPTION) {
                return;
            }
            keyStore.deleteEntry(newAlias);
            newState.removeEntryPassword(newAlias);
        }
        keyStore.setKeyEntry(newAlias, privateKey, password.toCharArray(), certs);
        newState.setEntryPassword(newAlias, new Password(password));
        keyStore.deleteEntry(alias);
        newState.removeEntryPassword(alias);
        currentState.append(newState);
        kseFrame.updateControls(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : DGetAlias(org.kse.gui.dialogs.DGetAlias) KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) KeyStore(java.security.KeyStore) Key(java.security.Key) Password(org.kse.crypto.Password) Certificate(java.security.cert.Certificate)

Example 49 with Password

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

the class SignJarAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    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();
        Provider provider = history.getExplicitProvider();
        PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
        X509Certificate[] certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
        KeyPairType keyPairType = KeyPairUtil.getKeyPairType(privateKey);
        DSignJar dSignJar = new DSignJar(frame, privateKey, keyPairType, alias, provider);
        dSignJar.setLocationRelativeTo(frame);
        dSignJar.setVisible(true);
        SignatureType signatureType = dSignJar.getSignatureType();
        String signatureName = dSignJar.getSignatureName();
        File inputJarFile = dSignJar.getInputJar();
        File outputJarFile = dSignJar.getOutputJar();
        String tsaUrl = dSignJar.getTimestampingServerUrl();
        if (signatureType == null) {
            return;
        }
        String signer = KSE.getFullApplicationName();
        DigestType digestType = dSignJar.getDigestType();
        if (inputJarFile.equals(outputJarFile)) {
            JarSigner.sign(inputJarFile, privateKey, certs, signatureType, signatureName, signer, digestType, tsaUrl, provider);
        } else {
            JarSigner.sign(inputJarFile, outputJarFile, privateKey, certs, signatureType, signatureName, signer, digestType, tsaUrl, provider);
        }
        JOptionPane.showMessageDialog(frame, res.getString("SignJarAction.SignJarSuccessful.message"), res.getString("SignJarAction.SignJar.Title"), JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) SignatureType(org.kse.crypto.signing.SignatureType) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) Provider(java.security.Provider) DigestType(org.kse.crypto.digest.DigestType) DSignJar(org.kse.gui.dialogs.sign.DSignJar) KeyPairType(org.kse.crypto.keypair.KeyPairType) File(java.io.File) Password(org.kse.crypto.Password)

Example 50 with Password

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

the class SignMidletAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    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());
        X509Certificate[] certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
        if (!privateKey.getAlgorithm().equals(KeyPairType.RSA.jce())) {
            JOptionPane.showMessageDialog(frame, res.getString("SignMidletAction.ReqRsaKeyPairMidletSigning.message"), res.getString("SignMidletAction.SignMidlet.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        DSignMidlet dSignMidlet = new DSignMidlet(frame);
        dSignMidlet.setLocationRelativeTo(frame);
        dSignMidlet.setVisible(true);
        File inputJadFile = dSignMidlet.getInputJad();
        File outputJadFile = dSignMidlet.getOutputJad();
        File jarFile = dSignMidlet.getJar();
        if (inputJadFile == null) {
            return;
        }
        if (inputJadFile.equals(outputJadFile)) {
            MidletSigner.sign(inputJadFile, jarFile, (RSAPrivateKey) privateKey, certs, 1);
        } else {
            MidletSigner.sign(inputJadFile, outputJadFile, jarFile, (RSAPrivateKey) privateKey, certs, 1);
        }
        JOptionPane.showMessageDialog(frame, res.getString("SignMidletAction.SignMidletSuccessful.message"), res.getString("SignMidletAction.SignMidlet.Title"), JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) PrivateKey(java.security.PrivateKey) DSignMidlet(org.kse.gui.dialogs.sign.DSignMidlet) KeyStore(java.security.KeyStore) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) 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