blob: 48b75a85dcf885d8582f1915ee54b38b52b0f572 [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 *
7import scapy
8from nose.tools import *
9from CordTestBase import CordTester
10PAP_USER = "raduser"
11PAP_PASSWD = "radpass"
12
13class PAPAuthTest(EapolPacket, CordTester):
14
15 PAPStateTable = Enumeration("PAPStateTable", ("ST_EAP_SETUP",
16 "ST_EAP_START",
17 "ST_EAP_ID_REQ",
18 "ST_EAP_PAP_USER_REQ",
19 "ST_EAP_PAP_PASSWD_REQ",
20 "ST_EAP_PAP_DONE"
21 )
22 )
23 PAPEventTable = Enumeration("PAPEventTable", ("EVT_EAP_SETUP",
24 "EVT_EAP_START",
25 "EVT_EAP_ID_REQ",
26 "EVT_EAP_PAP_USER_REQ",
27 "EVT_EAP_PAP_PASSWD_REQ",
28 "EVT_EAP_PAP_DONE"
29 )
30 )
31 def __init__(self, intf = 'veth0'):
32 self.fsmTable = PAPAuthHolder.initPAPAuthHolderFsmTable(self, self.PAPStateTable, self.PAPEventTable)
33 EapolPacket.__init__(self, intf)
34 CordTester.__init__(self, self.fsmTable, self.PAPStateTable.ST_EAP_PAP_DONE)
35 #self.PAPStateTable, self.PAPEventTable)
36 self.currentState = self.PAPStateTable.ST_EAP_SETUP
37 self.currentEvent = self.PAPEventTable.EVT_EAP_SETUP
38 self.nextState = None
39 self.nextEvent = None
40
41 def _eapSetup(self):
42 print 'Inside EAP PAP Setup'
43 self.setup()
44 self.nextEvent = self.PAPEventTable.EVT_EAP_START
45
46 def _eapStart(self):
47 print 'Inside EAP PAP Start'
48 self.eapol_start()
49 self.nextEvent = self.PAPEventTable.EVT_EAP_ID_REQ
50
51 def _eapIdReq(self):
52 print 'Inside EAP ID Req'
53 p = self.eapol_recv()
54 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
55 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
56 assert_equal(code, EAP_REQUEST)
57 reqtype = unpack("!B", p[4:5])[0]
58 reqdata = p[5:4+eaplen]
59 assert_equal(reqtype, EAP_TYPE_ID)
60 print "<====== Send EAP Response with identity = %s ================>" % PAP_USER
61 self.eapol_id_req(pkt_id, PAP_USER)
62 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ
63
64 def _eapPAPUserReq(self):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080065 print 'UserReq Inside Challenge'
Chetan Gaonkere2b78722016-02-22 17:27:09 -080066 p = self.eapol_recv()
67 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
68 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
69 assert_equal(code, EAP_REQUEST)
70 reqtype = unpack("!B", p[4:5])[0]
71 reqdata = p[5:4+eaplen]
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080072 assert_equal(reqtype, EAP_TYPE_TLS)
Chetan Gaonkere2b78722016-02-22 17:27:09 -080073 print "<====== Send EAP Response with Password = %s ================>" % PAP_PASSWD
74 self.eapol_id_req(pkt_id, PAP_PASSWD)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080075 #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ
76 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE
Chetan Gaonkere2b78722016-02-22 17:27:09 -080077
78 def _eapPAPPassReq(self):
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080079 print 'PassReq Inside Challenge'
Chetan Gaonkere2b78722016-02-22 17:27:09 -080080 p = self.eapol_recv()
81 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
82 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
83 assert_equal(code, EAP_SUCCESS)
84 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE
85