Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 1 | import sys, os |
| 2 | cord_root = os.getenv('CORD_TEST_ROOT') or './' |
| 3 | CORD_TEST_FSM = 'fsm' |
| 4 | sys.path.append(cord_root + CORD_TEST_FSM) |
| 5 | from EapolAAA import * |
| 6 | from enum import * |
| 7 | import nosePAPAuthHolder as PAPAuthHolder |
| 8 | from socket import * |
| 9 | from struct import * |
| 10 | import scapy |
| 11 | from nose.tools import * |
| 12 | from CordTestBase import CordTester |
| 13 | PAP_USER = "raduser" |
| 14 | PAP_PASSWD = "radpass" |
| 15 | |
| 16 | class 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 68 | print 'UserReq Inside Challenge' |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 69 | 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 75 | assert_equal(reqtype, EAP_TYPE_TLS) |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 76 | print "<====== Send EAP Response with Password = %s ================>" % PAP_PASSWD |
| 77 | self.eapol_id_req(pkt_id, PAP_PASSWD) |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 78 | #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ |
| 79 | self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 80 | |
| 81 | def _eapPAPPassReq(self): |
Chetan Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 82 | print 'PassReq Inside Challenge' |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 83 | 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 | |