summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
Diffstat (limited to 'methods')
-rw-r--r--methods/http.cc3
-rw-r--r--methods/https.cc2
-rw-r--r--methods/server.cc26
-rw-r--r--methods/server.h3
4 files changed, 34 insertions, 0 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 1ed2e3629..0358b50cd 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -357,6 +357,9 @@ bool HttpServerState::Open()
Proxy = "";
}
+ if (Proxy.empty() == false)
+ Owner->AddProxyAuth(Proxy, ServerName);
+
if (Proxy.Access == "socks5h")
{
if (Connect(Proxy.Host, Proxy.Port, "socks", 1080, ServerFd, TimeOut, Owner) == false)
diff --git a/methods/https.cc b/methods/https.cc
index 47dce2ea0..283126f6b 100644
--- a/methods/https.cc
+++ b/methods/https.cc
@@ -213,6 +213,8 @@ bool HttpsMethod::SetupProxy() /*{{{*/
if (UseProxy.empty() == false)
{
Proxy = UseProxy;
+ AddProxyAuth(Proxy, ServerName);
+
if (Proxy.Access == "socks5h")
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
else if (Proxy.Access == "socks5")
diff --git a/methods/server.cc b/methods/server.cc
index 7c85c8abb..0888617b1 100644
--- a/methods/server.cc
+++ b/methods/server.cc
@@ -794,3 +794,29 @@ ServerMethod::ServerMethod(std::string &&Binary, char const * const Ver,unsigned
{
}
/*}}}*/
+bool ServerMethod::Configuration(std::string Message) /*{{{*/
+{
+ if (aptMethod::Configuration(Message) == false)
+ return false;
+
+ _config->CndSet("Acquire::tor::Proxy",
+ "socks5h://apt-transport-tor@localhost:9050");
+ return true;
+}
+ /*}}}*/
+bool ServerMethod::AddProxyAuth(URI &Proxy, URI const &Server) const /*{{{*/
+{
+ if (std::find(methodNames.begin(), methodNames.end(), "tor") != methodNames.end() &&
+ Proxy.User == "apt-transport-tor" && Proxy.Password.empty())
+ {
+ std::string pass = Server.Host;
+ pass.erase(std::remove_if(pass.begin(), pass.end(), [](char const c) { return std::isalnum(c) == 0; }), pass.end());
+ if (pass.length() > 255)
+ Proxy.Password = pass.substr(0, 255);
+ else
+ Proxy.Password = std::move(pass);
+ }
+ // FIXME: should we support auth.conf for proxies?
+ return true;
+}
+ /*}}}*/
diff --git a/methods/server.h b/methods/server.h
index f6a635dca..1d114354f 100644
--- a/methods/server.h
+++ b/methods/server.h
@@ -156,6 +156,9 @@ class ServerMethod : public aptMethod
virtual void SendReq(FetchItem *Itm) = 0;
virtual std::unique_ptr<ServerState> CreateServerState(URI const &uri) = 0;
virtual void RotateDNS() = 0;
+ virtual bool Configuration(std::string Message) APT_OVERRIDE;
+
+ bool AddProxyAuth(URI &Proxy, URI const &Server) const;
ServerMethod(std::string &&Binary, char const * const Ver,unsigned long const Flags);
virtual ~ServerMethod() {};