Merge pull request #5 from Mega-Mewthree/e2ee-dev

E2ee dev
This commit is contained in:
Mega-Mewthree 2018-08-11 18:29:38 -07:00 committed by GitHub
commit ee9cba328f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 32 deletions

View File

@ -190,43 +190,20 @@ export default new class E2EE extends BuiltinModule {
if (!this._ecdh) this._ecdh = {};
return this._ecdh;
}
get ecdh() {
if (!this._ecdh) this._ecdh = {};
return this._ecdh;
createKeyExchange(dmChannelID) {
this.ecdh[dmChannelID] = crypto.createECDH('secp521r1');
return this.ecdh[dmChannelID].generateKeys('base64');
}
createKeyExchange(userID) {
this.ecdh[userID] = crypto.createECDH('secp521r1');
return this.ecdh[userID].generateKeys('base64');
publicKeyFor(dmChannelID) {
return this.ecdh[dmChannelID].getPublicKey('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');
}
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) {
computeSecret(dmChannelID, otherKey) {
try {
const secret = this.ecdh[userID].computeSecret(otherKey, 'base64', 'base64');
delete this.ecdh[userID];
const secret = this.ecdh[dmChannelID].computeSecret(otherKey, 'base64', 'base64');
delete this.ecdh[dmChannelID];
const hash = crypto.createHash('sha256');
hash.update(secret);
return hash.digest('base64');