blob: 848aa9bc19dcfd2cd791e6256168a874f9329d0f [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-----
A R Karthickaa10a202016-08-15 15:06:21 -070032MIIEyTCCA7GgAwIBAgIJAM6l2jUG56pLMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
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MCQGA1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
50dXRob3JpdHmCCQDOpdo1BueqSzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
51oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
52hvcNAQELBQADggEBAK+fyAFO8CbH35P5mOX+5wf7+AeC+5pwaFcoCV0zlfwniANp
53jISgcIX9rcetLxeYRAO5com3+qLdd9dGVNL0kwufH4QhlSPErG7OLHHAs4JWVhUo
54bH3lK9lgFVlnCDBtQhslzqScR64SCicWcQEjv3ZMZsJwYLvl8unSaKz4+LVPeJ2L
55opCpmZw/V/S2NhBbe3QjTiRPmDev2gbaO4GCfi/6sCDU7UO3o8KryrkeeMIiFIej
56gfwn9fovmpeqCEyupy2JNNUTJibEuFknwx7JAX+htPL27nEgwV1FYtwI3qLiZqkM
57729wo9cFSslJNZBu+GsBP5LszQSuvNTDWytV+qY=
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070058-----END CERTIFICATE-----'''
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080059
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070060 def setUp(self):
61 self.onos_ctrl = OnosCtrl(self.app)
62 self.onos_aaa_config()
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080063
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070064 def onos_aaa_config(self):
65 aaa_dict = {'apps' : { 'org.onosproject.aaa' : { 'AAA' : { 'radiusSecret': 'radius_password',
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080066 'radiusIp': '172.17.0.2' } } } }
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070067 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
68 aaa_dict['apps']['org.onosproject.aaa']['AAA']['radiusIp'] = radius_ip
69 self.onos_ctrl.activate()
70 time.sleep(2)
71 self.onos_load_config(aaa_dict)
Chetan Gaonker1f7c3f82016-03-08 12:17:37 -080072
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070073 def onos_load_config(self, config):
74 status, code = OnosCtrl.config(config)
75 if status is False:
76 log.info('Configure request for AAA returned status %d' %code)
77 assert_equal(status, True)
Chetan Gaonker41d2e072016-03-15 16:41:31 -070078 time.sleep(3)
A R Karthick22aa0c62016-05-31 11:17:12 -070079
ChetanGaonkerd43b7d42016-06-08 11:07:34 -070080 @deferred(TLS_TIMEOUT)
81 def test_eap_tls(self):
82 df = defer.Deferred()
83 def eap_tls_verify(df):
84 tls = TLSAuthTest()
85 tls.runTest()
86 df.callback(0)
87 reactor.callLater(0, eap_tls_verify, df)
88 return df
89
90 @deferred(TLS_TIMEOUT)
91 def test_eap_tls_with_no_cert(self):
92 df = defer.Deferred()
93 def eap_tls_no_cert(df):
94 def tls_no_cert_cb():
95 log.info('TLS authentication failed with no certificate')
96
97 tls = TLSAuthTest(fail_cb = tls_no_cert_cb, client_cert = '')
98 tls.runTest()
99 assert_equal(tls.failTest, True)
100 df.callback(0)
101 reactor.callLater(0, eap_tls_no_cert, df)
102 return df
103
104 @deferred(TLS_TIMEOUT)
105 def test_eap_tls_with_invalid_cert(self):
106 df = defer.Deferred()
107 def eap_tls_invalid_cert(df):
108 def tls_invalid_cert_cb():
109 log.info('TLS authentication failed with invalid certificate')
110
111 tls = TLSAuthTest(fail_cb = tls_invalid_cert_cb,
112 client_cert = self.CLIENT_CERT_INVALID)
113 tls.runTest()
114 assert_equal(tls.failTest, True)
115 df.callback(0)
116 reactor.callLater(0, eap_tls_invalid_cert, df)
117 return df
118
119 @deferred(TLS_TIMEOUT)
120 def test_eap_tls_Nusers_with_same_valid_cert(self):
121 df = defer.Deferred()
122 def eap_tls_Nusers_with_same_valid_cert(df):
123 num_users = 3
124 for i in xrange(num_users):
125 tls = TLSAuthTest(intf = 'veth{}'.format(i*2))
126 tls.runTest()
127 df.callback(0)
128 reactor.callLater(0, eap_tls_Nusers_with_same_valid_cert, df)
129 return df
A R Karthicka2e53d62016-02-19 17:38:30 -0800130
131if __name__ == '__main__':
132 t = TLSAuthTest()
133 t.runTest()