python-tds
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: python-tds | ||
| Version: 1.12.0 | ||
| Version: 1.13.0 | ||
| Summary: Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/denisenkom/pytds |
+16
-32
@@ -9,4 +9,4 @@ # vim: set fileencoding=utf8 : | ||
| """ | ||
| import logging | ||
| import socket | ||
| import logging | ||
@@ -91,8 +91,9 @@ logger = logging.getLogger(__name__) | ||
| self._ctx.close() | ||
| self._cred.close() | ||
| class NtlmAuth(object): | ||
| """ NTLM authentication, uses Python implementation | ||
| """ NTLM authentication, uses Python implementation (ntlm-auth) | ||
| For more information about NTLM authentication see https://github.com/jborean93/ntlm-auth | ||
| :param user_name: User name | ||
@@ -102,4 +103,7 @@ :type user_name: str | ||
| :type password: str | ||
| :param ntlm_compatibility: NTLM compatibility level, default is 3(NTLMv2) | ||
| :type ntlm_compatibility: int | ||
| """ | ||
| def __init__(self, user_name, password): | ||
| def __init__(self, user_name, password, ntlm_compatibility=3): | ||
| self._user_name = user_name | ||
@@ -113,37 +117,17 @@ if '\\' in user_name: | ||
| self._password = password | ||
| self._workstation = socket.gethostname().upper() | ||
| try: | ||
| from ntlm_auth.ntlm import NegotiateFlags | ||
| from ntlm_auth.ntlm import NtlmContext | ||
| except ImportError: | ||
| raise ImportError("To use NTLM authentication you need to install ntlm-auth module") | ||
| self._nego_flags = NegotiateFlags.NTLMSSP_NEGOTIATE_128 | \ | ||
| NegotiateFlags.NTLMSSP_NEGOTIATE_56 | \ | ||
| NegotiateFlags.NTLMSSP_NEGOTIATE_UNICODE | \ | ||
| NegotiateFlags.NTLMSSP_NEGOTIATE_VERSION | \ | ||
| NegotiateFlags.NTLMSSP_REQUEST_TARGET | \ | ||
| NegotiateFlags.NTLMSSP_NEGOTIATE_NTLM | \ | ||
| NegotiateFlags.NTLMSSP_NEGOTIATE_EXTENDED_SESSIONSECURITY | \ | ||
| NegotiateFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN | ||
| self._ntlm_compat = 2 | ||
| self._workstation = socket.gethostname().upper() | ||
| self._ntlm_context = NtlmContext(self._user, self._password, self._domain, self._workstation, | ||
| ntlm_compatibility=ntlm_compatibility) | ||
| def create_packet(self): | ||
| import ntlm_auth.ntlm | ||
| return ntlm_auth.ntlm.NegotiateMessage( | ||
| negotiate_flags=self._nego_flags, | ||
| domain_name=self._domain, | ||
| workstation=self._workstation, | ||
| ).get_data() | ||
| return self._ntlm_context.step() | ||
| def handle_next(self, packet): | ||
| import ntlm_auth.ntlm | ||
| challenge = ntlm_auth.ntlm.ChallengeMessage(packet) | ||
| return ntlm_auth.ntlm.AuthenticateMessage( | ||
| user_name=self._user, | ||
| password=self._password, | ||
| domain_name=self._domain, | ||
| workstation=self._workstation, | ||
| challenge_message=challenge, | ||
| ntlm_compatibility=self._ntlm_compat, | ||
| server_certificate_hash=None, | ||
| ).get_data() | ||
| return self._ntlm_context.step(packet) | ||
@@ -150,0 +134,0 @@ def close(self): |
+10
-3
| import six | ||
| import logging | ||
| from ctypes import c_ulong, c_ushort, c_void_p, c_ulonglong, POINTER,\ | ||
| Structure, c_wchar_p, WINFUNCTYPE, windll, byref, cast | ||
| logger = logging.getLogger(__name__) | ||
@@ -324,2 +327,3 @@ class Status(object): | ||
| self._ts = TimeStamp() | ||
| logger.debug("Acquiring credentials handle") | ||
| sec_fn.AcquireCredentialsHandle( | ||
@@ -331,6 +335,6 @@ None, package, use, | ||
| def close(self): | ||
| if self._handle.lower or self._handle.upper: | ||
| if self._handle and (self._handle.lower or self._handle.upper): | ||
| logger.debug("Releasing credentials handle") | ||
| sec_fn.FreeCredentialsHandle(byref(self._handle)) | ||
| self._handle.lower = 0 | ||
| self._handle.upper = 0 | ||
| self._handle = None | ||
@@ -360,2 +364,4 @@ def __del__(self): | ||
| output_buffers=None): | ||
| if self._handle is None: | ||
| raise RuntimeError("Using closed SspiCredentials object") | ||
| ctx = _SecContext() | ||
@@ -368,2 +374,3 @@ ctx._cred = self | ||
| output_buffers_desc = _make_buffers_desc(output_buffers) if output_buffers else None | ||
| logger.debug("Initializing security context") | ||
| status = sec_fn.InitializeSecurityContext( | ||
@@ -370,0 +377,0 @@ byref(self._handle), |
+14
-3
@@ -84,2 +84,14 @@ import logging | ||
| def is_san_matching(san: str, host_name: str) -> bool: | ||
| for item in san.split(','): | ||
| dnsentry = item.lstrip('DNS:').strip() | ||
| # SANs are usually have form like: DNS:hostname | ||
| if dnsentry == host_name: | ||
| return True | ||
| if dnsentry[0:2] == "*.": # support for wildcards, but only at the first position | ||
| afterstar_parts = dnsentry[2:] | ||
| afterstar_parts_sname = '.'.join(host_name.split('.')[1:]) # remove first part of dns name | ||
| if afterstar_parts == afterstar_parts_sname: | ||
| return True | ||
| return False | ||
@@ -109,7 +121,6 @@ def validate_host(cert, name): | ||
| s = str(ext) | ||
| # SANs are usually have form like: DNS:hostname | ||
| if s.startswith('DNS:') and s[4:] == s_name: | ||
| if is_san_matching(s, s_name): | ||
| return True | ||
| # TODO handle wildcards | ||
| # TODO check if wildcard is needed in CN as well | ||
| return False | ||
@@ -116,0 +127,0 @@ |
| Metadata-Version: 2.1 | ||
| Name: python-tds | ||
| Version: 1.12.0 | ||
| Version: 1.13.0 | ||
| Summary: Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/denisenkom/pytds |
| pytest>=3.3.2 | ||
| pytest-cov | ||
| codecov | ||
| pyOpenSSL | ||
| # pyOpenSSL 23.0.0 fails with error: | ||
| # TypeError: deprecated() got an unexpected keyword argument 'name' | ||
| # Example failing build: https://ci.appveyor.com/project/denisenkom/pytds/builds/46539355/job/aq6d65ej1oi0i59p | ||
| pyOpenSSL<22.1.0 | ||
| pyDes | ||
@@ -6,0 +9,0 @@ ntlm-auth |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
304570
0.09%7313
-0.04%