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