Search in sources :

Example 1 with DSignJar

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

Aggregations

File (java.io.File)1 KeyStore (java.security.KeyStore)1 PrivateKey (java.security.PrivateKey)1 Provider (java.security.Provider)1 X509Certificate (java.security.cert.X509Certificate)1 Password (org.kse.crypto.Password)1 DigestType (org.kse.crypto.digest.DigestType)1 KeyPairType (org.kse.crypto.keypair.KeyPairType)1 SignatureType (org.kse.crypto.signing.SignatureType)1 DSignJar (org.kse.gui.dialogs.sign.DSignJar)1 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)1 KeyStoreState (org.kse.utilities.history.KeyStoreState)1