net.i2p.crypto

## Class SU3File

- java.lang.Object
- - net.i2p.crypto.SU3File

-     public class SU3File
      extends Object

  I2P update file format handler for .su3 files. Supports reading, writing, and verification of signed update packages.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CONTENT_BLOCKLIST`
    `static int` | `CONTENT_NEWS`
    `static int` | `CONTENT_PLUGIN`
    `static int` | `CONTENT_RESEED`
    `static int` | `CONTENT_ROUTER`
    `static int` | `CONTENT_UNKNOWN`
    `static String` | `MAGIC`
    `static int` | `TYPE_DMG`
    `static int` | `TYPE_EXE`
    `static int` | `TYPE_HTML`
    `static int` | `TYPE_TXT_GZ`
    `static int` | `TYPE_XML`
    `static int` | `TYPE_XML_GZ`
    `static int` | `TYPE_ZIP` The file type is advisory and is application-dependent.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SU3File(File file)`
    `SU3File(I2PAppContext context, File file)`
    `SU3File(String file)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getContentType()` The ContentType is the trust domain for the content.
    `int` | `getFileType()` The file type is advisory and is application-dependent.
    `String` | `getSignerString()` This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
    `SigType` | `getSigType()` This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
    `String` | `getVersionString()` This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
    `static void` | `main(String[] args)` Parses command line arguments when this class is used from the command line.
    `void` | `setVerifySignature(boolean shouldVerify)` Should the signature be verified? Default true
    `boolean` | `verify()` One-pass verify.
    `boolean` | `verifyAndMigrate(File migrateTo)` One-pass verify and extract the content.
    `void` | `verifyHeader()` This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
    `void` | `write(File content, int fileType, int contentType, String version, String signer, PrivateKey privkey, SigType sigType)` One-pass wrap and sign the content.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CONTENT_BLOCKLIST

          public static final int CONTENT_BLOCKLIST

      See Also:
        Constant Field Values

    - #### CONTENT_NEWS

          public static final int CONTENT_NEWS

      See Also:
        Constant Field Values

    - #### CONTENT_PLUGIN

          public static final int CONTENT_PLUGIN

      See Also:
        Constant Field Values

    - #### CONTENT_RESEED

          public static final int CONTENT_RESEED

      See Also:
        Constant Field Values

    - #### CONTENT_ROUTER

          public static final int CONTENT_ROUTER

      See Also:
        Constant Field Values

    - #### CONTENT_UNKNOWN

          public static final int CONTENT_UNKNOWN

      See Also:
        Constant Field Values

    - #### MAGIC

          public static final String MAGIC

      See Also:
        Constant Field Values

    - #### TYPE_DMG

          public static final int TYPE_DMG

      See Also:
        Constant Field Values

    - #### TYPE_EXE

          public static final int TYPE_EXE

      See Also:
        Constant Field Values

    - #### TYPE_HTML

          public static final int TYPE_HTML

      See Also:
        Constant Field Values

    - #### TYPE_TXT_GZ

          public static final int TYPE_TXT_GZ

      See Also:
        Constant Field Values

    - #### TYPE_XML

          public static final int TYPE_XML

      See Also:
        Constant Field Values

    - #### TYPE_XML_GZ

          public static final int TYPE_XML_GZ

      See Also:
        Constant Field Values

    - #### TYPE_ZIP

          public static final int TYPE_ZIP

      The file type is advisory and is application-dependent. The following values are defined but any value 0-255 is allowed.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SU3File

          public SU3File(File file)

    - #### SU3File

          public SU3File(I2PAppContext context,
                         File file)

    - #### SU3File

          public SU3File(String file)

  - ### Method Detail

    - #### getContentType

          public int getContentType()
                             throws IOException

      The ContentType is the trust domain for the content. The signer and signature will be checked with the trusted certificates for that type. This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
      Returns:
        -1 if unknown
      Throws:
        `IOException`

    - #### getFileType

          public int getFileType()
                          throws IOException

      The file type is advisory and is application-dependent. The following values are defined but any value 0-255 is allowed. This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
      Returns:
        0-255 or -1 if unknown
      Throws:
        `IOException`

    - #### getSignerString

          public String getSignerString()
                                 throws IOException

      This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
      Throws:
        `IOException`

    - #### getSigType

          public SigType getSigType()
                             throws IOException

      This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
      Returns:
        null if unknown
      Throws:
        `IOException`

    - #### getVersionString

          public String getVersionString()
                                  throws IOException

      This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called.
      Throws:
        `IOException`

    - #### main

          public static void main(String[] args)

      Parses command line arguments when this class is used from the command line. Exits 1 on failure so this can be used in scripts.
      Parameters:
        `args` - Command line parameters.

    - #### setVerifySignature

          public void setVerifySignature(boolean shouldVerify)

      Should the signature be verified? Default true

    - #### verify

          public boolean verify()
                         throws IOException

      One-pass verify. Throws IOE on all format errors.
      Returns:
        true if signature is good
      Throws:
        `IOException`

    - #### verifyAndMigrate

          public boolean verifyAndMigrate(File migrateTo)
                                   throws IOException

      One-pass verify and extract the content. Recommend extracting to a temp location as the sig is not checked until after extraction. This will delete the file if the sig does not verify. Throws IOE on all format errors.
      Parameters:
        `migrateTo` - the output file, probably in zip format. Null for verify only.
      Returns:
        true if signature is good
      Throws:
        `IOException`

    - #### verifyHeader

          public void verifyHeader()
                            throws IOException

      This does not check the signature, but it will fail if the signer is unknown, unless setVerifySignature(false) has been called. Throws IOE if verify vails.
      Throws:
        `IOException`

    - #### write

          public void write(File content,
                            int fileType,
                            int contentType,
                            String version,
                            String signer,
                            PrivateKey privkey,
                            SigType sigType)
                     throws IOException

      One-pass wrap and sign the content. Writes to the file specified in the constructor. Throws on all errors.
      Parameters:
        `content` - the input file, probably in zip format
        `fileType` - 0-255, 0 for zip
        `contentType` - 0-255
        `version` - 1-255 bytes when converted to UTF-8
        `signer` - ID of the public key, 1-255 bytes when converted to UTF-8
      Throws:
        `IOException`