Support for decorated anonymous identity prefix am: 959219308b

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/wpa_supplicant_8/+/13847810

Change-Id: I5f1edd87fe6a55500e27fc4447f9065dea5698f9
diff --git a/src/eap_common/eap_sim_common.c b/src/eap_common/eap_sim_common.c
index 4a93244..58861cd 100644
--- a/src/eap_common/eap_sim_common.c
+++ b/src/eap_common/eap_sim_common.c
@@ -1209,10 +1209,10 @@
 	}
 }
 
-
 int eap_sim_anonymous_username(const u8 *id, size_t id_len)
 {
 	static const char *anonymous_id_prefix = "anonymous@";
+	const char *decorated;
 	size_t anonymous_id_len = os_strlen(anonymous_id_prefix);
 
 	if (id_len > anonymous_id_len &&
@@ -1226,5 +1226,12 @@
 	if (id_len > 1 && id[0] == '@')
 		return 1; /* '@realm' */
 
+	/* RFC 7542 decorated username, for example;
+	   homerealm.example.org!anonymous@otherrealm.example.net */
+	decorated = os_strrchr((const char *)id, '!');
+	if (decorated && os_strlen(decorated + 1) > 1) {
+		return eap_sim_anonymous_username((const u8 *)(decorated + 1),
+				os_strlen(decorated + 1));
+	}
 	return 0;
 }