[socks] Report errors elegantly when credentails are required but missing
authorYen Chi Hsuan <yan12125@gmail.com>
Sat, 22 Apr 2017 13:44:01 +0000 (21:44 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Sat, 22 Apr 2017 13:48:41 +0000 (21:48 +0800)
In some non-standard implementations, the server may respond AUTH_USER_PASS
even if's not listed in available authentication methods. (it should
respond AUTH_NO_ACCEPTABLE per standards)

ChangeLog
youtube_dl/socks.py

index d699acb315e722aae4cd18ee5703848dc412c4ad..8dc6e6857508e3cc9d0b25b8a8c39494f668d609 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 version <unreleased>
 
+Core
+
+* [socks] Handle cases where credentials are required but missing
+
 Extractors
 - [azubu] Remove extractor (#12813)
 * [porn91] Fix extraction (#12814)
index 0f5d7bdb2128b17c2e1dba3144ff01d9b3d2f06a..5d4adbe72de5d273a11f0fc2d66b7829c4bbfb37 100644 (file)
@@ -193,9 +193,10 @@ class sockssocket(socket.socket):
 
         self._check_response_version(SOCKS5_VERSION, version)
 
-        if method == Socks5Auth.AUTH_NO_ACCEPTABLE:
+        if method == Socks5Auth.AUTH_NO_ACCEPTABLE or (
+                method == Socks5Auth.AUTH_USER_PASS and (not self._proxy.username or not self._proxy.password)):
             self.close()
-            raise Socks5Error(method)
+            raise Socks5Error(Socks5Auth.AUTH_NO_ACCEPTABLE)
 
         if method == Socks5Auth.AUTH_USER_PASS:
             username = self._proxy.username.encode('utf-8')