Skip to content

Commit

Permalink
Add support for system truststore
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Oct 28, 2024
1 parent 856e5f4 commit 92a8ca0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ tomli = { version = "^2.0.1", python = "<3.11" }
tomlkit = ">=0.11.4,<1.0.0"
# trove-classifiers uses calver, so version is unclamped
trove-classifiers = ">=2022.5.19"
truststore = { version = ">=0.10.0,<1.0.0", python = ">=3.10" }
virtualenv = "^20.26.6"
xattr = { version = "^1.0.0", markers = "sys_platform == 'darwin'" }

Expand Down
2 changes: 2 additions & 0 deletions src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Config:
"keyring": {
"enabled": True,
},
"system-truststore": True,
}

def __init__(self, use_environment: bool = True) -> None:
Expand Down Expand Up @@ -301,6 +302,7 @@ def _get_normalizer(name: str) -> Callable[[str], Any]:
"solver.lazy-wheel",
"system-git-client",
"keyring.enabled",
"system-truststore",
}:
return boolean_normalizer

Expand Down
11 changes: 11 additions & 0 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def _run(self, io: IO) -> int:

self._load_plugins(io)

self._load_system_truststore()

exit_code: int = super()._run(io)
return exit_code

Expand Down Expand Up @@ -342,6 +344,15 @@ def _load_plugins(self, io: IO | None = None) -> None:

self._plugins_loaded = True

@staticmethod
def _load_system_truststore() -> None:
from poetry.utils.ssl_truststore import is_truststore_enabled

if is_truststore_enabled():
import truststore

truststore.inject_into_ssl()

@property
def _default_definition(self) -> Definition:
from cleo.io.inputs.option import Option
Expand Down
32 changes: 32 additions & 0 deletions src/poetry/utils/ssl_truststore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import logging
import sys

from poetry.config.config import Config


logger = logging.getLogger(__name__)


def _is_truststore_available() -> bool:
if sys.version_info < (3, 10):
logger.debug("Disabling truststore because Python version isn't 3.10+")
return False

try:
import ssl # noqa: F401
except ImportError:
logger.warning("Disabling truststore since ssl support is missing")
return False

try:
import truststore # noqa: F401
except ImportError:
logger.warning("Disabling truststore because `truststore` package is missing`")
return False
return True


def is_truststore_enabled() -> bool:
return Config.create().get("system-truststore") and _is_truststore_available()

0 comments on commit 92a8ca0

Please sign in to comment.