This SO Q&A titled: Is there a standard that defines what is a valid SSID and password? answers some of your questions.
Section 126.96.36.199 of the 802.11-2007 specification (http://standards.ieee.org/getieee802/download/802.11-2007.pdf) defines SSIDs.
A valid SSID is 0-32 octets with arbitrary contents. A 0-length SSID indicates the wildcard SSID (in probe request frames for instance).
There's no character set associated with the SSID - a 32-byte string of NUL-bytes is a valid SSID.
- you should never use normal string functions when manipulating generic SSIDs (strcpy() and friends).
- you should not assume that the SSID is printable when, for instance, logging it to disk
There is also this comment on the answer to the SO question:
There's updated version of standard (http://standards.ieee.org/getieee802/download/802.11-2012.pdf ), which defines
SSIDEncoding field. It can be
UNSPECIFIED (for arbitrary data) or
So I would look to the latest standard for guidance and make sure you can deal with what's legal based on that.
Additionally I might be inclined to guard my self by normalize a user's input using some form of a URL encoding function (something that would work with SSID's obviously) or simply strip out illegal characters and simply not allow them prior to writing these strings to this file.
The only issues I could find with strange/special characters related to the
interfaces file were these types of bugs that were filed against the debian-installer.
debian-installer asked for my wireless networking information and
successfully used it to connect wirelessly to the network. It also
wrote my wireless networking information to /etc/network/interfaces.
However, the WPA key that I entered contained at least one special
character, and debian-installer did not escape or quote the special
character(s) in /etc/network/interfaces. The result was that, on
reboot, the system hung for a very long time during the boot process
as it tried (unsuccessfully) to re-connect to the wireless network. I
fixed the problem by simply quoting the WPA key listed in
/etc/network/interfaces. This should happen automatically if the key
contains special characters.
Also there were these bugs, one related to spaces within the SSID, the others related to the passphrase:
In either cases it would seem that wrapping the strings with double quotes is enough to protect the values for both.
Digging through the official documentation I found this bit here:
The official docs show this example:
So it would appear that spaces are allowed, so long as they're quoted correctly. Also there is this example explaining how to provide a SSID with spaces to the
Add the name (ssid) for the network you want to create/join. Use single quotes if there is a space in the name.
$ sudo iwconfig eth1 essid 'name'
I found this example which looks to be Debian under the hood, so the example may be appropriate to your situation, but it's difficult to tell for sure. I bring it up only because it shows an example of how I would've expected a URI encoding method to be exposed to protect against illegal characters.
Example 4 "Spaces in the ESSID", broadcasting essid 'Hopstock Gjestenett', with WPA key uiopzxcv
Please avoid spaces in ESSIDs. In this case we workaround with a encodeURI('Hopstock Gjestenett'), to get the following boot recipe:
So you might be able to encode the spaces that show up in SSIDs using
Digging even deeper I found this comment from the Wikipedia page on Service set (802.11 network).
Each BSS or ESS is identified by a service set identifier (SSID) - a 1 to 32 byte string. This is normally a human-readable string and thus commonly called the "network name".6 In an IBSS, the SSID is chosen by the client device that starts the network, and broadcasting of the SSID is performed in a pseudo-random order by all devices that are members of the network.
This comment is backed up by this presentation from Blackhat EU 2013, titled: Practical Exploitation Using A Malicious Service Set Identifier (SSID).
- No defined restrictions as to what characters can be used within an SSID (IEEE Std 802.11™-2012)
- Some limitation based on products
- Some character limitation (ascii only)
So technically any character is allowed in an SSID, different implementations such as Windows XP, Windows 7, vs. various Linux versions allow/disallow subsets of characters within SSIDs.