Functions to create an ECDH key exchange

Allows 2 users to securely obtain a shared key for usage with AES.
This commit is contained in:
Mega-Mewthree 2018-08-10 09:56:55 -07:00 committed by GitHub
parent 7899312e73
commit fd7a0f4051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import { WebpackModules, ReactComponents, MonkeyPatch, Patcher } from 'modules';
import { VueInjector, Reflection } from 'ui';
import E2EEComponent from './E2EEComponent.vue';
import aes256 from 'aes256';
import crypto from 'crypto';
export default new class E2EE extends BuiltinModule {
@ -36,6 +37,29 @@ export default new class E2EE extends BuiltinModule {
handleSubmit(component, args, retVal) {
component.props.value = aes256.encrypt('randomkey', component.props.value);
}
get ecdh() {
if (!this._ecdh) this._ecdh = {};
return this._ecdh;
}
createKeyExchange(userID) {
this.ecdh[userID] = crypto.createECDH('secp521r1');
return this.ecdh[userID].generateKeys('base64');
}
publicKeyFor(userID) {
return this.ecdh[userID].getPublicKey('base64');
}
computeSecret(userID, otherKey) {
const secret = this.ecdh[userID].computeSecret(otherKey, 'base64', 'base64');
delete this.ecdh[userID];
// Hashing the shared secret future-proofs against some possible attacks.
const hash = crypto.createHash('sha256');
hash.update(secret);
return hash.digest('base64');
}
disabled(e) {
for (const patch of Patcher.getPatchesByCaller('BD:E2EE')) patch.unpatch();