blob: a342132e7263e979f486b91a6583b04b33bcc958 [file] [log] [blame]
Chetan Gaonkercfcce782016-05-10 10:10:42 -07001#
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 Gaonkere2b78722016-02-22 17:27:09 -080016import sys, os
Chetan Gaonkere2b78722016-02-22 17:27:09 -080017from EapolAAA import *
18from enum import *
19import 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
25PAP_USER = "raduser"
26PAP_PASSWD = "radpass"
Chetan Gaonker5b366302016-03-21 16:18:21 -070027log.setLevel('INFO')
Chetan Gaonkere2b78722016-02-22 17:27:09 -080028
29class 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 Gaonker5b366302016-03-21 16:18:21 -070068 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 Gaonkere2b78722016-02-22 17:27:09 -080077 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_USER_REQ
78
79 def _eapPAPUserReq(self):
Chetan Gaonker5b366302016-03-21 16:18:21 -070080 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 Gaonkerb2bd8242016-03-03 15:39:24 -080089 #self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_PASSWD_REQ
Chetan Gaonker5b366302016-03-21 16:18:21 -070090 self.nextEvent = None
91
Chetan Gaonkere2b78722016-02-22 17:27:09 -080092 def _eapPAPPassReq(self):
Chetan Gaonker5b366302016-03-21 16:18:21 -070093 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 Gaonkere2b78722016-02-22 17:27:09 -0800100 self.nextEvent = self.PAPEventTable.EVT_EAP_PAP_DONE
101