groups key generation bug fix

This commit is contained in:
Adhiraj Singh
2021-09-27 12:48:57 +05:30
parent 4aaf7b6a48
commit 12105a17ee
2 changed files with 39 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
//const utils = require('../../common/utils'); //const utils = require('../../common/utils');
const SenderKeyDistributionMessage = require('./sender_key_distribution_message'); const SenderKeyDistributionMessage = require('./sender_key_distribution_message');
const keyhelper = require("libsignal/src/keyhelper"); const keyhelper = require("./keyhelper");
class GroupSessionBuilder { class GroupSessionBuilder {
constructor(senderKeyStore) { constructor(senderKeyStore) {
this.senderKeyStore = senderKeyStore; this.senderKeyStore = senderKeyStore;
@@ -21,7 +21,6 @@ class GroupSessionBuilder {
// [{"senderKeyId":1742199468,"senderChainKey":{"iteration":0,"seed":"yxMY9VFQcXEP34olRAcGCtsgx1XoKsHfDIh+1ea4HAQ="},"senderSigningKey":{"public":""}}] // [{"senderKeyId":1742199468,"senderChainKey":{"iteration":0,"seed":"yxMY9VFQcXEP34olRAcGCtsgx1XoKsHfDIh+1ea4HAQ="},"senderSigningKey":{"public":""}}]
async create(senderKeyName) { async create(senderKeyName) {
try {
const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName); const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
//console.log('GroupSessionBuilder create session', senderKeyName, senderKeyRecord); //console.log('GroupSessionBuilder create session', senderKeyName, senderKeyRecord);
@@ -42,10 +41,6 @@ class GroupSessionBuilder {
state.getSenderChainKey().getSeed(), state.getSenderChainKey().getSeed(),
state.getSigningKeyPublic() state.getSigningKeyPublic()
); );
} catch (e) {
//console.log(e.stack);
throw new Error(e);
}
} }
} }
module.exports = GroupSessionBuilder; module.exports = GroupSessionBuilder;

View File

@@ -0,0 +1,21 @@
const curve = require('libsignal/src/curve');
const nodeCrypto = require('crypto');
exports.generateSenderKey = function() {
return nodeCrypto.randomBytes(32);
}
exports.generateSenderKeyId = function() {
return nodeCrypto.randomInt(2147483647);
}
exports.generateSenderSigningKey = function(key) {
if (!key) {
key = curve.generateKeyPair();
}
return {
public: key.pubKey,
private: key.privKey,
};
}