blob: a128f05b55f0e2046c41c688dbc4f309673afdd0 [file] [log] [blame]
Chetan Gaonkere2b78722016-02-22 17:27:09 -08001import sys, os
Chetan Gaonkere2b78722016-02-22 17:27:09 -08002from EapolAAA import *
3from enum import *
4import nosePAPAuthHolder as PAPAuthHolder
5from socket import *
6from struct import *
Chetan Gaonker5b366302016-03-21 16:18:21 -07007from scapy.all import *
Chetan Gaonkere2b78722016-02-22 17:27:09 -08008from nose.tools import *
9from CordTestBase import CordTester
10PAP_USER = "raduser"
11PAP_PASSWD = "radpass"
Chetan Gaonker5b366302016-03-21 16:18:21 -070012log.setLevel('INFO')
Chetan Gaonkere2b78722016-02-22 17:27:09 -080013
14class PAPAuthTest(EapolPacket, CordTester):
15
16 PAPStateTable = Enumeration("PAPStateTable", ("ST_EAP_SETUP",
17 "ST_EAP_START",
18 "ST_EAP_ID_REQ",
19 "ST_EAP_PAP_USER_REQ",
20 "ST_EAP_PAP_PASSWD_REQ",
21 "ST_EAP_PAP_DONE"
22 )
23 )
24 PAPEventTable = Enumeration("PAPEventTable", ("EVT_EAP_SETUP",
25 "EVT_EAP_START",
26 "EVT_EAP_ID_REQ",
27 "EVT_EAP_PAP_USER_REQ",
28 "EVT_EAP_PAP_PASSWD_REQ",
29 "EVT_EAP_PAP_DONE"
30 )
31 )
32 def __init__(self, intf = 'veth0'):
33 self.fsmTable = PAPAuthHolder.initPAPAuthHolderFsmTable(self, self.PAPStateTable, self.PAPEventTable)
34 EapolPacket.__init__(self, intf)
35 CordTester.__init__(self, self.fsmTable, self.PAPStateTable.ST_EAP_PAP_DONE)
36 #self.PAPStateTable, self.PAPEventTable)
37 self.currentState = self.PAPStateTable.ST_EAP_SETUP
38 self.currentEvent = self.PAPEventTable.EVT_EAP_SETUP
39 self.nextState = None
40 self.nextEvent = None
41
42 def _eapSetup(self):
43 print 'Inside EAP PAP Setup'
44 self.setup()
45 self.nextEvent = self.PAPEventTable.EVT_EAP_START
46
47 def _eapStart(self):
48 print 'Inside EAP PAP Start'
49 self.eapol_start()
50 self.nextEvent = self.PAPEventTable.EVT_EAP_ID_REQ
51
52 def _eapIdReq(self):
Chetan Gaonker5b366302016-03-21 16:18:21 -070053 log.info( 'Inside EAP ID Req' )
54 def eapol_cb(pkt):
55 log.info('Got EAPOL packet with type id and code request')
56 log.info('Packet code: %d, type: %d, id: %s', pkt[EAP].code, pkt[EAP].type, pkt[EAP].id)
57 log.info("<====== Send EAP Response with identity = %s ================>" % PAP_USER)
58 self.eapol_id_req(pkt[EAP].id, PAP_USER)
59
60 self.eapol_scapy_recv(cb = eapol_cb,
61 lfilter = lambda pkt: pkt[EAP].type == EAP.TYPE_ID and pkt[EAP].code == EAP.REQUEST)
Chetan Gaonkere2b78722016-02-22 17:27:09 -080062 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ
63
64 def _eapPAPUserReq(self):
Chetan Gaonker5b366302016-03-21 16:18:21 -070065 log.info('UserReq Inside Challenge')
66 def eapol_cb(pkt):
67 log.info('Got EAPOL packet with type id and code request')
68 log.info('Packet code: %d, id: %s', pkt[EAP].code, pkt[EAP].id)
69 log.info('Send EAP Response for id %s with Password = %s' %(pkt[EAP].id, PAP_PASSWD) )
70 self.eapol_id_req(pkt[EAP].id, PAP_PASSWD)
71
72 self.eapol_scapy_recv(cb = eapol_cb,
73 lfilter = lambda pkt: pkt[EAP].type == EAP_TYPE_TLS and pkt[EAP].code == EAP.REQUEST)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080074 #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ
Chetan Gaonker5b366302016-03-21 16:18:21 -070075 self.nextEvent = None
76
Chetan Gaonkere2b78722016-02-22 17:27:09 -080077 def _eapPAPPassReq(self):
Chetan Gaonker5b366302016-03-21 16:18:21 -070078 log.info('PassReq Inside Challenge')
79 def eapol_cb(pkt):
80 log.info('Got EAPOL packet with type id and code request')
81 log.info('Packet code: %d, type: %d', pkt[EAP].code, pkt[EAP].type)
82
83 self.eapol_scapy_recv(cb = eapol_cb,
84 lfilter = lambda pkt: pkt[EAP].code == EAP.SUCCESS)
Chetan Gaonkere2b78722016-02-22 17:27:09 -080085 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE
86