1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Auto-detect of CA bundle for SSL connections"""
21
from bzrlib.trace import mutter
27
def get_ca_path(use_cache=True):
28
"""Return location of CA bundle"""
31
if _ca_path is not None and use_cache:
34
# Find CA bundle for SSL
35
# Reimplementation in Python the magic of curl command line tool
36
# from "Details on Server SSL Certificates"
37
# http://curl.haxx.se/docs/sslcerts.html
39
# 4. If you're using the curl command line tool, you can specify your own CA
40
# cert path by setting the environment variable CURL_CA_BUNDLE to the path
43
# If you're using the curl command line tool on Windows, curl will search
44
# for a CA cert file named "curl-ca-bundle.crt" in these directories and in
46
# 1. application's directory
47
# 2. current working directory
48
# 3. Windows System directory (e.g. C:\windows\system32)
49
# 4. Windows Directory (e.g. C:\windows)
50
# 5. all directories along %PATH%
53
# bialix: Windows directories usually listed in PATH env variable
54
# j-a-meinel: bzr should not look in current working dir
56
path = os.environ.get('CURL_CA_BUNDLE')
57
if not path and sys.platform == 'win32':
58
dirs = [os.path.realpath(os.path.dirname(sys.argv[0]))] # app dir
59
paths = os.environ.get('PATH')
61
# don't include the cwd in the search
62
paths = [i for i in paths.split(os.pathsep) if i not in ('', '.')]
65
fname = os.path.join(d, "curl-ca-bundle.crt")
66
if os.path.isfile(fname):
70
mutter('using CA bundle: %r', path)