Skip to content

Commit

Permalink
πŸš‘πŸ› Fix TLS locations init when unsupported
Browse files Browse the repository at this point in the history
Ignore TLS certificate lookup file and dir locations initialization
failure when the TLS backend library doesn't support it.

Ref #878
  • Loading branch information
webknjaz committed Mar 9, 2019
1 parent ea4622d commit d1632fb
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions pygit2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from _pygit2 import GIT_OPT_SET_CACHE_MAX_SIZE
from _pygit2 import GIT_OPT_SET_SSL_CERT_LOCATIONS

from .errors import GitError


__metaclass__ = type # make all classes new-style by default

Expand All @@ -59,11 +61,23 @@ class Settings:
_search_path = SearchPathList()

def __init__(self):
"""Initialize global pygit2 and libgit2 settings."""
self._initialize_tls_certificate_locations()

def _initialize_tls_certificate_locations(self):
"""Set up initial TLS file and directory lookup locations."""
self._default_tls_verify_paths = get_default_verify_paths()
self.set_ssl_cert_locations(
self._default_tls_verify_paths.cafile,
self._default_tls_verify_paths.capath,
)
try:
self.set_ssl_cert_locations(
self._default_tls_verify_paths.cafile,
self._default_tls_verify_paths.capath,
)
except GitError as git_err:
valid_msg = "TLS backend doesn't support certificate locations"
if str(git_err) != valid_msg:
raise
self._ssl_cert_file = self._default_tls_verify_paths.cafile
self._ssl_cert_dir = self._default_tls_verify_paths.capath

@property
def search_path(self):
Expand Down

0 comments on commit d1632fb

Please sign in to comment.