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.*;
/**
*/
public class HTTP {
+ public static InetAddress originAddr = null;
+ public static String originHost = null;
// Public Methods ////////////////////////////////////////////////////////////////////////////////////////
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 {
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");
+ */
}
}
/** 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;
if (Log.on) Log.info(this, "all PAC results exhausted");
return null;
}
-
+ */
// Everything Else ////////////////////////////////////////////////////////////////////////////
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) {
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);
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");
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")));
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);
}
if (ret.httpProxyHost == null && ret.socksProxyHost == null) return null;
+ */
return ret;
}
-
+
+ /*
public static JSScope proxyAutoConfigRootScope = new ProxyAutoConfigRootScope();
public static JS getProxyAutoConfigFunction(String url) {
try {
return null;
}
}
-
+ */
// Authorization ///////////////////////////////////////////////////////////////////////////////////
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 {
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;
case "dateRange": return METHOD;
case "timeRange": return METHOD;
case "ProxyConfig": return ProxyConfig;
- //#end
+ // #end
return super.get(name);
}
};
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":
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) {
}
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