@@ -874,17 +874,14 @@ def _try_authenticate_gssapi_sspi_implementation(self, future):
874
874
received_token = self ._recv_bytes_blocking (token_size )
875
875
log_sspi .debug ("Received token from server (size %s)" , token_size )
876
876
877
- # Add some extra attributes to the context
878
- sspi_amend_ctx_metadata (client_ctx )
879
-
880
877
# Process the security layer negotiation token, sent by the server
881
878
# once the security context is established.
882
879
883
880
# The following part is required by SASL, but not by classic Kerberos.
884
881
# See RFC 4752
885
882
886
883
# unwraps message containing supported protection levels and msg size
887
- msg = sspi_gss_unwrap_step ( client_ctx , received_token )
884
+ msg , was_encrypted = client_ctx . unwrap ( received_token )
888
885
889
886
# Kafka currently doesn't support integrity or confidentiality security layers, so we
890
887
# simply set QoP to 'auth' only (first octet). We reuse the max message size proposed
@@ -893,7 +890,7 @@ def _try_authenticate_gssapi_sspi_implementation(self, future):
893
890
894
891
# add authorization identity to the response, GSS-wrap and send it
895
892
msg = msg + service_principal_name .encode ("utf-8" )
896
- msg = sspi_gss_wrap_step ( client_ctx , msg )
893
+ msg = client_ctx . wrap ( msg )
897
894
size = Int32 .encode (len (msg ))
898
895
self ._send_bytes_blocking (size + msg )
899
896
@@ -1671,63 +1668,3 @@ def dns_lookup(host, port, afi=socket.AF_UNSPEC):
1671
1668
' correct and resolvable?' ,
1672
1669
host , port , ex )
1673
1670
return []
1674
-
1675
-
1676
- # noinspection PyUnresolvedReferences
1677
- def sspi_gss_unwrap_step (sec_ctx , token ):
1678
- """
1679
- GSSAPI's unwrap with SSPI.
1680
- https://docs.microsoft.com/en-us/windows/win32/secauthn/sspi-kerberos-interoperability-with-gssapi
1681
- """
1682
- buffer = win32security .PySecBufferDescType ()
1683
- # This buffer contains a stream, which is a token coming from the other side
1684
- buffer .append (win32security .PySecBufferType (len (token ), sspicon .SECBUFFER_STREAM ))
1685
- buffer [0 ].Buffer = token
1686
-
1687
- # This buffer will receive the clear, or just unwrapped text if no encryption was used.
1688
- # Will be resized.
1689
- buffer .append (win32security .PySecBufferType (0 , sspicon .SECBUFFER_DATA ))
1690
-
1691
- pfQOP = sec_ctx .ctxt .DecryptMessage (buffer , sec_ctx ._get_next_seq_num ())
1692
- if pfQOP == sspicon .SECQOP_WRAP_NO_ENCRYPT :
1693
- log_sspi .debug ("Received token was not encrypted" )
1694
- r = buffer [1 ].Buffer
1695
- return r
1696
-
1697
-
1698
- def sspi_gss_wrap_step (sec_ctx , msg , encrypt = False ):
1699
- """
1700
- GSSAPI's wrap with SSPI.
1701
- https://docs.microsoft.com/en-us/windows/win32/secauthn/sspi-kerberos-interoperability-with-gssapi
1702
- """
1703
-
1704
- size_info = sec_ctx .ctxt .QueryContextAttributes (sspicon .SECPKG_ATTR_SIZES )
1705
- trailer_size = size_info ['SecurityTrailer' ]
1706
- block_size = size_info ['BlockSize' ]
1707
-
1708
- buffer = win32security .PySecBufferDescType ()
1709
-
1710
- # This buffer will contain unencrypted data to wrap, and maybe encrypt.
1711
- buffer .append (win32security .PySecBufferType (len (msg ), sspicon .SECBUFFER_DATA ))
1712
- buffer [0 ].Buffer = msg
1713
-
1714
- # Will receive the token that forms the beginning of the msg
1715
- buffer .append (win32security .PySecBufferType (trailer_size , sspicon .SECBUFFER_TOKEN ))
1716
-
1717
- # The trailer is needed in case of block encryption
1718
- buffer .append (win32security .PySecBufferType (block_size , sspicon .SECBUFFER_PADDING ))
1719
-
1720
- fQOP = 0 if encrypt else sspicon .SECQOP_WRAP_NO_ENCRYPT
1721
- sec_ctx .ctxt .EncryptMessage (fQOP , buffer , sec_ctx ._get_next_seq_num ())
1722
- # Sec token, then data, then padding
1723
- r = buffer [1 ].Buffer + buffer [0 ].Buffer + buffer [2 ].Buffer
1724
- return r
1725
-
1726
-
1727
- def sspi_amend_ctx_metadata (sec_ctx ):
1728
- """Adds initiator and service names in the security context for ease of use"""
1729
- if not sec_ctx .authenticated :
1730
- raise ValueError ("Sec context is not completely authenticated" )
1731
-
1732
- names = sec_ctx .ctxt .QueryContextAttributes (sspicon .SECPKG_ATTR_NATIVE_NAMES )
1733
- sec_ctx .initiator_name , sec_ctx .service_name = names
0 commit comments