36
36
from twisted.internet import error, ssl
37
37
from twisted.python import log
39
if sys.platform == "win32":
40
# diable pylint warning, as it may be the wrong platform
41
# pylint: disable=F0401
44
# First open the registry hive
45
hive = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
46
# Open the registry key where Windows stores the Shell Folder locations
47
key = _winreg.OpenKey(hive, str(
48
"Software\\Microsoft\\Windows\\CurrentVersion"
49
"\\Explorer\\Shell Folders"))
50
for i in range(0, _winreg.QueryInfoKey(key)[1]):
51
name, value, val_type = _winreg.EnumValue(key, i)
52
# Common AppData will always be present unless the user
54
if name == "Common AppData":
55
ssl_cert_location = os.path.join(value,
56
"ubuntuone-storageprotocol")
59
ssl_cert_location = '/etc/ssl/certs'
39
from dirspec.basedir import load_config_paths
42
def get_cert_location():
43
"""Return path to certificate files."""
45
if sys.platform == "win32":
46
ssl_cert_location = list(load_config_paths(
47
"ubuntuone-storageprotocol"))[0]
49
elif sys.platform == "darwin":
50
if getattr(sys, "frozen", None) is not None:
51
main_app_dir = "".join(__file__.partition(".app")[:-1])
52
main_app_resources_dir = os.path.join(main_app_dir,
55
ssl_cert_location = main_app_resources_dir
57
pkg_dir = os.path.dirname(__file__)
58
src_tree_path = os.path.dirname(os.path.dirname(pkg_dir))
59
ssl_cert_location = os.path.join(src_tree_path,
62
ssl_cert_location = '/etc/ssl/certs'
64
return ssl_cert_location
62
67
class HostnameVerifyContextFactory(ssl.CertificateOptions):
89
94
def get_certificates():
90
95
"""Get a list of certificate paths."""
96
ssl_cert_location = get_cert_location()
91
97
ca_file = ssl.Certificate.loadPEM(file(os.path.join(ssl_cert_location,
92
98
'UbuntuOne-Go_Daddy_Class_2_CA.pem'), 'r').read())
93
99
ca_file_2 = ssl.Certificate.loadPEM(file(os.path.join(ssl_cert_location,