Package pro.gravit.launchserver.binary
Class SignerJar
- java.lang.Object
-
- pro.gravit.launchserver.binary.SignerJar
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class SignerJar extends java.lang.Object implements java.lang.AutoCloseableGenerator 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
Constructors Constructor Description SignerJar(java.util.zip.ZipOutputStream out, java.util.function.Supplier<org.bouncycastle.cms.CMSSignedDataGenerator> gen, java.lang.String sig_fn, java.lang.String sig_key_fn)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFileContents(java.lang.String filename, byte[] contents)Adds a file to the JAR.voidaddFileContents(java.lang.String filename, java.io.InputStream contents)Adds a file to the JAR.voidaddFileContents(java.util.zip.ZipEntry entry, byte[] contents)Adds a file to the JAR.voidaddFileContents(java.util.zip.ZipEntry entry, java.io.InputStream contents)Adds a file to the JAR.voidaddManifestAttribute(java.lang.String name, java.lang.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.java.util.zip.ZipOutputStreamgetZos()
-
-
-
Method Detail
-
addFileContents
public void addFileContents(java.lang.String filename, byte[] contents) throws java.io.IOExceptionAdds 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:
java.io.IOExceptionjava.lang.NullPointerException- if any of the arguments isnull
-
addFileContents
public void addFileContents(java.lang.String filename, java.io.InputStream contents) throws java.io.IOExceptionAdds 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:
java.io.IOExceptionjava.lang.NullPointerException- if any of the arguments isnull
-
addFileContents
public void addFileContents(java.util.zip.ZipEntry entry, byte[] contents) throws java.io.IOExceptionAdds 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:
java.io.IOExceptionjava.lang.NullPointerException- if any of the arguments isnull
-
addFileContents
public void addFileContents(java.util.zip.ZipEntry entry, java.io.InputStream contents) throws java.io.IOExceptionAdds 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:
java.io.IOExceptionjava.lang.NullPointerException- if any of the arguments isnull
-
addManifestAttribute
public void addManifestAttribute(java.lang.String name, java.lang.String value)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
public void close() throws java.io.IOExceptionCloses 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 interfacejava.lang.AutoCloseable- Throws:
java.io.IOExceptionjava.lang.RuntimeException- if the signing goes wrong
-
finish
public void finish() throws java.io.IOExceptionFinishes the JAR file by writing the manifest and signature data to it and finishing the ZIP entries. It leaves the underlying stream open.- Throws:
java.io.IOExceptionjava.lang.RuntimeException- if the signing goes wrong
-
getZos
public java.util.zip.ZipOutputStream getZos()
-
-