blob: bdf06d9b898ddf43a9fb7311767e48e2aa335a17 [file] [log] [blame]
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07001#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07002# 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
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07007#
Chetan Gaonkercfcce782016-05-10 10:10:42 -07008# http://www.apache.org/licenses/LICENSE-2.0
ChetanGaonkerd43b7d42016-06-08 11:07:34 -07009#
Chetan Gaonkercfcce782016-05-10 10:10:42 -070010# 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#
A R Karthicka2e53d62016-02-19 17:38:30 -080016import unittest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080017import time
18import os
19from nose.tools import *
A R Karthick22aa0c62016-05-31 11:17:12 -070020from nose.twistedtools import reactor, deferred
21from twisted.internet import defer
A R Karthicka2e53d62016-02-19 17:38:30 -080022from EapTLS import TLSAuthTest
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080023from OnosCtrl import OnosCtrl
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070024from scapy.all import *
25log.setLevel('INFO')
A R Karthicka2e53d62016-02-19 17:38:30 -080026
27class eap_auth_exchange(unittest.TestCase):
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080028
A.R Karthick95d044e2016-06-10 18:44:36 -070029 app = 'org.opencord.aaa'
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070030 TLS_TIMEOUT = 20
31 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
32MIIDvTCCAqWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
33CzAJBgNVBAgTAkNBMRIwEAYDV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eDuVDoEBgErSUC44pq5ioDw2xelc+Y6hQ
50dmtYwfY0DbvwxHtA495frLyPcastDiT/zre7NL51MyUDPjjYjghNQEwvu66IKbQ3
51T1tJBrgI7/WI+dqhKBFolKGKTDWIHsZXQvZ1snGu/FRYzg1l+R/jT8cRB9BDwhUt
52yg==
53-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080054
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070055 def setUp(self):
56 self.onos_ctrl = OnosCtrl(self.app)
57 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080058
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070059 def onos_aaa_config(self):
60 aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080061 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070062 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
63 aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip
64 self.onos_ctrl.activate()
65 time.sleep(2)
66 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080067
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070068 def onos_load_config(self, config):
69 status, code = OnosCtrl.config(config)
70 if status is False:
71 log.info('Configure request for AAA returned status %d' %code)
72 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -070073 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -070074
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070075 @deferred(TLS_TIMEOUT)
76 def test_eap_tls(self):
77 df = defer.Deferred()
78 def eap_tls_verify(df):
79 tls = TLSAuthTest()
80 tls.runTest()
81 df.callback(0)
82 reactor.callLater(0, eap_tls_verify, df)
83 return df
84
85 @deferred(TLS_TIMEOUT)
86 def test_eap_tls_with_no_cert(self):
87 df = defer.Deferred()
88 def eap_tls_no_cert(df):
89 def tls_no_cert_cb():
90 log.info('TLS authentication failed with no certificate')
91
92 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
93 tls.runTest()
94 assert_equal(tls.failTest, True)
95 df.callback(0)
96 reactor.callLater(0, eap_tls_no_cert, df)
97 return df
98
99 @deferred(TLS_TIMEOUT)
100 def test_eap_tls_with_invalid_cert(self):
101 df = defer.Deferred()
102 def eap_tls_invalid_cert(df):
103 def tls_invalid_cert_cb():
104 log.info('TLS authentication failed with invalid certificate')
105
106 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
107 client_cert = self.CLIENT_CERT_INVALID)
108 tls.runTest()
109 assert_equal(tls.failTest, True)
110 df.callback(0)
111 reactor.callLater(0, eap_tls_invalid_cert, df)
112 return df
113
114 @deferred(TLS_TIMEOUT)
115 def test_eap_tls_Nusers_with_same_valid_cert(self):
116 df = defer.Deferred()
117 def eap_tls_Nusers_with_same_valid_cert(df):
118 num_users = 3
119 for i in xrange(num_users):
120 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
121 tls.runTest()
122 df.callback(0)
123 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
124 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800125
126if __name__ == '__main__':
127 t = TLSAuthTest()
128 t.runTest()