From aef142e38959a90113031a2888eddafda14416b0 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 16 Feb 2023 15:25:39 +0100 Subject: [PATCH 1/3] Add groupkey in init msg --- index.js | 77 ++++++++++++++++++++++++++-------------------------- package.json | 2 +- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/index.js b/index.js index 21046fb..4db8dac 100644 --- a/index.js +++ b/index.js @@ -143,30 +143,31 @@ module.exports = { }) } - function secretKeyFromPurpose(purpose) { - return new SecretKey(Buffer.from(purpose, 'base64')) + function secretKeyFromString(string) { + return new SecretKey(Buffer.from(string, 'base64')) } function createGroupWithoutMembers(myRoot, cb) { - const content = { - type: 'group/init', - tangles: { - group: { root: null, previous: null }, - }, - } - if (!initSpec(content)) return cb(new Error(initSpec.errorsString)) - findOrCreateGroupFeed(null, function gotGroupFeed(err, groupFeed) { // prettier-ignore if (err) return cb(clarify(err, 'Failed to find or create group feed when creating a group')) - const secret = secretKeyFromPurpose(groupFeed.purpose) + const secret = secretKeyFromString(groupFeed.purpose) const recps = [ { key: secret.toBuffer(), scheme: keySchemes.private_group }, myRoot.id, ] + const content = { + type: 'group/init', + groupKey: secret.toString('base64'), + tangles: { + group: { root: null, previous: null }, + }, + } + if (!initSpec(content)) return cb(new Error(initSpec.errorsString)) + ssb.db.create( { keys: groupFeed.keys, @@ -257,37 +258,37 @@ module.exports = { function create(opts = {}, cb) { if (cb === undefined) return promisify(create)(opts) - findOrCreateGroupWithoutMembers( - (err, { groupInitMsg, groupFeed, myRoot }) => { - // prettier-ignore - if (err) return cb(clarify(err, 'Failed to create group init message when creating a group')) - - const secret = secretKeyFromPurpose(groupFeed.purpose) - - const data = { - id: buildGroupId({ - groupInitMsg, - groupKey: secret.toBuffer(), - }), - secret: secret.toBuffer(), - root: fromMessageSigil(groupInitMsg.key), - subfeed: groupFeed.keys, - } + findOrCreateGroupWithoutMembers((err, group) => { + // prettier-ignore + if (err) return cb(clarify(err, 'Failed to create group init message when creating a group')) - ssb.box2.addGroupInfo(data.id, { - key: data.secret, - root: data.root, - }) + const { groupInitMsg, groupFeed, myRoot } = group - // Adding myself for recovery reasons - addMembers(data.id, [myRoot.id], {}, (err) => { - // prettier-ignore - if (err) return cb(clarify(err, 'Failed to add myself to the group when creating a group')) + const secret = secretKeyFromString(groupFeed.purpose) - return cb(null, data) - }) + const data = { + id: buildGroupId({ + groupInitMsg, + groupKey: secret.toBuffer(), + }), + secret: secret.toBuffer(), + root: fromMessageSigil(groupInitMsg.key), + subfeed: groupFeed.keys, } - ) + + ssb.box2.addGroupInfo(data.id, { + key: data.secret, + root: data.root, + }) + + // Adding myself for recovery reasons + addMembers(data.id, [myRoot.id], {}, (err) => { + // prettier-ignore + if (err) return cb(clarify(err, 'Failed to add myself to the group when creating a group')) + + return cb(null, data) + }) + }) } function get(id, cb) { diff --git a/package.json b/package.json index f48f5a0..7cb62f8 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "fast-deep-equal": "^3.1.3", "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", - "private-group-spec": "^3.0.0", + "private-group-spec": "github:ssbc/private-group-spec#groupkey-in-init", "pull-paramap": "^1.2.2", "pull-stream": "^3.7.0", "ssb-bfe": "^3.7.0", From 7c5068e6a10c0e932712274ae03471fff1a947b9 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 17 Feb 2023 14:18:43 +0100 Subject: [PATCH 2/3] Verify groupKey is in root msg --- test/create.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/create.test.js b/test/create.test.js index e9fee5e..e43b93a 100644 --- a/test/create.test.js +++ b/test/create.test.js @@ -47,6 +47,7 @@ test('create more', async (t) => { msgVal.content, { type: 'group/init', + groupKey: group.secret.toString('base64'), tangles: { group: { root: null, previous: null }, }, From 59237fa062f4d9db7e091f4493a241ad376acea5 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Mon, 20 Feb 2023 17:15:40 +0100 Subject: [PATCH 3/3] Update private group spec --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7cb62f8..4ad3c7c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "fast-deep-equal": "^3.1.3", "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", - "private-group-spec": "github:ssbc/private-group-spec#groupkey-in-init", + "private-group-spec": "^4.0.0", "pull-paramap": "^1.2.2", "pull-stream": "^3.7.0", "ssb-bfe": "^3.7.0",