diff --git a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java
index d532a9c5c..65df785db 100644
--- a/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java
+++ b/apps/routerconsole/java/src/net/i2p/router/update/PluginUpdateRunner.java
@@ -1,6 +1,7 @@
package net.i2p.router.update;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.lang.IllegalArgumentException;
import java.net.URI;
@@ -9,6 +10,7 @@ import java.util.Map;
import java.util.Properties;
import net.i2p.CoreVersion;
+import net.i2p.crypto.SU3File;
import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper;
import net.i2p.router.RouterContext;
@@ -118,7 +120,6 @@ class PluginUpdateRunner extends UpdateRunner {
@Override
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
- boolean update = false;
updateStatus("" + _("Plugin downloaded") + "");
File f = new File(_updateFile);
File appDir = new SecureDirectory(_context.getConfigDir(), PLUGIN_DIR);
@@ -127,7 +128,43 @@ class PluginUpdateRunner extends UpdateRunner {
statusDone("" + _("Cannot create plugin directory {0}", appDir.getAbsolutePath()) + "");
return;
}
+ boolean isSU3;
+ try {
+ isSU3 = isSU3File(f);
+ } catch (IOException ioe) {
+ f.delete();
+ statusDone("" + ioe + "");
+ return;
+ }
+ if (isSU3)
+ processSU3(f, appDir, url);
+ else
+ processSUD(f, appDir, url);
+ }
+ /**
+ * @since 0.9.15
+ * @return if SU3
+ */
+ private static boolean isSU3File(File f) throws IOException {
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(f);
+ for (int i = 0; i < SU3File.MAGIC.length(); i++) {
+ if (fis.read() != SU3File.MAGIC.charAt(i))
+ return false;
+ }
+ return true;
+ } finally {
+ if (fis != null) try { fis.close(); } catch (IOException ioe) {}
+ }
+ }
+
+ /**
+ * @since 0.9.15
+ * @return success
+ */
+ private void processSUD(File f, File appDir, String url) {
TrustedUpdate up = new TrustedUpdate(_context);
File to = new File(_context.getTempDir(), "tmp" + _context.random().nextInt() + ZIP);
// extract to a zip file whether the sig is good or not, so we can get the properties file
@@ -222,7 +259,21 @@ class PluginUpdateRunner extends UpdateRunner {
String sudVersion = TrustedUpdate.getVersionString(f);
f.delete();
+ processFinal(to, appDir, tempDir, url, props, sudVersion, pubkey, signer);
+ }
+ /**
+ * @since 0.9.15
+ */
+ private void processSU3(File f, File appDir, String url) {
+ // TODO
+ }
+
+ /**
+ * @since 0.9.15
+ */
+ private void processFinal(File to, File appDir, File tempDir, String url, Properties props, String sudVersion, String pubkey, String signer) {
+ boolean update = false;
String appName = props.getProperty("name");
String version = props.getProperty("version");
if (appName == null || version == null || appName.length() <= 0 || version.length() <= 0 ||
diff --git a/core/java/src/net/i2p/crypto/SU3File.java b/core/java/src/net/i2p/crypto/SU3File.java
index a6fb62e5e..30e172d4d 100644
--- a/core/java/src/net/i2p/crypto/SU3File.java
+++ b/core/java/src/net/i2p/crypto/SU3File.java
@@ -56,7 +56,8 @@ public class SU3File {
private boolean _headerVerified;
private SigType _sigType;
- private static final byte[] MAGIC = DataHelper.getUTF8("I2Psu3");
+ public static final String MAGIC = "I2Psu3";
+ private static final byte[] MAGIC_BYTES = DataHelper.getASCII(MAGIC);
private static final int FILE_VERSION = 0;
private static final int MIN_VERSION_BYTES = 16;
private static final int VERSION_OFFSET = 40; // Signature.SIGNATURE_BYTES; avoid early ctx init
@@ -189,9 +190,9 @@ public class SU3File {
* Throws if verify vails.
*/
private void verifyHeader(InputStream in) throws IOException, DataFormatException {
- byte[] magic = new byte[MAGIC.length];
+ byte[] magic = new byte[MAGIC_BYTES.length];
DataHelper.read(in, magic);
- if (!DataHelper.eq(magic, MAGIC))
+ if (!DataHelper.eq(magic, MAGIC_BYTES))
throw new IOException("Not an su3 file");
skip(in, 1);
int foo = in.read();
@@ -300,9 +301,9 @@ public class SU3File {
// read 10 bytes to get the sig type
in.mark(10);
// following is a dup of that in verifyHeader()
- byte[] magic = new byte[MAGIC.length];
+ byte[] magic = new byte[MAGIC_BYTES.length];
DataHelper.read(in, magic);
- if (!DataHelper.eq(magic, MAGIC))
+ if (!DataHelper.eq(magic, MAGIC_BYTES))
throw new IOException("Not an su3 file");
skip(in, 1);
int foo = in.read();
@@ -379,7 +380,7 @@ public class SU3File {
in = new BufferedInputStream(new FileInputStream(content));
MessageDigest md = sigType.getDigestInstance();
out = new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(_file)), md);
- out.write(MAGIC);
+ out.write(MAGIC_BYTES);
out.write((byte) 0);
out.write((byte) FILE_VERSION);
DataHelper.writeLong(out, 2, sigType.getCode());