blob: 3a143a70b705e3bd90c9bd4b4787f97d216c8329 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
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 Karthick76a497a2017-04-12 10:59:39 -070017#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070018# 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 Karthick76a497a2017-04-12 10:59:39 -070023#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070024# http://www.apache.org/licenses/LICENSE-2.0
A R Karthick76a497a2017-04-12 10:59:39 -070025#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070026# 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 Gaonkere2b78722016-02-22 17:27:09 -080032import sys, os
Chetan Gaonkere2b78722016-02-22 17:27:09 -080033from EapolAAA import *
A R Karthick74d00312017-04-18 14:26:01 -070034from Enum import *
Chetan Gaonkere2b78722016-02-22 17:27:09 -080035import nosePAPAuthHolder as PAPAuthHolder
36from socket import *
37from struct import *
Chetan Gaonker5b366302016-03-21 16:18:21 -070038from scapy.all import *
Chetan Gaonkere2b78722016-02-22 17:27:09 -080039from nose.tools import *
40from CordTestBase import CordTester
A R Karthick76a497a2017-04-12 10:59:39 -070041from CordTestUtils import log_test
Chetan Gaonkere2b78722016-02-22 17:27:09 -080042PAP_USER = "raduser"
43PAP_PASSWD = "radpass"
A R Karthick76a497a2017-04-12 10:59:39 -070044log_test.setLevel('INFO')
Chetan Gaonkere2b78722016-02-22 17:27:09 -080045
46class 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 Karthick76a497a2017-04-12 10:59:39 -070078
Chetan Gaonkere2b78722016-02-22 17:27:09 -080079 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 Karthick76a497a2017-04-12 10:59:39 -070085 log_test.info( 'Inside EAP ID Req' )
Chetan Gaonker5b366302016-03-21 16:18:21 -070086 def eapol_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -070087 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 Gaonker5b366302016-03-21 16:18:21 -070090 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 Gaonkere2b78722016-02-22 17:27:09 -080094 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ
95
96 def _eapPAPUserReq(self):
A R Karthick76a497a2017-04-12 10:59:39 -070097 log_test.info('UserReq Inside Challenge')
Chetan Gaonker5b366302016-03-21 16:18:21 -070098 def eapol_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -070099 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 Gaonker5b366302016-03-21 16:18:21 -0700102 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 Gaonkerb2bd8242016-03-03 15:39:24 -0800106 #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ
Chetan Gaonker5b366302016-03-21 16:18:21 -0700107 self.nextEvent = None
108
Chetan Gaonkere2b78722016-02-22 17:27:09 -0800109 def _eapPAPPassReq(self):
A R Karthick76a497a2017-04-12 10:59:39 -0700110 log_test.info('PassReq Inside Challenge')
Chetan Gaonker5b366302016-03-21 16:18:21 -0700111 def eapol_cb(pkt):
A R Karthick76a497a2017-04-12 10:59:39 -0700112 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 Gaonker5b366302016-03-21 16:18:21 -0700114
115 self.eapol_scapy_recv(cb = eapol_cb,
116 lfilter = lambda pkt: pkt[EAP].code == EAP.SUCCESS)
Chetan Gaonkere2b78722016-02-22 17:27:09 -0800117 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE