Package proguard.io
Class SignedJarWriter
- java.lang.Object
-
- proguard.io.JarWriter
-
- proguard.io.SignedJarWriter
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,DataEntryWriter
public class SignedJarWriter extends JarWriter
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class proguard.io.JarWriter
JarWriter.MyMultiDigestOutputStream
-
-
Field Summary
-
Fields inherited from class proguard.io.JarWriter
creator, currentManifestEntry, DEFAULT_DIGEST_ALGORITHM, digestAlgorithms, manifestEntryWriter, zipEntryWriter
-
-
Constructor Summary
Constructors Constructor Description SignedJarWriter(java.security.KeyStore.PrivateKeyEntry privateKeyEntry, java.lang.String[] digestAlgorithms, java.lang.String creator, int[] apkSignatureSchemeIDs, DataEntryWriter zipEntryWriter)
Creates a new SignedJarWriter with the given settings.SignedJarWriter(java.security.KeyStore.PrivateKeyEntry privateKeyEntry, java.lang.String[] digestAlgorithms, java.lang.String creator, DataEntryWriter zipEntryWriter)
Creates a new SignedJarWriter with the given settings.SignedJarWriter(java.security.KeyStore.PrivateKeyEntry privateKeyEntry, DataEntryWriter zipEntryWriter)
Creates a new SignedJarWriter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.io.OutputStream
createManifestOutputStream(DataEntry manifestEntry)
Creates an output stream for the specified manifest file.java.io.OutputStream
createOutputStream(DataEntry dataEntry)
Creates a new output stream for writing data.protected void
finish()
Writes out the collected manifest file before closing the jar, if any.static void
main(java.lang.String[] args)
Provides a simple test for this class, creating a signed apk file (only v1) with the given name and a few aligned/compressed/uncompressed zip entries.protected void
openManifestFiles()
Prepares streams and writers for capturing digests of a parent entry.void
println(java.io.PrintWriter pw, java.lang.String prefix)
Prints out the structure of the data entry writer.-
Methods inherited from class proguard.io.JarWriter
close, createDirectory, finishIfNecessary, printWriter, sameOutputStream
-
-
-
-
Constructor Detail
-
SignedJarWriter
public SignedJarWriter(java.security.KeyStore.PrivateKeyEntry privateKeyEntry, DataEntryWriter zipEntryWriter)
Creates a new SignedJarWriter.- Parameters:
privateKeyEntry
- the private key to be used for signing the zip entries.zipEntryWriter
- the data entry writer that can provide output streams for the jar entries.
-
SignedJarWriter
public SignedJarWriter(java.security.KeyStore.PrivateKeyEntry privateKeyEntry, java.lang.String[] digestAlgorithms, java.lang.String creator, DataEntryWriter zipEntryWriter)
Creates a new SignedJarWriter with the given settings.- Parameters:
privateKeyEntry
- the private key to be used for signing the zip entries.digestAlgorithms
- the manifest digest algorithms, e.g. "SHA-256".creator
- the creator to mention in the manifest file.zipEntryWriter
- the data entry writer that can provide output streams for the jar entries.
-
SignedJarWriter
public SignedJarWriter(java.security.KeyStore.PrivateKeyEntry privateKeyEntry, java.lang.String[] digestAlgorithms, java.lang.String creator, int[] apkSignatureSchemeIDs, DataEntryWriter zipEntryWriter)
Creates a new SignedJarWriter with the given settings.- Parameters:
privateKeyEntry
- the private key to be used for signing the zip entries.digestAlgorithms
- the manifest digest algorithms, e.g. "SHA-256".creator
- the creator to mention in the manifest file.apkSignatureSchemeIDs
- an optional list of external APK signature scheme IDs to be specified with the attribute "X-Android-APK-Signed" in *.SF files.zipEntryWriter
- the data entry writer that can provide output streams for the jar entries.
-
-
Method Detail
-
createOutputStream
public java.io.OutputStream createOutputStream(DataEntry dataEntry) throws java.io.IOException
Description copied from interface:DataEntryWriter
Creates a new output stream for writing data. The caller is responsible for closing the stream.- Specified by:
createOutputStream
in interfaceDataEntryWriter
- Overrides:
createOutputStream
in classJarWriter
- Parameters:
dataEntry
- the data entry for which the output stream is to be created.- Returns:
- the output stream. The stream may be
null
to indicate that the data entry should not be written. - Throws:
java.io.IOException
-
println
public void println(java.io.PrintWriter pw, java.lang.String prefix)
Description copied from interface:DataEntryWriter
Prints out the structure of the data entry writer.- Specified by:
println
in interfaceDataEntryWriter
- Overrides:
println
in classJarWriter
- Parameters:
pw
- the print stream to which the structure should be printed.prefix
- a prefix for every printed line.
-
openManifestFiles
protected void openManifestFiles() throws java.io.IOException
Description copied from class:JarWriter
Prepares streams and writers for capturing digests of a parent entry.- Overrides:
openManifestFiles
in classJarWriter
- Throws:
java.io.IOException
-
createManifestOutputStream
protected java.io.OutputStream createManifestOutputStream(DataEntry manifestEntry) throws java.io.IOException
Description copied from class:JarWriter
Creates an output stream for the specified manifest file.- Overrides:
createManifestOutputStream
in classJarWriter
- Throws:
java.io.IOException
-
finish
protected void finish() throws java.io.IOException
Description copied from class:JarWriter
Writes out the collected manifest file before closing the jar, if any.
-
main
public static void main(java.lang.String[] args)
Provides a simple test for this class, creating a signed apk file (only v1) with the given name and a few aligned/compressed/uncompressed zip entries. Arguments: keystore keystore_password alias password jar_filename Create a keystore with: keytool -genkey -dname 'CN=John Doe, OU=Development, O=Guardsquare, STREET=Tervuursevest, L=Leuven, ST=Brabant, C=Belgium' -keystore /tmp/test.keystore -storepass android -alias AndroidDebugKey -keypass android -keyalg RSA -keysize 512 List the contents of the keystore with keytool -v -list -keystore /tmp/test.keystore -alias androiddebugkey -storepass android Verify the signed jar with: jarsigner -verify -verbose /tmp/test.jar or with: android-sdk/build-tools/24.0.3/apksigner verify --min-sdk-version 19 -v /tmp/test.jar
-
-