Skip to content

Commit

Permalink
Detect id_rsa permissions problems and bail out early. Fixes gh-1219 (#…
Browse files Browse the repository at this point in the history
…1222)

* Detect id_rsa permissions problems and bail out early. Fixes gh-1219

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>

* fs.readFileSync => fs.accessSync

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jun 5, 2017
1 parent 4692d0c commit 3a4280c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

// System Objects
var fs = require('fs');
var cp = require('child_process');
var util = require('util');

Expand Down Expand Up @@ -30,6 +31,17 @@ var responses = {
auth: 'No Tessels Found.'
};

// Alert the user that they have a permissions problem.
try {
fs.accessSync(Tessel.LOCAL_AUTH_KEY, fs.constants.R_OK | fs.constants.W_OK);
} catch (error) {
if (error.code === 'EACCES') {
log.error(`Permissions issue detected.`);
log.error(`Try using 'sudo t2 ${process.argv.slice(2).join(' ')}'`);
process.exit(1);
}
}

// Wrapper function for Tessel.list to set SSH key path
controller.list = function(opts) {
return controller.defaultHelpers(opts, Tessel.list);
Expand Down
3 changes: 1 addition & 2 deletions lib/lan-connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// System Objects
var events = require('events');
var path = require('path');
var util = require('util');

var Emitter = events.EventEmitter;
Expand Down Expand Up @@ -48,7 +47,7 @@ LAN.Connection = function(opts) {
this.ssh = undefined;

if (Tessel.isProvisioned()) {
this.auth.privateKey = opts.privateKey || fs.readFileSync(path.join(Tessel.LOCAL_AUTH_KEY));
this.auth.privateKey = opts.privateKey || fs.readFileSync(Tessel.LOCAL_AUTH_KEY);
}
};

Expand Down

0 comments on commit 3a4280c

Please sign in to comment.