• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1##############################
2% PPTP Related regression tests
3##############################
4
5+ GRE Tests
6
7= Test IP/GRE v0 decoding
8~ gre ip
9
10data = hex_bytes('45c00064000f0000ff2f1647c0a80c01c0a8170300000800')
11pkt = IP(data)
12assert GRE in pkt
13gre = pkt[GRE]
14assert gre.chksum_present == 0
15assert gre.routing_present == 0
16assert gre.key_present == 0
17assert gre.seqnum_present == 0
18assert gre.strict_route_source == 0
19assert gre.recursion_control == 0
20assert gre.flags == 0
21assert gre.version == 0
22assert gre.proto == 0x800
23
24= Test IP/GRE v1 decoding with PPP LCP
25~ gre ip pptp ppp lcp
26
27data = hex_bytes('4500003c18324000402f0e5a0a0000020a0000063001880b001c9bf500000000ff03'\
28       'c021010100180206000000000304c2270506fbb8831007020802')
29pkt = IP(data)
30assert GRE_PPTP in pkt
31gre_pptp = pkt[GRE_PPTP]
32assert gre_pptp.chksum_present == 0
33assert gre_pptp.routing_present == 0
34assert gre_pptp.key_present == 1
35assert gre_pptp.seqnum_present == 1
36assert gre_pptp.strict_route_source == 0
37assert gre_pptp.recursion_control == 0
38assert gre_pptp.acknum_present == 0
39assert gre_pptp.flags == 0
40assert gre_pptp.version == 1
41assert gre_pptp.proto == 0x880b
42assert gre_pptp.payload_len == 28
43assert gre_pptp.call_id == 39925
44assert gre_pptp.seqence_number == 0x0
45
46assert HDLC in pkt
47assert PPP in pkt
48assert PPP_LCP_Configure in pkt
49
50= Test IP/GRE v1 encoding/decoding with PPP LCP Echo
51~ gre ip pptp ppp hdlc lcp lcp_echo
52
53pkt = IP(src='192.168.0.1', dst='192.168.0.2') /\
54      GRE_PPTP(seqnum_present=1, acknum_present=1, seqence_number=47, ack_number=42) /\
55      HDLC() / PPP() / PPP_LCP_Echo(id=42, magic_number=4242, data='abcdef')
56pkt_data = raw(pkt)
57pkt_data_ref = hex_bytes('4500003600010000402ff944c0a80001c0a800023081880b001200000000002f000000'\
58                         '2aff03c021092a000e00001092616263646566')
59assert (pkt_data == pkt_data_ref)
60pkt_decoded = IP(pkt_data_ref)
61assert IP in pkt
62assert GRE_PPTP in pkt
63assert HDLC in pkt
64assert PPP in pkt
65assert PPP_LCP_Echo in pkt
66
67assert pkt[IP].proto == 47
68assert pkt[GRE_PPTP].chksum_present == 0
69assert pkt[GRE_PPTP].routing_present == 0
70assert pkt[GRE_PPTP].key_present == 1
71assert pkt[GRE_PPTP].seqnum_present == 1
72assert pkt[GRE_PPTP].acknum_present == 1
73assert pkt[GRE_PPTP].seqence_number == 47
74assert pkt[GRE_PPTP].ack_number == 42
75assert pkt[PPP].proto == 0xc021
76assert pkt[PPP_LCP_Echo].code == 9
77assert pkt[PPP_LCP_Echo].id == 42
78assert pkt[PPP_LCP_Echo].magic_number == 4242
79assert pkt[PPP_LCP_Echo].data == b'abcdef'
80
81+ PPP LCP Tests
82= Test LCP Echo Request / Reply
83~ ppp lcp lcp_echo
84
85lcp_echo_request_data = hex_bytes('c021090700080000002a')
86lcp_echo_reply_data = raw(PPP()/PPP_LCP_Echo(code=10, id=7, magic_number=77, data='defgh'))
87
88lcp_echo_request_pkt = PPP(lcp_echo_request_data)
89lcp_echo_reply_pkt = PPP(lcp_echo_reply_data)
90
91assert lcp_echo_reply_pkt.answers(lcp_echo_request_pkt)
92assert not lcp_echo_request_pkt.answers(lcp_echo_reply_pkt)
93
94lcp_echo_non_reply_data = raw(PPP()/PPP_LCP_Echo(code=10, id=3, magic_number=77))
95lcp_echo_non_reply_pkt = PPP(lcp_echo_non_reply_data)
96
97assert not lcp_echo_non_reply_pkt.answers(lcp_echo_request_pkt)
98
99lcp_echo_non_reply_data = raw(PPP()/PPP_LCP_Echo(id=7, magic_number=42))
100lcp_echo_non_reply_pkt = PPP(lcp_echo_non_reply_data)
101
102assert not lcp_echo_non_reply_pkt.answers(lcp_echo_request_pkt)
103
104= Test LCP Configure Request
105~ ppp lcp lcp_configure magic_number
106
107conf_req = PPP() / PPP_LCP_Configure(id=42, options=[PPP_LCP_Magic_Number_Option(magic_number=4242)])
108conf_req_ref_data = hex_bytes('c021012a000a050600001092')
109
110assert raw(conf_req) == conf_req_ref_data
111
112conf_req_pkt = PPP(conf_req_ref_data)
113
114assert PPP_LCP_Configure in conf_req_pkt
115assert conf_req_pkt[PPP_LCP_Configure].code == 1
116assert conf_req_pkt[PPP_LCP_Configure].id == 42
117assert len(conf_req_pkt[PPP_LCP_Configure].options) == 1
118assert isinstance(conf_req_pkt[PPP_LCP_Configure].options[0], PPP_LCP_Magic_Number_Option)
119assert conf_req_pkt[PPP_LCP_Configure].options[0].magic_number == 4242
120
121= Test LCP Configure Ack
122~ ppp lcp lcp_configure lcp_configure_ack
123
124conf_ack = PPP() / PPP_LCP_Configure(code='Configure-Ack', id=42,
125                                     options=[PPP_LCP_Magic_Number_Option(magic_number=4242)])
126conf_ack_ref_data = hex_bytes('c021022a000a050600001092')
127
128assert (raw(conf_ack) == conf_ack_ref_data)
129
130conf_ack_pkt = PPP(conf_ack_ref_data)
131
132assert PPP_LCP_Configure in conf_ack_pkt
133assert conf_ack_pkt[PPP_LCP_Configure].code == 2
134assert conf_ack_pkt[PPP_LCP_Configure].id == 42
135assert len(conf_ack_pkt[PPP_LCP_Configure].options) == 1
136assert isinstance(conf_ack_pkt[PPP_LCP_Configure].options[0], PPP_LCP_Magic_Number_Option)
137assert conf_ack_pkt[PPP_LCP_Configure].options[0].magic_number == 4242
138
139conf_req_pkt = PPP(hex_bytes('c021012a000a050600001092'))
140
141assert conf_ack_pkt.answers(conf_req_pkt)
142assert not conf_req_pkt.answers(conf_ack_pkt)
143
144= Test LCP Configure Nak
145~ ppp lcp lcp_configure lcp_configure_nak lcp_mru_option lcp_accm_option
146
147conf_nak = PPP() / PPP_LCP_Configure(code='Configure-Nak', id=42,
148                                     options=[PPP_LCP_MRU_Option(), PPP_LCP_ACCM_Option(accm=0xffff0000)])
149conf_nak_ref_data = hex_bytes('c021032a000e010405dc0206ffff0000')
150
151assert(raw(conf_nak) == conf_nak_ref_data)
152
153conf_nak_pkt = PPP(conf_nak_ref_data)
154
155assert PPP_LCP_Configure in conf_nak_pkt
156assert conf_nak_pkt[PPP_LCP_Configure].code == 3
157assert conf_nak_pkt[PPP_LCP_Configure].id == 42
158assert len(conf_nak_pkt[PPP_LCP_Configure].options) == 2
159assert isinstance(conf_nak_pkt[PPP_LCP_Configure].options[0], PPP_LCP_MRU_Option)
160assert conf_nak_pkt[PPP_LCP_Configure].options[0].max_recv_unit == 1500
161assert isinstance(conf_nak_pkt[PPP_LCP_Configure].options[1], PPP_LCP_ACCM_Option)
162assert conf_nak_pkt[PPP_LCP_Configure].options[1].accm == 0xffff0000
163
164conf_req_pkt = PPP(hex_bytes('c021012a000e010405dc0206ffff0000'))
165
166assert conf_nak_pkt.answers(conf_req_pkt)
167assert not conf_req_pkt.answers(conf_nak_pkt)
168
169= Test LCP Configure Reject
170~ ppp lcp lcp_configure lcp_configure_reject
171
172conf_reject = PPP() / PPP_LCP_Configure(code='Configure-Reject', id=42,
173                                        options=[PPP_LCP_Callback_Option(operation='Location identifier',
174                                                                         message='test')])
175conf_reject_ref_data = hex_bytes('c021042a000b0d070274657374')
176
177assert(raw(conf_reject) == conf_reject_ref_data)
178
179conf_reject_pkt = PPP(conf_reject_ref_data)
180
181assert PPP_LCP_Configure in conf_reject_pkt
182assert conf_reject_pkt[PPP_LCP_Configure].code == 4
183assert conf_reject_pkt[PPP_LCP_Configure].id == 42
184assert len(conf_reject_pkt[PPP_LCP_Configure].options) == 1
185assert isinstance(conf_reject_pkt[PPP_LCP_Configure].options[0], PPP_LCP_Callback_Option)
186assert conf_reject_pkt[PPP_LCP_Configure].options[0].operation == 2
187assert conf_reject_pkt[PPP_LCP_Configure].options[0].message == b'test'
188
189conf_req_pkt = PPP(hex_bytes('c021012a000b0d070274657374'))
190
191assert conf_reject_pkt.answers(conf_req_pkt)
192assert not conf_req_pkt.answers(conf_reject_pkt)
193
194= Test LCP Configure options
195~ ppp lcp lcp_configure
196
197conf_req = PPP() / PPP_LCP_Configure(id=42, options=[PPP_LCP_MRU_Option(max_recv_unit=5000),
198                                                     PPP_LCP_ACCM_Option(accm=0xf0f0f0f0),
199                                                     PPP_LCP_Auth_Protocol_Option(),
200                                                     PPP_LCP_Quality_Protocol_Option(data='test'),
201                                                     PPP_LCP_Magic_Number_Option(magic_number=4242),
202                                                     PPP_LCP_Callback_Option(operation='Distinguished name',message='test')])
203conf_req_ref_data = hex_bytes('c021012a0027010413880206f0f0f0f00304c0230408c025746573740506000010920d070474657374')
204
205assert(raw(conf_req) == conf_req_ref_data)
206
207conf_req_pkt = PPP(conf_req_ref_data)
208
209assert PPP_LCP_Configure in conf_req_pkt
210options = conf_req_pkt[PPP_LCP_Configure].options
211assert len(options) == 6
212assert isinstance(options[0], PPP_LCP_MRU_Option)
213assert options[0].max_recv_unit == 5000
214assert isinstance(options[1], PPP_LCP_ACCM_Option)
215assert options[1].accm == 0xf0f0f0f0
216assert isinstance(options[2], PPP_LCP_Auth_Protocol_Option)
217assert options[2].auth_protocol == 0xc023
218assert isinstance(options[3], PPP_LCP_Quality_Protocol_Option)
219assert options[3].quality_protocol == 0xc025
220assert options[3].data == b'test'
221assert isinstance(options[4], PPP_LCP_Magic_Number_Option)
222assert options[4].magic_number == 4242
223assert isinstance(options[5], PPP_LCP_Callback_Option)
224assert options[5].operation == 4
225assert options[5].message == b'test'
226
227= Test LCP Auth option
228~ ppp lcp lcp_configure
229
230pap = PPP_LCP_Auth_Protocol_Option()
231pap_ref_data = hex_bytes('0304c023')
232
233assert(raw(pap) == pap_ref_data)
234
235pap_pkt = PPP_LCP_Option(pap_ref_data)
236assert isinstance(pap_pkt, PPP_LCP_Auth_Protocol_Option)
237assert pap_pkt.auth_protocol == 0xc023
238
239chap_sha1 = PPP_LCP_Auth_Protocol_Option(auth_protocol='Challenge-response authentication protocol', algorithm="SHA1")
240chap_sha1_ref_data = hex_bytes('0305c22306')
241
242assert raw(chap_sha1) == chap_sha1_ref_data
243
244chap_sha1_pkt = PPP_LCP_Option(chap_sha1_ref_data)
245assert isinstance(chap_sha1_pkt, PPP_LCP_Auth_Protocol_Option)
246assert chap_sha1_pkt.auth_protocol == 0xc223
247assert chap_sha1_pkt.algorithm == 6
248
249eap = PPP_LCP_Auth_Protocol_Option(auth_protocol='PPP Extensible authentication protocol', data='test')
250eap_ref_data = hex_bytes('0308c22774657374')
251
252assert raw(eap) == eap_ref_data
253
254eap_pkt = PPP_LCP_Option(eap_ref_data)
255assert isinstance(eap_pkt, PPP_LCP_Auth_Protocol_Option)
256assert eap_pkt.auth_protocol == 0xc227
257assert eap_pkt.data == b'test'
258
259= Test LCP Code-Reject
260~ ppp lcp lcp_code_reject
261
262code_reject = PPP() / PPP_LCP_Code_Reject(id=42, rejected_packet=PPP_LCP(code=42, id=7, data='unknown_data'))
263code_reject_ref_data = hex_bytes('c021072a00142a070010756e6b6e6f776e5f64617461')
264
265assert raw(code_reject) == code_reject_ref_data
266
267code_reject_pkt = PPP(code_reject_ref_data)
268assert PPP_LCP_Code_Reject in code_reject_pkt
269assert code_reject_pkt[PPP_LCP_Code_Reject].id == 42
270assert isinstance(code_reject_pkt[PPP_LCP_Code_Reject].rejected_packet, PPP_LCP)
271assert code_reject[PPP_LCP_Code_Reject].rejected_packet.code == 42
272assert code_reject[PPP_LCP_Code_Reject].rejected_packet.id == 7
273assert code_reject[PPP_LCP_Code_Reject].rejected_packet.data == b'unknown_data'
274
275= Test LCP Protocol-Reject
276~ ppp lcp lcp_protocol_reject
277
278protocol_reject = PPP() / PPP_LCP_Protocol_Reject(id=42, rejected_protocol=0x8039,
279                                                  rejected_information=Packet(hex_bytes('0305c22306')))
280protocol_reject_ref_data = hex_bytes('c021082a000b80390305c22306')
281
282assert raw(protocol_reject) == protocol_reject_ref_data
283
284protocol_reject_pkt = PPP(protocol_reject_ref_data)
285assert PPP_LCP_Protocol_Reject in protocol_reject_pkt
286assert protocol_reject_pkt[PPP_LCP_Protocol_Reject].id == 42
287assert protocol_reject_pkt[PPP_LCP_Protocol_Reject].rejected_protocol == 0x8039
288assert len(protocol_reject_pkt[PPP_LCP_Protocol_Reject].rejected_information) == 5
289
290= Test LCP Discard Request
291~ ppp lcp lcp_discard_request
292
293discard_request = PPP() / PPP_LCP_Discard_Request(id=7, magic_number=4242, data='test')
294discard_request_ref_data = hex_bytes('c0210b07000c0000109274657374')
295
296assert raw(discard_request) == discard_request_ref_data
297
298discard_request_pkt = PPP(discard_request_ref_data)
299assert PPP_LCP_Discard_Request in discard_request_pkt
300assert discard_request_pkt[PPP_LCP_Discard_Request].id == 7
301assert discard_request_pkt[PPP_LCP_Discard_Request].magic_number == 4242
302assert discard_request_pkt[PPP_LCP_Discard_Request].data == b'test'
303
304= Test LCP Terminate-Request/Terminate-Ack
305~ ppp lcp lcp_terminate
306
307terminate_request = PPP() / PPP_LCP_Terminate(id=7, data='test')
308terminate_request_ref_data = hex_bytes('c0210507000874657374')
309
310assert raw(terminate_request) == terminate_request_ref_data
311
312terminate_request_pkt = PPP(terminate_request_ref_data)
313assert PPP_LCP_Terminate in terminate_request_pkt
314assert terminate_request_pkt[PPP_LCP_Terminate].code == 5
315assert terminate_request_pkt[PPP_LCP_Terminate].id == 7
316assert terminate_request_pkt[PPP_LCP_Terminate].data == b'test'
317
318terminate_ack = PPP() / PPP_LCP_Terminate(code='Terminate-Ack', id=7)
319terminate_ack_ref_data = hex_bytes('c02106070004')
320
321assert raw(terminate_ack) == terminate_ack_ref_data
322
323terminate_ack_pkt = PPP(terminate_ack_ref_data)
324assert PPP_LCP_Terminate in terminate_ack_pkt
325assert terminate_ack_pkt[PPP_LCP_Terminate].code == 6
326assert terminate_ack_pkt[PPP_LCP_Terminate].id == 7
327
328assert terminate_ack_pkt.answers(terminate_request_pkt)
329assert not terminate_request_pkt.answers(terminate_ack_pkt)
330
331+ PPP PAP Tests
332= Test PPP PAP Request
333~ ppp pap pap_request
334pap_request = PPP() / PPP_PAP_Request(id=42, username='administrator', password='secret_password')
335pap_request_ref_data = hex_bytes('c023012a00220d61646d696e6973747261746f720f7365637265745f70617373776f7264')
336
337assert raw(pap_request) == pap_request_ref_data
338
339pap_request_pkt = PPP(pap_request_ref_data)
340assert PPP_PAP_Request in pap_request_pkt
341assert pap_request_pkt[PPP_PAP_Request].code == 1
342assert pap_request_pkt[PPP_PAP_Request].id == 42
343assert pap_request_pkt[PPP_PAP_Request].username == b'administrator'
344assert pap_request_pkt[PPP_PAP_Request].password == b'secret_password'
345assert pap_request_pkt[PPP_PAP_Request].summary() in ['PAP-Request username=\'administrator\' password=\'secret_password\'',
346                                                      'PAP-Request username=b\'administrator\' password=b\'secret_password\'']
347
348= Test PPP PAP Authenticate-Ack
349~ ppp pap pap_response pap_ack
350pap_response = PPP() / PPP_PAP(code='Authenticate-Ack', id=42)
351pap_response_ref_data = hex_bytes('c023022a000500')
352
353assert raw(pap_response) == pap_response_ref_data
354
355pap_response_pkt = PPP(pap_response_ref_data)
356assert PPP_PAP_Response in pap_response_pkt
357assert pap_response_pkt[PPP_PAP_Response].code == 2
358assert pap_response_pkt[PPP_PAP_Response].id == 42
359assert pap_response_pkt[PPP_PAP_Response].msg_len == 0
360assert pap_response_pkt[PPP_PAP_Response].message == b''
361assert pap_response_pkt[PPP_PAP_Response].summary() == 'PAP-Ack'
362
363pap_request_pkt = PPP(hex_bytes('c023012a00220d61646d696e6973747261746f720f7365637265745f70617373776f7264'))
364assert pap_response_pkt.answers(pap_request_pkt)
365assert not pap_request_pkt.answers(pap_response_pkt)
366
367= Test PPP PAP Authenticate-Nak
368~ ppp pap pap_response pap_nak
369pap_response = PPP() / PPP_PAP(code=3, id=42, message='Bad password')
370pap_response_ref_data = hex_bytes('c023032a00110c4261642070617373776f7264')
371
372assert raw(pap_response) == pap_response_ref_data
373
374pap_response_pkt = PPP(pap_response_ref_data)
375assert PPP_PAP_Response in pap_response_pkt
376assert pap_response_pkt[PPP_PAP_Response].code == 3
377assert pap_response_pkt[PPP_PAP_Response].id == 42
378assert pap_response_pkt[PPP_PAP_Response].msg_len == len('Bad password')
379assert pap_response_pkt[PPP_PAP_Response].message == b'Bad password'
380assert pap_response_pkt[PPP_PAP_Response].summary() in ['PAP-Nak msg=\'Bad password\'', 'PAP-Nak msg=b\'Bad password\'']
381
382pap_request_pkt = PPP(hex_bytes('c023012a00220d61646d696e6973747261746f720f7365637265745f70617373776f7264'))
383assert pap_response_pkt.answers(pap_request_pkt)
384assert not pap_request_pkt.answers(pap_response_pkt)
385
386+ PPP CHAP Tests
387= Test PPP CHAP Challenge
388~ ppp chap chap_challenge
389chap_challenge = PPP() / PPP_CHAP(code=1, id=47, value=b'B' * 7,
390                                                        optional_name='server')
391chap_challenge_ref_data = hex_bytes('c223012f00120742424242424242736572766572')
392
393assert raw(chap_challenge) == chap_challenge_ref_data
394
395chap_challenge_pkt = PPP(chap_challenge_ref_data)
396assert PPP_CHAP_ChallengeResponse in chap_challenge_pkt
397assert chap_challenge_pkt[PPP_CHAP_ChallengeResponse].code == 1
398assert chap_challenge_pkt[PPP_CHAP_ChallengeResponse].id == 47
399assert chap_challenge_pkt[PPP_CHAP_ChallengeResponse].value_size == 7
400assert chap_challenge_pkt[PPP_CHAP_ChallengeResponse].value == b'B' * 7
401assert chap_challenge_pkt[PPP_CHAP_ChallengeResponse].optional_name == b'server'
402assert chap_challenge_pkt[PPP_CHAP_ChallengeResponse].summary() in ['CHAP challenge=0x42424242424242 optional_name=\'server\'',
403                                                                    'CHAP challenge=0x42424242424242 optional_name=b\'server\'']
404
405= Test PPP CHAP Response
406~ ppp chap chap_response
407chap_response = PPP() / PPP_CHAP(code='Response', id=47, value=b'\x00' * 16, optional_name='client')
408chap_response_ref_data = hex_bytes('c223022f001b1000000000000000000000000000000000636c69656e74')
409
410assert raw(chap_response) == chap_response_ref_data
411
412chap_response_pkt = PPP(chap_response_ref_data)
413assert PPP_CHAP_ChallengeResponse in chap_response_pkt
414assert chap_response_pkt[PPP_CHAP_ChallengeResponse].code == 2
415assert chap_response_pkt[PPP_CHAP_ChallengeResponse].id == 47
416assert chap_response_pkt[PPP_CHAP_ChallengeResponse].value_size == 16
417assert chap_response_pkt[PPP_CHAP_ChallengeResponse].value == b'\x00' * 16
418assert chap_response_pkt[PPP_CHAP_ChallengeResponse].optional_name == b'client'
419assert chap_response_pkt[PPP_CHAP_ChallengeResponse].summary() in ['CHAP response=0x00000000000000000000000000000000 optional_name=\'client\'',
420                                                                   'CHAP response=0x00000000000000000000000000000000 optional_name=b\'client\'']
421
422chap_request = PPP(hex_bytes('c223012f00120742424242424242736572766572'))
423
424assert chap_response.answers(chap_challenge)
425assert not chap_challenge.answers(chap_response)
426
427= Test PPP CHAP Success
428~ ppp chap chap_success
429
430chap_success = PPP() / PPP_CHAP(code='Success', id=47)
431chap_success_ref_data = hex_bytes('c223032f0004')
432
433assert raw(chap_success) == chap_success_ref_data
434
435chap_success_pkt = PPP(chap_success_ref_data)
436assert PPP_CHAP in chap_success_pkt
437assert chap_success_pkt[PPP_CHAP].code == 3
438assert chap_success_pkt[PPP_CHAP].id == 47
439assert chap_success_pkt[PPP_CHAP].data == b''
440assert chap_success_pkt[PPP_CHAP].summary() in ['CHAP Success message=\'\'', 'CHAP Success message=b\'\'']
441
442chap_response_pkt = PPP(hex_bytes('c223022f001b1000000000000000000000000000000000636c69656e74'))
443
444assert chap_success_pkt.answers(chap_response_pkt)
445assert not chap_response_pkt.answers(chap_success_pkt)
446
447= Test PPP CHAP Failure
448~ ppp chap chap_failure
449chap_failure = PPP() / PPP_CHAP(code='Failure', id=47, data='Go away')
450chap_failure_ref_data = hex_bytes('c223042f000b476f2061776179')
451
452assert raw(chap_failure) == chap_failure_ref_data
453
454chap_failure_pkt = PPP(chap_failure_ref_data)
455assert PPP_CHAP in chap_failure_pkt
456assert chap_failure_pkt[PPP_CHAP].code == 4
457assert chap_failure_pkt[PPP_CHAP].id == 47
458assert chap_failure_pkt[PPP_CHAP].data == b'Go away'
459assert chap_failure_pkt[PPP_CHAP].summary() in ['CHAP Failure message=\'Go away\'', 'CHAP Failure message=b\'Go away\'']
460
461chap_response_pkt = PPP(hex_bytes('c223022f001b1000000000000000000000000000000000636c69656e74'))
462
463assert chap_failure_pkt.answers(chap_response_pkt)
464assert not chap_failure_pkt.answers(chap_success_pkt)
465
466+ PPTP Tests
467= Test PPTP Start-Control-Connection-Request
468~ pptp
469start_control_connection = PPTPStartControlConnectionRequest(framing_capabilities='Asynchronous Framing supported',
470                                                             bearer_capabilities='Digital access supported',
471                                                             maximum_channels=42,
472                                                             firmware_revision=47,
473                                                             host_name='test host name',
474                                                             vendor_string='test vendor string')
475start_control_connection_ref_data = hex_bytes('009c00011a2b3c4d00010000000100000000000100000002002a00'\
476                                    '2f7465737420686f7374206e616d65000000000000000000000000'\
477                                    '000000000000000000000000000000000000000000000000000000'\
478                                    '0000000000000000000000746573742076656e646f722073747269'\
479                                    '6e6700000000000000000000000000000000000000000000000000'\
480                                    '000000000000000000000000000000000000000000')
481
482assert raw(start_control_connection) == start_control_connection_ref_data
483
484start_control_connection_pkt = PPTP(start_control_connection_ref_data)
485
486assert isinstance(start_control_connection_pkt, PPTPStartControlConnectionRequest)
487assert start_control_connection_pkt.magic_cookie == 0x1a2b3c4d
488assert start_control_connection_pkt.protocol_version == 1
489assert start_control_connection_pkt.framing_capabilities == 1
490assert start_control_connection_pkt.bearer_capabilities == 2
491assert start_control_connection_pkt.maximum_channels == 42
492assert start_control_connection_pkt.firmware_revision == 47
493assert start_control_connection_pkt.host_name == b'test host name' + b'\0' * (64-len('test host name'))
494assert start_control_connection_pkt.vendor_string == b'test vendor string' + b'\0' * (64-len('test vendor string'))
495
496= Test PPTP Start-Control-Connection-Reply
497~ pptp
498start_control_connection_reply = PPTPStartControlConnectionReply(result_code='General error',
499                                                                 error_code='Not-Connected',
500                                                                 framing_capabilities='Synchronous Framing supported',
501                                                                 bearer_capabilities='Analog access supported',
502                                                                 vendor_string='vendor')
503start_control_connection_reply_ref_data = hex_bytes('009c00011a2b3c4d00020000000102010000000200000001ffff0'\
504                                          '1006c696e75780000000000000000000000000000000000000000'\
505                                          '00000000000000000000000000000000000000000000000000000'\
506                                          '000000000000000000000000076656e646f720000000000000000'\
507                                          '00000000000000000000000000000000000000000000000000000'\
508                                          '00000000000000000000000000000000000000000000000')
509
510assert raw(start_control_connection_reply) == start_control_connection_reply_ref_data
511
512start_control_connection_reply_pkt = PPTP(start_control_connection_reply_ref_data)
513
514assert isinstance(start_control_connection_reply_pkt, PPTPStartControlConnectionReply)
515assert start_control_connection_reply_pkt.magic_cookie == 0x1a2b3c4d
516assert start_control_connection_reply_pkt.protocol_version == 1
517assert start_control_connection_reply_pkt.result_code == 2
518assert start_control_connection_reply_pkt.error_code == 1
519assert start_control_connection_reply_pkt.framing_capabilities == 2
520assert start_control_connection_reply_pkt.bearer_capabilities == 1
521assert start_control_connection_reply_pkt.host_name == b'linux' + b'\0' * (64-len('linux'))
522assert start_control_connection_reply_pkt.vendor_string == b'vendor' + b'\0' * (64-len('vendor'))
523
524start_control_connection_request = PPTPStartControlConnectionRequest()
525
526assert start_control_connection_reply_pkt.answers(start_control_connection_request)
527assert not start_control_connection_request.answers(start_control_connection_reply_pkt)
528
529= Test PPTP Stop-Control-Connection-Request
530~ pptp
531stop_control_connection = PPTPStopControlConnectionRequest(reason='Stop-Local-Shutdown')
532stop_control_connection_ref_data = hex_bytes('001000011a2b3c4d0003000003000000')
533
534assert raw(stop_control_connection) == stop_control_connection_ref_data
535
536stop_control_connection_pkt = PPTP(stop_control_connection_ref_data)
537
538assert isinstance(stop_control_connection_pkt, PPTPStopControlConnectionRequest)
539assert stop_control_connection_pkt.magic_cookie == 0x1a2b3c4d
540assert stop_control_connection_pkt.reason == 3
541
542= Test PPTP Stop-Control-Connection-Reply
543~ pptp
544stop_control_connection_reply = PPTPStopControlConnectionReply(result_code='General error',error_code='PAC-Error')
545stop_control_connection_reply_ref_data = hex_bytes('001000011a2b3c4d0004000002060000')
546
547assert raw(stop_control_connection_reply) == stop_control_connection_reply_ref_data
548
549stop_control_connection_reply_pkt = PPTP(stop_control_connection_reply_ref_data)
550
551assert isinstance(stop_control_connection_reply_pkt, PPTPStopControlConnectionReply)
552assert stop_control_connection_reply_pkt.magic_cookie == 0x1a2b3c4d
553assert stop_control_connection_reply_pkt.result_code == 2
554assert stop_control_connection_reply_pkt.error_code == 6
555
556stop_control_connection_request = PPTPStopControlConnectionRequest()
557
558assert stop_control_connection_reply_pkt.answers(stop_control_connection_request)
559assert not stop_control_connection_request.answers(stop_control_connection_reply_pkt)
560
561= Test PPTP Echo-Request
562~ pptp
563echo_request = PPTPEchoRequest(identifier=42)
564echo_request_ref_data = hex_bytes('001000011a2b3c4d000500000000002a')
565
566assert raw(echo_request) == echo_request_ref_data
567
568echo_request_pkt = PPTP(echo_request_ref_data)
569
570assert isinstance(echo_request_pkt, PPTPEchoRequest)
571assert echo_request_pkt.magic_cookie == 0x1a2b3c4d
572assert echo_request_pkt.identifier == 42
573
574= Test PPTP Echo-Reply
575~ pptp
576echo_reply = PPTPEchoReply(identifier=42, result_code='OK')
577echo_reply_ref_data = hex_bytes('001400011a2b3c4d000600000000002a01000000')
578
579assert raw(echo_reply) == echo_reply_ref_data
580
581echo_reply_pkt = PPTP(echo_reply_ref_data)
582
583assert isinstance(echo_reply_pkt, PPTPEchoReply)
584assert echo_reply_pkt.magic_cookie == 0x1a2b3c4d
585assert echo_reply_pkt.identifier == 42
586assert echo_reply_pkt.result_code == 1
587assert echo_reply_pkt.error_code == 0
588
589echo_request = PPTPEchoRequest(identifier=42)
590
591assert echo_reply_pkt.answers(echo_request)
592assert not echo_request.answers(echo_reply)
593
594echo_request_incorrect = PPTPEchoRequest(identifier=47)
595
596assert not echo_reply_pkt.answers(echo_request_incorrect)
597assert not echo_request_incorrect.answers(echo_reply_pkt)
598
599= Test PPTP Outgoing-Call-Request
600~ pptp
601outgoing_call = PPTPOutgoingCallRequest(call_id=4242, call_serial_number=47,
602                                        minimum_bps=1000, maximum_bps=10000,
603                                        bearer_type='Digital channel',
604                                        pkt_window_size=16, pkt_proc_delay=1,
605                                        phone_number_len=9, phone_number='123456789',
606                                        subaddress='test')
607outgoing_call_ref_data = hex_bytes('00a800011a2b3c4d000700001092002f000003e8000027100000000200'\
608                         '0000030010000100090000313233343536373839000000000000000000'\
609                         '0000000000000000000000000000000000000000000000000000000000'\
610                         '0000000000000000000000000000000000746573740000000000000000'\
611                         '0000000000000000000000000000000000000000000000000000000000'\
612                         '0000000000000000000000000000000000000000000000')
613
614assert raw(outgoing_call) == outgoing_call_ref_data
615
616outgoing_call_pkt = PPTP(outgoing_call_ref_data)
617
618assert isinstance(outgoing_call_pkt, PPTPOutgoingCallRequest)
619assert outgoing_call_pkt.magic_cookie == 0x1a2b3c4d
620assert outgoing_call_pkt.call_id == 4242
621assert outgoing_call_pkt.call_serial_number == 47
622assert outgoing_call_pkt.minimum_bps == 1000
623assert outgoing_call_pkt.maximum_bps == 10000
624assert outgoing_call_pkt.bearer_type == 2
625assert outgoing_call_pkt.framing_type == 3
626assert outgoing_call_pkt.pkt_window_size == 16
627assert outgoing_call_pkt.pkt_proc_delay == 1
628assert outgoing_call_pkt.phone_number_len == 9
629assert outgoing_call_pkt.phone_number == b'123456789' + b'\0' * (64-len('123456789'))
630assert outgoing_call_pkt.subaddress == b'test' + b'\0' * (64-len('test'))
631
632= Test PPTP Outgoing-Call-Reply
633~ pptp
634outgoing_call_reply = PPTPOutgoingCallReply(call_id=4243, peer_call_id=4242,
635                                            result_code='Busy', error_code='No-Resource',
636                                            cause_code=42, connect_speed=5000,
637                                            pkt_window_size=32, pkt_proc_delay=3,
638                                            channel_id=42)
639outgoing_call_reply_ref_data = hex_bytes('002000011a2b3c4d00080000109310920404002a00001388002000030000002a')
640
641assert raw(outgoing_call_reply) == outgoing_call_reply_ref_data
642
643outgoing_call_reply_pkt = PPTP(outgoing_call_reply_ref_data)
644
645assert isinstance(outgoing_call_reply_pkt, PPTPOutgoingCallReply)
646assert outgoing_call_reply_pkt.magic_cookie == 0x1a2b3c4d
647assert outgoing_call_reply_pkt.call_id == 4243
648assert outgoing_call_reply_pkt.peer_call_id == 4242
649assert outgoing_call_reply_pkt.result_code == 4
650assert outgoing_call_reply_pkt.error_code == 4
651assert outgoing_call_reply_pkt.cause_code == 42
652assert outgoing_call_reply_pkt.connect_speed == 5000
653assert outgoing_call_reply_pkt.pkt_window_size == 32
654assert outgoing_call_reply_pkt.pkt_proc_delay == 3
655assert outgoing_call_reply_pkt.channel_id == 42
656
657outgoing_call_request = PPTPOutgoingCallRequest(call_id=4242)
658
659assert outgoing_call_reply_pkt.answers(outgoing_call_request)
660assert not outgoing_call_request.answers(outgoing_call_reply_pkt)
661
662outgoing_call_request_incorrect = PPTPOutgoingCallRequest(call_id=5656)
663
664assert not outgoing_call_reply_pkt.answers(outgoing_call_request_incorrect)
665assert not outgoing_call_request_incorrect.answers(outgoing_call_reply_pkt)
666
667= Test PPTP Incoming-Call-Request
668~ pptp
669incoming_call = PPTPIncomingCallRequest(call_id=4242, call_serial_number=47, bearer_type='Digital channel',
670                                        channel_id=12, dialed_number_len=9, dialing_number_len=10,
671                                        dialed_number='123456789', dialing_number='0123456789',
672                                        subaddress='test')
673incoming_call_ref_data = hex_bytes('00dc00011a2b3c4d000900001092002f000000020000000c0009000a313233343536373839'\
674                         '00000000000000000000000000000000000000000000000000000000000000000000000000'\
675                         '00000000000000000000000000000000000030313233343536373839000000000000000000'\
676                         '00000000000000000000000000000000000000000000000000000000000000000000000000'\
677                         '00000000000000007465737400000000000000000000000000000000000000000000000000'\
678                         '0000000000000000000000000000000000000000000000000000000000000000000000')
679
680assert raw(incoming_call) == incoming_call_ref_data
681
682incoming_call_pkt = PPTP(incoming_call_ref_data)
683
684assert isinstance(incoming_call_pkt, PPTPIncomingCallRequest)
685assert incoming_call_pkt.magic_cookie == 0x1a2b3c4d
686assert incoming_call_pkt.call_id == 4242
687assert incoming_call_pkt.call_serial_number == 47
688assert incoming_call_pkt.bearer_type == 2
689assert incoming_call_pkt.channel_id == 12
690assert incoming_call_pkt.dialed_number_len == 9
691assert incoming_call_pkt.dialing_number_len == 10
692assert incoming_call_pkt.dialed_number == b'123456789' + b'\0' * (64-len('123456789'))
693assert incoming_call_pkt.dialing_number == b'0123456789' + b'\0' * (64-len('0123456879'))
694assert incoming_call_pkt.subaddress == b'test' + b'\0' * (64-len('test'))
695
696= Test PPTP Incoming-Call-Reply
697~ pptp
698incoming_call_reply = PPTPIncomingCallReply(call_id=4243, peer_call_id=4242, result_code='Connected',
699                                            error_code='None', pkt_window_size=16, pkt_transmit_delay=42)
700incoming_call_reply_ref_data = hex_bytes('009400011a2b3c4d000a00001093109201000010002a0000')
701
702assert raw(incoming_call_reply) == incoming_call_reply_ref_data
703
704incoming_call_reply_pkt = PPTP(incoming_call_reply_ref_data)
705assert isinstance(incoming_call_reply_pkt, PPTPIncomingCallReply)
706assert incoming_call_reply_pkt.magic_cookie == 0x1a2b3c4d
707assert incoming_call_reply_pkt.call_id == 4243
708assert incoming_call_reply_pkt.peer_call_id == 4242
709assert incoming_call_reply_pkt.result_code == 1
710assert incoming_call_reply_pkt.error_code == 0
711assert incoming_call_reply_pkt.pkt_window_size == 16
712assert incoming_call_reply_pkt.pkt_transmit_delay == 42
713
714incoming_call_req = PPTPIncomingCallRequest(call_id=4242)
715
716assert incoming_call_reply_pkt.answers(incoming_call_req)
717assert not incoming_call_req.answers(incoming_call_reply)
718
719incoming_call_req_incorrect = PPTPIncomingCallRequest(call_id=4343)
720assert not incoming_call_reply_pkt.answers(incoming_call_req_incorrect)
721assert not incoming_call_req_incorrect.answers(incoming_call_reply_pkt)
722
723= Test PPTP Incoming-Call-Connected
724~ pptp
725incoming_call_connected = PPTPIncomingCallConnected(peer_call_id=4242, connect_speed=47474747,
726                                                    pkt_window_size=16, pkt_transmit_delay=7,
727                                                    framing_type='Any type of framing')
728incoming_call_connected_ref_data = hex_bytes('001c00011a2b3c4d000b00001092000002d4683b0010000700000003')
729
730assert raw(incoming_call_connected) == incoming_call_connected_ref_data
731
732incoming_call_connected_pkt = PPTP(incoming_call_connected_ref_data)
733assert isinstance(incoming_call_connected_pkt, PPTPIncomingCallConnected)
734assert incoming_call_connected_pkt.magic_cookie == 0x1a2b3c4d
735assert incoming_call_connected_pkt.peer_call_id == 4242
736assert incoming_call_connected_pkt.connect_speed == 47474747
737assert incoming_call_connected_pkt.pkt_window_size == 16
738assert incoming_call_connected_pkt.pkt_transmit_delay == 7
739assert incoming_call_connected_pkt.framing_type == 3
740
741incoming_call_reply = PPTPIncomingCallReply(call_id=4242)
742
743assert incoming_call_connected_pkt.answers(incoming_call_reply)
744assert not incoming_call_reply.answers(incoming_call_connected_pkt)
745
746incoming_call_reply_incorrect = PPTPIncomingCallReply(call_id=4243)
747
748assert not incoming_call_connected_pkt.answers(incoming_call_reply_incorrect)
749assert not incoming_call_reply_incorrect.answers(incoming_call_connected_pkt)
750
751= Test PPTP Call-Clear-Request
752~ pptp
753call_clear_request = PPTPCallClearRequest(call_id=4242)
754call_clear_request_ref_data = hex_bytes('001000011a2b3c4d000c000010920000')
755
756assert raw(call_clear_request) == call_clear_request_ref_data
757
758call_clear_request_pkt = PPTP(call_clear_request_ref_data)
759
760assert isinstance(call_clear_request_pkt, PPTPCallClearRequest)
761assert call_clear_request_pkt.magic_cookie == 0x1a2b3c4d
762assert call_clear_request_pkt.call_id == 4242
763
764= Test PPTP Call-Disconnect-Notify
765~ pptp
766call_disconnect_notify = PPTPCallDisconnectNotify(call_id=4242, result_code='Admin Shutdown', error_code='None',
767                                                  cause_code=47, call_statistic='some description')
768call_disconnect_notify_ref_data = hex_bytes('009400011a2b3c4d000d000010920300002f0000736f6d65206465736372697074696'\
769                                  'f6e000000000000000000000000000000000000000000000000000000000000000000'\
770                                  '000000000000000000000000000000000000000000000000000000000000000000000'\
771                                  '000000000000000000000000000000000000000000000000000000000000000000000'\
772                                  '00000000000000000000')
773
774assert raw(call_disconnect_notify) == call_disconnect_notify_ref_data
775
776call_disconnect_notify_pkt = PPTP(call_disconnect_notify_ref_data)
777
778assert isinstance(call_disconnect_notify_pkt, PPTPCallDisconnectNotify)
779assert call_disconnect_notify_pkt.magic_cookie == 0x1a2b3c4d
780assert call_disconnect_notify_pkt.call_id == 4242
781assert call_disconnect_notify_pkt.result_code == 3
782assert call_disconnect_notify_pkt.error_code == 0
783assert call_disconnect_notify_pkt.cause_code == 47
784assert call_disconnect_notify_pkt.call_statistic == b'some description' + b'\0' * (128-len('some description'))
785
786= Test PPTP WAN-Error-Notify
787~ pptp
788wan_error_notify = PPTPWANErrorNotify(peer_call_id=4242, crc_errors=1, framing_errors=2,
789                                      hardware_overruns=3, buffer_overruns=4, time_out_errors=5,
790                                      alignment_errors=6)
791wan_error_notify_ref_data = hex_bytes('002800011a2b3c4d000e000010920000000000010000000200000003000000040000000500000006')
792
793assert raw(wan_error_notify) == wan_error_notify_ref_data
794
795wan_error_notify_pkt = PPTP(wan_error_notify_ref_data)
796
797assert isinstance(wan_error_notify_pkt, PPTPWANErrorNotify)
798assert wan_error_notify_pkt.magic_cookie == 0x1a2b3c4d
799assert wan_error_notify_pkt.peer_call_id == 4242
800assert wan_error_notify_pkt.crc_errors == 1
801assert wan_error_notify_pkt.framing_errors == 2
802assert wan_error_notify_pkt.hardware_overruns == 3
803assert wan_error_notify_pkt.buffer_overruns == 4
804
805= Test PPTP Set-Link-Info
806~ pptp
807set_link_info = PPTPSetLinkInfo(peer_call_id=4242, send_accm=0x0f0f0f0f, receive_accm=0xf0f0f0f0)
808set_link_info_ref_data = hex_bytes('001800011a2b3c4d000f0000109200000f0f0f0ff0f0f0f0')
809
810assert raw(set_link_info) == set_link_info_ref_data
811
812set_link_info_pkt = PPTP(set_link_info_ref_data)
813
814assert isinstance(set_link_info_pkt, PPTPSetLinkInfo)
815assert set_link_info_pkt.magic_cookie == 0x1a2b3c4d
816assert set_link_info_pkt.peer_call_id == 4242
817assert set_link_info_pkt.send_accm == 0x0f0f0f0f
818assert set_link_info_pkt.receive_accm == 0xf0f0f0f0
819