blob: a40ae9d3082bfd14ad933f4640f11f0bb167e6ba [file] [log] [blame]
Chetan Gaonkere2b78722016-02-22 17:27:09 -08001import sys, os
2cord_root = os.getenv('CORD_TEST_ROOT') or './'
3CORD_TEST_FSM = 'fsm'
4sys.path.append(cord_root + CORD_TEST_FSM)
5from EapolAAA import *
6from enum import *
7import nosePAPAuthHolder as PAPAuthHolder
8from socket import *
9from struct import *
10import scapy
11from nose.tools import *
12from CordTestBase import CordTester
13PAP_USER = "raduser"
14PAP_PASSWD = "radpass"
15
16class PAPAuthTest(EapolPacket, CordTester):
17
18 PAPStateTable = Enumeration("PAPStateTable", ("ST_EAP_SETUP",
19 "ST_EAP_START",
20 "ST_EAP_ID_REQ",
21 "ST_EAP_PAP_USER_REQ",
22 "ST_EAP_PAP_PASSWD_REQ",
23 "ST_EAP_PAP_DONE"
24 )
25 )
26 PAPEventTable = Enumeration("PAPEventTable", ("EVT_EAP_SETUP",
27 "EVT_EAP_START",
28 "EVT_EAP_ID_REQ",
29 "EVT_EAP_PAP_USER_REQ",
30 "EVT_EAP_PAP_PASSWD_REQ",
31 "EVT_EAP_PAP_DONE"
32 )
33 )
34 def __init__(self, intf = 'veth0'):
35 self.fsmTable = PAPAuthHolder.initPAPAuthHolderFsmTable(self, self.PAPStateTable, self.PAPEventTable)
36 EapolPacket.__init__(self, intf)
37 CordTester.__init__(self, self.fsmTable, self.PAPStateTable.ST_EAP_PAP_DONE)
38 #self.PAPStateTable, self.PAPEventTable)
39 self.currentState = self.PAPStateTable.ST_EAP_SETUP
40 self.currentEvent = self.PAPEventTable.EVT_EAP_SETUP
41 self.nextState = None
42 self.nextEvent = None
43
44 def _eapSetup(self):
45 print 'Inside EAP PAP Setup'
46 self.setup()
47 self.nextEvent = self.PAPEventTable.EVT_EAP_START
48
49 def _eapStart(self):
50 print 'Inside EAP PAP Start'
51 self.eapol_start()
52 self.nextEvent = self.PAPEventTable.EVT_EAP_ID_REQ
53
54 def _eapIdReq(self):
55 print 'Inside EAP ID Req'
56 p = self.eapol_recv()
57 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
58 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
59 assert_equal(code, EAP_REQUEST)
60 reqtype = unpack("!B", p[4:5])[0]
61 reqdata = p[5:4+eaplen]
62 assert_equal(reqtype, EAP_TYPE_ID)
63 print "<====== Send EAP Response with identity = %s ================>" % PAP_USER
64 self.eapol_id_req(pkt_id, PAP_USER)
65 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ
66
67 def _eapPAPUserReq(self):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080068 print 'UserReq Inside Challenge'
Chetan Gaonkere2b78722016-02-22 17:27:09 -080069 p = self.eapol_recv()
70 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
71 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
72 assert_equal(code, EAP_REQUEST)
73 reqtype = unpack("!B", p[4:5])[0]
74 reqdata = p[5:4+eaplen]
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080075 assert_equal(reqtype, EAP_TYPE_TLS)
Chetan Gaonkere2b78722016-02-22 17:27:09 -080076 print "<====== Send EAP Response with Password = %s ================>" % PAP_PASSWD
77 self.eapol_id_req(pkt_id, PAP_PASSWD)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080078 #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ
79 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE
Chetan Gaonkere2b78722016-02-22 17:27:09 -080080
81 def _eapPAPPassReq(self):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080082 print 'PassReq Inside Challenge'
Chetan Gaonkere2b78722016-02-22 17:27:09 -080083 p = self.eapol_recv()
84 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
85 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
86 assert_equal(code, EAP_SUCCESS)
87 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE
88