@@ -33,29 +33,29 @@ def split_messages(sport, dport):
3333 def activate (self ):
3434 if not (self .contact_init and self .contact_ack ):
3535 raise Exception ("tried to activate a session before initialization and acknowledgement" )
36-
36+
3737 self .is_active = self .contact_init and self .contact_ack
3838
3939 Session .bind_messages (self .sport , self .dport )
4040
4141 def terminate (self ):
4242 if not (self .contact_init and self .contact_ack ):
4343 raise Exception ("tried to terminate a session while none was active" )
44-
44+
4545 self .is_active = self .contact_ack = self .contact_init = False
4646
4747 Session .split_messages (self .sport , self .dport )
48-
48+
4949 def init_contact (self , sport , dport ):
50- self .contact_init = True
50+ self .contact_init = True
5151 self .sport = sport
5252 self .dport = dport
5353
5454 def init_timeout (self ):
55- self .contact_init = False
55+ self .contact_init = False
5656
5757 def proc_ack (self ):
58- self .contact_ack = True
58+ self .contact_ack = True
5959 self .activate ()
6060
6161 def proc_term (self ):
@@ -64,49 +64,50 @@ def proc_term(self):
6464 def proc_term_ack (self ):
6565 self .terminate ()
6666
67+
6768class TestTcpcl ():
6869
6970 @staticmethod
7071 def check_pkt (pkt : Packet , options : List [Packet ]):
7172 """Asserts that pkt is equal to one of the packets in options (according to the raw representation)"""
7273 for opt in options :
7374 assert raw (pkt ) in list (map (raw , options )), "Failed to build a properly formatted TCPCL message"
74-
75+
7576 @staticmethod
7677 def make_prn ():
7778 """Define a function for processing packets that closes over a new Session.
7879 Return it for use in Scapy.sniff."""
79-
80+
8081 sess = Session ()
8182
8283 def process (pkt ):
8384 # Manage session initialization
8485 if not sess .is_active :
85- try : # try to find a Contact Header
86+ try : # try to find a Contact Header
8687 pay = pkt [Raw ].load
87- contact = TCPCL .ContactHeader (pay ) # should raise unhandled error if
88- # the TCP payload does not fit ContactHeader
88+ contact = TCPCL .ContactHeader (pay ) # should raise unhandled error if
89+ # the TCP payload does not fit ContactHeader
8990 # replace pkt's raw payload with a ContactHeader formatted payload
9091 pkt [TCP ].remove_payload ()
9192 pkt = pkt / contact
9293
9394 # process ContactHeader
94- if sess .contact_init : # session aready initialized, Header is an ack
95+ if sess .contact_init : # session aready initialized, Header is an ack
9596 sess .proc_ack ()
9697 print ("BEGIN TCPCL SESSION" )
9798 else :
9899 sess .init_contact (pkt [TCP ].sport , pkt [TCP ].dport )
99- except IndexError : # no TCP payload to process
100+ except IndexError : # no TCP payload to process
100101 pass
101- else : # currently in an active session
102+ else : # currently in an active session
102103 if TCPCL .SessTerm in pkt :
103104 # process SessTerm
104105 if sess .term_begun :
105106 sess .proc_term_ack ()
106107 print ("END TCPCL SESSION" )
107108 else :
108109 sess .proc_term ()
109-
110- return pkt # end of process
111-
112- return process # end of make_prn
110+
111+ return pkt # end of process
112+
113+ return process # end of make_prn
0 commit comments