Verify step

This commit is contained in:
Jiiks 2018-08-30 07:05:14 +03:00
parent 8c060314da
commit ecb0b3e9d0
2 changed files with 24 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import { Modals } from 'ui';
import { Utils } from 'common';
import PluginManager from './pluginmanager';
import Globals from './globals';
import Security from './security';
export default class {
@ -57,6 +58,19 @@ export default class {
} catch (err) {}
}
/**
* Hash and verify a package
* @param {Byte[]|String} bytesOrPath byte array of binary or path to local file
*/
static async verifyPackage(bytesOrPath) {
const bytes = typeof bytesOrPath === 'string' ? fs.readFileSync(bytesOrPath) : bytesOrPath;
// Temporary hash to simulate response from server
const tempVerified = '2e3532ee366816adc37b0f478bfef35e03f96e7aeee9b115f5918ef6a4e94de8';
const hashBytes = Security.hash('sha256', bytes, 'hex');
return hashBytes === tempVerified;
}
// TODO lots of stuff
/**
* Installs or updates defined package
@ -66,6 +80,7 @@ export default class {
*/
static async installPackage(bytesOrPath, name, update = false) {
const bytes = typeof bytesOrPath === 'string' ? fs.readFileSync(bytesOrPath) : bytesOrPath;
const outputPath = path.join(Globals.getPath('plugins'), `${name}.bd`);
fs.writeFileSync(outputPath, bytes);

View File

@ -30,6 +30,9 @@
<div v-if="verifying" slot="footer" class="bd-installModalFooter">
<span class="bd-installModalStatus">Verifying {{this.modal.contentType}}</span>
</div>
<div v-else-if="!verified" slot="footer" class="bd-installModalFooter">
<span class="bd-installModalStatus">Not verified!</span>
</div>
<div v-else-if="alreadyInstalled && upToDate" slot="footer" class="bd-installModalFooter">
<span class="bd-installModalStatus">Up to date version already installed!</span>
</div>
@ -67,14 +70,14 @@
this.upToDate = false;
}
}
// TODO Verify
setTimeout(() => {
this.verifying = false;
}, 2000);
this.verify();
},
methods: {
async verify() {
const verified = await PackageInstaller.verifyPackage(this.modal.config.path);
this.verified = verified;
this.verifying = false;
},
async install() {
const installed = await PackageInstaller.installPackage(this.modal.config.path, this.modal.config.info.name, this.alreadyInstalled);
console.log(installed);