* Update:

- Reset found version in update loop so we don't fetch from
     the next host too.
   - Prevent NPE on version after SSL fetch
   - Fix su3 version check
 * EepGet:
   - Fix non-proxied PartialEepGet
   - Prevent non-proxied eepget for an I2P host
   - Fail if no hostname in URL
This commit is contained in:
zzz
2013-10-06 16:02:33 +00:00
parent d0f6be3161
commit 4bd27ea1d3
5 changed files with 30 additions and 8 deletions

View File

@ -1104,7 +1104,7 @@ public class ConsoleUpdateManager implements UpdateManager {
if (up.verifyAndMigrate(temp)) {
String ver = up.getVersionString();
int type = up.getContentType();
if (ver == null || VersionComparator.comp(RouterVersion.VERSION, ver) <= 0)
if (ver == null || VersionComparator.comp(RouterVersion.VERSION, ver) >= 0)
err = "Old version " + ver;
else if (type != SU3File.CONTENT_ROUTER)
err = "Bad su3 content type " + type;

View File

@ -150,8 +150,14 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
boolean isSSL = false;
if (_method == HTTP) {
shouldProxy = _context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY);
if (shouldProxy) {
proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
proxyPort = ConfigUpdateHandler.proxyPort(_context);
} else {
// TODO, wrong method, fail
proxyHost = null;
proxyPort = 0;
}
} else if (_method == HTTP_CLEARNET) {
shouldProxy = false;
proxyHost = null;
@ -191,7 +197,8 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
_log.debug("Selected update URL: " + updateURL);
// Check the first 56 bytes for the version
// PartialEepGet works with clearnet but not with SSL
// FIXME PartialEepGet works with clearnet but not with SSL
_newVersion = null;
if (!isSSL) {
_isPartial = true;
_baos.reset();
@ -265,6 +272,9 @@ class UpdateRunner extends I2PAppThread implements UpdateTask, EepGet.StatusList
return;
}
// FIXME if we didn't do a partial, we don't know
if (_newVersion == null)
_newVersion = "unknown";
File tmp = new File(_updateFile);
if (_mgr.notifyComplete(this, _newVersion, tmp))
this.done = true;

View File

@ -1055,12 +1055,14 @@ public class EepGet {
URL url = new URL(_actualURL);
if ("http".equals(url.getProtocol())) {
String host = url.getHost();
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
throw new MalformedURLException("I2P addresses must be proxied");
int port = url.getPort();
if (port == -1)
port = 80;
_proxy = new Socket(host, port);
} else {
throw new IOException("URL is not supported:" + _actualURL);
throw new MalformedURLException("URL is not supported:" + _actualURL);
}
// an MUE is an IOE
//} catch (MalformedURLException mue) {
@ -1089,6 +1091,8 @@ public class EepGet {
post = true;
URL url = new URL(_actualURL);
String host = url.getHost();
if (host == null || host.length() <= 0)
throw new MalformedURLException("Bad URL, no host");
int port = url.getPort();
String path = url.getPath();
String query = url.getQuery();

View File

@ -3,6 +3,7 @@ package net.i2p.util;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import net.i2p.I2PAppContext;
@ -32,8 +33,10 @@ public class PartialEepGet extends EepGet {
public PartialEepGet(I2PAppContext ctx, String proxyHost, int proxyPort,
OutputStream outputStream, String url, long size) {
// we're using this constructor:
// public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries, long minSize, long maxSize, String outputFile, OutputStream outputStream, String url, boolean allowCaching, String etag, String postData) {
super(ctx, true, proxyHost, proxyPort, 0, size, size, null, outputStream, url, true, null, null);
// public EepGet(I2PAppContext ctx, boolean shouldProxy, String proxyHost, int proxyPort, int numRetries,
// long minSize, long maxSize, String outputFile, OutputStream outputStream, String url, boolean allowCaching, String etag, String postData) {
super(ctx, proxyHost != null && proxyPort > 0, proxyHost, proxyPort, 0,
size, size, null, outputStream, url, true, null, null);
_fetchSize = size;
}
@ -106,6 +109,8 @@ public class PartialEepGet extends EepGet {
StringBuilder buf = new StringBuilder(2048);
URL url = new URL(_actualURL);
String host = url.getHost();
if (host == null || host.length() <= 0)
throw new MalformedURLException("Bad URL, no host");
int port = url.getPort();
String path = url.getPath();
String query = url.getQuery();

View File

@ -46,6 +46,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyStore;
import java.security.GeneralSecurityException;
@ -492,6 +493,8 @@ public class SSLEepGet extends EepGet {
int port = 0;
if ("https".equals(url.getProtocol())) {
host = url.getHost();
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
throw new MalformedURLException("I2P addresses unsupported");
port = url.getPort();
if (port == -1)
port = 443;
@ -500,7 +503,7 @@ public class SSLEepGet extends EepGet {
else
_proxy = SSLSocketFactory.getDefault().createSocket(host, port);
} else {
throw new IOException("Only https supported: " + _actualURL);
throw new MalformedURLException("Only https supported: " + _actualURL);
}
// an MUE is an IOE
//} catch (MalformedURLException mue) {