Explorar o código

Merge pull request #1110 from adam-yang/gettaef-tls2

Modified hctgettaef.py to use tls1.2 when requesting files files github.
Adam Yang %!s(int64=7) %!d(string=hai) anos
pai
achega
1f5ef0430e
Modificáronse 1 ficheiros con 9 adicións e 2 borrados
  1. 9 2
      utils/hct/hctgettaef.py

+ 9 - 2
utils/hct/hctgettaef.py

@@ -1,5 +1,6 @@
 import urllib
 import os
+import ssl
 import zipfile
 
 url = "https://github.com/Microsoft/WinObjC/raw/develop/deps/prebuilt/nuget/taef.redist.wlk.1.0.170206001-nativetargets.nupkg"
@@ -11,11 +12,17 @@ if not os.path.isdir(taef_dir):
   os.makedirs(taef_dir)
 
 try:
-  urllib.urlretrieve(url, zipfile_name)
+  ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
+  response = urllib.urlopen(url, context=ctx)
+  f = open(zipfile_name, 'wb')
+  f.write(response.read())
+  f.close()
 except:
   print("Unable to read file with urllib, trying via powershell...")
   from subprocess import check_call
-  cmd = "(new-object System.Net.WebClient).DownloadFile('" + url + "', '" + zipfile_name + "')"
+  cmd = ""
+  cmd += "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;"
+  cmd += "(new-object System.Net.WebClient).DownloadFile('" + url + "', '" + zipfile_name + "')"
   check_call(['powershell.exe', '-Command', cmd])
 
 z = zipfile.ZipFile(zipfile_name)