X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fibex%2Fnet%2FHTTP.java;fp=src%2Forg%2Fibex%2Fnet%2FHTTP.java;h=18c40690412dd75580556aa5371a56cfe546934d;hb=222248ba3f050224a55b8457a3a6e4af0020c2fe;hp=15ba89928f3ed499d85984de9172215a418094a1;hpb=2d5539a40aebddc8b35c830dd4077a2b16bd5d17;p=org.ibex.net.git diff --git a/src/org/ibex/net/HTTP.java b/src/org/ibex/net/HTTP.java index 15ba899..18c4069 100644 --- a/src/org/ibex/net/HTTP.java +++ b/src/org/ibex/net/HTTP.java @@ -4,10 +4,7 @@ package org.ibex.net; import java.net.*; import java.io.*; import java.util.*; -import org.ibex.js.*; import org.ibex.util.*; -import org.ibex.plat.*; -import org.ibex.core.*; import org.ibex.crypto.*; /** @@ -16,6 +13,8 @@ import org.ibex.crypto.*; */ public class HTTP { + public static InetAddress originAddr = null; + public static String originHost = null; // Public Methods //////////////////////////////////////////////////////////////////////////////////////// @@ -150,7 +149,7 @@ public class HTTP { if (resolvedHosts.get(host) != null) return; // if all scripts are trustworthy (local FS), continue - if (Main.originAddr == null) return; + if (originAddr == null) return; // resolve using DNS try { @@ -158,14 +157,16 @@ public class HTTP { byte[] quadbyte = addr.getAddress(); if ((quadbyte[0] == 10 || (quadbyte[0] == 192 && quadbyte[1] == 168) || - (quadbyte[0] == 172 && (quadbyte[1] & 0xF0) == 16)) && !addr.equals(Main.originAddr)) + (quadbyte[0] == 172 && (quadbyte[1] & 0xF0) == 16)) && !addr.equals(originAddr)) throw new HTTPException("security violation: " + host + " [" + addr.getHostAddress() + "] is in a firewalled netblock"); return; } catch (UnknownHostException uhe) { } + /* if (Platform.detectProxy() == null) throw new HTTPException("could not resolve hostname \"" + host + "\" and no proxy configured"); + */ } @@ -267,6 +268,7 @@ public class HTTP { } /** executes the PAC script and dispatches a call to one of the other attempt methods based on the result */ + /* private Socket attemptPAC(org.ibex.js.JS pacFunc) { if (Log.verbose) Log.info(this, "evaluating PAC script"); String pac = null; @@ -301,7 +303,7 @@ public class HTTP { if (Log.on) Log.info(this, "all PAC results exhausted"); return null; } - + */ // Everything Else //////////////////////////////////////////////////////////////////////////// @@ -341,6 +343,7 @@ public class HTTP { host = temphost; if (Log.verbose) Log.info(this, "creating HTTP object for connection to " + host + ":" + port); + /* Proxy pi = Platform.detectProxy(); OUTER: do { if (pi != null) { @@ -351,6 +354,7 @@ public class HTTP { if (sock == null && pi.socksProxyHost != null) sock = attemptSocksProxy(pi.socksProxyHost, pi.socksProxyPort); } } while (false); + */ proxied = sock != null; if (sock == null) sock = attemptDirect(); if (sock == null) throw new HTTPException("unable to contact host " + host); @@ -374,7 +378,7 @@ public class HTTP { pw.print("User-Agent: Ibex\r\n"); pw.print("Accept-encoding: gzip\r\n"); pw.print("Host: " + (host + (port == 80 ? "" : (":" + port))) + "\r\n"); - if (proxied) pw.print("X-RequestOrigin: " + Main.originHost + "\r\n"); + if (proxied) pw.print("X-RequestOrigin: " + originHost + "\r\n"); if (Proxy.Authorization.authorization != null) pw.print("Proxy-Authorization: "+Proxy.Authorization.authorization2+"\r\n"); if (authCache.get(originalUrl) != null) pw.print("Authorization: " + authCache.get(originalUrl) + "\r\n"); @@ -430,11 +434,11 @@ public class HTTP { Proxy.Authorization.authorization2 = "NTLM " + Base64.encode(Proxy.NTLM.type1); return; } - + /* if (!realm.equals("Digest") || Proxy.Authorization.authorization2 == null || !"true".equals(h.get("stale"))) Proxy.Authorization.getPassword(realm, style, sock.getInetAddress().getHostAddress(), Proxy.Authorization.authorization); - + */ if (style.equals("Basic")) { Proxy.Authorization.authorization2 = "Basic " + new String(Base64.encode(Proxy.Authorization.authorization.getBytes("UTF8"))); @@ -664,11 +668,14 @@ public class HTTP { public String socksProxyHost = null; ///< the SOCKS Proxy Host to use public int socksProxyPort = -1; ///< the SOCKS Proxy Port to use public String[] excluded = new String[] { }; ///< hosts to be excluded from proxy use; wildcards permitted - public JS proxyAutoConfigFunction = null; ///< the PAC script + + // ** temporarily disabled so HTTP does not depend on org.ibex.js ** + //public JS proxyAutoConfigFunction = null; ///< the PAC script + public Object proxyAutoConfigFunction = null; ///< the PAC script public static Proxy detectProxyViaManual() { Proxy ret = new Proxy(); - + /* ret.httpProxyHost = Platform.getEnv("http_proxy"); if (ret.httpProxyHost != null) { if (ret.httpProxyHost.startsWith("http://")) ret.httpProxyHost = ret.httpProxyHost.substring(7); @@ -716,9 +723,11 @@ public class HTTP { } if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null; + */ return ret; } - + + /* public static JSScope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope(); public static JS getProxyAutoConfigFunction(String url) { try { @@ -765,7 +774,7 @@ public class HTTP { return null; } } - + */ // Authorization /////////////////////////////////////////////////////////////////////////////////// @@ -775,6 +784,8 @@ public class HTTP { static public String authorization2 = null; static public Semaphore waitingForUser = new Semaphore(); + // FIXME: temporarily disabled so we can use HTTP outside the core + /* public static synchronized void getPassword(final String realm, final String style, final String proxyIP, String oldAuth) throws IOException { @@ -799,17 +810,18 @@ public class HTTP { waitingForUser.block(); if (Log.on) Log.info(Authorization.class, "got proxy authorization info; re-attempting connection"); } + */ } // ProxyAutoConfigRootJSScope //////////////////////////////////////////////////////////////////// - + /* public static class ProxyAutoConfigRootScope extends JSScope.Global { public ProxyAutoConfigRootScope() { super(); } public Object get(Object name) throws JSExn { - //#switch(name) + // #switch(name) case "isPlainHostName": return METHOD; case "dnsDomainIs": return METHOD; case "localHostOrDomainIs": return METHOD; @@ -823,7 +835,7 @@ public class HTTP { case "dateRange": return METHOD; case "timeRange": return METHOD; case "ProxyConfig": return ProxyConfig; - //#end + // #end return super.get(name); } @@ -836,7 +848,7 @@ public class HTTP { }; public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { - //#switch(method) + // #switch(method) case "isPlainHostName": return (a0.toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE; case "dnsDomainIs": return (a0.toString().endsWith(a1.toString())) ? Boolean.TRUE : Boolean.FALSE; case "localHostOrDomainIs": @@ -904,7 +916,7 @@ public class HTTP { case "dateRange": throw new JSExn("Ibex does not support dateRange() in PAC scripts"); case "timeRange": throw new JSExn("Ibex does not support timeRange() in PAC scripts"); - //#end + // #end return super.callMethod(method, a0, a1, a2, rest, nargs); } private static boolean match(String[] arr, String s, int index) { @@ -917,7 +929,7 @@ public class HTTP { } public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; } - + */ /** * An implementation of Microsoft's proprietary NTLM authentication protocol. This code was derived from Eric