Add --no-check-certificate (#814)
authorPhilipp Hagemeister <phihag@phihag.de>
Sat, 4 May 2013 10:19:02 +0000 (12:19 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Sat, 4 May 2013 10:22:56 +0000 (12:22 +0200)
youtube_dl/__init__.py
youtube_dl/utils.py

index b8a82f932cddb927d0b2de7c31737a998b5f0bf2..05cb6e36ab80949597d84a427f1c8fac253003e1 100644 (file)
@@ -149,6 +149,7 @@ def parseOpts(overrideArguments=None):
             action='store_true', dest='list_extractors',
             help='List all supported extractors and the URLs they would handle', default=False)
     general.add_option('--proxy', dest='proxy', default=None, help='Use the specified HTTP/HTTPS proxy', metavar='URL')
+    general.add_option('--no-check-certificate', action='store_true', dest='no_check_certificate', default=False, help='Suppress HTTPS certificate validation.')
     general.add_option('--test', action='store_true', dest='test', default=False, help=optparse.SUPPRESS_HELP)
 
     selection.add_option('--playlist-start',
@@ -395,7 +396,7 @@ def _real_main(argv=None):
         if 'http' in proxies and 'https' not in proxies:
             proxies['https'] = proxies['http']
     proxy_handler = compat_urllib_request.ProxyHandler(proxies)
-    https_handler = compat_urllib_request.HTTPSHandler()
+    https_handler = make_HTTPS_handler(opts)
     opener = compat_urllib_request.build_opener(https_handler, proxy_handler, cookie_processor, YoutubeDLHandler())
     compat_urllib_request.install_opener(opener)
     socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words)
index 4ec0ebfe10e4f96c56723e2dd2bdc67e16dcb11c..f2342b10a0e2521be52c8ffed0c279bceaa15e5c 100644 (file)
@@ -438,6 +438,20 @@ def formatSeconds(secs):
     else:
         return '%d' % secs
 
+def make_HTTPS_handler(opts):
+    if sys.version_info < (3,2):
+        # Python's 2.x handler is very simplistic
+        return compat_urllib_request.HTTPSHandler()
+    else:
+        import ssl
+        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+        context.set_default_verify_paths()
+        
+        context.verify_mode = (ssl.CERT_NONE
+                               if opts.no_check_certificate
+                               else ssl.CERT_REQUIRED)
+        return compat_urllib_request.HTTPSHandler(context=context)
+
 class ExtractorError(Exception):
     """Error during info extraction."""
     def __init__(self, msg, tb=None):