Skip to content

Commit c72d63e

Browse files
committed
Enable CA Cert verification by default
1 parent c887db1 commit c72d63e

File tree

6 files changed

+7
-5138
lines changed

6 files changed

+7
-5138
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ python:
99
# e.g. pip install -r requirements.txt --use-mirrors
1010
before_install:
1111
- sudo apt-get update -qq
12-
- sudo apt-get install -y pandoc
1312
- sudo apt-get install -y aria2
1413
install:
1514
- pip install -r requirements.txt
16-
- pip install pypandoc
1715
- pip install pyflakes
1816
- pip install coverage
1917
- pip install coveralls

HISTORY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Version History:
22

3-
- 1.3.1: Fix setup.py failure
3+
- 1.3.2: Enable SSL check by default now
4+
- 1.3.1: Fix setup.py failures
45
- 1.3.0: Major change: Make bypy a real Python package
56

67
---
File renamed without changes.

bypy/bypy.py

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@
5050
from argparse import RawDescriptionHelpFormatter
5151
# unify Python 2 and 3
5252
if sys.version_info[0] == 2:
53-
import urllib2 as ulr
5453
import urllib as ulp
5554
import cPickle as pickle
5655
pickleload = pickle.load
5756
elif sys.version_info[0] == 3:
58-
import urllib.request as ulr
5957
import urllib.parse as ulp
6058
import pickle
6159
unicode = str
@@ -75,7 +73,7 @@
7573
jsondump, jsonload, formatex, rb,
7674
joinpath, get_pcs_path, print_pcs_list, str2bool, str2int,
7775
human_size, interpret_size, ls_time, ls_type,
78-
makedir, removedir, copyfile, movefile, removefile, getfilesize,
76+
makedir, removedir, movefile, removefile, getfilesize,
7977
MyPrettyPrinter)
8078
from .chkreq import (check_requirements, CheckResult)
8179
from .requester import RequestsRequester
@@ -167,26 +165,6 @@ def migratesettings():
167165

168166
return result
169167

170-
def getcertfile(self):
171-
result = const.ENoError
172-
if not os.path.exists(self.__certspath):
173-
if os.path.exists(const.ByPyCertsFileName):
174-
result = copyfile(const.ByPyCertsFileName, self.__certspath)
175-
else:
176-
try:
177-
# perform a simple download from github
178-
CACertUrl = 'https://raw.githubusercontent.com/houtianze/bypy/master/bypy.cacerts.pem'
179-
resp = ulr.urlopen(CACertUrl)
180-
with io.open(self.__certspath, 'wb') as f:
181-
f.write(resp.read())
182-
except IOError as ex:
183-
perr("Fail download CA Certs to '{}'.\n{}".format(
184-
self.__certspath, formatex(ex)))
185-
186-
result = const.EDownloadCerts
187-
188-
return result
189-
190168
# TODO: save settings here?
191169
def quit(retcode = const.ENoError):
192170
# saving is the most important
@@ -264,9 +242,7 @@ def __init__(self,
264242
perr("Error loading settings: {}, using default settings".format(formatex(ex)))
265243
self.__hashcachepath = configdir + os.sep + const.HashCacheFileName
266244
cached.hashcachepath = self.__hashcachepath
267-
self.__certspath = configdir + os.sep + const.ByPyCertsFileName
268-
# it doesn't matter if it failed, we can disable SSL verification anyway
269-
self.getcertfile()
245+
self.__certspath = os.path.join(os.path.dirname(__file__), const.ByPyCertsFileName)
270246

271247
self.__requester = requester
272248
self.__apikey = apikey
@@ -308,15 +284,13 @@ def __init__(self,
308284
self.__followlink = followlink;
309285
self.__rapiduploadonly = rapiduploadonly
310286

311-
# TODO: properly fix this InsecurePlatformWarning
312-
checkssl = False
313287
self.__checkssl = checkssl
314288
if self.__checkssl:
315289
# sort of undocumented by requests
316290
# http://stackoverflow.com/questions/10667960/python-requests-throwing-up-sslerror
317291
if cacerts is not None:
318292
if os.path.isfile(cacerts):
319-
self.__checkssl = cacerts
293+
self.__certspath = cacerts
320294
else:
321295
perr("Invalid CA Bundle '{}' specified")
322296

@@ -2990,7 +2964,7 @@ def getparser():
29902964
dest="checkssl", action="store_false",
29912965
help="DON'T verify host SSL cerificate")
29922966
parser.add_argument(const.CaCertsOption,
2993-
dest="cacerts",
2967+
dest="cacerts", default=None,
29942968
help="Specify the path for CA Bundle [default: %(default)s]")
29952969
parser.add_argument("--mirror",
29962970
dest="mirror", default=None,

bypy/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# https://packaging.python.org/single_source_version/
1414
__title__ = 'bypy'
15-
__version__ = '1.3.1'
15+
__version__ = '1.3.2'
1616
__author__ = 'Hou Tianze'
1717
__license__ = 'MIT'
1818
__desc__ ='Python client for Baidu Yun (Personal Cloud Storage) 百度云/百度网盘 Python 客户端'

0 commit comments

Comments
 (0)