[network-manager-openvpn] export: fix tls-auth export



commit 985ea72eea9c1ede160e07a47dc27f61f57aeb8d
Author: Dan Williams <dcbw redhat com>
Date:   Mon Jan 18 00:20:29 2010 -0800

    export: fix tls-auth export

 properties/import-export.c            |   26 +++++++++++++++++++++++---
 properties/tests/conf/tls.ovpn        |    1 +
 properties/tests/test-import-export.c |    7 +++++--
 3 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 298c5f1..1285765 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -457,6 +457,8 @@ do_export (const char *path, NMConnection *connection, GError **error)
 	const char *local_ip = NULL;
 	const char *remote_ip = NULL;
 	const char *tls_remote = NULL;
+	const char *tls_auth = NULL;
+	const char *tls_auth_dir = NULL;
 	gboolean success = FALSE;
 	gboolean device_tun = TRUE;
 	gboolean proto_udp = TRUE;
@@ -557,6 +559,14 @@ do_export (const char *path, NMConnection *connection, GError **error)
 	if (value && strlen (value))
 		remote_ip = value;
 
+	value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA);
+	if (value && strlen (value))
+		tls_auth = value;
+
+	value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA_DIR);
+	if (value && strlen (value))
+		tls_auth_dir = value;
+
 	/* Advanced values end */
 
 	fprintf (f, "client\n");
@@ -573,7 +583,7 @@ do_export (const char *path, NMConnection *connection, GError **error)
 	    || !strcmp(connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS))
 		fprintf (f, "auth-user-pass\n");
 
-	if (!strcmp(connection_type, NM_OPENVPN_CONTYPE_STATIC_KEY)) {
+	if (!strcmp (connection_type, NM_OPENVPN_CONTYPE_STATIC_KEY)) {
 		if (static_key) {
 			fprintf (f, "secret %s%s%s\n",
 			         static_key,
@@ -598,8 +608,18 @@ do_export (const char *path, NMConnection *connection, GError **error)
 	if (local_ip && remote_ip)
 		fprintf (f, "ifconfig %s %s\n", local_ip, remote_ip);
 
-	if (tls_remote)
-		fprintf (f,"tls-remote \"%s\"\n", tls_remote);
+	if (   !strcmp(connection_type, NM_OPENVPN_CONTYPE_TLS)
+	    || !strcmp(connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) {
+		if (tls_remote)
+			fprintf (f,"tls-remote \"%s\"\n", tls_remote);
+
+		if (tls_auth) {
+			fprintf (f, "tls-auth %s%s%s\n",
+			         tls_auth,
+			         tls_auth_dir ? " " : "",
+			         tls_auth_dir ? tls_auth_dir : "");
+		}
+	}
 
 	/* Add hard-coded stuff */
 	fprintf (f,
diff --git a/properties/tests/conf/tls.ovpn b/properties/tests/conf/tls.ovpn
index ae11c78..2748519 100644
--- a/properties/tests/conf/tls.ovpn
+++ b/properties/tests/conf/tls.ovpn
@@ -14,6 +14,7 @@ ca keys/mg8.ca
 cert keys/clee.crt
 key keys/clee.key
 
+tls-auth keys/46.key 1
 tls-remote "/CN=myvpn.company.com"
 
 comp-lzo
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index a1245ed..7f3496f 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -282,8 +282,6 @@ test_tls_import (NMVpnPluginUiInterface *plugin, const char *dir)
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_PORT, "1194");
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_STATIC_KEY, NULL);
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION, NULL);
-	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_TA, NULL);
-	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_TA_DIR, NULL);
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_CIPHER, NULL);
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_LOCAL_IP, NULL);
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_REMOTE_IP, NULL);
@@ -302,6 +300,11 @@ test_tls_import (NMVpnPluginUiInterface *plugin, const char *dir)
 	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_KEY, expected_path);
 	g_free (expected_path);
 
+	expected_path = g_strdup_printf ("%s/keys/46.key", dir);
+	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_TA, expected_path);
+	g_free (expected_path);
+	test_item ("tls-import-data", s_vpn, NM_OPENVPN_KEY_TA_DIR, "1");
+
 	/* Secrets */
 	test_secret ("tls-import-secrets", s_vpn, NM_OPENVPN_KEY_PASSWORD, NULL);
 	test_secret ("tls-import-secrets", s_vpn, NM_OPENVPN_KEY_CERTPASS, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]