Package proguard.io

Class SignedJarWriter

java.lang.Object
proguard.io.JarWriter
proguard.io.SignedJarWriter
All Implemented Interfaces:
AutoCloseable, DataEntryWriter

public class SignedJarWriter extends JarWriter
This JarWriter sends data entries to a given jar file, automatically adding a manifest file and signing it with JAR signature scheme v1.

You'll typically wrap a ZipWriter or one of its extensions:

     new SignedApkWriter(privateKeyEntry, new ZipWriter(...))
 
  • Constructor Details

    • SignedJarWriter

      public SignedJarWriter(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(KeyStore.PrivateKeyEntry privateKeyEntry, String[] digestAlgorithms, 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(KeyStore.PrivateKeyEntry privateKeyEntry, String[] digestAlgorithms, 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 Details

    • createOutputStream

      public OutputStream createOutputStream(DataEntry dataEntry) throws 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 interface DataEntryWriter
      Overrides:
      createOutputStream in class JarWriter
      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:
      IOException
    • println

      public void println(PrintWriter pw, String prefix)
      Description copied from interface: DataEntryWriter
      Prints out the structure of the data entry writer.
      Specified by:
      println in interface DataEntryWriter
      Overrides:
      println in class JarWriter
      Parameters:
      pw - the print stream to which the structure should be printed.
      prefix - a prefix for every printed line.
    • openManifestFiles

      protected void openManifestFiles() throws IOException
      Description copied from class: JarWriter
      Prepares streams and writers for capturing digests of a parent entry.
      Overrides:
      openManifestFiles in class JarWriter
      Throws:
      IOException
    • createManifestOutputStream

      protected OutputStream createManifestOutputStream(DataEntry manifestEntry) throws IOException
      Description copied from class: JarWriter
      Creates an output stream for the specified manifest file.
      Overrides:
      createManifestOutputStream in class JarWriter
      Throws:
      IOException
    • finish

      protected void finish() throws IOException
      Description copied from class: JarWriter
      Writes out the collected manifest file before closing the jar, if any.
      Overrides:
      finish in class JarWriter
      Throws:
      IOException
    • main

      public static void main(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