Skip to content

Commit

Permalink
Save credential (Password and private key etc) in webpage memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
NI committed Aug 29, 2019
1 parent e414144 commit c815f73
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 30 deletions.
17 changes: 13 additions & 4 deletions ui/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ class Builder {
*/
constructor(command) {
this.cid = command.id();
this.builder = (n, i, r, u, y, x) => {
return command.builder(n, i, r, u, y, x);
this.builder = (n, i, r, u, y, x, l) => {
return command.builder(n, i, r, u, y, x, l);
};
this.launchCmd = (n, i, r, u, y, x) => {
return command.launch(n, i, r, u, y, x);
Expand Down Expand Up @@ -633,16 +633,25 @@ class Builder {
* @param {controls.Controls} controls
* @param {history.History} history
* @param {object} config
* @param {object} session
* @param {function} done Callback which will be called when wizard is done
*
* @returns {Wizard} Command wizard
*
*/
build(streams, controls, history, config, done) {
build(streams, controls, history, config, session, done) {
let subs = new subscribe.Subscribe();

return new Wizard(
this.builder(new Info(this), config, streams, subs, controls, history),
this.builder(
new Info(this),
config,
session,
streams,
subs,
controls,
history
),
subs,
done
);
Expand Down
32 changes: 28 additions & 4 deletions ui/commands/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export class History {
* @param {command.Info} info Command info
* @param {Date} lastUsed Last used
* @param {object} data Data
* @param {object} sessionData Data which only available for current session
*
*/
save(uname, title, lastUsed, info, data) {
save(uname, title, lastUsed, info, data, sessionData) {
for (let i in this.records) {
if (this.records[i].uname !== uname) {
continue;
Expand All @@ -58,7 +59,8 @@ export class History {
type: info.name(),
color: info.color(),
last: lastUsed.getTime(),
data: data
data: data,
session: sessionData
});

if (this.records.length > this.maxItems) {
Expand All @@ -68,7 +70,28 @@ export class History {
);
}

this.saver(this, this.records);
this.store();
}

/**
* Save current records to storage
*
*/
store() {
let r = [];

for (let i in this.records) {
r.push({
uname: this.records[i].uname,
title: this.records[i].title,
type: this.records[i].type,
color: this.records[i].color,
last: this.records[i].last,
data: this.records[i].data
});
}

this.saver(this, r);
}

/**
Expand Down Expand Up @@ -106,7 +129,8 @@ export class History {
type: this.records[i].type,
color: this.records[i].color,
last: new Date(this.records[i].last),
data: this.records[i].data
data: this.records[i].data,
session: this.records[i].session
});
}

Expand Down
57 changes: 43 additions & 14 deletions ui/commands/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,23 @@ class Wizard {
*
* @param {command.Info} info
* @param {object} config
* @param {object} session
* @param {streams.Streams} streams
* @param {subscribe.Subscribe} subs
* @param {controls.Controls} controls
* @param {history.History} history
*
*/
constructor(info, config, streams, subs, controls, history) {
constructor(info, config, session, streams, subs, controls, history) {
this.info = info;
this.hasStarted = false;
this.streams = streams;
this.config = config;
this.session = session
? session
: {
credential: ""
};
this.step = subs;
this.controls = controls;
this.history = history;
Expand Down Expand Up @@ -504,14 +510,16 @@ class Wizard {
*
* @param {stream.Sender} sender
* @param {object} configInput
* @param {object} sessionData
*
*/
buildCommand(sender, configInput) {
buildCommand(sender, configInput, sessionData) {
let self = this;

let config = {
user: common.strToUint8Array(configInput.user),
auth: getAuthMethodFromStr(configInput.authentication),
credential: sessionData.credential,
host: address.parseHostPort(configInput.host, DEFAULT_PORT),
fingerprint: configInput.fingerprint
};
Expand Down Expand Up @@ -581,7 +589,8 @@ class Wizard {
configInput.user + "@" + configInput.host,
new Date(),
self.info,
configInput
configInput,
sessionData
);
},
async "connect.fingerprint"(rd, sd) {
Expand All @@ -607,7 +616,11 @@ class Wizard {
);
},
async "connect.credential"(rd, sd) {
self.step.resolve(self.stepCredentialPrompt(rd, sd, config));
self.step.resolve(
self.stepCredentialPrompt(rd, sd, config, newCredential => {
sessionData.credential = newCredential;
})
);
},
"@stdout"(rd) {},
"@stderr"(rd) {},
Expand All @@ -630,7 +643,7 @@ class Wizard {
self.hasStarted = true;

self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, this.config);
return self.buildCommand(sd, this.config, this.session);
});

return self.stepWaitForAcceptWait();
Expand All @@ -644,12 +657,16 @@ class Wizard {
self.hasStarted = true;

self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, {
user: r.user,
authentication: r.authentication,
host: r.host,
fingerprint: ""
});
return self.buildCommand(
sd,
{
user: r.user,
authentication: r.authentication,
host: r.host,
fingerprint: ""
},
this.session
);
});

self.step.resolve(self.stepWaitForAcceptWait());
Expand Down Expand Up @@ -712,10 +729,19 @@ class Wizard {
);
}

async stepCredentialPrompt(rd, sd, config) {
async stepCredentialPrompt(rd, sd, config, newCredential) {
let self = this,
fields = [];

if (config.credential.length > 0) {
sd.send(
CLIENT_CONNECT_RESPOND_CREDENTIAL,
new TextEncoder("utf-8").encode(config.credential)
);

return this.stepContinueWaitForEstablishWait();
}

switch (config.auth) {
case AUTHMETHOD_PASSPHRASE:
fields = [{ name: "Passphrase" }];
Expand Down Expand Up @@ -743,6 +769,8 @@ class Wizard {
new TextEncoder("utf-8").encode(vv)
);

newCredential(vv);

self.step.resolve(self.stepContinueWaitForEstablishWait());
},
() => {
Expand Down Expand Up @@ -779,8 +807,8 @@ export class Command {
return "#3c8";
}

builder(info, config, streams, subs, controls, history) {
return new Wizard(info, config, streams, subs, controls, history);
builder(info, config, session, streams, subs, controls, history) {
return new Wizard(info, config, session, streams, subs, controls, history);
}

launch(info, launcher, streams, subs, controls, history) {
Expand Down Expand Up @@ -811,6 +839,7 @@ export class Command {
host: host,
authentication: auth
},
null,
streams,
subs,
controls,
Expand Down
19 changes: 12 additions & 7 deletions ui/commands/telnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,19 @@ class Wizard {
*
* @param {command.Info} info
* @param {object} config
* @param {object} session
* @param {streams.Streams} streams
* @param {subscribe.Subscribe} subs
* @param {controls.Controls} controls
* @param {history.History} history
*
*/
constructor(info, config, streams, subs, controls, history) {
constructor(info, config, session, streams, subs, controls, history) {
this.info = info;
this.hasStarted = false;
this.streams = streams;
this.config = config;
this.session = session;
this.step = subs;
this.controls = controls;
this.history = history;
Expand Down Expand Up @@ -279,9 +281,10 @@ class Wizard {
*
* @param {stream.Sender} sender
* @param {object} configInput
* @param {object} sessionData
*
*/
buildCommand(sender, configInput) {
buildCommand(sender, configInput, sessionData) {
let self = this;

let parsedConfig = {
Expand Down Expand Up @@ -333,7 +336,8 @@ class Wizard {
configInput.host,
new Date(),
self.info,
configInput
configInput,
sessionData
);
},
async "connect.failed"(rd) {
Expand All @@ -355,7 +359,7 @@ class Wizard {
self.hasStarted = true;

self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, this.config);
return self.buildCommand(sd, this.config, this.session);
});

return self.stepWaitForAcceptWait();
Expand All @@ -369,7 +373,7 @@ class Wizard {
self.hasStarted = true;

self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, r);
return self.buildCommand(sd, r, this.session);
});

self.step.resolve(self.stepWaitForAcceptWait());
Expand Down Expand Up @@ -399,8 +403,8 @@ export class Command {
return "#6ac";
}

builder(info, config, streams, subs, controls, history) {
return new Wizard(info, config, streams, subs, controls, history);
builder(info, config, session, streams, subs, controls, history) {
return new Wizard(info, config, session, streams, subs, controls, history);
}

launch(info, launcher, streams, subs, controls, history) {
Expand All @@ -417,6 +421,7 @@ export class Command {
{
host: launcher
},
null,
streams,
subs,
controls,
Expand Down
2 changes: 2 additions & 0 deletions ui/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export default {
this.controls,
this.connector.historyRec,
null,
null,
() => {}
)
};
Expand Down Expand Up @@ -361,6 +362,7 @@ export default {
this.controls,
this.connector.historyRec,
known.data,
known.session,
() => {}
)
};
Expand Down
4 changes: 4 additions & 0 deletions ui/widgets/connect_known.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@
margin-right: 5px;
font-weight: normal;
}

#connect-known-list li h2.highlight::before {
color: #eee;
}
7 changes: 6 additions & 1 deletion ui/widgets/connect_known.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
</a>
</div>
<div class="lst-wrap" @click="select(known.data)">
<h2 :title="known.data.title">{{ known.data.title }}</h2>
<h2
:title="known.data.title"
:class="{ highlight: known.data.session }"
>
{{ known.data.title }}
</h2>
Last: {{ known.data.last.toLocaleString() }}
</div>
</li>
Expand Down

0 comments on commit c815f73

Please sign in to comment.