@@ -58,6 +58,7 @@ def test_server_mode(self):
5858 "status" : "/var/log/openvpn.status 10" ,
5959 "status_version" : 1 ,
6060 "tls_server" : True ,
61+ "tls_auth" : "tls_auth.key 0" ,
6162 "tun_ipv6" : False ,
6263 "up" : "" ,
6364 "up_delay" : 0 ,
@@ -98,6 +99,7 @@ def test_server_mode(self):
9899script-security 0
99100status /var/log/openvpn.status 10
100101status-version 1
102+ tls-auth tls_auth.key 0
101103tls-server
102104user nobody
103105verb 3
@@ -151,6 +153,7 @@ def test_client_mode(self):
151153 "status" : "/var/log/openvpn.status 30" ,
152154 "status_version" : 1 ,
153155 "tls_client" : True ,
156+ "tls_auth" : "tls_auth.key 1" ,
154157 "topology" : "p2p" ,
155158 "tun_ipv6" : True ,
156159 "up" : "/home/user/up-command.sh" ,
@@ -193,6 +196,7 @@ def test_client_mode(self):
193196script-security 1
194197status /var/log/openvpn.status 30
195198status-version 1
199+ tls-auth tls_auth.key 1
196200tls-client
197201topology p2p
198202tun-ipv6
@@ -742,3 +746,139 @@ def test_override(self):
742746 o = OpenVpn (self ._simple_conf , templates = [template ])
743747 # ensure dummy values in template have been overridden
744748 self .assertDictEqual (o .config , self ._simple_conf )
749+
750+ _openvpn_server_tls_auth_config = {
751+ "openvpn" : [
752+ {
753+ "name" : "test" ,
754+ "ca" : "/etc/openvpn/ca.pem" ,
755+ "cert" : "/etc/openvpn/cert.pem" ,
756+ "dev" : "tap0" ,
757+ "dev_type" : "tap" ,
758+ "dh" : "/etc/openvpn/dh.pem" ,
759+ "key" : "/etc/openvpn/key.pem" ,
760+ "mode" : "server" ,
761+ "proto" : "udp" ,
762+ "status" : "" ,
763+ "status_version" : 1 ,
764+ "tls_server" : True ,
765+ "tls_auth" : (
766+ "#\n "
767+ "# 2048 bit OpenVPN static key\n "
768+ "#\n -----BEGIN OpenVPN Static key V1-----\n "
769+ "tls-auth-key\n "
770+ "-----END OpenVPN Static key V1-----"
771+ ),
772+ },
773+ {
774+ "name" : "test2" ,
775+ "ca" : "/etc/openvpn/ca2.pem" ,
776+ "cert" : "/etc/openvpn/cert2.pem" ,
777+ "dev" : "tap1" ,
778+ "dev_type" : "tap" ,
779+ "dh" : "/etc/openvpn/dh2.pem" ,
780+ "key" : "/etc/openvpn/key2.pem" ,
781+ "mode" : "server" ,
782+ "proto" : "udp" ,
783+ "status" : "" ,
784+ "status_version" : 1 ,
785+ "tls_server" : True ,
786+ "tls_auth" : (
787+ "#\n "
788+ "# 2048 bit OpenVPN static key\n "
789+ "#\n -----BEGIN OpenVPN Static key V1-----\n "
790+ "tls-auth-key2\n "
791+ "-----END OpenVPN Static key V1-----"
792+ ),
793+ },
794+ ],
795+ }
796+
797+ _openvpn_server_tls_auth_render = """# openvpn config: test
798+
799+ ca /etc/openvpn/ca.pem
800+ cert /etc/openvpn/cert.pem
801+ dev tap0
802+ dev-type tap
803+ dh /etc/openvpn/dh.pem
804+ key /etc/openvpn/key.pem
805+ mode server
806+ proto udp
807+ tls-auth /etc/openvpn/tap0_tls_auth.key 0
808+ tls-server
809+
810+ # openvpn config: test2
811+
812+ ca /etc/openvpn/ca2.pem
813+ cert /etc/openvpn/cert2.pem
814+ dev tap1
815+ dev-type tap
816+ dh /etc/openvpn/dh2.pem
817+ key /etc/openvpn/key2.pem
818+ mode server
819+ proto udp
820+ tls-auth /etc/openvpn/tap1_tls_auth.key 0
821+ tls-server
822+
823+ # ---------- files ---------- #
824+
825+ # path: /etc/openvpn/tap0_tls_auth.key
826+ # mode: 0600
827+
828+ #
829+ # 2048 bit OpenVPN static key
830+ #
831+ -----BEGIN OpenVPN Static key V1-----
832+ tls-auth-key
833+ -----END OpenVPN Static key V1-----
834+
835+ # path: /etc/openvpn/tap1_tls_auth.key
836+ # mode: 0600
837+
838+ #
839+ # 2048 bit OpenVPN static key
840+ #
841+ -----BEGIN OpenVPN Static key V1-----
842+ tls-auth-key2
843+ -----END OpenVPN Static key V1-----
844+
845+ """
846+
847+ _openvpn_client_tls_auth_render = """# openvpn config: test
848+
849+ ca /etc/openvpn/ca.pem
850+ cert /etc/openvpn/cert.pem
851+ dev tap0
852+ dev-type tap
853+ key /etc/openvpn/key.pem
854+ mode p2p
855+ nobind
856+ proto udp
857+ remote vpn1.test.com 1195
858+ resolv-retry infinite
859+ tls-auth /etc/openvpn/tap0_tls_auth.key 1
860+ tls-client
861+
862+ # ---------- files ---------- #
863+
864+ # path: /etc/openvpn/tap0_tls_auth.key
865+ # mode: 0600
866+
867+ #
868+ # 2048 bit OpenVPN static key
869+ #
870+ -----BEGIN OpenVPN Static key V1-----
871+ tls-auth-key
872+ -----END OpenVPN Static key V1-----
873+
874+ """
875+
876+ def test_tls_auth_key_present (self ):
877+ server = OpenVpn (self ._openvpn_server_tls_auth_config )
878+ self .assertEqual (server .render (), self ._openvpn_server_tls_auth_render )
879+ client_config = OpenVpn .auto_client (
880+ 'vpn1.test.com' ,
881+ self ._openvpn_server_tls_auth_config ['openvpn' ][0 ],
882+ )
883+ client = OpenVpn (client_config )
884+ self .assertEqual (client .render (), self ._openvpn_client_tls_auth_render )
0 commit comments