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 * |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 7 | from scapy.all import * |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 8 | from nose.tools import * |
| 9 | from CordTestBase import CordTester |
| 10 | PAP_USER = "raduser" |
| 11 | PAP_PASSWD = "radpass" |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 12 | log.setLevel('INFO') |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 13 | |
| 14 | class 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 Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 53 | 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 Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 62 | self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ |
| 63 | |
| 64 | def _eapPAPUserReq(self): |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 65 | 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 Gaonker | b2bd824 | 2016-03-03 15:39:24 -0800 | [diff] [blame] | 74 | #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 75 | self.nextEvent = None |
| 76 | |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 77 | def _eapPAPPassReq(self): |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 78 | 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 Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 85 | self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE |
| 86 | |