I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 79fe799a authored by zzz's avatar zzz
Browse files

Plugins: Stub out SU3 support

parent 2878a648
No related branches found
No related tags found
No related merge requests found
package net.i2p.router.update; package net.i2p.router.update;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.IllegalArgumentException; import java.lang.IllegalArgumentException;
import java.net.URI; import java.net.URI;
...@@ -9,6 +10,7 @@ import java.util.Map; ...@@ -9,6 +10,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import net.i2p.CoreVersion; import net.i2p.CoreVersion;
import net.i2p.crypto.SU3File;
import net.i2p.crypto.TrustedUpdate; import net.i2p.crypto.TrustedUpdate;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
...@@ -118,7 +120,6 @@ class PluginUpdateRunner extends UpdateRunner { ...@@ -118,7 +120,6 @@ class PluginUpdateRunner extends UpdateRunner {
@Override @Override
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) { public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) {
boolean update = false;
updateStatus("<b>" + _("Plugin downloaded") + "</b>"); updateStatus("<b>" + _("Plugin downloaded") + "</b>");
File f = new File(_updateFile); File f = new File(_updateFile);
File appDir = new SecureDirectory(_context.getConfigDir(), PLUGIN_DIR); File appDir = new SecureDirectory(_context.getConfigDir(), PLUGIN_DIR);
...@@ -127,7 +128,43 @@ class PluginUpdateRunner extends UpdateRunner { ...@@ -127,7 +128,43 @@ class PluginUpdateRunner extends UpdateRunner {
statusDone("<b>" + _("Cannot create plugin directory {0}", appDir.getAbsolutePath()) + "</b>"); statusDone("<b>" + _("Cannot create plugin directory {0}", appDir.getAbsolutePath()) + "</b>");
return; return;
} }
boolean isSU3;
try {
isSU3 = isSU3File(f);
} catch (IOException ioe) {
f.delete();
statusDone("<b>" + ioe + "</b>");
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); TrustedUpdate up = new TrustedUpdate(_context);
File to = new File(_context.getTempDir(), "tmp" + _context.random().nextInt() + ZIP); 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 // 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 { ...@@ -222,7 +259,21 @@ class PluginUpdateRunner extends UpdateRunner {
String sudVersion = TrustedUpdate.getVersionString(f); String sudVersion = TrustedUpdate.getVersionString(f);
f.delete(); 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 appName = props.getProperty("name");
String version = props.getProperty("version"); String version = props.getProperty("version");
if (appName == null || version == null || appName.length() <= 0 || version.length() <= 0 || if (appName == null || version == null || appName.length() <= 0 || version.length() <= 0 ||
......
...@@ -56,7 +56,8 @@ public class SU3File { ...@@ -56,7 +56,8 @@ public class SU3File {
private boolean _headerVerified; private boolean _headerVerified;
private SigType _sigType; 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 FILE_VERSION = 0;
private static final int MIN_VERSION_BYTES = 16; private static final int MIN_VERSION_BYTES = 16;
private static final int VERSION_OFFSET = 40; // Signature.SIGNATURE_BYTES; avoid early ctx init private static final int VERSION_OFFSET = 40; // Signature.SIGNATURE_BYTES; avoid early ctx init
...@@ -189,9 +190,9 @@ public class SU3File { ...@@ -189,9 +190,9 @@ public class SU3File {
* Throws if verify vails. * Throws if verify vails.
*/ */
private void verifyHeader(InputStream in) throws IOException, DataFormatException { 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); DataHelper.read(in, magic);
if (!DataHelper.eq(magic, MAGIC)) if (!DataHelper.eq(magic, MAGIC_BYTES))
throw new IOException("Not an su3 file"); throw new IOException("Not an su3 file");
skip(in, 1); skip(in, 1);
int foo = in.read(); int foo = in.read();
...@@ -300,9 +301,9 @@ public class SU3File { ...@@ -300,9 +301,9 @@ public class SU3File {
// read 10 bytes to get the sig type // read 10 bytes to get the sig type
in.mark(10); in.mark(10);
// following is a dup of that in verifyHeader() // 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); DataHelper.read(in, magic);
if (!DataHelper.eq(magic, MAGIC)) if (!DataHelper.eq(magic, MAGIC_BYTES))
throw new IOException("Not an su3 file"); throw new IOException("Not an su3 file");
skip(in, 1); skip(in, 1);
int foo = in.read(); int foo = in.read();
...@@ -379,7 +380,7 @@ public class SU3File { ...@@ -379,7 +380,7 @@ public class SU3File {
in = new BufferedInputStream(new FileInputStream(content)); in = new BufferedInputStream(new FileInputStream(content));
MessageDigest md = sigType.getDigestInstance(); MessageDigest md = sigType.getDigestInstance();
out = new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(_file)), md); out = new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(_file)), md);
out.write(MAGIC); out.write(MAGIC_BYTES);
out.write((byte) 0); out.write((byte) 0);
out.write((byte) FILE_VERSION); out.write((byte) FILE_VERSION);
DataHelper.writeLong(out, 2, sigType.getCode()); DataHelper.writeLong(out, 2, sigType.getCode());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment