Skip to content

Verify signed JAR files. - #633

Merged
kaikramer merged 4 commits into
kaikramer:mainfrom
jonwltn:verify-jar
Sep 29, 2025
Merged

kaikramer merged 4 commits into
kaikramer:mainfrom
jonwltn:verify-jar

Conversation

@jonwltn

@jonwltn jonwltn commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

Closes #439 by adding a menu item and toolbar button for verifying a signed JAR file.

Action items: Need a new icon for the Verify JAR File Signature action

New Tools menu item
image

New toolbar button
image

Handles unsigned JARs:
image

Displays the same message as jarsigner when JAR verification fails:
image

Displays a table similar to the verbose jarsigner output for a verified jar:
image

Entry certificates can be viewed by double clicking on the entry or clicking the Certificates button (uses DViewCertificate). This is the KSE method of displaying the entry certs (jarsigner -verify -verbose -certs) The signers of the JAR can be viewed by clicking the Signatures button (uses DViewSignature). This is the KSE method of display the signers and time stamp information.

This action works just like jarsigner in that only Certificate entries in a KeyStore are used for establishing trust. Any KeyPair entries will be ignored. This is unlike the Verify Signature action which will consider KeyPair entries, too.

Other changes:

  • Updates JarSigner to align with the most recent JAR spec to account for .EC signature blocks
  • Updates DViewSignature to support multiple signatures
  • Introduced a new abstract AuthorityCertificatesAction subclass for common code shared between the VerifySignatureAction and the new VerifyJarAction.
  • Removed some old TODO comments.

private static final String SIGNATURE_VERSION = "1.0";

// Manifest location in JAR file
private static final String MANIFEST_LOCATION = "META-INF/MANIFEST.MF";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant is duplicate of JarFile.MANIFEST_NAME.

return;
}

KeyStore caCertificates = getCaCertificates();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this block to the super class since it's code that VerifyJarAction needs to have.


return signatureFile;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code was moved to the super class.

jdnIssuer.setEnabled(false);
jbTimeStamp.setEnabled(false);
jbSignerAsn1.setEnabled(false);
jbCertificates.setEnabled(false);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the CMSSignedData object was not linked to the selected item so these buttons could always be enabled, but now that the object is linked to the selected item need to disable/enable based on the selection.

}
};
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a JTable extension is the Java Swing Tutorial method of adding tooltips to column headers. I'm considering doing a full refactoring of KSE to follow this model. I'd move this inner class to a new org.kse.gui.tables package and use it as the super class for JKseTable or just bring this code directly into JKseTable.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

@kaikramer kaikramer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! Thank you very much.

I'll take care of the icon.

Comment thread kse/src/main/java/org/kse/crypto/x509/X509CertUtil.java
trustedCerts.addAll(extractCertificates(keyStore));

if (caCertificates != null)
{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep the code formatting consistent. There are several other occurrences of this in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. I'll find them all and fix them.

Comment thread kse/src/main/java/org/kse/gui/dialogs/DViewSignedJar.java Outdated
importTrustedCertificateAction.setEnabled(false);
importKeyPairAction.setEnabled(false);
verifySignatureAction.setEnabled(false);
verifyJarAction.setEnabled(false);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missing something but there is no reason to not allow the 2 verify actions when no keystore is open, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As currently coded up, the verify actions will throw a NullPointerException when looking up the trusted certs, but I can change them to automatically use the cacerts if a key store is not loaded.

@jonwltn
jonwltn requested a review from kaikramer September 27, 2025 23:21
@kaikramer
kaikramer merged commit b41ee23 into kaikramer:main Sep 29, 2025
4 checks passed
@jonwltn
jonwltn deleted the verify-jar branch September 29, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please allow the verifying of signed jar files.

2 participants