mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Revert "Tls fingerprints"
This commit is contained in:
parent
ec708ea273
commit
c86ad88c96
6 changed files with 13 additions and 46 deletions
|
|
@ -7,4 +7,3 @@ In alphabetical order:
|
|||
- Clément Mondon
|
||||
- Julian Mehne
|
||||
- Markus Unterwaditzer
|
||||
- Thomas Weißschuh
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@
|
|||
|
||||
* But not because you wrote too few tests.
|
||||
|
||||
* Add yourself to ``AUTHORS.rst``. Don't add anything to
|
||||
* Add yourself to ``CONTRIBUTORS.rst``. Don't add anything to
|
||||
``CHANGELOG.rst``, I do that myself shortly before the release. You can
|
||||
help by writing meaningful commit messages.
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ def test_list(monkeypatch):
|
|||
u'\n'.join([u'BEGIN:VCALENDAR'] + items + [u'END:VCALENDAR'])
|
||||
] * 2
|
||||
|
||||
def get(self, method, url, *a, **kw):
|
||||
def get(method, url, *a, **kw):
|
||||
assert method == 'GET'
|
||||
assert url == collection_url
|
||||
r = Response()
|
||||
|
|
@ -52,7 +52,7 @@ def test_list(monkeypatch):
|
|||
r.encoding = 'ISO-8859-1'
|
||||
return r
|
||||
|
||||
monkeypatch.setattr('requests.sessions.Session.request', get)
|
||||
monkeypatch.setattr('requests.request', get)
|
||||
|
||||
s = HttpStorage(url=collection_url)
|
||||
|
||||
|
|
|
|||
|
|
@ -162,14 +162,13 @@ class DavSession(object):
|
|||
'''
|
||||
|
||||
def __init__(self, url, username='', password='', verify=True, auth=None,
|
||||
useragent=USERAGENT, tls_fingerprint=None, dav_header=None):
|
||||
useragent=USERAGENT, dav_header=None):
|
||||
if username and not password:
|
||||
password = utils.get_password(username, url)
|
||||
|
||||
self._settings = {
|
||||
'verify': prepare_verify(verify),
|
||||
'auth': prepare_auth(auth, username, password),
|
||||
'tls_fingerprint': tls_fingerprint,
|
||||
'auth': prepare_auth(auth, username, password)
|
||||
}
|
||||
self.useragent = useragent
|
||||
self.url = url.rstrip('/') + '/'
|
||||
|
|
@ -223,8 +222,6 @@ class DavStorage(Storage):
|
|||
:param password: Password for authentication.
|
||||
:param verify: Verify SSL certificate, default True. This can also be a
|
||||
local path to a self-signed SSL certificate.
|
||||
:param tls_fingerprint: Optional. SHA1 or MD5 fingerprint of the
|
||||
expected server certificate.
|
||||
:param auth: Optional. Either ``basic``, ``digest`` or ``guess``. Default
|
||||
``guess``. If you know yours, consider setting it explicitly for
|
||||
performance.
|
||||
|
|
@ -251,15 +248,14 @@ class DavStorage(Storage):
|
|||
|
||||
def __init__(self, url, username='', password='', collection=None,
|
||||
verify=True, auth=None, useragent=USERAGENT,
|
||||
unsafe_href_chars='@', tls_fingerprint=None, **kwargs):
|
||||
unsafe_href_chars='@', **kwargs):
|
||||
super(DavStorage, self).__init__(**kwargs)
|
||||
|
||||
url = url.rstrip('/') + '/'
|
||||
if collection is not None:
|
||||
url = utils.urlparse.urljoin(url, collection)
|
||||
self.session = DavSession(url, username, password, verify, auth,
|
||||
useragent, tls_fingerprint,
|
||||
dav_header=self.dav_header)
|
||||
useragent, dav_header=self.dav_header)
|
||||
self.collection = collection
|
||||
self.unsafe_href_chars = unsafe_href_chars
|
||||
|
||||
|
|
@ -272,8 +268,7 @@ class DavStorage(Storage):
|
|||
if kwargs.pop('collection', None) is not None:
|
||||
raise TypeError('collection argument must not be given.')
|
||||
discover_args, _ = utils.split_dict(kwargs, lambda key: key in (
|
||||
'username', 'password', 'verify', 'auth', 'useragent',
|
||||
'tls_fingerprint',
|
||||
'username', 'password', 'verify', 'auth', 'useragent'
|
||||
))
|
||||
d = cls.discovery_class(DavSession(
|
||||
url=url, dav_header=cls.dav_header, **discover_args))
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@ class HttpStorage(Storage):
|
|||
:param password: Password for authentication.
|
||||
:param verify: Verify SSL certificate, default True. This can also be a
|
||||
local path to a self-signed SSL certificate.
|
||||
:param tls_fingerprint: Optional. SHA1 or MD5 fingerprint of the
|
||||
expected server certificate.
|
||||
:param auth: Optional. Either ``basic``, ``digest`` or ``guess``. Default
|
||||
``guess``. If you know yours, consider setting it explicitly for
|
||||
performance.
|
||||
|
|
@ -83,8 +81,7 @@ class HttpStorage(Storage):
|
|||
_items = None
|
||||
|
||||
def __init__(self, url, username='', password='', collection=None,
|
||||
verify=True, auth=None, useragent=USERAGENT,
|
||||
tls_fingerprint=None, **kwargs):
|
||||
verify=True, auth=None, useragent=USERAGENT, **kwargs):
|
||||
super(HttpStorage, self).__init__(**kwargs)
|
||||
|
||||
if username and not password:
|
||||
|
|
@ -92,7 +89,6 @@ class HttpStorage(Storage):
|
|||
|
||||
self._settings = {
|
||||
'verify': prepare_verify(verify),
|
||||
'tls_fingerprint': tls_fingerprint,
|
||||
'auth': prepare_auth(auth, username, password),
|
||||
'latin1_fallback': False
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
import os
|
||||
|
||||
import requests
|
||||
from requests.packages.urllib3.poolmanager import PoolManager
|
||||
|
||||
from .. import exceptions, log
|
||||
from ..doubleclick import click
|
||||
|
|
@ -178,23 +177,8 @@ def _password_from_keyring(username, resource):
|
|||
key = new_key
|
||||
|
||||
|
||||
class _FingerprintAdapter(requests.adapters.HTTPAdapter):
|
||||
def __init__(self, fingerprint=None, **kwargs):
|
||||
self.fingerprint = str(fingerprint)
|
||||
super(_FingerprintAdapter, self).__init__(**kwargs)
|
||||
|
||||
def send(self, *args, **kwargs):
|
||||
return super(_FingerprintAdapter, self).send(*args, **kwargs)
|
||||
|
||||
def init_poolmanager(self, connections, maxsize, block=False):
|
||||
self.poolmanager = PoolManager(num_pools=connections,
|
||||
maxsize=maxsize,
|
||||
block=block,
|
||||
assert_fingerprint=self.fingerprint)
|
||||
|
||||
|
||||
def request(method, url, data=None, headers=None, auth=None, verify=None,
|
||||
session=None, latin1_fallback=True, tls_fingerprint=None):
|
||||
session=None, latin1_fallback=True):
|
||||
'''
|
||||
Wrapper method for requests, to ease logging and mocking. Parameters should
|
||||
be the same as for ``requests.request``, except:
|
||||
|
|
@ -209,16 +193,9 @@ def request(method, url, data=None, headers=None, auth=None, verify=None,
|
|||
'''
|
||||
|
||||
if session is None:
|
||||
session = requests.Session()
|
||||
|
||||
if tls_fingerprint is not None:
|
||||
https_prefix = 'https://'
|
||||
|
||||
if not isinstance(session.adapters[https_prefix], _FingerprintAdapter):
|
||||
fingerprint_adapter = _FingerprintAdapter(tls_fingerprint)
|
||||
session.mount(https_prefix, fingerprint_adapter)
|
||||
|
||||
func = session.request
|
||||
func = requests.request
|
||||
else:
|
||||
func = session.request
|
||||
|
||||
logger.debug(u'{} {}'.format(method, url))
|
||||
logger.debug(headers)
|
||||
|
|
|
|||
Loading…
Reference in a new issue