Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/ntlm_auth/gss_channel_bindings.py: 48%

29 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 07:03 +0000

1# Copyright: (c) 2018, Jordan Borean (@jborean93) <jborean93@gmail.com> 

2# MIT License (see LICENSE or https://opensource.org/licenses/MIT) 

3 

4import struct 

5 

6 

7class GssChannelBindingsStruct(object): 

8 

9 INITIATOR_ADDTYPE = 'initiator_addtype' 

10 INITIATOR_ADDRESS_LENGTH = 'initiator_address_length' 

11 ACCEPTOR_ADDRTYPE = 'acceptor_addrtype' 

12 ACCEPTOR_ADDRESS_LENGTH = 'acceptor_address_length' 

13 APPLICATION_DATA_LENGTH = 'application_data_length' 

14 INITIATOR_ADDRESS = 'initiator_address' 

15 ACCEPTOR_ADDRESS = 'acceptor_address' 

16 APPLICATION_DATA = 'application_data' 

17 

18 def __init__(self): 

19 """ 

20 Used to send the out of band channel info as part of the authentication 

21 process. This is used as a way of verifying the target is who it says 

22 it is as this information is provided by the higher layer. In most 

23 cases, the CBT is just the hash of the server's TLS certificate to the 

24 application_data field. 

25 

26 This bytes string of the packed structure is then MD5 hashed and 

27 included in the NTv2 response. 

28 """ 

29 self.fields = { 

30 self.INITIATOR_ADDTYPE: 0, 

31 self.INITIATOR_ADDRESS_LENGTH: 0, 

32 self.ACCEPTOR_ADDRTYPE: 0, 

33 self.ACCEPTOR_ADDRESS_LENGTH: 0, 

34 self.APPLICATION_DATA_LENGTH: 0, 

35 self.INITIATOR_ADDRESS: b"", 

36 self.ACCEPTOR_ADDRESS: b"", 

37 self.APPLICATION_DATA: b"" 

38 } 

39 

40 def __setitem__(self, key, value): 

41 self.fields[key] = value 

42 

43 def __getitem__(self, key): 

44 return self.fields[key] 

45 

46 def get_data(self): 

47 # Set the lengths of each len field in case they have changed 

48 self[self.INITIATOR_ADDRESS_LENGTH] = len(self[self.INITIATOR_ADDRESS]) 

49 self[self.ACCEPTOR_ADDRESS_LENGTH] = len(self[self.ACCEPTOR_ADDRESS]) 

50 self[self.APPLICATION_DATA_LENGTH] = len(self[self.APPLICATION_DATA]) 

51 

52 # Add all the values together to create the gss_channel_bindings_struct 

53 data = struct.pack("<L", self[self.INITIATOR_ADDTYPE]) 

54 data += struct.pack("<L", self[self.INITIATOR_ADDRESS_LENGTH]) 

55 data += self[self.INITIATOR_ADDRESS] 

56 data += struct.pack("<L", self[self.ACCEPTOR_ADDRTYPE]) 

57 data += struct.pack("<L", self[self.ACCEPTOR_ADDRESS_LENGTH]) 

58 data += self[self.ACCEPTOR_ADDRESS] 

59 data += struct.pack("<L", self[self.APPLICATION_DATA_LENGTH]) 

60 data += self[self.APPLICATION_DATA] 

61 

62 return data