From 19a4a604105c9e8292df59d4f15dd2d69ffefcb7 Mon Sep 17 00:00:00 2001
From: Jonathan Kang <jonathan121537@gmail.com>
Date: Thu, 24 Nov 2016 15:02:37 +0800
Subject: [PATCH] add support for TTLS/MSCHAPV2

Currently, nm-applet only support TTLS/EAP-MSCHAPV2. It makes users
unable to connect to wifis that only supports TTLS/MSCHAPv2.

https://bugzilla.gnome.org/show_bug.cgi?id=768489
---
 src/wireless-security/eap-method-simple.c | 15 ++++++++-------
 src/wireless-security/eap-method-simple.h |  1 +
 src/wireless-security/eap-method-ttls.c   | 26 ++++++++++++++++++++++----
 3 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c
index 411bba6..a6e9bc4 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -115,13 +115,14 @@ typedef struct {
 
 /* Indexed by EAP_METHOD_SIMPLE_TYPE_* */
 static const EapType eap_table[EAP_METHOD_SIMPLE_TYPE_LAST] = {
-	[EAP_METHOD_SIMPLE_TYPE_PAP]       = { "pap",      FALSE },
-	[EAP_METHOD_SIMPLE_TYPE_MSCHAP]    = { "mschap",   FALSE },
-	[EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2] = { "mschapv2", TRUE  },
-	[EAP_METHOD_SIMPLE_TYPE_MD5]       = { "md5",      TRUE  },
-	[EAP_METHOD_SIMPLE_TYPE_PWD]       = { "pwd",      TRUE  },
-	[EAP_METHOD_SIMPLE_TYPE_CHAP]      = { "chap",     FALSE },
-	[EAP_METHOD_SIMPLE_TYPE_GTC]       = { "gtc",      TRUE  },
+	[EAP_METHOD_SIMPLE_TYPE_PAP]           = { "pap",      FALSE },
+	[EAP_METHOD_SIMPLE_TYPE_MSCHAP]        = { "mschap",   FALSE },
+	[EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2]     = { "mschapv2", FALSE },
+	[EAP_METHOD_SIMPLE_TYPE_EAP_MSCHAP_V2] = { "mschapv2", TRUE  },
+	[EAP_METHOD_SIMPLE_TYPE_MD5]           = { "md5",      TRUE  },
+	[EAP_METHOD_SIMPLE_TYPE_PWD]           = { "pwd",      TRUE  },
+	[EAP_METHOD_SIMPLE_TYPE_CHAP]          = { "chap",     FALSE },
+	[EAP_METHOD_SIMPLE_TYPE_GTC]           = { "gtc",      TRUE  },
 };
 
 static void
diff --git a/src/wireless-security/eap-method-simple.h b/src/wireless-security/eap-method-simple.h
index 293d17b..af01c80 100644
--- a/src/wireless-security/eap-method-simple.h
+++ b/src/wireless-security/eap-method-simple.h
@@ -30,6 +30,7 @@ typedef enum {
 	EAP_METHOD_SIMPLE_TYPE_PAP = 0,
 	EAP_METHOD_SIMPLE_TYPE_MSCHAP,
 	EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2,
+	EAP_METHOD_SIMPLE_TYPE_EAP_MSCHAP_V2,
 	EAP_METHOD_SIMPLE_TYPE_MD5,
 	EAP_METHOD_SIMPLE_TYPE_PWD,
 	EAP_METHOD_SIMPLE_TYPE_CHAP,
diff --git a/src/wireless-security/eap-method-ttls.c b/src/wireless-security/eap-method-ttls.c
index 789f0fa..6030908 100644
--- a/src/wireless-security/eap-method-ttls.c
+++ b/src/wireless-security/eap-method-ttls.c
@@ -227,6 +227,7 @@ inner_auth_combo_init (EAPMethodTTLS *method,
 	EAPMethodSimple *em_pap;
 	EAPMethodSimple *em_mschap;
 	EAPMethodSimple *em_mschap_v2;
+	EAPMethodSimple *em_eap_mschap_v2;
 	EAPMethodSimple *em_chap;
 	EAPMethodSimple *em_md5;
 	EAPMethodSimple *em_gtc;
@@ -291,9 +292,26 @@ inner_auth_combo_init (EAPMethodTTLS *method,
 	eap_method_unref (EAP_METHOD (em_mschap_v2));
 
 	/* Check for defaulting to MSCHAPv2 */
-	if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2"))
+	if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2") &&
+	    nm_setting_802_1x_get_phase2_auth (s_8021x) != NULL)
 		active = 2;
 
+	em_eap_mschap_v2 = eap_method_simple_new (method->sec_parent,
+	                                          connection,
+	                                          EAP_METHOD_SIMPLE_TYPE_EAP_MSCHAP_V2,
+	                                          simple_flags);
+	gtk_list_store_append (auth_model, &iter);
+	gtk_list_store_set (auth_model, &iter,
+	                    I_NAME_COLUMN, _("EAP-MSCHAPv2"),
+	                    I_METHOD_COLUMN, em_eap_mschap_v2,
+	                    -1);
+	eap_method_unref (EAP_METHOD (em_eap_mschap_v2));
+
+	/* Check for defaulting to EAP-MSCHAPv2 */
+	if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2") &&
+	    nm_setting_802_1x_get_phase2_autheap (s_8021x) != NULL)
+		active = 3;
+
 	em_chap = eap_method_simple_new (method->sec_parent,
 	                                 connection,
 	                                 EAP_METHOD_SIMPLE_TYPE_CHAP,
@@ -307,7 +325,7 @@ inner_auth_combo_init (EAPMethodTTLS *method,
 
 	/* Check for defaulting to CHAP */
 	if (phase2_auth && !strcasecmp (phase2_auth, "chap"))
-		active = 3;
+		active = 4;
 
 	em_md5 = eap_method_simple_new (method->sec_parent,
 	                                connection,
@@ -322,7 +340,7 @@ inner_auth_combo_init (EAPMethodTTLS *method,
 
 	/* Check for defaulting to MD5 */
 	if (phase2_auth && !strcasecmp (phase2_auth, "md5"))
-		active = 4;
+		active = 5;
 
 	em_gtc = eap_method_simple_new (method->sec_parent,
 	                                connection,
@@ -337,7 +355,7 @@ inner_auth_combo_init (EAPMethodTTLS *method,
 
 	/* Check for defaulting to GTC */
 	if (phase2_auth && !strcasecmp (phase2_auth, "gtc"))
-		active = 5;
+		active = 6;
 
 	combo = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_ttls_inner_auth_combo"));
 	g_assert (combo);
-- 
2.9.3

