Package pro.gravit.launchserver.binary
Class SignerJar
java.lang.Object
pro.gravit.launchserver.binary.SignerJar
- All Implemented Interfaces:
AutoCloseable
Generator of signed Jars. It stores some data in memory therefore it is not suited for creation of large files. The
usage:
KeyStore keystore = KeyStore.getInstance("JKS");
keyStore.load(keystoreStream, "keystorePassword");
SignerJar jar = new SignerJar(out, keyStore, "keyAlias", "keyPassword");
signedJar.addManifestAttribute("Main-Class", "com.example.MainClass");
signedJar.addManifestAttribute("Application-Name", "Example");
signedJar.addManifestAttribute("Permissions", "all-permissions");
signedJar.addManifestAttribute("Codebase", "*");
signedJar.addFileContents("com/example/MainClass.class", clsData);
signedJar.addFileContents("JNLP-INF/APPLICATION.JNLP", generateJnlpContents());
signedJar.close();
-
Constructor Summary
ConstructorsConstructorDescriptionSignerJar(ZipOutputStream out, Supplier<org.bouncycastle.cms.CMSSignedDataGenerator> gen, String sig_fn, String sig_key_fn) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileContents(String filename, byte[] contents)Adds a file to the JAR.voidaddFileContents(String filename, InputStream contents)Adds a file to the JAR.voidaddFileContents(ZipEntry entry, byte[] contents)Adds a file to the JAR.voidaddFileContents(ZipEntry entry, InputStream contents)Adds a file to the JAR.voidaddManifestAttribute(String name, String value)Adds a header to the manifest of the JAR.voidclose()Closes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries.voidfinish()Finishes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries.getZos()
-
Constructor Details
-
SignerJar
public SignerJar(ZipOutputStream out, Supplier<org.bouncycastle.cms.CMSSignedDataGenerator> gen, String sig_fn, String sig_key_fn)
-
-
Method Details
-
addFileContents
Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.- Parameters:
filename- name of the file to add (use forward slash as a path separator)contents- contents of the file- Throws:
IOExceptionNullPointerException- if any of the arguments isnull
-
addFileContents
Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.- Parameters:
filename- name of the file to add (use forward slash as a path separator)contents- contents of the file- Throws:
IOExceptionNullPointerException- if any of the arguments isnull
-
addFileContents
Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.- Parameters:
entry- name of the file to add (use forward slash as a path separator)contents- contents of the file- Throws:
IOExceptionNullPointerException- if any of the arguments isnull
-
addFileContents
Adds a file to the JAR. The file is immediately added to the zipped output stream. This method cannot be called once the stream is closed.- Parameters:
entry- name of the file to add (use forward slash as a path separator)contents- contents of the file- Throws:
IOExceptionNullPointerException- if any of the arguments isnull
-
addManifestAttribute
Adds a header to the manifest of the JAR.- Parameters:
name- name of the attribute, it is placed into the main section of the manifest filevalue- value of the attribute
-
close
Closes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It closes the underlying stream.- Specified by:
closein interfaceAutoCloseable- Throws:
IOExceptionRuntimeException- if the signing goes wrong
-
finish
Finishes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It leaves the underlying stream open.- Throws:
IOExceptionRuntimeException- if the signing goes wrong
-
getZos
-