Skip to content

Commit

Permalink
fix(controller): better comments, feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Aug 18, 2016
1 parent dee6432 commit 7f17a63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ makeCommand('ap')
abbr: 'n',
help: 'Name of the network.'
})
.option('pass', {
.option('password', {
abbr: 'p',
help: 'Password to access network.'
})
Expand Down
12 changes: 9 additions & 3 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,12 @@ controller.connectToNetwork = function(opts) {
return reject('Invalid credentials: must set a password with the -p or --password option.');
}

if (security && securityOptions.indexOf(security) < 0) {
return reject(`"${security}" is not a valid security option. Please choose on of the following: ${securityOptions.join(', ')}`);
if (security) {
if (securityOptions.indexOf(security) < 0) {
return reject(`"${security}" is not a valid security option. Please choose on of the following: ${securityOptions.join(', ')}`);
} else if (security.match(/wpa2?/)) {
return reject(`"${security}" security is not yet implemented. Please see this issue for more details -> https://github.com/tessel/t2-cli/issues/803`);
}
}

if (security === 'wep') {
Expand Down Expand Up @@ -733,7 +737,7 @@ controller.setWiFiState = function(opts) {
controller.createAccessPoint = function(opts) {
opts.authorized = true;
var ssid = opts.ssid;
var password = opts.pass;
var password = opts.password;
var security = opts.security;
var securityOptions = ['none', 'wep', 'psk', 'psk2'];

Expand All @@ -752,6 +756,7 @@ controller.createAccessPoint = function(opts) {

if (security === 'wep') {
// WEP passphrases can be 10, 26, or 58 hexadecimal digits long.
// Reference -> http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=654749&isnumber=14251&punumber=5258&k2dockey=654749@ieeestds&query=%28802.11+1997%29%3Cin%3Emetadata&pos=0
// Match for hexadecimal characters:
if (isNaN(`0x${password}`)) {
return reject('Invalid passphrase: WEP keys must consist of hexadecimal digits, i.e. 0 through 9 and "a" through "f".');
Expand All @@ -765,6 +770,7 @@ controller.createAccessPoint = function(opts) {

if (security === 'psk' || security === 'psk2') {
// WPA/WPA2-PSK passphrases can be 8-63 ASCII characters, or 64 hexadecimal digits.
// Reference -> http://standards.ieee.org/getieee802/download/802.11i-2004.pdf
// Match ASCII codes for all 127 printable ASCII characters:
const asciiRegex = /^[\x00-\x7F]{8,63}$/;
// Match exactly 64 hexadecimal digits:
Expand Down

0 comments on commit 7f17a63

Please sign in to comment.