[PATCH] wpa_passphrase: Encode non-ascii SSID in hex

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

 



Issue: wpa_passphrase does not encode non-ascii SSID names.
       wpa_supplicant needs the name to be encoded to identify the
       right configuration entry when connecting.
Cause: Feature is missing
Fix: Check if the SSID contains non-ascii characters and then encode it
     as a hex string without quotes.

This is my first contribution to this project.

Demo:

Current implementation:

$ wpa_passphrase "netwörk" thepassword
network={
	ssid="netwörk"
	#psk="thepassword"
	psk=30cd9c223d9ba6bf1536b2fd88947c4f21c3b0b4ce680ab502b06d293721e327
}

The password is correct. But the SSID won't be matched by
wpa_supplicant.

Patched implementation:

$ ./wpa_passphrase "netwörk" thepassword
network={
	#ssid="netwörk"
	ssid=6e657477c3b6726b
	#psk="thepassword"
	psk=30cd9c223d9ba6bf1536b2fd88947c4f21c3b0b4ce680ab502b06d293721e327
}

The patched wpa_passphrase includes the human-readable SSID as a
comment, just like what we already have for the psk parameter. In the
above example, the "ö" is represented by the two-byte sequence c3b6.

If the SSID is all-ASCII, then the old quoted SSID will be used:

$ ./wpa_passphrase "network" mypassword
network={
	ssid="network"
	#psk="mypassword"
	psk=41551420291c01bdaaa5a93798f1519e9bd31d34055cbfaad942dda786157d74
}

Signed-off-by : Jörn Bethune <bethune+hostap at posteo dot de>


diff --git a/src/utils/common.c b/src/utils/common.c
index 6acfcbd89..28bb03d6e 100644
--- a/src/utils/common.c
+++ b/src/utils/common.c
@@ -731,6 +731,17 @@ int has_newline(const char *str)
 }
 
 
+int is_within_ascii_range(const char *str)
+{
+	while (*str) {
+		if (*str < 0 || *str >= 0x80)
+			return 0;
+		str++;
+	}
+	return 1;
+}
+
+
 size_t merge_byte_arrays(u8 *res, size_t res_len,
 			 const u8 *src1, size_t src1_len,
 			 const u8 *src2, size_t src2_len)
diff --git a/src/utils/common.h b/src/utils/common.h
index 435a9a84c..5ce03d2ac 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -511,6 +511,7 @@ char * wpa_config_parse_string(const char *value, size_t *len);
 int is_hex(const u8 *data, size_t len);
 int has_ctrl_char(const u8 *data, size_t len);
 int has_newline(const char *str);
+int is_within_ascii_range(const char *str);
 size_t merge_byte_arrays(u8 *res, size_t res_len,
 			 const u8 *src1, size_t src1_len,
 			 const u8 *src2, size_t src2_len);
diff --git a/wpa_supplicant/wpa_passphrase.c b/wpa_supplicant/wpa_passphrase.c
index d9c07e673..ad942f37c 100644
--- a/wpa_supplicant/wpa_passphrase.c
+++ b/wpa_supplicant/wpa_passphrase.c
@@ -65,7 +65,17 @@ int main(int argc, char *argv[])
 	}
 
 	printf("network={\n");
-	printf("\tssid=\"%s\"\n", ssid);
+	if (is_within_ascii_range(ssid)) {
+		printf("\tssid=\"%s\"\n", ssid);
+	} else {
+		printf("\t#ssid=\"%s\"\n", ssid);
+		printf("\tssid=");
+		unsigned char * s = (unsigned char *) ssid;
+		while (*s) {
+			printf("%02x", *s++);
+		}
+		putchar('\n');
+	}
 	printf("\t#psk=\"%s\"\n", passphrase);
 	printf("\tpsk=");
 	for (i = 0; i < 32; i++)

_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap




[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux