Chetan Gaonker | cfcce78 | 2016-05-10 10:10:42 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016-present Ciena Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 16 | import sys, os |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 17 | from EapolAAA import * |
| 18 | from enum import * |
| 19 | import nosePAPAuthHolder as PAPAuthHolder |
| 20 | from socket import * |
| 21 | from struct import * |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 22 | from scapy.all import * |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 23 | from nose.tools import * |
| 24 | from CordTestBase import CordTester |
| 25 | PAP_USER = "raduser" |
| 26 | PAP_PASSWD = "radpass" |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 27 | log.setLevel('INFO') |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 28 | |
| 29 | class PAPAuthTest(EapolPacket, CordTester): |
| 30 | |
| 31 | PAPStateTable = Enumeration("PAPStateTable", ("ST_EAP_SETUP", |
| 32 | "ST_EAP_START", |
| 33 | "ST_EAP_ID_REQ", |
| 34 | "ST_EAP_PAP_USER_REQ", |
| 35 | "ST_EAP_PAP_PASSWD_REQ", |
| 36 | "ST_EAP_PAP_DONE" |
| 37 | ) |
| 38 | ) |
| 39 | PAPEventTable = Enumeration("PAPEventTable", ("EVT_EAP_SETUP", |
| 40 | "EVT_EAP_START", |
| 41 | "EVT_EAP_ID_REQ", |
| 42 | "EVT_EAP_PAP_USER_REQ", |
| 43 | "EVT_EAP_PAP_PASSWD_REQ", |
| 44 | "EVT_EAP_PAP_DONE" |
| 45 | ) |
| 46 | ) |
| 47 | def __init__(self, intf = 'veth0'): |
| 48 | self.fsmTable = PAPAuthHolder.initPAPAuthHolderFsmTable(self, self.PAPStateTable, self.PAPEventTable) |
| 49 | EapolPacket.__init__(self, intf) |
| 50 | CordTester.__init__(self, self.fsmTable, self.PAPStateTable.ST_EAP_PAP_DONE) |
| 51 | #self.PAPStateTable, self.PAPEventTable) |
| 52 | self.currentState = self.PAPStateTable.ST_EAP_SETUP |
| 53 | self.currentEvent = self.PAPEventTable.EVT_EAP_SETUP |
| 54 | self.nextState = None |
| 55 | self.nextEvent = None |
| 56 | |
| 57 | def _eapSetup(self): |
| 58 | print 'Inside EAP PAP Setup' |
| 59 | self.setup() |
| 60 | self.nextEvent = self.PAPEventTable.EVT_EAP_START |
| 61 | |
| 62 | def _eapStart(self): |
| 63 | print 'Inside EAP PAP Start' |
| 64 | self.eapol_start() |
| 65 | self.nextEvent = self.PAPEventTable.EVT_EAP_ID_REQ |
| 66 | |
| 67 | def _eapIdReq(self): |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 68 | log.info( 'Inside EAP ID Req' ) |
| 69 | def eapol_cb(pkt): |
| 70 | log.info('Got EAPOL packet with type id and code request') |
| 71 | log.info('Packet code: %d, type: %d, id: %s', pkt[EAP].code, pkt[EAP].type, pkt[EAP].id) |
| 72 | log.info("<====== Send EAP Response with identity = %s ================>" % PAP_USER) |
| 73 | self.eapol_id_req(pkt[EAP].id, PAP_USER) |
| 74 | |
| 75 | self.eapol_scapy_recv(cb = eapol_cb, |
| 76 | 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] | 77 | self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ |
| 78 | |
| 79 | def _eapPAPUserReq(self): |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 80 | log.info('UserReq Inside Challenge') |
| 81 | def eapol_cb(pkt): |
| 82 | log.info('Got EAPOL packet with type id and code request') |
| 83 | log.info('Packet code: %d, id: %s', pkt[EAP].code, pkt[EAP].id) |
| 84 | log.info('Send EAP Response for id %s with Password = %s' %(pkt[EAP].id, PAP_PASSWD) ) |
| 85 | self.eapol_id_req(pkt[EAP].id, PAP_PASSWD) |
| 86 | |
| 87 | self.eapol_scapy_recv(cb = eapol_cb, |
| 88 | 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] | 89 | #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 90 | self.nextEvent = None |
| 91 | |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 92 | def _eapPAPPassReq(self): |
Chetan Gaonker | 5b36630 | 2016-03-21 16:18:21 -0700 | [diff] [blame] | 93 | log.info('PassReq Inside Challenge') |
| 94 | def eapol_cb(pkt): |
| 95 | log.info('Got EAPOL packet with type id and code request') |
| 96 | log.info('Packet code: %d, type: %d', pkt[EAP].code, pkt[EAP].type) |
| 97 | |
| 98 | self.eapol_scapy_recv(cb = eapol_cb, |
| 99 | lfilter = lambda pkt: pkt[EAP].code == EAP.SUCCESS) |
Chetan Gaonker | e2b7872 | 2016-02-22 17:27:09 -0800 | [diff] [blame] | 100 | self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE |
| 101 | |