Skip to content

Commit

Permalink
Merge pull request puremourning#103 from axrt/no_ssl
Browse files Browse the repository at this point in the history
Add a --no-ssl flag that switches off certificate verification
  • Loading branch information
mergify[bot] authored Jan 31, 2020
2 parents 9c18f3e + 5eb042b commit 9485a9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ README.md.toc.*
.DS_Store
*.vimspector.log
support/test/csharp/*.exe*
.neomake.log
23 changes: 20 additions & 3 deletions install_gadget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import json
import functools
import time
import ssl

try:
from io import BytesIO # for Python 3
Expand Down Expand Up @@ -484,7 +485,7 @@ def UrlOpen( *args, **kwargs ):
return urllib2.urlopen( *args, **kwargs )


def DownloadFileTo( url, destination, file_name = None, checksum = None ):
def DownloadFileTo( url, destination, file_name = None, checksum = None, sslcheck = True):
if not file_name:
file_name = url.split( '/' )[ -1 ]

Expand All @@ -509,7 +510,15 @@ def DownloadFileTo( url, destination, file_name = None, checksum = None ):

print( "Downloading {} to {}/{}".format( url, destination, file_name ) )

with contextlib.closing( UrlOpen( r ) ) as u:
if not sslcheck:
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
kwargs = { "context": context }
else:
kwargs = {}

with contextlib.closing( UrlOpen( r, **kwargs ) ) as u:
with open( file_path, 'wb' ) as f:
f.write( u.read() )

Expand Down Expand Up @@ -662,6 +671,12 @@ def CloneRepoTo( url, ref, destination ):
help = "Don't install the {} debug adapter for {} support "
'(when supplying --all)'.format( name, lang ) )

parser.add_argument(
"--no-check-certificate",
action = "store_true",
help = "Do not verify SSL certificates for file downloads."
)

args = parser.parse_args()

if args.force_all and not args.all:
Expand Down Expand Up @@ -693,12 +708,14 @@ def CloneRepoTo( url, ref, destination ):
destination = os.path.join( gadget_dir, 'download', name, v[ 'version' ] )

url = string.Template( gadget[ 'download' ][ 'url' ] ).substitute( v )
verify_cert_off = args.no_check_certificate

file_path = DownloadFileTo(
url,
destination,
file_name = gadget[ 'download' ].get( 'target' ),
checksum = v.get( 'checksum' ) )
checksum = v.get( 'checksum' ),
sslcheck = not verify_cert_off)
root = os.path.join( destination, 'root' )
ExtractZipTo( file_path,
root,
Expand Down

0 comments on commit 9485a9f

Please sign in to comment.