/** * Connect to a HTTP proxy. * Proxy address must be in _proxyHost and _proxyPort. * Side effects: Sets _proxy, _proxyIn, _proxyOut, * and other globals via readHeaders() * * @param port what the proxy should connect to, probably 4444 * @since 0.9.33 */ private void internalHttpProxyConnect(String host, int port) throws IOException { // connect to the proxy _proxy = InternalSocket.getSocket(_proxyHost, _proxyPort); httpProxyConnect(_proxy, host, port); }
/** * outputFile, outputStream: One null, one non-null * * @param state an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. * This makes repeated fetches from the same host MUCH faster, * and prevents repeated key store loads even for different hosts. * @since 0.9.9 */ private SSLEepGet(I2PAppContext ctx, String outputFile, OutputStream outputStream, String url, SSLState state) { // 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, false, null, -1, 0, -1, -1, outputFile, outputStream, url, true, null, null); _proxyType = ProxyType.NONE; if (state != null && state.context != null) _sslContext = state.context; else _sslContext = initSSLContext(); if (_sslContext == null) _log.error("Failed to initialize custom SSL context, using default context"); }
String req = getRequest(); DNSOverHTTPS doh = new DNSOverHTTPS(_context, getSSLState()); String ip = doh.lookup(host); if (ip != null) switch (_proxyType) { case HTTP: httpProxyConnect(host, port); break; internalHttpProxyConnect(host, port); break; socksProxyConnect(false, host, port); break; socksProxyConnect(true, host, port); break; } catch (SSLException ssle) { if (_saveCerts > 0 && _stm != null) saveCerts(host, _stm); throw ssle; _proxyOut.flush(); if (_saveCerts > 1 && _stm != null) saveCerts(host, _stm); } catch (SSLException sslhe) {
usage(); System.exit(1); String saveAs = suggestName(url); proxyPort = 1080; get = new SSLEepGet(I2PAppContext.getGlobalContext(), ptype, proxyHost, proxyPort, saveAs, url); } else { get = new SSLEepGet(I2PAppContext.getGlobalContext(), saveAs, url); get._bypassVerification = true; get._commandLine = true; get.addStatusListener(get.new CLIStatusListener(1024, 40)); if(!get.fetch(45*1000, -1, 60*1000)) System.exit(1);
/** * @return null if not found */ private String query(String host, boolean isv6, List<String> toQuery) { for (String url : toQuery) { if (fails.count(url) > MAX_FAILS) continue; int tcode = isv6 ? V6_CODE : V4_CODE; String furl = url + "name=" + host + "&type=" + tcode; log("Fetching " + furl); baos.reset(); SSLEepGet eepget = new SSLEepGet(ctx, baos, furl, state); if (ctx.isRouterContext()) eepget.addStatusListener(this); else fetchStart = System.currentTimeMillis(); // debug String rv = fetch(eepget, host, isv6); if (rv != null) { fails.clear(url); return rv; } if (state == null) state = eepget.getSSLState(); // we treat all fails the same, whether server responded or not fails.increment(url); log("No result from " + furl); } return null; }
if (_sslState == null) { if (_shouldProxySSL) sslget = new SSLEepGet(_context, _sproxyType, _sproxyHost, _sproxyPort, baos, url.toString()); else sslget = new SSLEepGet(_context, baos, url.toString()); _sslState = sslget.getSSLState(); } else { if (_shouldProxySSL) sslget = new SSLEepGet(_context, _sproxyType, _sproxyHost, _sproxyPort, baos, url.toString(), _sslState); else sslget = new SSLEepGet(_context, baos, url.toString(), _sslState);
@Override protected void doFetch(SocketTimeout timeout) throws IOException { _aborted = false; readHeaders(); if (_aborted) throw new IOException("Timed out reading the HTTP headers"); int char2 = _proxyIn.read(); if (char2 == '\n') { remaining = (int) readChunkLength(); } else { _out.write(char1);
if (eepget.fetch(TIMEOUT, TIMEOUT, TIMEOUT) && eepget.getStatusCode() == 200 && baos.size() > 0) { long end = System.currentTimeMillis(); log("Got response in " + (end - fetchStart) + "ms");
if (_sslState == null) { if (_shouldProxySSL) sslget = new SSLEepGet(_context, _sproxyType, _sproxyHost, _sproxyPort, out.getPath(), url.toString()); else sslget = new SSLEepGet(_context, out.getPath(), url.toString()); _sslState = sslget.getSSLState(); } else { if (_shouldProxySSL) sslget = new SSLEepGet(_context, _sproxyType, _sproxyHost, _sproxyPort, out.getPath(), url.toString(), _sslState); else sslget = new SSLEepGet(_context, out.getPath(), url.toString(), _sslState);
/** * Use a proxy. * * @param proxyHost Must be valid hostname or literal IPv4/v6. * If type is INTERNAL, set to "localhost". * @param proxyPort Must be valid, -1 disallowed, no default. * If type is INTERNAL, set to 4444. * @param state an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. * This makes repeated fetches from the same host MUCH faster, * and prevents repeated key store loads even for different hosts. * @since 0.9.33 */ public SSLEepGet(I2PAppContext ctx, ProxyType type, String proxyHost, int proxyPort, OutputStream outputStream, String url, SSLState state) { // 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, type != ProxyType.NONE, proxyHost, proxyPort, 0, -1, -1, null, outputStream, url, true, null, null); if (type != ProxyType.NONE && !_shouldProxy) throw new IllegalArgumentException("Bad proxy params"); _proxyType = type; if (state != null && state.context != null) _sslContext = state.context; else _sslContext = initSSLContext(); if (_sslContext == null) _log.error("Failed to initialize custom SSL context, using default context"); }
/** * Connect to a HTTP proxy. * Proxy address must be in _proxyHost and _proxyPort. * Side effects: Sets _proxy, _proxyIn, _proxyOut, * and other globals via readHeaders() * * @param host what the proxy should connect to * @param port what the proxy should connect to * @since 0.9.33 */ private void httpProxyConnect(String host, int port) throws IOException { // connect to the proxy // _proxyPort validated in superconstrutor, no need to set default here if (_fetchHeaderTimeout > 0) { _proxy = new Socket(); _proxy.setSoTimeout(_fetchHeaderTimeout); _proxy.connect(new InetSocketAddress(_proxyHost, _proxyPort), _fetchHeaderTimeout); } else { _proxy = new Socket(_proxyHost, _proxyPort); } httpProxyConnect(_proxy, host, port); }
/** * Use a proxy. * * @param proxyHost Must be valid hostname or literal IPv4/v6. * If type is INTERNAL, set to "localhost". * @param proxyPort Must be valid, -1 disallowed, no default. * If type is INTERNAL, set to 4444. * @param state an SSLState retrieved from a previous SSLEepGet with getSSLState(), or null. * This makes repeated fetches from the same host MUCH faster, * and prevents repeated key store loads even for different hosts. * @since 0.9.33 */ public SSLEepGet(I2PAppContext ctx, ProxyType type, String proxyHost, int proxyPort, String outputFile, String url, SSLState state) { // 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, type != ProxyType.NONE, proxyHost, proxyPort, 0, -1, -1, outputFile, null, url, true, null, null); if (type != ProxyType.NONE && !_shouldProxy) throw new IllegalArgumentException("Bad proxy params"); _proxyType = type; if (state != null && state.context != null) _sslContext = state.context; else _sslContext = initSSLContext(); if (_sslContext == null) _log.error("Failed to initialize custom SSL context, using default context"); }