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