Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoprobe the gnubby extension #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion mosh_app/mosh_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ mosh.CommandInstance = function(argv) {

// App ID of an SSH agent.
// TODO: Make this a user setting.
this.agentAppID_ = 'beknehfpfkghjoafdifaflglpjkojoco';
this.agentAppID_ = null;
this.findGnubbyExtension();
};

mosh.CommandInstance.prototype.run = function() {
Expand Down Expand Up @@ -297,3 +298,50 @@ mosh.CommandInstance.prototype.sendToAgent_ = function(data) {
var message = {'type': '[email protected]', 'data': data};
this.agentPort_.postMessage(message);
}

// Try and probe for a gnubby extension/app.
mosh.CommandInstance.prototype.findGnubbyExtension = function() {
// The possible gnubby extensions.
const stableAppId = 'beknehfpfkghjoafdifaflglpjkojoco';
const stableExtId = 'lkjlajklkdhaneeelolkfgbpikkgnkpk';
// The order matches the gnubby team preferences: https://crbug.com/902588
// Prefer the extension over the app, and dev over stable.
const extensions = [
'klnjmillfildbbimkincljmfoepfhjjj', // extension (dev)
stableExtId, // extension (stable)
'dlfcjilkjfhdnfiecknlnddkmmiofjbg', // app (dev)
stableAppId, // app (stable)
'kmendfapggjehodndflmmgagdbamhnfd', // component
];

// Ping the extension to see if it's installed/enabled/alive.
const check = (id) => new Promise((resolve, reject) => {
chrome.runtime.sendMessage(id, {'type': 'HELLO'}, (result) => {
// If the remote side doesn't exist (which is normal), Chrome complains
// if we don't read the lastError. Clear that here.
void chrome.runtime.lastError;

// If the probe worked, return the id, else return nothing so we can
// clear out all the pending promises.
if (result !== undefined && result['rc'] == 0)
resolve(id);
else
resolve();
});
});

// Guess a reasonable default based on the OS.
this.agentAppID_ = (hterm.os == 'cros' ? stableAppId : stableExtId);

// We don't set a timeout here as it doesn't block overall execution.
Promise.all(extensions.map((id) => check(id))).then((results) => {
console.log(`gnubby probe results: ${results}`);
for (let i = 0; i < extensions.length; ++i) {
const extId = extensions[i];
if (results.includes(extId)) {
nassh.GoogleRelay.defaultGnubbyExtension = extId;
break;
}
}
});
};