blob: 61ca4056b42ce584523776b17aec1d65510c3fba [file] [log] [blame]
Chetan Gaonkerb424ff82016-03-08 12:11:12 -08001import sys, os
2from EapolAAA import *
3from enum import *
4import noseMd5AuthHolder as md5AuthHolder
5from socket import *
6from struct import *
7from md5 import md5
8from scapy.all import *
9from nose.tools import *
10from CordTestBase import CordTester
11
12class MD5AuthTest(EapolPacket, CordTester):
13
14 md5StateTable = Enumeration("MD5StateTable", ("ST_EAP_SETUP",
15 "ST_EAP_START",
16 "ST_EAP_ID_REQ",
17 "ST_EAP_MD5_CHALLENGE",
18 "ST_EAP_STATUS",
19 "ST_EAP_MD5_DONE"
20 )
21 )
22 md5EventTable = Enumeration("MD5EventTable", ("EVT_EAP_SETUP",
23 "EVT_EAP_START",
24 "EVT_EAP_ID_REQ",
25 "EVT_EAP_MD5_CHALLENGE",
26 "EVT_EAP_STATUS",
27 "EVT_EAP_MD5_DONE"
28 )
29 )
30 def __init__(self, intf = 'veth0', password = "password", required_status = "EAP_SUCCESS"):
31 self.passwd = password
32 self.req_status = required_status
33 self.fsmTable = md5AuthHolder.initMd5AuthHolderFsmTable(self, self.md5StateTable, self.md5EventTable)
34 EapolPacket.__init__(self, intf)
35 CordTester.__init__(self, self.fsmTable, self.md5StateTable.ST_EAP_MD5_DONE)
36 self.currentState = self.md5StateTable.ST_EAP_SETUP
37 self.currentEvent = self.md5EventTable.EVT_EAP_SETUP
38 self.nextState = None
39 self.nextEvent = None
40
41 def _eapSetup(self):
42 print 'Inside EAP Setup'
43 self.setup()
44 self.nextEvent = self.md5EventTable.EVT_EAP_START
45
46 def _eapStart(self):
47 print 'Inside EAP Start'
48 self.eapol_start()
49 self.nextEvent = self.md5EventTable.EVT_EAP_ID_REQ
50
51 def _eapIdReq(self):
52 print 'Inside EAP ID Req'
53 p = self.eapol_recv()
54 code, pkt_id, eaplen = unpack("!BBH", p[0:4])
55 print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
56 assert_equal(code, EAP_REQUEST)
57 reqtype = unpack("!B", p[4:5])[0]
58 reqdata = p[5:4+eaplen]
59 assert_equal(reqtype, EAP_TYPE_ID)
60 print "<====== Send EAP Response with identity = %s ================>" % USER
61 self.eapol_id_req(pkt_id, USER)
62 self.nextEvent = self.md5EventTable.EVT_EAP_MD5_CHALLENGE
63
64 def _eapMd5Challenge(self):
65 print 'Inside EAP MD5 Challenge Exchange'
66 challenge,pkt_id =self.eap_md5_challenge_recv(self.passwd)
67 resp=md5(challenge).digest()
68 resp=chr(len(resp))+resp
69 length= 5+len(resp)
70 print "Generated MD5 challenge is %s Length : %d" % (resp,length)
71 print "--> Send EAP response with MD5 challenge"
72 eap_payload = self.eap(EAP_RESPONSE, pkt_id, EAP_TYPE_MD5, str(resp))
73 self.eapol_send(EAPOL_EAPPACKET, eap_payload)
74 self.nextEvent = self.md5EventTable.EVT_EAP_STATUS
75
76 def _eapStatus(self):
77 print 'Inside EAP Status -- Sucess/Failure'
78 if self.req_status == "EAP_SUCCESS":
79 status=self.eap_Status()
80 print "<============EAP code received is = %d ====================>" % status
81 assert_equal(status, EAP_SUCCESS)
82 print"Received EAP SUCCESS"
83 else:
84 print 'Inside EAP Status -- Sucess/Failure ===> SUCCESS should not be received , Since Negative Testcase'
85 self.s.settimeout(10)
86 assert_equal(self.s.gettimeout(), 10)
87 print "Check if the socket timed out ====> Since negative testcase socket should timeout because ONOS is not sending the EAP FAILURE Message"
88 assert_raises(socket.error, self.s.recv, 1024)
89 self.nextEvent = self.md5EventTable.EVT_EAP_MD5_DONE
90
91 def _wrong_password(self):
92 print 'Start Testcase for EAP-MD5 Wrong Password'
93 #self._eap_md5_states()
94 self.__init__(intf = 'veth0', password = "wrong_password", required_status = "EAP_FAILURE")
95
96