Commit 5a1a2058 authored by Patrick McManus's avatar Patrick McManus Committed by Georg Koppen
Browse files

Bug 1463509 - SOCKS support for Alternative Services r=valentin

MozReview-Commit-ID: 1oXnQuzOqsC

--HG--
extra : rebase_source : 84bfaec48c5fc216da6586e7f06f118292d3fb17
parent fb6abcfc
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -1199,12 +1199,30 @@ nsSocketTransport::BuildSocket(PRFileDesc *&fd, bool &proxyTransparent, bool &us
                // if this is the first type, we'll want the
                // service to allocate a new socket

                // Most layers _ESPECIALLY_ PSM want the origin name here as they
                // will use it for secure checks, etc.. and any connection management
                // differences between the origin name and the routed name can be
                // taken care of via DNS. However, SOCKS is a special case as there is
                // no DNS. in the case of SOCKS and PSM the PSM is a separate layer
                // and receives the origin name.
                const char *socketProviderHost = host;
                int32_t socketProviderPort = port;
                if (mProxyTransparentResolvesHost &&
                    (!strcmp(mTypes[0], "socks") || !strcmp(mTypes[0], "socks4"))) {
                    SOCKET_LOG(("SOCKS %d Host/Route override: %s:%d -> %s:%d\n",
                                mHttpsProxy,
                                socketProviderHost, socketProviderPort,
                                mHost.get(), mPort));
                    socketProviderHost = mHost.get();
                    socketProviderPort = mPort;
                }

                // when https proxying we want to just connect to the proxy as if
                // it were the end host (i.e. expect the proxy's cert)

                rv = provider->NewSocket(mNetAddr.raw.family,
                                         mHttpsProxy ? mProxyHost.get() : host,
                                         mHttpsProxy ? mProxyPort : port,
                                         mHttpsProxy ? mProxyHost.get() : socketProviderHost,
                                         mHttpsProxy ? mProxyPort : socketProviderPort,
                                         proxyInfo, mOriginAttributes,
                                         controlFlags, mTlsFlags, &fd,
                                         getter_AddRefs(secinfo));
@@ -1213,8 +1231,7 @@ nsSocketTransport::BuildSocket(PRFileDesc *&fd, bool &proxyTransparent, bool &us
                    NS_NOTREACHED("NewSocket succeeded but failed to create a PRFileDesc");
                    rv = NS_ERROR_UNEXPECTED;
                }
            }
            else {
            } else {
                // the socket has already been allocated,
                // so we just want the service to add itself
                // to the stack (such as pushing an io layer)
@@ -1245,8 +1262,7 @@ nsSocketTransport::BuildSocket(PRFileDesc *&fd, bool &proxyTransparent, bool &us
                    secCtrl->SetNotificationCallbacks(callbacks);
                // remember if socket type is SSL so we can ProxyStartSSL if need be.
                usingSSL = isSSL;
            }
            else if ((strcmp(mTypes[i], "socks") == 0) ||
            } else if ((strcmp(mTypes[i], "socks") == 0) ||
                       (strcmp(mTypes[i], "socks4") == 0)) {
                // since socks is transparent, any layers above
                // it do not have to worry about proxy stuff
+7 −1
Original line number Diff line number Diff line
@@ -46,6 +46,12 @@ SchemeIsHTTPS(const nsACString &originScheme, bool &outIsHTTPS)
  return NS_OK;
}

bool
AltSvcMapping::AcceptableProxy(nsProxyInfo *proxyInfo)
{
  return !proxyInfo || proxyInfo->IsDirect() || proxyInfo->IsSOCKS();
}

void
AltSvcMapping::ProcessHeader(const nsCString &buf, const nsCString &originScheme,
                             const nsCString &originHost, int32_t originPort,
@@ -59,7 +65,7 @@ AltSvcMapping::ProcessHeader(const nsCString &buf, const nsCString &originScheme
    return;
  }

  if (proxyInfo && !proxyInfo->IsDirect()) {
  if (!AcceptableProxy(proxyInfo)) {
    LOG(("AltSvcMapping::ProcessHeader ignoring due to proxy\n"));
    return;
  }
+4 −0
Original line number Diff line number Diff line
@@ -66,6 +66,10 @@ public:
                            nsIInterfaceRequestor *callbacks, nsProxyInfo *proxyInfo,
                            uint32_t caps, const OriginAttributes &originAttributes);

  // AcceptableProxy() decides whether a particular proxy configuration (pi) is suitable
  // for use with Alt-Svc. No proxy (including a null pi) is suitable.
  static bool AcceptableProxy(nsProxyInfo *pi);

  const nsCString &AlternateHost() const { return mAlternateHost; }
  const nsCString &OriginHost() const { return mOriginHost; }
  uint32_t OriginPort() const { return mOriginPort; }
+2 −3
Original line number Diff line number Diff line
@@ -6156,9 +6156,8 @@ nsHttpChannel::BeginConnect()
    RefPtr<AltSvcMapping> mapping;
    if (!mConnectionInfo && mAllowAltSvc && // per channel
        !(mLoadFlags & LOAD_FRESH_CONNECTION) &&
        (scheme.EqualsLiteral("http") ||
         scheme.EqualsLiteral("https")) &&
        (!proxyInfo || proxyInfo->IsDirect()) &&
        AltSvcMapping::AcceptableProxy(proxyInfo) &&
        (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https")) &&
        (mapping = gHttpHandler->GetAltServiceMapping(scheme,
                                                      host, port,
                                                      mPrivateBrowsing,