blob: d6b6b7e923630cb5e5dbf2e0af250f614b946804 [file] [log] [blame]
import sys, os
cord_root = os.getenv('CORD_TEST_ROOT') or './'
CORD_TEST_FSM = 'fsm'
sys.path.append(cord_root + CORD_TEST_FSM)
from EapolAAA import *
from enum import *
import noseTlsAuthHolder as tlsAuthHolder
from scapy_ssl_tls.ssl_tls import *
from socket import *
from struct import *
import scapy
from nose.tools import *
from CordTestBase import CordTester
import re
class TLSAuthTest(EapolPacket, CordTester):
tlsStateTable = Enumeration("TLSStateTable", ("ST_EAP_SETUP",
"ST_EAP_START",
"ST_EAP_ID_REQ",
"ST_EAP_TLS_HELLO_REQ",
"ST_EAP_TLS_CERT_REQ",
"ST_EAP_TLS_DONE"
)
)
tlsEventTable = Enumeration("TLSEventTable", ("EVT_EAP_SETUP",
"EVT_EAP_START",
"EVT_EAP_ID_REQ",
"EVT_EAP_TLS_HELLO_REQ",
"EVT_EAP_TLS_CERT_REQ",
"EVT_EAP_TLS_DONE"
)
)
def __init__(self, intf = 'veth0'):
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.nextState = None
self.nextEvent = None
def _eapSetup(self):
print 'Inside EAP Setup'
self.setup()
self.nextEvent = self.tlsEventTable.EVT_EAP_START
def _eapStart(self):
print 'Inside EAP Start'
self.eapol_start()
self.nextEvent = self.tlsEventTable.EVT_EAP_ID_REQ
def _eapIdReq(self):
print 'Inside EAP ID Req'
p = self.eapol_recv()
code, pkt_id, eaplen = unpack("!BBH", p[0:4])
print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
assert_equal(code, EAP_REQUEST)
reqtype = unpack("!B", p[4:5])[0]
reqdata = p[5:4+eaplen]
assert_equal(reqtype, EAP_TYPE_ID)
print "<====== Send EAP Response with identity = %s ================>" % USER
self.eapol_id_req(pkt_id, USER)
self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_HELLO_REQ
def _eapTlsHelloReq(self):
print 'Inside EAP TLS Hello Req'
p = self.eapol_recv()
code, pkt_id, eaplen = unpack("!BBH", p[0:4])
print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
assert_equal(code, EAP_REQUEST)
reqtype = unpack("!B", p[4:5])[0]
assert_equal(reqtype, EAP_TYPE_TLS)
reqdata = TLSRecord(version="TLS_1_0")/TLSHandshake()/TLSClientHello(version="TLS_1_0",
gmt_unix_time=1234,
random_bytes="A" * 28,
session_id='',
compression_methods=(TLSCompressionMethod.NULL),
cipher_suites=[TLSCipherSuite.RSA_WITH_AES_128_CBC_SHA]
)
#reqdata.show()
print "------> Sending Client Hello TLS payload of len %d ----------->" %len(reqdata)
eap_payload = self.eapTLS(EAP_RESPONSE, pkt_id, TLS_LENGTH_INCLUDED, str(reqdata))
self.eapol_send(EAPOL_EAPPACKET, eap_payload)
self.nextEvent = self.tlsEventTable.EVT_EAP_TLS_CERT_REQ
def _eapTlsCertReq(self):
print 'Inside EAP TLS Cert Req'
p = self.eapol_recv()
print 'Got TLS Cert Req with payload len: %d' %len(p)
code, pkt_id, eaplen = unpack("!BBH", p[0:4])
print "Code %d, id %d, len %d" %(code, pkt_id, eaplen)
assert_equal(code, EAP_REQUEST)
reqtype = unpack("!B", p[4:5])[0]
assert_equal(reqtype, EAP_TYPE_TLS)
rex_pem = re.compile(r'\-+BEGIN[^\-]+\-+(.*?)\-+END[^\-]+\-+', re.DOTALL)
self.pem_cert="""-----BEGIN CERTIFICATE-----
MIIE4TCCA8mgAwIBAgIJANhJTS6x4B0iMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD
VQQGEwJGUjEPMA0GA1UECBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTAT
BgNVBAoTDEV4YW1wb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0aWZpY2F0ZSBBdXRob3JpdHmCCQDYSU0useAdIjAMBgNV
HRMEBTADAQH/MDYGA1UdHwQvMC0wK6ApoCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5j
b20vZXhhbXBsZV9jYS5jcmwwDQYJKoZIhvcNAQELBQADggEBAEbkq17kbT7X/oiy
E2DOV7g1W8Au+TQR0GKzjXPgmYVGixN8l/9dQZ9WVDmCetBy71UHgTxPp20My2zr
uA7hy9FYNGtZ2jmu0p019fH+CSCL7RHHgKsY63UsldT1qPYiWiyqbWy5GvJX778N
GxVo7oN33se1c4KEmMOLVqQqX5dDWjN2r27l0GFh1ssx4RHqOc57G5Txq861i6UT
KlrN0xpyu7LjcQGMwKbfzCXfwys5i4rrAVX1spILTIihUKpD6FYxp6oj+d4ELZOh
br3zfhKrkbvPCG0gEziBLnwd11ZJELQfm89IYBhmoOYkk5+ZOszDsXKGWzfV6XSW
ZRv+LU0=
-----END CERTIFICATE-----"""
self.der_cert = rex_pem.findall(self.pem_cert)[0].decode("base64")
self.pem_priv_key = """-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA84TzkjbcskbKZnrlKcXzSSgi07n+4N7kOM7uIhzpkTuU0HIv
h4VZS2axxfV6hV3CD9MuKVg2zEhroqK1Js5n4ke230nSP/qiELfCl0R+hzRtbfKL
tFUr1iHeU0uQ6v3q+Tg1K/Tmmg72uxKrhyHDL7z0BriPjhAHJ5XlQsvR1RCMkqzu
D9wjSInJxpMMIgLndOclAKv4D1wQtYU7ZpTw+01XBlUhIiXb86qpYL9NqnnRq5JI
uhmOEuxo2ca63+xaHNhD/udSyc8C0Md/yX6wlONTRFgLLv0pdLUGm1xEjfsydaQ6
qGd7hzIKUI3hohNKJa/mHLElv7SZolPTogK/EQIDAQABAoIBAADq9FwNtuE5IRQn
zGtO4q7Y5uCzZ8GDNYr9RKp+P2cbuWDbvVAecYq2NV9QoIiWJOAYZKklOvekIju3
r0UZLA0PRiIrTg6NrESx3JrjWDK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ZuSMFOCr/lGPAoOQU0fskidGEHi1/kW+suSr28TqsyYZpwBDQ==
-----END RSA PRIVATE KEY-----
"""
self.der_priv_key = rex_pem.findall(self.pem_priv_key)[0].decode("base64")
reqdata = TLSRecord(version="TLS_1_0")/TLSHandshake()/TLSCertificateList(
certificates=[TLSCertificate(data=x509.X509Cert(self.der_cert))])
#reqdata.show()
print "------> Sending Client Hello TLS Certificate payload of len %d ----------->" %len(reqdata)
eap_payload = self.eapTLS(EAP_RESPONSE, pkt_id, TLS_LENGTH_INCLUDED, str(reqdata))
self.eapol_send(EAPOL_EAPPACKET, eap_payload)
self.nextEvent = None