Skip to content

Use OS trustore for certificate resolution #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*
install_requires =
keyring >= 16.0
requests >= 2.20.0
truststore >= 0.10.0

[options.packages.find]
where=src
Expand Down
17 changes: 16 additions & 1 deletion src/artifacts_keyring/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@

import json
import os
import ssl
import truststore
import requests
import subprocess
import sys
import warnings
import shutil

from requests.adapters import HTTPAdapter

from . import __version__
from .support import Popen


class TruststoreAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
return super().init_poolmanager(connections, maxsize, block, ssl_context=ctx)


class CredentialProvider(object):
_NON_INTERACTIVE_VAR_NAME = "ARTIFACTS_KEYRING_NONINTERACTIVE_MODE"

def __init__(self):
self.session = requests.Session()
adapter = TruststoreAdapter()
self.session.mount("http://", adapter)
self.session.mount("https://", adapter)

if sys.platform.startswith("win"):
# by default, attempt to search netfx plugins folder.
# if that doesn't exist, search netcore for newer credprovider versions.
Expand Down Expand Up @@ -96,7 +111,7 @@ def _is_upload_endpoint(self, url):


def _can_authenticate(self, url, auth):
response = requests.get(url, auth=auth)
response = self.session.get(url, auth=auth)

return response.status_code < 500 and \
response.status_code != 401 and \
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def validating_provider(monkeypatch):
def mock_get_credentials(self, url, is_retry):
return url, is_retry

def mock_requests_get(url, auth):
def mock_requests_get(self, url, **kwargs):
response = MockGetResponse()
response.status_code = int(url[:3])
return response

monkeypatch.setattr(CredentialProvider, "_get_credentials_from_credential_provider", mock_get_credentials)
monkeypatch.setattr(requests, "get", mock_requests_get)
monkeypatch.setattr(requests.Session, "get", mock_requests_get)

yield CredentialProvider()

Expand Down