use of org.kse.crypto.digest.DigestType in project keystore-explorer by kaikramer.
the class JCertificateFingerprint method populateFingerprintAlgs.
private void populateFingerprintAlgs() {
DigestType[] digestAlgs = DigestType.values();
for (DigestType digestAlg : digestAlgs) {
jcbFingerprintAlg.addItem(digestAlg);
}
jcbFingerprintAlg.setSelectedIndex(0);
}
use of org.kse.crypto.digest.DigestType in project keystore-explorer by kaikramer.
the class DSignJar method initComponents.
private void initComponents(String signatureName) throws CryptoException {
jlInputJar = new JLabel(res.getString("DSignJar.jlInputJar.text"));
jtfInputJar = new JTextField(30);
jtfInputJar.setCaretPosition(0);
jtfInputJar.setToolTipText(res.getString("DSignJar.jtfInputJar.tooltip"));
jbInputJarBrowse = new JButton(res.getString("DSignJar.jbInputJarBrowse.text"));
PlatformUtil.setMnemonic(jbInputJarBrowse, res.getString("DSignJar.jbInputJarBrowse.mnemonic").charAt(0));
jbInputJarBrowse.setToolTipText(res.getString("DSignJar.jbInputJarBrowse.tooltip"));
jlSignDirectly = new JLabel(res.getString("DSignJar.jlSignDirectly.text"));
jcbSignDirectly = new JCheckBox();
jcbSignDirectly.setSelected(true);
jcbSignDirectly.setToolTipText(res.getString("DSignJar.jcbSignDirectly.tooltip"));
jlOutputJar = new JLabel(res.getString("DSignJar.jlOutputJar.text"));
jtfOutputJar = new JTextField(30);
jtfOutputJar.setEnabled(false);
jtfOutputJar.setCaretPosition(0);
jtfOutputJar.setToolTipText(res.getString("DSignJar.jtfOutputJar.tooltip"));
jbOutputJarBrowse = new JButton(res.getString("DSignJar.jbOutputJarBrowse.text"));
PlatformUtil.setMnemonic(jbOutputJarBrowse, res.getString("DSignJar.jbOutputJarBrowse.mnemonic").charAt(0));
jbOutputJarBrowse.setToolTipText(res.getString("DSignJar.jbOutputJarBrowse.tooltip"));
jbOutputJarBrowse.setEnabled(false);
jlSignatureName = new JLabel(res.getString("DSignJar.jlSignatureName.text"));
jtfSignatureName = new JTextField(convertSignatureName(signatureName), 15);
jtfSignatureName.setCaretPosition(0);
jtfSignatureName.setToolTipText(res.getString("DSignJar.jtfSignatureName.tooltip"));
jlSignatureAlgorithm = new JLabel(res.getString("DSignJar.jlSignatureAlgorithm.text"));
jcbSignatureAlgorithm = new JComboBox<SignatureType>();
DialogHelper.populateSigAlgs(signKeyPairType, this.signPrivateKey, provider, jcbSignatureAlgorithm);
jcbSignatureAlgorithm.setToolTipText(res.getString("DSignJar.jcbSignatureAlgorithm.tooltip"));
jlDigestAlgorithm = new JLabel(res.getString("DSignJar.jlDigestAlgorithm.text"));
jcbDigestAlgorithm = new JComboBox<DigestType>();
populateDigestAlgs();
jcbDigestAlgorithm.setToolTipText(res.getString("DSignJar.jcbDigestAlgorithm.tooltip"));
jlAddTimestamp = new JLabel(res.getString("DSignJar.jlAddTimestamp.text"));
jcbAddTimestamp = new JCheckBox();
jcbAddTimestamp.setSelected(false);
jcbAddTimestamp.setToolTipText(res.getString("DSignJar.jcbAddTimestamp.tooltip"));
jlTimestampServerUrl = new JLabel(res.getString("DSignJar.jlTimestampServerUrl.text"));
jcbTimestampServerUrl = new JComboBox<String>();
jcbTimestampServerUrl.setEditable(true);
jcbTimestampServerUrl.setEnabled(false);
jcbTimestampServerUrl.setToolTipText(res.getString("DSignJar.jcbTimestampServerUrl.tooltip"));
jcbTimestampServerUrl.setModel(new DefaultComboBoxModel<String>(getTsaUrls()));
jbOK = new JButton(res.getString("DSignJar.jbOK.text"));
jbCancel = new JButton(res.getString("DSignJar.jbCancel.text"));
jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
jpButtons = PlatformUtil.createDialogButtonPanel(jbOK, jbCancel);
// layout
Container pane = getContentPane();
pane.setLayout(new MigLayout("insets dialog, fill", "[para]unrel[right]unrel[]", "[]unrel[]"));
MiGUtil.addSeparator(pane, res.getString("DSignJar.jlFiles.text"));
pane.add(jlInputJar, "skip");
pane.add(jtfInputJar, "sgx");
pane.add(jbInputJarBrowse, "wrap");
pane.add(jlSignDirectly, "skip");
pane.add(jcbSignDirectly, "wrap");
pane.add(jlOutputJar, "skip");
pane.add(jtfOutputJar, "sgx");
pane.add(jbOutputJarBrowse, "wrap para");
MiGUtil.addSeparator(pane, res.getString("DSignJar.jlSignature.text"));
pane.add(jlSignatureName, "skip");
pane.add(jtfSignatureName, "sgx, wrap");
pane.add(jlSignatureAlgorithm, "skip");
pane.add(jcbSignatureAlgorithm, "sgx, wrap");
pane.add(jlDigestAlgorithm, "skip");
pane.add(jcbDigestAlgorithm, "sgx, wrap para");
MiGUtil.addSeparator(pane, res.getString("DSignJar.jlTimestamp.text"));
pane.add(jlAddTimestamp, "skip");
pane.add(jcbAddTimestamp, "wrap");
pane.add(jlTimestampServerUrl, "skip");
pane.add(jcbTimestampServerUrl, "sgx, wrap para");
pane.add(new JSeparator(), "spanx, growx, wrap para");
pane.add(jpButtons, "right, spanx");
// actions
jbInputJarBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DSignJar.this);
inputJarBrowsePressed();
} finally {
CursorUtil.setCursorFree(DSignJar.this);
}
}
});
jcbSignDirectly.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
jtfOutputJar.setEnabled(!jcbSignDirectly.isSelected());
jbOutputJarBrowse.setEnabled(!jcbSignDirectly.isSelected());
}
});
jbOutputJarBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DSignJar.this);
outputJarBrowsePressed();
} finally {
CursorUtil.setCursorFree(DSignJar.this);
}
}
});
jcbAddTimestamp.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
jcbTimestampServerUrl.setEnabled(jcbAddTimestamp.isSelected());
}
});
jbOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
okPressed();
}
});
jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jbCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
closeDialog();
}
});
setResizable(false);
getRootPane().setDefaultButton(jbOK);
pack();
setLocationRelativeTo(null);
}
use of org.kse.crypto.digest.DigestType in project keystore-explorer by kaikramer.
the class JCertificateFingerprint method initComponents.
private void initComponents(int columns) {
jcbFingerprintAlg = new JComboBox<DigestType>();
jcbFingerprintAlg.setToolTipText(res.getString("JCertificateFingerprint.jcbFingerprintAlg.tooltip"));
jcbFingerprintAlg.setMaximumRowCount(10);
jcbFingerprintAlg.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
populateFingerprint();
}
});
GridBagConstraints gbc_jcbFingerprintAlg = new GridBagConstraints();
gbc_jcbFingerprintAlg.gridwidth = 1;
gbc_jcbFingerprintAlg.gridheight = 1;
gbc_jcbFingerprintAlg.gridx = 0;
gbc_jcbFingerprintAlg.gridy = 0;
gbc_jcbFingerprintAlg.insets = new Insets(0, 0, 0, 5);
jtfCertificateFingerprint = new JTextField(columns);
jtfCertificateFingerprint.setEditable(false);
jtfCertificateFingerprint.setToolTipText(res.getString("JCertificateFingerprint.jtfCertificateFingerprint.tooltip"));
GridBagConstraints gbc_jtfCertificateFingerprint = new GridBagConstraints();
gbc_jtfCertificateFingerprint.gridwidth = 1;
gbc_jtfCertificateFingerprint.gridheight = 1;
gbc_jtfCertificateFingerprint.gridx = 1;
gbc_jtfCertificateFingerprint.gridy = 0;
gbc_jtfCertificateFingerprint.insets = new Insets(0, 0, 0, 5);
ImageIcon viewIcon = new ImageIcon(getClass().getResource(res.getString("JCertificateFingerprint.jbViewCertificateFingerprint.image")));
jbViewCertificateFingerprint = new JButton(viewIcon);
jbViewCertificateFingerprint.setToolTipText(res.getString("JCertificateFingerprint.jbViewCertificateFingerprint.tooltip"));
jbViewCertificateFingerprint.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(JCertificateFingerprint.this);
displayFingerprint();
} finally {
CursorUtil.setCursorFree(JCertificateFingerprint.this);
}
}
});
GridBagConstraints gbc_jbViewCertificateFingerprint = new GridBagConstraints();
gbc_jbViewCertificateFingerprint.gridwidth = 1;
gbc_jbViewCertificateFingerprint.gridheight = 1;
gbc_jbViewCertificateFingerprint.gridx = 2;
gbc_jbViewCertificateFingerprint.gridy = 0;
gbc_jbViewCertificateFingerprint.insets = new Insets(0, 0, 0, 0);
setLayout(new GridBagLayout());
add(jcbFingerprintAlg, gbc_jcbFingerprintAlg);
add(jtfCertificateFingerprint, gbc_jtfCertificateFingerprint);
add(jbViewCertificateFingerprint, gbc_jbViewCertificateFingerprint);
populateFingerprintAlgs();
populateFingerprint();
}
use of org.kse.crypto.digest.DigestType in project keystore-explorer by kaikramer.
the class JCertificateFingerprint method displayFingerprint.
private void displayFingerprint() {
Container container = getTopLevelAncestor();
DigestType fingerprintAlg = (DigestType) jcbFingerprintAlg.getSelectedItem();
if (container instanceof JDialog) {
DViewCertificateFingerprint dViewCertificateFingerprint = new DViewCertificateFingerprint((JDialog) container, encodedCertificate, fingerprintAlg);
dViewCertificateFingerprint.setLocationRelativeTo(container);
dViewCertificateFingerprint.setVisible(true);
} else if (container instanceof JFrame) {
DViewCertificateFingerprint dViewCertificateFingerprint = new DViewCertificateFingerprint((JFrame) container, encodedCertificate, fingerprintAlg);
dViewCertificateFingerprint.setLocationRelativeTo(container);
dViewCertificateFingerprint.setVisible(true);
}
}
use of org.kse.crypto.digest.DigestType 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);
}
}
Aggregations