TEST : Multiple basic validation scenarios for TLS and AAA.

Change-Id: Ic0bb12fc2143bbbc572b00b14e2defdbd253edf3
diff --git a/src/test/tls/tlsTest.py b/src/test/tls/tlsTest.py
index 848aa9b..15547e2 100644
--- a/src/test/tls/tlsTest.py
+++ b/src/test/tls/tlsTest.py
@@ -22,12 +22,15 @@
 from EapTLS import TLSAuthTest
 from OnosCtrl import OnosCtrl
 from scapy.all import *
+from scapy_ssl_tls.ssl_tls import *
+from scapy_ssl_tls.ssl_tls_crypto import *
 log.setLevel('INFO')
 
 class eap_auth_exchange(unittest.TestCase):
 
     app = 'org.opencord.aaa'
     TLS_TIMEOUT = 20
+    TEST_TIMEOUT = 3600
     CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
 MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
 VQQGEwJVUzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVNvbWV3aGVyZTETMBEGA1UE
@@ -57,6 +60,17 @@
 729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
 -----END CERTIFICATE-----'''
 
+    invalid_cipher_suites = ['TLS_RSA_WITH_NULL_SHA256',
+                             'TLS_RSA_WITH_AES_128_CBC_SHA',
+                             'TLS_RSA_WITH_AES_128_CBC_SHA256',
+                             'TLS_RSA_WITH_AES_256_CBC_SHA256',
+                             'TLS_DHE_DSS_WITH_AES_128_CBC_SHA256',
+                             'TLS_DHE_RSA_WITH_AES_128_CBC_SHA256',
+                             'TLS_DH_anon_WITH_AES_128_CBC_SHA256',
+                             'TLS_DHE_DSS_WITH_AES_256_CBC_SHA256',
+                             'TLS_DHE_RSA_WITH_AES_256_CBC_SHA256',
+                             'TLS_DH_anon_WITH_AES_256_CBC_SHA256']
+
     def setUp(self):
         self.onos_ctrl = OnosCtrl(self.app)
         self.onos_aaa_config()
@@ -93,7 +107,6 @@
         def eap_tls_no_cert(df):
             def tls_no_cert_cb():
                 log.info('TLS authentication failed with no certificate')
-
             tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
             tls.runTest()
             assert_equal(tls.failTest, True)
@@ -128,6 +141,296 @@
         reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
         return df
 
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_session_id(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_session_id(df):
+            def tls_invalid_session_id_cb():
+                log.info('TLS authentication failed with invalid session  id')
+            tls = TLSAuthTest(fail_cb = tls_invalid_session_id_cb,session_id = 12345, session_id_length = 1)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_session_id, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_random_gmt_unix_time(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_gmt_unix_time(df):
+            def eap_tls_invalid_gmt_unix_time_cb():
+                log.info('TLS authentication failed with invalid gmt_unix_time in Client Hello Packet')
+            for i in [0,7265,98758,23627238]:
+                log.info("\nExecuting test case with gmt_unix_time value is set to %d"%i)
+                tls = TLSAuthTest(fail_cb = eap_tls_invalid_gmt_unix_time_cb, gmt_unix_time = i)
+                tls.runTest()
+                assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_gmt_unix_time, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_content_type(self,Positive_Test=True):
+        df = defer.Deferred()
+        def eap_tls_invalid_content_type(df):
+            def tls_invalid_content_type_cb():
+                log.info('TLS authentication failed with invalid content type in TLSContentType packet')
+            tls = TLSAuthTest(fail_cb = tls_invalid_content_type_cb, invalid_content_type = 24)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_content_type, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_record_fragment_length(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_record_fragment_length(df):
+            def eap_tls_invalid_record_fragment_length_cb():
+                log.info('TLS authentication failed with invalid fragment length field in TLSRecord packet')
+            tls = TLSAuthTest(fail_cb = eap_tls_invalid_record_fragment_length_cb, record_fragment_length = 17384)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_record_fragment_length, df)
+        return df
+
+    #invalid id field in identifier response packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_with_invalid_id_in_identifier_response_packet(self):
+        df = defer.Deferred()
+        def eap_tls_with_invalid_id_in_identifier_response_packet(df):
+            def tls_with_invalid_id_in_identifier_response_packet_cb():
+                log.info('TLS authentication failed with invalid id in identifier packet')
+            tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_identifier_response_packet_cb,
+                              id_mismatch_in_identifier_response_packet = True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_with_invalid_id_in_identifier_response_packet, df)
+        return df
+
+    #invalid id field in client hello packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_with_invalid_id_in_client_hello_packet(self):
+        df = defer.Deferred()
+        def eap_tls_with_invalid_id_in_client_hello_packet(df):
+            def tls_with_invalid_id_in_client_hello_packet_cb():
+                log.info('TLS authentication failed with invalid id in client hello packet')
+            tls = TLSAuthTest(fail_cb = tls_with_invalid_id_in_client_hello_packet_cb,
+                              id_mismatch_in_client_hello_packet = True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_with_invalid_id_in_client_hello_packet, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_without_sending_client_hello(self):
+        df = defer.Deferred()
+        def eap_tls_without_sending_client_hello(df):
+            def tls_without_sending_client_hello_cb():
+                log.info('TLS authentication failed with not sending client hello')
+            tls = TLSAuthTest(fail_cb = tls_without_sending_client_hello_cb,
+                              dont_send_client_hello = True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_without_sending_client_hello, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_aaa_app_deactivate(self):
+        df = defer.Deferred()
+        def eap_tls_aaa_app_deactivate(df):
+            def tls_aaa_app_deactivate_cb():
+                log.info('TLS authentication failed with aaa app deactivated in ONOS')
+            tls = TLSAuthTest(fail_cb = tls_aaa_app_deactivate_cb)
+            self.onos_ctrl.deactivate()
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_aaa_app_deactivate, df)
+        return df
+
+    #keeping cipher suite length as zero but including cipher suite key which is more than zero length in client hello packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_incorrect_cipher_suite_length_field(self):
+        df = defer.Deferred()
+        def eap_tls_incorrect_cipher_suite_length_field(df):
+            def tls_incorrect_cipher_suite_length_field_cb():
+                log.info('TLS authentication failed with incorrect cipher suite length field in client hello packet')
+            tls = TLSAuthTest(fail_cb = tls_incorrect_cipher_suite_length_field_cb, cipher_suites_length = 0)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_incorrect_cipher_suite_length_field, df)
+        return df
+
+    #keeping compression methods length to zero but sending compression method of more than 0 zero length in client hello packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_incorrect_compression_methods_length_field(self):
+        df = defer.Deferred()
+        def eap_tls_incorrect_compression_methods_length_field(df):
+            def tls_incorrect_compression_methods_length_field_cb():
+                log.info('TLS authentication failed with incorrect compression methods length field in client hello packet')
+            tls = TLSAuthTest(fail_cb = tls_incorrect_compression_methods_length_field_cb, compression_methods_length=1,compression_methods=TLSCompressionMethod.LZS)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_incorrect_compression_methods_length_field, df)
+        return df
+
+    #checking with broadcast source mac of EAPOL packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_source_mac_broadcast(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_source_mac_broadcast(df):
+            def tls_invalid_source_mac_broadcast_cb():
+                log.info('TLS authentication failed with invalid source mac as broadcast in EAPOL packet')
+            tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_broadcast_cb, src_mac='bcast')
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_source_mac_broadcast, df)
+        return df
+
+    #checking with multicast source mac of EAPOL packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_source_mac_multicast(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_source_mac_multicast(df):
+            def tls_invalid_source_mac_multicast_cb():
+                log.info('TLS authentication failed with invalid source mac as multicast in EAPOL packet')
+            tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_multicast_cb, src_mac='mcast')
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_source_mac_multicast, df)
+        return df
+
+    #checking with zero source mac of EAPOL packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_source_mac_zero(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_source_mac_zero(df):
+            def tls_invalid_source_mac_zero_cb():
+                log.info('TLS authentication failed with invalid source mac as zero in EAPOL packet')
+            tls = TLSAuthTest(fail_cb = tls_invalid_source_mac_zero_cb, src_mac='zeros')
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_source_mac_zero, df)
+        return df
+
+    #Restarting Radius server after sending client hello
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_restart_radius_server(self):
+        df = defer.Deferred()
+        def eap_tls_restart_radius_server(df):
+            def tls_restart_radius_server_cb():
+                log.info('TLS authentication failed with  radius server down in middle of authentication process')
+            tls = TLSAuthTest(fail_cb = tls_restart_radius_server_cb, restart_radius=True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_restart_radius_server, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_with_incorrect_handshake_type_client_hello(self):
+        df = defer.Deferred()
+        def eap_tls_incorrect_handshake_type_client_hello(df):
+            def tls_incorrect_handshake_type_client_hello_cb():
+                log.info('TLS authentication failed with incorrect handshake type in client hello packet')
+            tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_client_hello_cb, invalid_client_hello_handshake_type=True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_incorrect_handshake_type_client_hello, df)
+        return df
+
+    #Sending certificate request type of handhsake instead of  certificate verify in client certificate request message
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_with_incorrect_handshake_type_certificate_request(self):
+        df = defer.Deferred()
+        def eap_tls_incorrect_handshake_type_certificate_request(df):
+            def tls_incorrect_handshake_type_certificate_request_cb():
+                log.info('TLS authentication failed with incorrect handshake type in client certificate request packet')
+            tls = TLSAuthTest(fail_cb = tls_incorrect_handshake_type_certificate_request_cb, invalid_cert_req_handshake=True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_incorrect_handshake_type_certificate_request, df)
+        return df
+
+    #Sending tls record content type as 'ALERT' instead of 'HANDSHAKE' in certificate request packet
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_with_incorrect_tlsrecord_certificate_request(self):
+        df = defer.Deferred()
+        def eap_tls_incorrect_tlsrecord_certificate_request(df):
+            def tls_incorrect_tlsrecord_certificate_request_cb():
+                log.info('TLS authentication failed with incorrect tlsrecord type  in certificate request packet')
+            tls = TLSAuthTest(fail_cb = tls_incorrect_tlsrecord_certificate_request_cb, incorrect_tlsrecord_type_cert_req=True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_incorrect_tlsrecord_certificate_request, df)
+        return df
+
+    #Sending client hello with zero lenght field in Handshake protocol
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_invalid_handshake_length_client_hello(self):
+        df = defer.Deferred()
+        def eap_tls_invalid_handshake_length_client_hello(df):
+            def tls_invalid_handshake_length_client_hello_cb():
+                log.info('TLS authentication failed with invalid handshake length in client hello packet')
+            tls = TLSAuthTest(fail_cb = tls_invalid_handshake_length_client_hello_cb, invalid_client_hello_handshake_length=True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_invalid_handshake_length_client_hello, df)
+        return df
+
+    @deferred(TLS_TIMEOUT)
+    def test_eap_tls_clientkeyex_replace_with_serverkeyex(self):
+        df = defer.Deferred()
+        def eap_tls_clientkeyex_replace_with_serverkeyex(df):
+            def tls_clientkeyex_replace_with_serverkeyex_cb():
+                log.info('TLS authentication failed with client key exchange replaced with server key exchange')
+            tls = TLSAuthTest(fail_cb = tls_clientkeyex_replace_with_serverkeyex_cb,clientkeyex_replace_with_serverkeyex=True)
+            tls.runTest()
+            assert_equal(tls.failTest, True)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_clientkeyex_replace_with_serverkeyex, df)
+        return df
+
+    #simulating authentication for multiple users, 1K in this test case
+    @deferred(TEST_TIMEOUT)
+    def test_eap_tls_1k_with_diff_mac(self):
+        df = defer.Deferred()
+        def eap_tls_1k_with_diff_mac(df):
+            for i in xrange(1000):
+                tls = TLSAuthTest(src_mac = 'random')
+                tls.runTest()
+		log.info('Authentication successfull for user %d'%i)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_1k_with_diff_mac, df)
+        return df
+
+    #simulating authentication for multiple users, 5K in this test case
+    @deferred(TEST_TIMEOUT)
+    def test_eap_tls_5k_with_diff_mac(self):
+        df = defer.Deferred()
+        def eap_tls_5k_with_diff_mac(df):
+            for i in xrange(5000):
+                tls = TLSAuthTest(src_mac = 'random')
+                tls.runTest()
+                log.info('Authentication successfull for user %d'%i)
+            df.callback(0)
+        reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
+        return df
+
 if __name__ == '__main__':
     t = TLSAuthTest()
     t.runTest()
diff --git a/src/test/utils/CordContainer.py b/src/test/utils/CordContainer.py
index a4971d3..e5a3a1d 100644
--- a/src/test/utils/CordContainer.py
+++ b/src/test/utils/CordContainer.py
@@ -183,6 +183,9 @@
             res += 0 if result['ExitCode'] == None else result['ExitCode']
         return res
 
+    def restart(self, timeout =10):
+        return self.dckr.restart(self.name, timeout)
+
 def get_mem():
     with open('/proc/meminfo', 'r') as fd:
         meminfo = fd.readlines()
diff --git a/src/test/utils/EapTLS.py b/src/test/utils/EapTLS.py
index 6d93683..8f31509 100644
--- a/src/test/utils/EapTLS.py
+++ b/src/test/utils/EapTLS.py
@@ -21,11 +21,14 @@
 from scapy_ssl_tls.ssl_tls_crypto import *
 from tls_cert import Key
 from socket import *
+from CordTestServer import cord_test_radius_restart
 import struct
 import scapy
 from nose.tools import *
 from CordTestBase import CordTester
+from CordContainer import *
 import re
+import time
 
 log.setLevel('INFO')
 
@@ -121,15 +124,49 @@
 
     def handle_server_hello_done(self, server_hello_done):
         if server_hello_done[-4:] == self.server_hello_done_signature:
+	    log.info('server hello received')
             self.server_hello_done_received = True
 
-    def __init__(self, intf = 'veth0', client_cert = None, client_priv_key = None, fail_cb = None):
+    def __init__(self, intf = 'veth0', client_cert = None, client_priv_key = None,
+                 fail_cb = None, src_mac='default', version = "TLS_1_0", session_id = '',
+                 session_id_length = None, gmt_unix_time=1234, invalid_content_type = 22,
+                 record_fragment_length = None, cipher_suites_length = None,
+                 compression_methods_length = None, compression_methods = TLSCompressionMethod.NULL,
+                 CipherSuite = True, cipher_suite = 'RSA_WITH_AES_256_CBC_SHA', id_mismatch_in_identifier_response_packet = False,
+                 id_mismatch_in_client_hello_packet = False , dont_send_client_certificate = False,
+                 dont_send_client_hello = False, restart_radius = False, invalid_client_hello_handshake_type = False,
+                 invalid_cert_req_handshake = False, incorrect_tlsrecord_type_cert_req = False,
+                 invalid_client_hello_handshake_length = False, clientkeyex_replace_with_serverkeyex = False):
+
         self.fsmTable = tlsAuthHolder.initTlsAuthHolderFsmTable(self, self.tlsStateTable, self.tlsEventTable)
         EapolPacket.__init__(self, intf)
         CordTester.__init__(self, self.fsmTable, self.tlsStateTable.ST_EAP_TLS_DONE)
                             #self.tlsStateTable, self.tlsEventTable)
         self.currentState = self.tlsStateTable.ST_EAP_SETUP
         self.currentEvent = self.tlsEventTable.EVT_EAP_SETUP
+	self.src_mac = src_mac
+	self.version = version
+        self.session_id_length = session_id_length
+        self.session_id = session_id
+        self.gmt_unix_time = gmt_unix_time
+        self.invalid_content_type = invalid_content_type
+        self.CipherSuite = CipherSuite
+        self.cipher_suites_length = cipher_suites_length
+        self.compression_methods_length = compression_methods_length
+        self.cipher_suite = cipher_suite
+        self.compression_methods_length = compression_methods_length
+        self.compression_methods = compression_methods
+        self.record_fragment_length = record_fragment_length
+	self.invalid_client_hello_handshake_type = invalid_client_hello_handshake_type
+	self.invalid_client_hello_handshake_length = invalid_client_hello_handshake_length
+	self.invalid_cert_req_handshake = invalid_cert_req_handshake
+        self.id_mismatch_in_identifier_response_packet = id_mismatch_in_identifier_response_packet
+        self.id_mismatch_in_client_hello_packet = id_mismatch_in_client_hello_packet
+        self.dont_send_client_certificate = dont_send_client_certificate
+        self.dont_send_client_hello = dont_send_client_hello
+	self.incorrect_tlsrecord_type_cert_req = incorrect_tlsrecord_type_cert_req
+	self.restart_radius = restart_radius
+	self.clientkeyex_replace_with_serverkeyex = clientkeyex_replace_with_serverkeyex
         self.nextState = None
         self.nextEvent = None
         self.pending_bytes = 0 #for TLS fragment reassembly
@@ -145,7 +182,10 @@
                          self.SERVER_HELLO_DONE: ['', '', self.handle_server_hello_done ],
                          self.SERVER_UNKNOWN: ['', '', lambda pkt: pkt ]
                        }
-        self.tls_ctx = TLSSessionCtx(client = True)
+	if self.clientkeyex_replace_with_serverkeyex:
+            self.tls_ctx = TLSSessionCtx(client = False)
+	else:
+	    self.tls_ctx = TLSSessionCtx(client = True)
         self.client_cert = self.CLIENT_CERT if client_cert is None else client_cert
         self.client_priv_key = self.CLIENT_PRIV_KEY if client_priv_key is None else client_priv_key
         self.failTest = False
@@ -179,6 +219,7 @@
 
     def tlsFail(self):
         ##Force a failure
+	log.info('entering into testFail funciton')
         self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_FINISHED
         self.nextState = self.tlsStateTable.ST_EAP_TLS_FINISHED
         self.failTest = True
@@ -240,10 +281,15 @@
             self.eapol_send(EAPOL_EAPPACKET, eap_payload)
 
     def _eapSetup(self):
-        self.setup()
+	#if self.src_mac == 'bcast':self.setup(src_mac='bcast')
+	#if self.src_mac == 'mcast': self.setup(src_mac='mcast')
+	#if self.src_mac == 'zeros': self.setup(src_mac='zeros')
+	#if self.src_mac == 'default': self.setup(src_mac='default')
+	self.setup(src_mac=self.src_mac)
         self.nextEvent = self.tlsEventTable.EVT_EAP_START
 
     def _eapStart(self):
+	log.info('_eapStart method started')
         self.eapol_start()
         self.nextEvent = self.tlsEventTable.EVT_EAP_ID_REQ
 
@@ -268,20 +314,44 @@
 
         def eapol_cb(pkt):
                 log.info('Got hello request for id %d', pkt[EAP].id)
-                self.client_hello = TLSClientHello(version="TLS_1_0",
-                                                   gmt_unix_time=1234,
+                self.client_hello = TLSClientHello(version= self.version,
+                                                   gmt_unix_time=self.gmt_unix_time,
                                                    random_bytes= '\xAB' * 28,
-                                                   session_id='',
-                                                   compression_methods=[TLSCompressionMethod.NULL],
-                                                   cipher_suites=[TLSCipherSuite.RSA_WITH_AES_256_CBC_SHA]
+                                                   session_id_length = self.session_id_length,
+                                                   session_id= self.session_id,
+                                                   compression_methods_length = self.compression_methods_length,
+                                                   compression_methods= self.compression_methods,
+                                                   cipher_suites_length = self.cipher_suites_length,
+                                                   cipher_suites=[self.cipher_suite]
                                                    )
-                client_hello_data = TLSHandshake()/self.client_hello
+		if self.invalid_client_hello_handshake_type:
+		    log.info('sending server_hello instead of client_hello handshape type in client hello packet')
+		    client_hello_data = TLSHandshake(type='server_hello')/self.client_hello
+		elif self.invalid_client_hello_handshake_length:
+		    log.info('sending TLS Handshake message with zero length field in client hello packet')
+		    client_hello_data = TLSHandshake(length=0)/self.client_hello
+		else:
+		    client_hello_data = TLSHandshake()/self.client_hello
+                #client_hello_data = TLSHandshake()/self.client_hello
                 self.pkt_history.append( str(client_hello_data) )
-                reqdata = TLSRecord()/client_hello_data
+		if self.record_fragment_length:
+                    reqdata = TLSRecord(length=self.record_fragment_length)/client_hello_data
+		else:
+		    reqdata = TLSRecord()/client_hello_data
                 self.load_tls_record(str(reqdata))
                 log.info("Sending Client Hello TLS payload of len %d, id %d" %(len(reqdata),pkt[EAP].id))
-                eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id, TLS_LENGTH_INCLUDED, str(reqdata))
-                self.eapol_send(EAPOL_EAPPACKET, eap_payload)
+		if self.id_mismatch_in_client_hello_packet:
+                    log.info('\nsending invalid id field in client hello packet')
+                    eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id+10, TLS_LENGTH_INCLUDED, str(reqdata))
+                else:
+                    eap_payload = self.eapTLS(EAP_RESPONSE, pkt[EAP].id, TLS_LENGTH_INCLUDED, str(reqdata))
+                if self.dont_send_client_hello:
+                    log.info('\nskipping client hello packet sending part')
+                    pass
+                else:
+                    self.eapol_send(EAPOL_EAPPACKET, eap_payload)
+		if self.restart_radius:
+                    cord_test_radius_restart()
 
         r = self.eapol_scapy_recv(cb = eapol_cb,
                                   lfilter =
@@ -339,7 +409,7 @@
         else:
             client_certificate_list = TLSHandshake()/TLSCertificateList(certificates=[])
         client_certificate = TLSRecord(version="TLS_1_0")/client_certificate_list
-        kex_data = self.tls_ctx.get_client_kex_data()
+	kex_data = self.tls_ctx.get_client_kex_data()
         client_key_ex_data = TLSHandshake()/kex_data
         client_key_ex = TLSRecord()/client_key_ex_data
         if self.client_cert:
@@ -348,24 +418,40 @@
         self.load_tls_record(str(client_key_ex))
         self.pkt_history.append(str(client_key_ex_data))
         verify_signature = self.get_verify_signature(self.client_priv_key)
-        client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_VERIFY)/verify_signature
-        client_cert_record = TLSRecord(content_type=TLSContentType.HANDSHAKE)/client_cert_verify
+	if self.invalid_cert_req_handshake:
+	    log.info("sending 'certificate-request' type of handshake message instead of 'certificate-verify' type")
+	    client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_REQUEST)/verify_signature
+	else:
+            client_cert_verify = TLSHandshake(type=TLSHandshakeType.CERTIFICATE_VERIFY)/verify_signature
+	if self.incorrect_tlsrecord_type_cert_req:
+	    log.info("sending TLS Record type as ALERT instead of HANDSHAKE in certificate request packet")
+            client_cert_record = TLSRecord(content_type=TLSContentType.ALERT)/client_cert_verify
+	else:
+	    client_cert_record = TLSRecord(content_type=TLSContentType.HANDSHAKE)/client_cert_verify
         self.pkt_history.append(str(client_cert_verify))
         #log.info('TLS ctxt: %s' %self.tls_ctx)
         client_ccs = TLSRecord(version="TLS_1_0")/TLSChangeCipherSpec()
         enc_handshake_msg = self.get_encrypted_handshake_msg()
-        handshake_msg = str(TLSRecord(content_type=TLSContentType.HANDSHAKE)/enc_handshake_msg)
+	if self.invalid_content_type:
+            handshake_msg = str(TLSRecord(content_type=self.invalid_content_type)/enc_handshake_msg)
+	else:
+	    handshake_msg = str(TLSRecord(content_type=TLSContentType.HANDSHAKE)/enc_handshake_msg)
         reqdata = str(TLS.from_records([client_certificate, client_key_ex, client_cert_record, client_ccs]))
         reqdata += handshake_msg
         log.info("------> Sending Client Hello TLS Certificate payload of len %d ----------->" %len(reqdata))
-        status = self.eapFragmentSend(EAP_RESPONSE, self.server_hello_done_eap_id, TLS_LENGTH_INCLUDED,
+	if self.dont_send_client_certificate:
+	    log.info('\nskipping sending client certificate part')
+	    pass
+	else:
+            status = self.eapFragmentSend(EAP_RESPONSE, self.server_hello_done_eap_id, TLS_LENGTH_INCLUDED,
                                       payload = reqdata, fragsize = 1024)
-        assert_equal(status, True)
-        self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_CHANGE_CIPHER_SPEC
+            assert_equal(status, True)
+            self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_CHANGE_CIPHER_SPEC
 
     def _eapTlsChangeCipherSpec(self):
         def eapol_cb(pkt):
             r = str(pkt)
+	    log.info('data received in change cipher spec function is %s'%pkt.show())
             tls_data = r[self.TLS_OFFSET:]
             log.info('Verifying TLS Change Cipher spec record type %x' %ord(tls_data[0]))
             assert tls_data[0] == self.CHANGE_CIPHER
diff --git a/src/test/utils/EapolAAA.py b/src/test/utils/EapolAAA.py
index c51f111..5cf79fd 100644
--- a/src/test/utils/EapolAAA.py
+++ b/src/test/utils/EapolAAA.py
@@ -50,16 +50,29 @@
 
 class EapolPacket(object):
 
+    src_mac_map = { 'bcast': 'ff:ff:ff:ff:ff:ff',
+                    'mcast': '01:80:C2:00:00:03',
+                    'zeros': '00:00:00:00:00:00',
+                    'default': None
+                    }
+
     def __init__(self, intf = 'veth0'):
         self.intf = intf
         self.s = None
         self.max_recv_size = 1600
 
-    def setup(self):
+    def setup(self, src_mac = 'default'):
         self.s = socket(AF_PACKET, SOCK_RAW, htons(ETHERTYPE_PAE))
         self.s.bind((self.intf, ETHERTYPE_PAE))
         self.mymac = self.s.getsockname()[4]
-        self.llheader = Ether(dst = PAE_GROUP_ADDR, src = self.mymac, type = ETHERTYPE_PAE)
+        mac = None
+        if self.src_mac_map.has_key(src_mac):
+            mac = self.src_mac_map[src_mac]
+        if mac is None:
+            mac = self.mymac
+        self.llheader = Ether(dst = PAE_GROUP_ADDR, src = mac, type = ETHERTYPE_PAE)
+	log.info('llheader packet is %s'%self.llheader.show())
+	log.info('source mac of  packet is %s'%mac)
         self.recv_sock = L2Socket(iface = self.intf, type = ETHERTYPE_PAE)
 
     def cleanup(self):