blob: 984327a4ab55031ade5172048faef7b135144171 [file] [log] [blame]
A R Karthick76a497a2017-04-12 10:59:39 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# 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
A R Karthick76a497a2017-04-12 10:59:39 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick76a497a2017-04-12 10:59:39 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# 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 Gaonkere2b78722016-02-22 17:27:09 -080016import sys, os
Chetan Gaonkere2b78722016-02-22 17:27:09 -080017from EapolAAA import *
A R Karthick74d00312017-04-18 14:26:01 -070018from Enum import *
Chetan Gaonkere2b78722016-02-22 17:27:09 -080019import nosePAPAuthHolder as PAPAuthHolder
20from socket import *
21from struct import *
Chetan Gaonker5b366302016-03-21 16:18:21 -070022from scapy.all import *
Chetan Gaonkere2b78722016-02-22 17:27:09 -080023from nose.tools import *
24from CordTestBase import CordTester
A R Karthick76a497a2017-04-12 10:59:39 -070025from CordTestUtils import log_test
Chetan Gaonkere2b78722016-02-22 17:27:09 -080026PAP_USER = "raduser"
27PAP_PASSWD = "radpass"
A R Karthick76a497a2017-04-12 10:59:39 -070028log_test.setLevel('INFO')
Chetan Gaonkere2b78722016-02-22 17:27:09 -080029
30class PAPAuthTest(EapolPacket, CordTester):
31
32 PAPStateTable = Enumeration("PAPStateTable", ("ST_EAP_SETUP",
33 "ST_EAP_START",
34 "ST_EAP_ID_REQ",
35 "ST_EAP_PAP_USER_REQ",
36 "ST_EAP_PAP_PASSWD_REQ",
37 "ST_EAP_PAP_DONE"
38 )
39 )
40 PAPEventTable = Enumeration("PAPEventTable", ("EVT_EAP_SETUP",
41 "EVT_EAP_START",
42 "EVT_EAP_ID_REQ",
43 "EVT_EAP_PAP_USER_REQ",
44 "EVT_EAP_PAP_PASSWD_REQ",
45 "EVT_EAP_PAP_DONE"
46 )
47 )
48 def __init__(self, intf = 'veth0'):
49 self.fsmTable = PAPAuthHolder.initPAPAuthHolderFsmTable(self, self.PAPStateTable, self.PAPEventTable)
50 EapolPacket.__init__(self, intf)
51 CordTester.__init__(self, self.fsmTable, self.PAPStateTable.ST_EAP_PAP_DONE)
52 #self.PAPStateTable, self.PAPEventTable)
53 self.currentState = self.PAPStateTable.ST_EAP_SETUP
54 self.currentEvent = self.PAPEventTable.EVT_EAP_SETUP
55 self.nextState = None
56 self.nextEvent = None
57
58 def _eapSetup(self):
59 print 'Inside EAP PAP Setup'
60 self.setup()
61 self.nextEvent = self.PAPEventTable.EVT_EAP_START
A R Karthick76a497a2017-04-12 10:59:39 -070062
Chetan Gaonkere2b78722016-02-22 17:27:09 -080063 def _eapStart(self):
64 print 'Inside EAP PAP Start'
65 self.eapol_start()
66 self.nextEvent = self.PAPEventTable.EVT_EAP_ID_REQ
67
68 def _eapIdReq(self):
A R Karthick76a497a2017-04-12 10:59:39 -070069 log_test.info( 'Inside EAP ID Req' )
Chetan Gaonker5b366302016-03-21 16:18:21 -070070 def eapol_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -070071 log_test.info('Got EAPOL packet with type id and code request')
72 log_test.info('Packet code: %d, type: %d, id: %s', pkt[EAP].code, pkt[EAP].type, pkt[EAP].id)
73 log_test.info("<====== Send EAP Response with identity = %s ================>" % PAP_USER)
Chetan Gaonker5b366302016-03-21 16:18:21 -070074 self.eapol_id_req(pkt[EAP].id, PAP_USER)
75
76 self.eapol_scapy_recv(cb = eapol_cb,
77 lfilter = lambda pkt: pkt[EAP].type == EAP.TYPE_ID and pkt[EAP].code == EAP.REQUEST)
Chetan Gaonkere2b78722016-02-22 17:27:09 -080078 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ
79
80 def _eapPAPUserReq(self):
A R Karthick76a497a2017-04-12 10:59:39 -070081 log_test.info('UserReq Inside Challenge')
Chetan Gaonker5b366302016-03-21 16:18:21 -070082 def eapol_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -070083 log_test.info('Got EAPOL packet with type id and code request')
84 log_test.info('Packet code: %d, id: %s', pkt[EAP].code, pkt[EAP].id)
85 log_test.info('Send EAP Response for id %s with Password = %s' %(pkt[EAP].id, PAP_PASSWD) )
Chetan Gaonker5b366302016-03-21 16:18:21 -070086 self.eapol_id_req(pkt[EAP].id, PAP_PASSWD)
87
88 self.eapol_scapy_recv(cb = eapol_cb,
89 lfilter = lambda pkt: pkt[EAP].type == EAP_TYPE_TLS and pkt[EAP].code == EAP.REQUEST)
Chetan Gaonkerb2bd8242016-03-03 15:39:24 -080090 #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ
Chetan Gaonker5b366302016-03-21 16:18:21 -070091 self.nextEvent = None
92
Chetan Gaonkere2b78722016-02-22 17:27:09 -080093 def _eapPAPPassReq(self):
A R Karthick76a497a2017-04-12 10:59:39 -070094 log_test.info('PassReq Inside Challenge')
Chetan Gaonker5b366302016-03-21 16:18:21 -070095 def eapol_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -070096 log_test.info('Got EAPOL packet with type id and code request')
97 log_test.info('Packet code: %d, type: %d', pkt[EAP].code, pkt[EAP].type)
Chetan Gaonker5b366302016-03-21 16:18:21 -070098
99 self.eapol_scapy_recv(cb = eapol_cb,
100 lfilter = lambda pkt: pkt[EAP].code == EAP.SUCCESS)
Chetan Gaonkere2b78722016-02-22 17:27:09 -0800101 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE