public class JarSignatureValidator extends Object
This class provides both offline and online validation capabilities with graceful degradation. When online checks are requested but network connectivity is unavailable, the validator completes all possible offline checks before reporting the connectivity issue.
verify(File)): Quick certificate extraction
and validation without reading all JAR entries.verifyThoroughly(File)): Complete JAR
integrity check, verifying every entry against its signature.Both verification methods attempt online revocation checking by default. Use the
offlineOnly parameter to skip network checks. If online checks are requested
but network connectivity is unavailable, the validator completes all offline checks
and records the communication failure in the status.
// Simple verification with online checks (default)
JarSignatureStatus status = JarSignatureValidator.verify(new File("app.jar"));
// Simple verification, offline only
JarSignatureStatus status = JarSignatureValidator.verify(new File("app.jar"), true);
// Thorough verification with pre-opened JarFile
JarFile jarFile = new JarFile("app.jar", true);
JarSignatureStatus status = JarSignatureValidator.verifyThoroughly(jarFile);
jarFile.close();
// Check results
if ( status.isValid() )
{
System.out.println("JAR is valid");
if ( status.isOfflineOnly() )
System.out.println("Warning: Could not verify revocation online");
}
This class is compatible with Java 8 and later versions.
| Modifier and Type | Class and Description |
|---|---|
static class |
JarSignatureValidator.CertificateInfo
Contains detailed information about an X.509 certificate from a JAR signature.
|
static class |
JarSignatureValidator.JarSignatureStatus
Represents the complete result of JAR signature validation with
comprehensive interrogation methods.
|
static class |
JarSignatureValidator.RevocationInfo
Contains the result of an online certificate revocation check.
|
| Constructor and Description |
|---|
JarSignatureValidator() |
| Modifier and Type | Method and Description |
|---|---|
static List<X509Certificate> |
extractSignerCertificates(File file)
Extracts X.509 certificates from a JAR file's signature block files.
|
static List<X509Certificate> |
extractSignerCertificates(JarFile jar)
Extracts X.509 certificates from a JarFile's signature block files.
|
static JarSignatureValidator.JarSignatureStatus |
verify(File file)
Performs a simple verification of a JAR file's signature with online checks.
|
static JarSignatureValidator.JarSignatureStatus |
verify(File file,
boolean offlineOnly)
Performs a simple verification of a JAR file's signature.
|
static JarSignatureValidator.JarSignatureStatus |
verify(JarFile jarFile)
Performs a simple verification using a pre-opened JarFile with online checks.
|
static JarSignatureValidator.JarSignatureStatus |
verify(JarFile jarFile,
boolean offlineOnly)
Performs a simple verification using a pre-opened JarFile.
|
static JarSignatureValidator.JarSignatureStatus |
verifyThoroughly(File file)
Performs a thorough verification of a JAR file with online checks.
|
static JarSignatureValidator.JarSignatureStatus |
verifyThoroughly(File file,
boolean offlineOnly)
Performs a thorough verification of a JAR file's signature and integrity.
|
static JarSignatureValidator.JarSignatureStatus |
verifyThoroughly(JarFile jarFile)
Performs a thorough verification using a pre-opened JarFile with online checks.
|
static JarSignatureValidator.JarSignatureStatus |
verifyThoroughly(JarFile jarFile,
boolean offlineOnly)
Performs a thorough verification using a pre-opened JarFile.
|
public static JarSignatureValidator.JarSignatureStatus verify(File file)
This method provides a convenient way to verify a JAR file with sensible defaults. It performs:
This method never throws exceptions for I/O or network failures. All failures are captured in the returned status object.
file - the JAR file to verify.public static JarSignatureValidator.JarSignatureStatus verify(File file, boolean offlineOnly)
This method provides a convenient way to verify a JAR file. It performs:
This method never throws exceptions for I/O or network failures. All failures are captured in the returned status object.
file - the JAR file to verify.offlineOnly - if true, skip online revocation checks;
if false, attempt online checks (with graceful fallback).public static JarSignatureValidator.JarSignatureStatus verify(JarFile jarFile)
Use this method when you already have an open JarFile instance.
The JarFile should typically be opened with verification enabled:
JarFile jarFile = new JarFile(filename, true); JarSignatureStatus status = JarSignatureValidator.verify(jarFile); jarFile.close();
Note: This method does not close the JarFile. The caller is responsible for closing it.
jarFile - the pre-opened JarFile to verify.public static JarSignatureValidator.JarSignatureStatus verify(JarFile jarFile, boolean offlineOnly)
Use this method when you already have an open JarFile instance.
The JarFile should typically be opened with verification enabled:
JarFile jarFile = new JarFile(filename, true); JarSignatureStatus status = JarSignatureValidator.verify(jarFile, false); jarFile.close();
Note: This method does not close the JarFile. The caller is responsible for closing it.
jarFile - the pre-opened JarFile to verify.offlineOnly - if true, skip online revocation checks;
if false, attempt online checks (with graceful fallback).public static JarSignatureValidator.JarSignatureStatus verifyThoroughly(File file)
This method provides complete JAR verification including:
This method never throws exceptions for I/O or network failures. All failures are captured in the returned status object.
Performance note: This method reads every byte of every entry
in the JAR file, which can be slow for large JARs. Use verify(File)
for quick certificate-only checks.
file - the JAR file to verify.public static JarSignatureValidator.JarSignatureStatus verifyThoroughly(File file, boolean offlineOnly)
This method provides complete JAR verification including:
This method never throws exceptions for I/O or network failures. All failures are captured in the returned status object.
file - the JAR file to verify.offlineOnly - if true, skip online revocation checks;
if false, attempt online checks (with graceful fallback).public static JarSignatureValidator.JarSignatureStatus verifyThoroughly(JarFile jarFile)
Use this method when you already have an open JarFile instance.
For thorough verification, the JarFile should be opened with verification enabled:
JarFile jarFile = new JarFile(filename, true); JarSignatureStatus status = JarSignatureValidator.verifyThoroughly(jarFile); jarFile.close();
Note: This method does not close the JarFile. The caller is responsible for closing it.
jarFile - the pre-opened JarFile to verify (should be opened with verify=true).public static JarSignatureValidator.JarSignatureStatus verifyThoroughly(JarFile jarFile, boolean offlineOnly)
Use this method when you already have an open JarFile instance.
For thorough verification, the JarFile should be opened with verification enabled:
JarFile jarFile = new JarFile(filename, true); JarSignatureStatus status = JarSignatureValidator.verifyThoroughly(jarFile, true); jarFile.close();
Note: This method does not close the JarFile. The caller is responsible for closing it.
jarFile - the pre-opened JarFile to verify (should be opened with verify=true).offlineOnly - if true, skip online revocation checks;
if false, attempt online checks (with graceful fallback).public static List<X509Certificate> extractSignerCertificates(File file) throws IOException, CertificateException
file - the JAR file to extract certificates from.IOException - if the JAR file cannot be read.CertificateException - if certificate parsing fails.public static List<X509Certificate> extractSignerCertificates(JarFile jar) throws IOException, CertificateException
Note: This method does not close the JarFile.
jar - the JarFile to extract certificates from.IOException - if the JAR file cannot be read.CertificateException - if certificate parsing fails.Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.