blob: f6fdfd90e1f532a46623c7637e8fb089236b0bcb [file] [log] [blame]
Chetan Gaonkercb122cc2016-05-10 10:58:34 -07001#!/usr/bin/env python
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002#
3# Copyright 2016-present Ciena Corporation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Chetan Gaonkere2b78722016-02-22 17:27:09 -080017import sys, os
Chetan Gaonkere2b78722016-02-22 17:27:09 -080018from EapolAAA import *
19from enum import *
20import nosePAPAuthHolder as PAPAuthHolder
21from socket import *
22from struct import *
Chetan Gaonker5b366302016-03-21 16:18:21 -070023from scapy.all import *
Chetan Gaonkere2b78722016-02-22 17:27:09 -080024from nose.tools import *
25from CordTestBase import CordTester
26PAP_USER = "raduser"
27PAP_PASSWD = "radpass"
Chetan Gaonker5b366302016-03-21 16:18:21 -070028log.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
62
63 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):
Chetan Gaonker5b366302016-03-21 16:18:21 -070069 log.info( 'Inside EAP ID Req' )
70 def eapol_cb(pkt):
71 log.info('Got EAPOL packet with type id and code request')
72 log.info('Packet code: %d, type: %d, id: %s', pkt[EAP].code, pkt[EAP].type, pkt[EAP].id)
73 log.info("<====== Send EAP Response with identity = %s ================>" % PAP_USER)
74 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):
Chetan Gaonker5b366302016-03-21 16:18:21 -070081 log.info('UserReq Inside Challenge')
82 def eapol_cb(pkt):
83 log.info('Got EAPOL packet with type id and code request')
84 log.info('Packet code: %d, id: %s', pkt[EAP].code, pkt[EAP].id)
85 log.info('Send EAP Response for id %s with Password = %s' %(pkt[EAP].id, PAP_PASSWD) )
86 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):
Chetan Gaonker5b366302016-03-21 16:18:21 -070094 log.info('PassReq Inside Challenge')
95 def eapol_cb(pkt):
96 log.info('Got EAPOL packet with type id and code request')
97 log.info('Packet code: %d, type: %d', pkt[EAP].code, pkt[EAP].type)
98
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
102