Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for group decrypt vectors #35

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,6 +31,7 @@
"mkdirp": "^1.0.4",
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"private-group-spec": "^8.1.0",
"pull-cat": "1.1.11",
"rimraf": "^3.0.2",
"secret-stack": "6.3.2",
Expand Down
37 changes: 37 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,43 @@ test('encrypt accepts keys as recps', (t) => {
})
})

test('decrypt group vectors', async (t) => {
const vectors = [
require('private-group-spec/vectors/unbox1.classic.json'),
require('private-group-spec/vectors/unbox2.classic.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')
}
})

test('decrypt as pobox recipient', (t) => {
const box2 = Box2()
const keys = ssbKeys.generate(null, 'alice', 'classic')
Expand Down
Loading