Save credential (Password and private key etc) in webpage memory.

This commit is contained in:
NI
2019-08-29 22:47:20 +08:00
parent e414144331
commit c815f73e7a
7 changed files with 108 additions and 30 deletions

View File

@@ -572,8 +572,8 @@ class Builder {
*/ */
constructor(command) { constructor(command) {
this.cid = command.id(); this.cid = command.id();
this.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); return command.builder(n, i, r, u, y, x, l);
}; };
this.launchCmd = (n, i, r, u, y, x) => { this.launchCmd = (n, i, r, u, y, x) => {
return command.launch(n, i, r, u, y, x); return command.launch(n, i, r, u, y, x);
@@ -633,16 +633,25 @@ class Builder {
* @param {controls.Controls} controls * @param {controls.Controls} controls
* @param {history.History} history * @param {history.History} history
* @param {object} config * @param {object} config
* @param {object} session
* @param {function} done Callback which will be called when wizard is done * @param {function} done Callback which will be called when wizard is done
* *
* @returns {Wizard} Command wizard * @returns {Wizard} Command wizard
* *
*/ */
build(streams, controls, history, config, done) { build(streams, controls, history, config, session, done) {
let subs = new subscribe.Subscribe(); let subs = new subscribe.Subscribe();
return new Wizard( 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, subs,
done done
); );

View File

@@ -40,9 +40,10 @@ export class History {
* @param {command.Info} info Command info * @param {command.Info} info Command info
* @param {Date} lastUsed Last used * @param {Date} lastUsed Last used
* @param {object} data Data * @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) { for (let i in this.records) {
if (this.records[i].uname !== uname) { if (this.records[i].uname !== uname) {
continue; continue;
@@ -58,7 +59,8 @@ export class History {
type: info.name(), type: info.name(),
color: info.color(), color: info.color(),
last: lastUsed.getTime(), last: lastUsed.getTime(),
data: data data: data,
session: sessionData
}); });
if (this.records.length > this.maxItems) { if (this.records.length > this.maxItems) {
@@ -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);
} }
/** /**
@@ -106,7 +129,8 @@ export class History {
type: this.records[i].type, type: this.records[i].type,
color: this.records[i].color, color: this.records[i].color,
last: new Date(this.records[i].last), last: new Date(this.records[i].last),
data: this.records[i].data data: this.records[i].data,
session: this.records[i].session
}); });
} }

View File

@@ -435,17 +435,23 @@ class Wizard {
* *
* @param {command.Info} info * @param {command.Info} info
* @param {object} config * @param {object} config
* @param {object} session
* @param {streams.Streams} streams * @param {streams.Streams} streams
* @param {subscribe.Subscribe} subs * @param {subscribe.Subscribe} subs
* @param {controls.Controls} controls * @param {controls.Controls} controls
* @param {history.History} history * @param {history.History} history
* *
*/ */
constructor(info, config, streams, subs, controls, history) { constructor(info, config, session, streams, subs, controls, history) {
this.info = info; this.info = info;
this.hasStarted = false; this.hasStarted = false;
this.streams = streams; this.streams = streams;
this.config = config; this.config = config;
this.session = session
? session
: {
credential: ""
};
this.step = subs; this.step = subs;
this.controls = controls; this.controls = controls;
this.history = history; this.history = history;
@@ -504,14 +510,16 @@ class Wizard {
* *
* @param {stream.Sender} sender * @param {stream.Sender} sender
* @param {object} configInput * @param {object} configInput
* @param {object} sessionData
* *
*/ */
buildCommand(sender, configInput) { buildCommand(sender, configInput, sessionData) {
let self = this; let self = this;
let config = { let config = {
user: common.strToUint8Array(configInput.user), user: common.strToUint8Array(configInput.user),
auth: getAuthMethodFromStr(configInput.authentication), auth: getAuthMethodFromStr(configInput.authentication),
credential: sessionData.credential,
host: address.parseHostPort(configInput.host, DEFAULT_PORT), host: address.parseHostPort(configInput.host, DEFAULT_PORT),
fingerprint: configInput.fingerprint fingerprint: configInput.fingerprint
}; };
@@ -581,7 +589,8 @@ class Wizard {
configInput.user + "@" + configInput.host, configInput.user + "@" + configInput.host,
new Date(), new Date(),
self.info, self.info,
configInput configInput,
sessionData
); );
}, },
async "connect.fingerprint"(rd, sd) { async "connect.fingerprint"(rd, sd) {
@@ -607,7 +616,11 @@ class Wizard {
); );
}, },
async "connect.credential"(rd, sd) { 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) {}, "@stdout"(rd) {},
"@stderr"(rd) {}, "@stderr"(rd) {},
@@ -630,7 +643,7 @@ class Wizard {
self.hasStarted = true; self.hasStarted = true;
self.streams.request(COMMAND_ID, sd => { self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, this.config); return self.buildCommand(sd, this.config, this.session);
}); });
return self.stepWaitForAcceptWait(); return self.stepWaitForAcceptWait();
@@ -644,12 +657,16 @@ class Wizard {
self.hasStarted = true; self.hasStarted = true;
self.streams.request(COMMAND_ID, sd => { self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, { return self.buildCommand(
user: r.user, sd,
authentication: r.authentication, {
host: r.host, user: r.user,
fingerprint: "" authentication: r.authentication,
}); host: r.host,
fingerprint: ""
},
this.session
);
}); });
self.step.resolve(self.stepWaitForAcceptWait()); self.step.resolve(self.stepWaitForAcceptWait());
@@ -712,10 +729,19 @@ class Wizard {
); );
} }
async stepCredentialPrompt(rd, sd, config) { async stepCredentialPrompt(rd, sd, config, newCredential) {
let self = this, let self = this,
fields = []; 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) { switch (config.auth) {
case AUTHMETHOD_PASSPHRASE: case AUTHMETHOD_PASSPHRASE:
fields = [{ name: "Passphrase" }]; fields = [{ name: "Passphrase" }];
@@ -743,6 +769,8 @@ class Wizard {
new TextEncoder("utf-8").encode(vv) new TextEncoder("utf-8").encode(vv)
); );
newCredential(vv);
self.step.resolve(self.stepContinueWaitForEstablishWait()); self.step.resolve(self.stepContinueWaitForEstablishWait());
}, },
() => { () => {
@@ -779,8 +807,8 @@ export class Command {
return "#3c8"; return "#3c8";
} }
builder(info, config, streams, subs, controls, history) { builder(info, config, session, streams, subs, controls, history) {
return new Wizard(info, config, streams, subs, controls, history); return new Wizard(info, config, session, streams, subs, controls, history);
} }
launch(info, launcher, streams, subs, controls, history) { launch(info, launcher, streams, subs, controls, history) {
@@ -811,6 +839,7 @@ export class Command {
host: host, host: host,
authentication: auth authentication: auth
}, },
null,
streams, streams,
subs, subs,
controls, controls,

View File

@@ -217,17 +217,19 @@ class Wizard {
* *
* @param {command.Info} info * @param {command.Info} info
* @param {object} config * @param {object} config
* @param {object} session
* @param {streams.Streams} streams * @param {streams.Streams} streams
* @param {subscribe.Subscribe} subs * @param {subscribe.Subscribe} subs
* @param {controls.Controls} controls * @param {controls.Controls} controls
* @param {history.History} history * @param {history.History} history
* *
*/ */
constructor(info, config, streams, subs, controls, history) { constructor(info, config, session, streams, subs, controls, history) {
this.info = info; this.info = info;
this.hasStarted = false; this.hasStarted = false;
this.streams = streams; this.streams = streams;
this.config = config; this.config = config;
this.session = session;
this.step = subs; this.step = subs;
this.controls = controls; this.controls = controls;
this.history = history; this.history = history;
@@ -279,9 +281,10 @@ class Wizard {
* *
* @param {stream.Sender} sender * @param {stream.Sender} sender
* @param {object} configInput * @param {object} configInput
* @param {object} sessionData
* *
*/ */
buildCommand(sender, configInput) { buildCommand(sender, configInput, sessionData) {
let self = this; let self = this;
let parsedConfig = { let parsedConfig = {
@@ -333,7 +336,8 @@ class Wizard {
configInput.host, configInput.host,
new Date(), new Date(),
self.info, self.info,
configInput configInput,
sessionData
); );
}, },
async "connect.failed"(rd) { async "connect.failed"(rd) {
@@ -355,7 +359,7 @@ class Wizard {
self.hasStarted = true; self.hasStarted = true;
self.streams.request(COMMAND_ID, sd => { self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, this.config); return self.buildCommand(sd, this.config, this.session);
}); });
return self.stepWaitForAcceptWait(); return self.stepWaitForAcceptWait();
@@ -369,7 +373,7 @@ class Wizard {
self.hasStarted = true; self.hasStarted = true;
self.streams.request(COMMAND_ID, sd => { self.streams.request(COMMAND_ID, sd => {
return self.buildCommand(sd, r); return self.buildCommand(sd, r, this.session);
}); });
self.step.resolve(self.stepWaitForAcceptWait()); self.step.resolve(self.stepWaitForAcceptWait());
@@ -399,8 +403,8 @@ export class Command {
return "#6ac"; return "#6ac";
} }
builder(info, config, streams, subs, controls, history) { builder(info, config, session, streams, subs, controls, history) {
return new Wizard(info, config, streams, subs, controls, history); return new Wizard(info, config, session, streams, subs, controls, history);
} }
launch(info, launcher, streams, subs, controls, history) { launch(info, launcher, streams, subs, controls, history) {
@@ -417,6 +421,7 @@ export class Command {
{ {
host: launcher host: launcher
}, },
null,
streams, streams,
subs, subs,
controls, controls,

View File

@@ -320,6 +320,7 @@ export default {
this.controls, this.controls,
this.connector.historyRec, this.connector.historyRec,
null, null,
null,
() => {} () => {}
) )
}; };
@@ -361,6 +362,7 @@ export default {
this.controls, this.controls,
this.connector.historyRec, this.connector.historyRec,
known.data, known.data,
known.session,
() => {} () => {}
) )
}; };

View File

@@ -109,3 +109,7 @@
margin-right: 5px; margin-right: 5px;
font-weight: normal; font-weight: normal;
} }
#connect-known-list li h2.highlight::before {
color: #eee;
}

View File

@@ -41,7 +41,12 @@
</a> </a>
</div> </div>
<div class="lst-wrap" @click="select(known.data)"> <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() }} Last: {{ known.data.last.toLocaleString() }}
</div> </div>
</li> </li>