Search in sources :

Example 1 with DSignMidlet

use of org.kse.gui.dialogs.sign.DSignMidlet 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

File (java.io.File)1 KeyStore (java.security.KeyStore)1 PrivateKey (java.security.PrivateKey)1 X509Certificate (java.security.cert.X509Certificate)1 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)1 Password (org.kse.crypto.Password)1 DSignMidlet (org.kse.gui.dialogs.sign.DSignMidlet)1 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)1 KeyStoreState (org.kse.utilities.history.KeyStoreState)1