From 2f2b032a1b67f6240c760d5d7842acce9c80713f Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 25 Oct 2023 16:22:47 +0200 Subject: [PATCH 1/4] Add test for group decrypt vectors --- package.json | 1 + test/index.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/package.json b/package.json index 07ccc50..baa7de6 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "ssb-meta-feeds": "~0.38.0", "ssb-query": "^2.4.5", "ssb-tribes": "^2.7.4", + "ssb-tribes-vectors": "github:ssbc/ssb-tribes", "tap-arc": "^0.3.4", "tape": "^5.2.2" }, diff --git a/test/index.js b/test/index.js index 8b789db..a26aaef 100644 --- a/test/index.js +++ b/test/index.js @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: Unlicense +const { promisify: p } = require('util') const test = require('tape') const { check } = require('ssb-encryption-format') const ssbKeys = require('ssb-keys') @@ -352,3 +353,40 @@ test('encrypt accepts keys as recps', (t) => { t.end() }) }) + +test('decrypt group vectors', async (t) => { + const vectors = [ + require('ssb-tribes-vectors/test/vectors/unbox1.json'), + require('ssb-tribes-vectors/test/vectors/unbox2.json') + ] + + for (let i = 0; i < vectors.length; i++) { + const vector = vectors[i] + + const keys = ssbKeys.generate(null, 'alice', 'classic') + const box2 = Box2() + + await p(box2.setup)({ keys }) + + // random letters, but shouldn't matter + const groupId = '%boopadoopt5CihjbOY6eZc0qCe0eKsrN2wfgXV2E3PM=.cloaked' + + await Promise.all(vector.input.trial_keys.map(trial_key => + box2.addGroupInfo(groupId, trial_key) + )) + + const msg = vector.input.msgs[0] + + const ciphertext = Buffer.from(msg.value.content.replace('.box2', ''), 'base64') + + const opts = { + previous: msg.value.previous, + author: msg.value.author + } + const decrypted = box2.decrypt(ciphertext, opts) + + const plaintext = Buffer.from(JSON.stringify(vector.output.msgsContent[0]), 'utf8') + + t.deepEqual(decrypted, plaintext, 'decrypted plaintext is the same') + } +}) From b3f9331445a8d64503849584572f0b8eb3d45767 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 25 Oct 2023 18:54:58 +0200 Subject: [PATCH 2/4] Get vectors from envelope-spec instead --- package.json | 2 +- test/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index baa7de6..bd99350 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "devDependencies": { "c8": "^7.11.0", + "envelope-spec": "github:ssbc/envelope-spec#group-test-vectors", "eslint": "^8.32.0", "fast-deep-equal": "3.1.3", "husky": "^4.3.0", @@ -48,7 +49,6 @@ "ssb-meta-feeds": "~0.38.0", "ssb-query": "^2.4.5", "ssb-tribes": "^2.7.4", - "ssb-tribes-vectors": "github:ssbc/ssb-tribes", "tap-arc": "^0.3.4", "tape": "^5.2.2" }, diff --git a/test/index.js b/test/index.js index a26aaef..02f3ed4 100644 --- a/test/index.js +++ b/test/index.js @@ -356,8 +356,8 @@ test('encrypt accepts keys as recps', (t) => { test('decrypt group vectors', async (t) => { const vectors = [ - require('ssb-tribes-vectors/test/vectors/unbox1.json'), - require('ssb-tribes-vectors/test/vectors/unbox2.json') + require('envelope-spec/vectors/unbox-group1.json'), + require('envelope-spec/vectors/unbox-group2.json') ] for (let i = 0; i < vectors.length; i++) { From 7ed6bde49c71924b5a951a8f79780e98946a1629 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 1 Nov 2023 17:53:28 +0100 Subject: [PATCH 3/4] Merge private-group-spec deps --- package.json | 3 +-- test/index.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 95e217d..4c521d0 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ ], "dependencies": { "envelope-js": "^1.3.2", - "private-group-spec": "^2.1.1", "pull-defer": "^0.2.3", "pull-stream": "^3.6.14", "ssb-bfe": "^3.7.0", @@ -32,7 +31,7 @@ "mkdirp": "^1.0.4", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", - "private-group-spec-vectors": "github:ssbc/private-group-spec#add-classic-unbox-vectors", + "private-group-spec": "github:ssbc/private-group-spec#add-classic-unbox-vectors", "pull-cat": "1.1.11", "rimraf": "^3.0.2", "secret-stack": "6.3.2", diff --git a/test/index.js b/test/index.js index 63c9212..0cde48b 100644 --- a/test/index.js +++ b/test/index.js @@ -358,8 +358,8 @@ test('encrypt accepts keys as recps', (t) => { test('decrypt group vectors', async (t) => { const vectors = [ - require('private-group-spec-vectors/vectors/unbox1.classic.json'), - require('private-group-spec-vectors/vectors/unbox2.classic.json') + require('private-group-spec/vectors/unbox1.classic.json'), + require('private-group-spec/vectors/unbox2.classic.json') ] for (let i = 0; i < vectors.length; i++) { From f9a21ef2a902bba2f828f18b8730a08188ff46d1 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Tue, 7 Nov 2023 17:36:29 +0100 Subject: [PATCH 4/4] Use private group spec release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 57bf590..a69f034 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "mkdirp": "^1.0.4", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", - "private-group-spec": "github:ssbc/private-group-spec#add-classic-unbox-vectors", + "private-group-spec": "^8.1.0", "pull-cat": "1.1.11", "rimraf": "^3.0.2", "secret-stack": "6.3.2",