forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.test2' (head 8fa44268a1dd2b7baaf01806e6994281ab031870)
to branch 'i2p.i2p' (head 44afdaa15ce8a95c112c7d58a5908f401c1a0145)
This commit is contained in:
@@ -862,7 +862,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
if ((duration > 100) && _log.shouldLog(Log.INFO))
|
||||
_log.info("Message availability notification for " + msgId.intValue() + " took "
|
||||
+ duration + " to " + _sessionListener);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Error notifying app of message availability", e);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -399,7 +399,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
|
||||
try {
|
||||
_demultiplexer.messageAvailable(I2PSessionMuxedImpl.this,
|
||||
msg.id, msg.size, msg.proto, msg.fromPort, msg.toPort);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.error("Error notifying app of message availability", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class SingleFileNamingService extends NamingService {
|
||||
key = getKey(hostname.substring(4));
|
||||
if (key != null)
|
||||
return lookupBase64(key);
|
||||
} catch (Exception ioe) {
|
||||
} catch (IOException ioe) {
|
||||
if (_file.exists())
|
||||
_log.error("Error loading hosts file " + _file, ioe);
|
||||
else if (_log.shouldLog(Log.WARN))
|
||||
@@ -123,7 +123,7 @@ public class SingleFileNamingService extends NamingService {
|
||||
return line.substring(0, split);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception ioe) {
|
||||
} catch (IOException ioe) {
|
||||
if (_file.exists())
|
||||
_log.error("Error loading hosts file " + _file, ioe);
|
||||
else if (_log.shouldLog(Log.WARN))
|
||||
|
||||
@@ -257,7 +257,7 @@ public class DSAEngine {
|
||||
_log.warn("Took too long to verify the signature (" + diff + "ms)");
|
||||
}
|
||||
return ok;
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Error verifying the signature", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.i2p.crypto;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.math.BigInteger;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.Provider;
|
||||
import java.security.Security;
|
||||
import java.security.spec.ECField;
|
||||
@@ -278,7 +279,7 @@ class ECConstants {
|
||||
AlgorithmParameters ap;
|
||||
try {
|
||||
ap = AlgorithmParameters.getInstance("EC");
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
if (BC_AVAILABLE) {
|
||||
log("Named curve " + name + " is not available, trying BC", e);
|
||||
ap = AlgorithmParameters.getInstance("EC", "BC");
|
||||
@@ -292,7 +293,7 @@ class ECConstants {
|
||||
ECParameterSpec rv = ap.getParameterSpec(ECParameterSpec.class);
|
||||
log("Named curve " + name + " loaded");
|
||||
return rv;
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
log("Named curve " + name + " is not available", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -327,12 +327,12 @@ public class ElGamalAESEngine {
|
||||
//ByteArrayInputStream bais = new ByteArrayInputStream(decrypted);
|
||||
int cur = 0;
|
||||
long numTags = DataHelper.fromLong(decrypted, cur, 2);
|
||||
if ((numTags < 0) || (numTags > MAX_TAGS_RECEIVED)) throw new Exception("Invalid number of session tags");
|
||||
if ((numTags < 0) || (numTags > MAX_TAGS_RECEIVED)) throw new IllegalArgumentException("Invalid number of session tags");
|
||||
if (numTags > 0) tags = new ArrayList<SessionTag>((int)numTags);
|
||||
cur += 2;
|
||||
//_log.debug("# tags: " + numTags);
|
||||
if (numTags * SessionTag.BYTE_LENGTH > decrypted.length - 2) {
|
||||
throw new Exception("# tags: " + numTags + " is too many for " + (decrypted.length - 2));
|
||||
throw new IllegalArgumentException("# tags: " + numTags + " is too many for " + (decrypted.length - 2));
|
||||
}
|
||||
for (int i = 0; i < numTags; i++) {
|
||||
byte tag[] = new byte[SessionTag.BYTE_LENGTH];
|
||||
@@ -344,7 +344,7 @@ public class ElGamalAESEngine {
|
||||
cur += 4;
|
||||
//_log.debug("len: " + len);
|
||||
if ((len < 0) || (len > decrypted.length - cur - Hash.HASH_LENGTH - 1))
|
||||
throw new Exception("Invalid size of payload (" + len + ", remaining " + (decrypted.length-cur) +")");
|
||||
throw new IllegalArgumentException("Invalid size of payload (" + len + ", remaining " + (decrypted.length-cur) +")");
|
||||
//byte hashval[] = new byte[Hash.HASH_LENGTH];
|
||||
//System.arraycopy(decrypted, cur, hashval, 0, Hash.HASH_LENGTH);
|
||||
//readHash = new Hash();
|
||||
@@ -379,8 +379,8 @@ public class ElGamalAESEngine {
|
||||
return unencrData;
|
||||
}
|
||||
|
||||
throw new Exception("Hash does not match");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Hash does not match");
|
||||
} catch (RuntimeException e) {
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Unable to decrypt AES block", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public enum EncType {
|
||||
return true;
|
||||
try {
|
||||
getParams();
|
||||
} catch (Exception e) {
|
||||
} catch (InvalidParameterSpecException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -343,7 +343,7 @@ public class KeyGenerator {
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
main2(args);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -381,7 +381,7 @@ public class KeyGenerator {
|
||||
try {
|
||||
System.out.println("Testing " + type);
|
||||
testSig(type, runs);
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
System.out.println("error testing " + type);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,8 @@ public class KeyStoreUtil {
|
||||
try {
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
success = addCerts(new File(System.getProperty("java.home"), "etc/security/cacerts"), ks) > 0;
|
||||
} catch (Exception e) {}
|
||||
} catch (IOException e) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
} else {
|
||||
success = loadCerts(new File(System.getProperty("java.home"), "etc/security/cacerts.bks"), ks);
|
||||
}
|
||||
@@ -113,7 +114,8 @@ public class KeyStoreUtil {
|
||||
try {
|
||||
// must be initted
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
} catch (Exception e) {}
|
||||
} catch (IOException e) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
error("All key store loads failed, will only load local certificates", null);
|
||||
}
|
||||
return ks;
|
||||
@@ -140,13 +142,15 @@ public class KeyStoreUtil {
|
||||
try {
|
||||
// not clear if null is allowed for password
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
} catch (Exception foo) {}
|
||||
} catch (IOException foo) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
return false;
|
||||
} catch (IOException ioe) {
|
||||
error("KeyStore load error, no default keys: " + file.getAbsolutePath(), ioe);
|
||||
try {
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
} catch (Exception foo) {}
|
||||
} catch (IOException foo) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
return false;
|
||||
} finally {
|
||||
try { if (fis != null) fis.close(); } catch (IOException foo) {}
|
||||
@@ -171,7 +175,7 @@ public class KeyStoreUtil {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} catch (Exception foo) {}
|
||||
} catch (GeneralSecurityException e) {}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -316,7 +320,10 @@ public class KeyStoreUtil {
|
||||
error("Not overwriting key " + alias + ", already exists in " + ks, null);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
error("Not overwriting key \"" + alias + "\", already exists in " + ks, e);
|
||||
return false;
|
||||
} catch (GeneralSecurityException e) {
|
||||
error("Not overwriting key \"" + alias + "\", already exists in " + ks, e);
|
||||
return false;
|
||||
}
|
||||
@@ -354,7 +361,10 @@ public class KeyStoreUtil {
|
||||
success = getPrivateKey(ks, ksPW, alias, keyPW) != null;
|
||||
if (!success)
|
||||
error("Key gen failed to get private key", null);
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
error("Key gen failed to get private key", e);
|
||||
success = false;
|
||||
} catch (GeneralSecurityException e) {
|
||||
error("Key gen failed to get private key", e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.i2p.crypto;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Signature;
|
||||
@@ -215,7 +216,9 @@ public enum SigType {
|
||||
}
|
||||
getDigestInstance();
|
||||
getHashInstance();
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
return false;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -344,7 +344,11 @@ riCe6OlAEiNpcc6mMyIYYWFICbrDFTrDR3wXqwc/Jkcx6L5VVWoagpSzbo3yGhc=
|
||||
System.out.println("\r\nPrivate key written to: " + privateKeyFile);
|
||||
System.out.println("Public key written to: " + publicKeyFile);
|
||||
System.out.println("\r\nPublic key: " + signingPublicKey.toBase64() + "\r\n");
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error writing keys:");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (DataFormatException e) {
|
||||
System.err.println("Error writing keys:");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@@ -758,7 +762,7 @@ riCe6OlAEiNpcc6mMyIYYWFICbrDFTrDR3wXqwc/Jkcx6L5VVWoagpSzbo3yGhc=
|
||||
bytesToSignInputStream = new SequenceInputStream(versionHeaderInputStream, fileInputStream);
|
||||
signature = _context.dsa().sign(bytesToSignInputStream, signingPrivateKey);
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error signing", e);
|
||||
|
||||
|
||||
@@ -722,7 +722,7 @@ public class GroupElement implements Serializable {
|
||||
if (!this.repr.equals(ge.repr)) {
|
||||
try {
|
||||
ge = ge.toRep(this.repr);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public class Certificate extends DataStructureImpl {
|
||||
throw new DataFormatException("Cert is too small [" + source.length + " off=" + offset + "]");
|
||||
|
||||
int cur = offset;
|
||||
_type = (int)DataHelper.fromLong(source, cur, 1);
|
||||
_type = source[cur] & 0xff;
|
||||
cur++;
|
||||
int length = (int)DataHelper.fromLong(source, cur, 2);
|
||||
cur += 2;
|
||||
|
||||
@@ -37,6 +37,9 @@ import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
@@ -1615,11 +1618,11 @@ public class DataHelper {
|
||||
* NOTE: formatDuration2() recommended in most cases for readability
|
||||
*/
|
||||
public static String formatSize(long bytes) {
|
||||
double val = bytes;
|
||||
float val = bytes;
|
||||
int scale = 0;
|
||||
while (val >= 1024) {
|
||||
while (val >= 1024.0f) {
|
||||
scale++;
|
||||
val /= 1024;
|
||||
val /= 1024.0f;
|
||||
}
|
||||
|
||||
DecimalFormat fmt = new DecimalFormat("##0.00");
|
||||
@@ -1888,4 +1891,54 @@ public class DataHelper {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as s.split(regex) but caches the compiled pattern for speed.
|
||||
* This saves about 10 microseconds (Bulldozer) on subsequent invocations.
|
||||
*
|
||||
* @param s non-null
|
||||
* @param regex non-null
|
||||
* @throws java.util.regex.PatternSyntaxException unchecked
|
||||
* @since 0.9.24
|
||||
*/
|
||||
public static String[] split(String s, String regex) {
|
||||
return split(s, regex, 0);
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<String, Pattern> patterns = new ConcurrentHashMap<String, Pattern>();
|
||||
|
||||
/**
|
||||
* Same as s.split(regex, limit) but caches the compiled pattern for speed.
|
||||
* This saves about 10 microseconds (Bulldozer) on subsequent invocations.
|
||||
*
|
||||
* @param s non-null
|
||||
* @param regex non-null
|
||||
* @param limit result threshold
|
||||
* @throws java.util.regex.PatternSyntaxException unchecked
|
||||
* @since 0.9.24
|
||||
*/
|
||||
public static String[] split(String s, String regex, int limit) {
|
||||
Pattern p = patterns.get(regex);
|
||||
if (p == null) {
|
||||
p = Pattern.compile(regex);
|
||||
patterns.putIfAbsent(regex, p);
|
||||
}
|
||||
return p.split(s, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* The system's time zone, which is probably different from the
|
||||
* JVM time zone, because Router changes the JVM default to GMT.
|
||||
* It saves the old default in the context properties where we can get it.
|
||||
* Use this to format a time in local time zone with DateFormat.setTimeZone().
|
||||
*
|
||||
* @return non-null
|
||||
* @since 0.9.24
|
||||
*/
|
||||
public static TimeZone getSystemTimeZone(I2PAppContext ctx) {
|
||||
String systemTimeZone = ctx.getProperty("i2p.systemTimeZone");
|
||||
if (systemTimeZone != null)
|
||||
return TimeZone.getTimeZone(systemTimeZone);
|
||||
return TimeZone.getDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -174,7 +175,10 @@ public class PrivateKeyFile {
|
||||
pkf.write();
|
||||
verifySignature(pkf.getDestination());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (I2PException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
@@ -358,7 +362,7 @@ public class PrivateKeyFile {
|
||||
HashCash hc;
|
||||
try {
|
||||
hc = HashCash.mintCash(resource, effort);
|
||||
} catch (Exception e) {
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
System.out.println("Generation took: " + DataHelper.formatDuration(System.currentTimeMillis() - begin));
|
||||
@@ -391,7 +395,9 @@ public class PrivateKeyFile {
|
||||
Destination d2;
|
||||
try {
|
||||
d2 = pkf2.getDestination();
|
||||
} catch (Exception e) {
|
||||
} catch (I2PException e) {
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
if (d2 == null)
|
||||
@@ -500,7 +506,7 @@ public class PrivateKeyFile {
|
||||
long low = Long.MAX_VALUE;
|
||||
try {
|
||||
low = HashCash.estimateTime(hashEffort);
|
||||
} catch (Exception e) {}
|
||||
} catch (NoSuchAlgorithmException e) {}
|
||||
// takes a lot longer than the estimate usually...
|
||||
// maybe because the resource string is much longer than used in the estimate?
|
||||
return "It is estimated that generating a HashCash Certificate with value " + hashEffort +
|
||||
|
||||
@@ -160,7 +160,7 @@ public class I2CPMessageReader {
|
||||
public void run() {
|
||||
try {
|
||||
run2();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Uncaught I2CP error", e);
|
||||
_listener.readError(I2CPMessageReader.this, e);
|
||||
cancelRunner();
|
||||
@@ -193,7 +193,7 @@ public class I2CPMessageReader {
|
||||
} catch (OutOfMemoryError oom) {
|
||||
// ooms seen here... maybe log and keep going?
|
||||
throw oom;
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Unhandled error reading I2CP stream", e);
|
||||
_listener.disconnected(I2CPMessageReader.this);
|
||||
cancelRunner();
|
||||
|
||||
@@ -145,7 +145,7 @@ public class BufferedStatLog implements StatLog {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("writing " + writeStart +"->"+ writeEnd);
|
||||
writeEvents(writeStart, writeEnd);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.error("error writing " + writeStart +"->"+ writeEnd, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -272,7 +273,7 @@ public class EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
@@ -321,17 +322,17 @@ public class EepGet {
|
||||
* @return a filename to save the resource as on local filesystem
|
||||
*/
|
||||
public static String suggestName(String url) {
|
||||
URL nameURL = null; // URL object
|
||||
URI nameURL = null;
|
||||
String name; // suggested name
|
||||
|
||||
try {
|
||||
nameURL = new URL(url);
|
||||
} catch (MalformedURLException e) {
|
||||
nameURL = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
System.err.println("Please enter a properly formed URL.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String path = nameURL.getPath(); // discard any URI queries
|
||||
String path = nameURL.getRawPath(); // discard any URI queries
|
||||
|
||||
// if no file specified, eepget scrapes webpage - use domain as name
|
||||
Pattern slashes = Pattern.compile("/+");
|
||||
@@ -722,24 +723,25 @@ public class EepGet {
|
||||
|
||||
if (_redirectLocation != null) {
|
||||
// we also are here after a 407
|
||||
//try {
|
||||
try {
|
||||
if (_redirectLocation.startsWith("http://")) {
|
||||
_actualURL = _redirectLocation;
|
||||
} else {
|
||||
// the Location: field has been required to be an absolute URI at least since
|
||||
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
||||
// This oddly adds a ":" even if no port, but that seems to work.
|
||||
URL url = new URL(_actualURL);
|
||||
URI url = new URI(_actualURL);
|
||||
if (_redirectLocation.startsWith("/"))
|
||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
||||
else
|
||||
// this blows up completely on a redirect to https://, for example
|
||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation;
|
||||
}
|
||||
// an MUE is an IOE
|
||||
//} catch (MalformedURLException mue) {
|
||||
// throw new IOException("Redirected from an invalid URL");
|
||||
//}
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
AuthState as = _authState;
|
||||
if (_responseCode == 407) {
|
||||
@@ -1131,7 +1133,7 @@ public class EepGet {
|
||||
private int handleStatus(String line) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Status line: [" + line.trim() + "]");
|
||||
String[] toks = line.split(" ", 3);
|
||||
String[] toks = DataHelper.split(line, " ", 3);
|
||||
if (toks.length < 2) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("ERR: status "+ line);
|
||||
@@ -1226,9 +1228,9 @@ public class EepGet {
|
||||
if (_shouldProxy) {
|
||||
_proxy = InternalSocket.getSocket(_proxyHost, _proxyPort);
|
||||
} else {
|
||||
//try {
|
||||
URL url = new URL(_actualURL);
|
||||
if ("http".equals(url.getProtocol())) {
|
||||
try {
|
||||
URI url = new URI(_actualURL);
|
||||
if ("http".equals(url.getScheme())) {
|
||||
String host = url.getHost();
|
||||
String hostlc = host.toLowerCase(Locale.US);
|
||||
if (hostlc.endsWith(".i2p"))
|
||||
@@ -1248,10 +1250,11 @@ public class EepGet {
|
||||
} else {
|
||||
throw new MalformedURLException("URL is not supported:" + _actualURL);
|
||||
}
|
||||
// an MUE is an IOE
|
||||
//} catch (MalformedURLException mue) {
|
||||
// throw new IOException("Request URL is invalid");
|
||||
//}
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Request URL is invalid");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
}
|
||||
_proxyIn = _proxy.getInputStream();
|
||||
if (!(_proxy instanceof InternalSocket))
|
||||
@@ -1273,13 +1276,20 @@ public class EepGet {
|
||||
boolean post = false;
|
||||
if ( (_postData != null) && (_postData.length() > 0) )
|
||||
post = true;
|
||||
URL url = new URL(_actualURL);
|
||||
URI url;
|
||||
try {
|
||||
url = new URI(_actualURL);
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Bad URL");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
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();
|
||||
String path = url.getRawPath();
|
||||
String query = url.getRawQuery();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Requesting " + _actualURL);
|
||||
// RFC 2616 sec 5.1.2 - full URL if proxied, absolute path only if not proxied
|
||||
|
||||
@@ -6,7 +6,9 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import gnu.getopt.Getopt;
|
||||
|
||||
@@ -107,7 +109,7 @@ public class EepHead extends EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
@@ -176,24 +178,25 @@ public class EepHead extends EepGet {
|
||||
|
||||
// Should we even follow redirects for HEAD?
|
||||
if (_redirectLocation != null) {
|
||||
//try {
|
||||
try {
|
||||
if (_redirectLocation.startsWith("http://")) {
|
||||
_actualURL = _redirectLocation;
|
||||
} else {
|
||||
// the Location: field has been required to be an absolute URI at least since
|
||||
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
||||
// This oddly adds a ":" even if no port, but that seems to work.
|
||||
URL url = new URL(_actualURL);
|
||||
URI url = new URI(_actualURL);
|
||||
if (_redirectLocation.startsWith("/"))
|
||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
||||
else
|
||||
// this blows up completely on a redirect to https://, for example
|
||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation;
|
||||
}
|
||||
// an MUE is an IOE
|
||||
//} catch (MalformedURLException mue) {
|
||||
// throw new IOException("Redirected from an invalid URL");
|
||||
//}
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
AuthState as = _authState;
|
||||
if (_responseCode == 407) {
|
||||
if (!_shouldProxy)
|
||||
@@ -252,11 +255,18 @@ public class EepHead extends EepGet {
|
||||
@Override
|
||||
protected String getRequest() throws IOException {
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
URL url = new URL(_actualURL);
|
||||
URI url;
|
||||
try {
|
||||
url = new URI(_actualURL);
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Bad URL");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
String host = url.getHost();
|
||||
int port = url.getPort();
|
||||
String path = url.getPath();
|
||||
String query = url.getQuery();
|
||||
String path = url.getRawPath();
|
||||
String query = url.getRawQuery();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Requesting " + _actualURL);
|
||||
// RFC 2616 sec 5.1.2 - full URL if proxied, absolute path only if not proxied
|
||||
|
||||
@@ -11,6 +11,7 @@ package net.i2p.util;
|
||||
|
||||
import gnu.crypto.prng.AsyncFortunaStandalone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
@@ -266,7 +267,7 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
|
||||
synchronized(_fortuna) {
|
||||
_fortuna.addRandomBytes(data, offset, len);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// AIOOBE seen, root cause unknown, ticket #1576
|
||||
Log log = _context.logManager().getLog(FortunaRandomSource.class);
|
||||
log.warn("feedEntropy()", e);
|
||||
@@ -290,6 +291,6 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
|
||||
rand.nextBytes(buf);
|
||||
System.out.write(buf);
|
||||
}
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.crypto.KeyStoreUtil;
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
||||
import org.apache.http.conn.util.PublicSuffixList;
|
||||
@@ -443,7 +444,7 @@ public class I2PSSLSocketFactory {
|
||||
try {
|
||||
if (line.charAt(0) == '#')
|
||||
continue;
|
||||
String[] s = line.split(",");
|
||||
String[] s = DataHelper.split(line, ",");
|
||||
String lc = s[0].toLowerCase(Locale.US);
|
||||
tlds.add(lc);
|
||||
i++;
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -479,9 +478,7 @@ public class LogManager implements Flushable {
|
||||
if (!format.equals(""))
|
||||
fmt.applyPattern(format);
|
||||
// the router sets the JVM time zone to UTC but saves the original here so we can get it
|
||||
String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
|
||||
if (systemTimeZone != null)
|
||||
fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
|
||||
fmt.setTimeZone(DataHelper.getSystemTimeZone(_context));
|
||||
_dateFormatPattern = format;
|
||||
_dateFormat = fmt;
|
||||
return true;
|
||||
|
||||
@@ -75,7 +75,7 @@ abstract class LogWriterBase implements Runnable {
|
||||
if (_write && shouldReadConfig)
|
||||
rereadConfig();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println("Error writing the log: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import freenet.support.CPUInformation.UnknownCPUException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.crypto.CryptoConstants;
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
/**
|
||||
* <p>BigInteger that takes advantage of the jbigi library for the modPow operation,
|
||||
@@ -734,7 +735,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
in = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/cpuinfo"), "ISO-8859-1"), 4096);
|
||||
String line = null;
|
||||
while ( (line = in.readLine()) != null) {
|
||||
String[] parts = line.split(":", 2);
|
||||
String[] parts = DataHelper.split(line, ":", 2);
|
||||
if (parts.length < 2)
|
||||
continue;
|
||||
String key = parts[0].trim().toLowerCase(Locale.US);
|
||||
|
||||
@@ -6,7 +6,8 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Locale;
|
||||
|
||||
import gnu.getopt.Getopt;
|
||||
@@ -106,7 +107,7 @@ public class PartialEepGet extends EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
@@ -167,13 +168,20 @@ public class PartialEepGet extends EepGet {
|
||||
@Override
|
||||
protected String getRequest() throws IOException {
|
||||
StringBuilder buf = new StringBuilder(2048);
|
||||
URL url = new URL(_actualURL);
|
||||
URI url;
|
||||
try {
|
||||
url = new URI(_actualURL);
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Bad URL");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
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();
|
||||
String path = url.getRawPath();
|
||||
String query = url.getRawQuery();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Requesting " + _actualURL);
|
||||
// RFC 2616 sec 5.1.2 - full URL if proxied, absolute path only if not proxied
|
||||
|
||||
@@ -124,7 +124,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public long getTotalRead() {
|
||||
try {
|
||||
return inf.getBytesRead();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public long getTotalExpanded() {
|
||||
try {
|
||||
return inf.getBytesWritten();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// possible NPE in some implementations
|
||||
return 0;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public long getRemaining() {
|
||||
try {
|
||||
return inf.getRemaining();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// possible NPE in some implementations
|
||||
return 0;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public boolean getFinished() {
|
||||
try {
|
||||
return inf.finished();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// possible NPE in some implementations
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.CertificateException;
|
||||
@@ -179,7 +180,7 @@ public class SSLEepGet extends EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
@@ -369,7 +370,7 @@ public class SSLEepGet extends EepGet {
|
||||
System.out.println(" Valid To: " + cert.getNotAfter());
|
||||
try {
|
||||
cert.checkValidity();
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
System.out.println(" WARNING: Certificate is not currently valid, it cannot be used");
|
||||
}
|
||||
CertUtil.saveCert(cert, new File(name));
|
||||
@@ -553,11 +554,11 @@ public class SSLEepGet extends EepGet {
|
||||
|
||||
String req = getRequest();
|
||||
|
||||
//try {
|
||||
URL url = new URL(_actualURL);
|
||||
String host = null;
|
||||
int port = 0;
|
||||
if ("https".equals(url.getProtocol())) {
|
||||
String host;
|
||||
int port;
|
||||
try {
|
||||
URI url = new URI(_actualURL);
|
||||
if ("https".equals(url.getScheme())) {
|
||||
host = url.getHost();
|
||||
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
|
||||
throw new MalformedURLException("I2P addresses unsupported");
|
||||
@@ -589,10 +590,11 @@ public class SSLEepGet extends EepGet {
|
||||
} else {
|
||||
throw new MalformedURLException("Only https supported: " + _actualURL);
|
||||
}
|
||||
// an MUE is an IOE
|
||||
//} catch (MalformedURLException mue) {
|
||||
// throw new IOException("Request URL is invalid");
|
||||
//}
|
||||
} catch (URISyntaxException use) {
|
||||
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||
ioe.initCause(use);
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
_proxyIn = _proxy.getInputStream();
|
||||
_proxyOut = _proxy.getOutputStream();
|
||||
|
||||
@@ -439,7 +439,7 @@ public class ShellCommand {
|
||||
System.out.println("ShellCommand waiting for \"" + name + '\"');
|
||||
try {
|
||||
process.waitFor();
|
||||
} catch (Exception e) {
|
||||
} catch (InterruptedException e) {
|
||||
if (DEBUG) {
|
||||
System.out.println("ShellCommand exception waiting for \"" + name + '\"');
|
||||
e.printStackTrace();
|
||||
@@ -457,7 +457,7 @@ public class ShellCommand {
|
||||
if (process.exitValue() > 0)
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
// probably IOException, file not found from exec()
|
||||
if (DEBUG) {
|
||||
System.out.println("ShellCommand execute exception for \"" + name + '\"');
|
||||
|
||||
@@ -147,7 +147,7 @@ public class BlockFile implements Closeable {
|
||||
bf.bfck(true);
|
||||
bf.close();
|
||||
raif.close();
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user