diff --git a/.travis.yml b/.travis.yml index e5ef98c..e10d016 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,13 @@ language: python +os: linux +dist: xenial + python: - - "2.6" - "2.7" - - "3.3" - - "3.4" - "3.5" - "3.6" + - "3.7" install: - pip install -U pip setuptools diff --git a/requests_ntlm/requests_ntlm.py b/requests_ntlm/requests_ntlm.py index 23db0cc..a253607 100644 --- a/requests_ntlm/requests_ntlm.py +++ b/requests_ntlm/requests_ntlm.py @@ -1,3 +1,4 @@ +import base64 import binascii import sys import warnings @@ -71,8 +72,12 @@ def retry_using_http_NTLM_auth(self, auth_header_field, auth_header, # ntlm returns the headers as a base64 encoded bytestring. Convert to # a string. - context = ntlm.Ntlm() - negotiate_message = context.create_negotiate_message(self.domain).decode('ascii') + context = ntlm.NtlmContext( + username=self.username, + password=self.password, + domain=self.domain or None, + ) + negotiate_message = base64.b64encode(context.step()).decode('ascii') auth = u'%s %s' % (auth_type, negotiate_message) request.headers[auth_header] = auth @@ -110,17 +115,12 @@ def retry_using_http_NTLM_auth(self, auth_header_field, auth_header, ).strip() # Parse the challenge in the ntlm context - context.parse_challenge_message(ntlm_header_value[len(auth_strip):]) + challenge_token = base64.b64decode(ntlm_header_value[len(auth_strip):]) # build response # Get the response based on the challenge message - authenticate_message = context.create_authenticate_message( - self.username, - self.password, - self.domain, - server_certificate_hash=server_certificate_hash - ) - authenticate_message = authenticate_message.decode('ascii') + context._server_certificate_hash = server_certificate_hash + authenticate_message = base64.b64encode(context.step(challenge_token)).decode('ascii') auth = u'%s %s' % (auth_type, authenticate_message) request.headers[auth_header] = auth @@ -131,7 +131,7 @@ def retry_using_http_NTLM_auth(self, auth_header_field, auth_header, response3.history.append(response2) # Get the session_security object created by ntlm-auth for signing and sealing of messages - self.session_security = context.session_security + self.session_security = context._session_security return response3 diff --git a/requirements.txt b/requirements.txt index ede853a..b396b6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ requests>=2.0.0 -ntlm-auth>=1.0.2 +ntlm-auth>=1.2.0 cryptography>=1.3 flask pytest -pytest-cov +pytest-cov<2.6 wheel diff --git a/setup.py b/setup.py index d7c6e0b..fff258a 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ name='requests_ntlm', version='1.1.0', packages=[ 'requests_ntlm' ], - install_requires=[ 'requests>=2.0.0', 'ntlm-auth>=1.0.2', 'cryptography>=1.3' ], + install_requires=[ 'requests>=2.0.0', 'ntlm-auth>=1.2.0', 'cryptography>=1.3' ], provides=[ 'requests_ntlm' ], author='Ben Toews', author_email='mastahyeti@gmail.com',