git ssb

1+

Dominic / ssb-private-groups



Commit 56bb6630cc8a69ba81b64ae16b943768e2708080

test receiving a message after switching keys

Dominic Tarr committed on 12/27/2018, 9:50:45 PM
Parent: 9e251a0ec3bb0d48caf9ec19c7e8d4552cd44e4a

Files changed

test/index.jschanged
test/index.jsView
@@ -32,56 +32,96 @@
3232 function scalarmult (pk,sk) {
3333 return chloride.crypto_scalarmult(toBuffer(pk), toBuffer(sk))
3434 }
3535 var alice_keys = generate(hash('alice_secret2'))
36-var bob_keys = generate(hash('bob_secret2'))
36 +var bob_keys = generate(hash('bob_secret2.1'))
37 +var bob_keys2 = generate(hash('bob_secret2.2'))
3738
3839 tape('create a private-msg-key', function (t) {
40 + //normally alice would publish a 'private-msg-key' message
41 + //to advertise this key, but in this test bob is constructing
42 + //messages manually, so it's not needed.
43 + //in the future, have a way to call publish and look at the recipients
44 + //and then choose the keys.
3945 alice.privateGroups.addCurvePair(alice_keys, function (err) {
4046 if(err) throw err
41- alice.publish({
47 +
48 + //bob doesn't call addCurvePair because bob is remote.
49 + //(we are just adding his feed directly so we don't
50 + // need to bother with replication)
51 +
52 + bob.publish({
4253 type: 'private-msg-key',
43- key: alice_keys.public
44- }, function (err, msg) {
54 + key: bob_keys.public
55 + }, function (err, data) {
4556 if(err) throw err
57 + t.ok(data.key)
4658
47- //bob doesn't call addCurvePair because bob is remote.
48- //(we are just adding his feed directly so we don't
49- // need to bother with replication)
50- bob.publish({
51- type: 'private-msg-key',
52- key: bob_keys.public
53- }, function (err, data) {
54- if(err) throw err
55- t.ok(data.key)
56-
57- var content = { type: 'private', text: 'hello, alice' }
58- var ptxt = Buffer.from(JSON.stringify(content))
59- var nonce = u.id2Buffer(data.key)
60- var keys = [bob_keys, alice_keys].map(function (key) {
61- return scalarmult(bob_keys.private, key.public)
62- })
63- var ctxt = group_box.box(ptxt, nonce, keys)
64- var _key = group_box.unboxKey(ctxt, nonce, keys, 8)
65- t.ok(_key, 'message can be decrypted')
66- bob.publish(
67- ctxt.toString('base64')+'.box2',
68- function (err, data) {
59 + var content = { type: 'private', text: 'hello, alice' }
60 + var ptxt = Buffer.from(JSON.stringify(content))
61 + var nonce = u.id2Buffer(data.key)
62 + var keys = [bob_keys, alice_keys].map(function (key) {
63 + return scalarmult(bob_keys.private, key.public)
64 + })
65 + var ctxt = group_box.box(ptxt, nonce, keys)
66 + var _key = group_box.unboxKey(ctxt, nonce, keys, 8)
67 + t.ok(_key, 'message can be decrypted')
68 + bob.publish(
69 + ctxt.toString('base64')+'.box2',
70 + function (err, data) {
71 + if(err) throw err
72 + t.ok(data)
73 + alice.get({id: data.key, private: true}, function (err, msg) {
6974 if(err) throw err
70- t.ok(data)
71- alice.get({id: data.key, private: true}, function (err, msg) {
72- if(err) throw err
73- t.deepEqual(msg.content, content)
74- t.end()
75 + t.deepEqual(msg.content, content)
76 + t.end()
77 + })
78 + }
79 + )
80 + })
81 + })
82 +})
7583
76- })
77- }
78- )
79- })
84 +tape('bob switches keys', function (t) {
85 +
86 + //bob doesn't call addCurvePair because bob is remote.
87 + //(we are just adding his feed directly so we don't
88 + // need to bother with replication)
89 + bob.publish({
90 + type: 'private-msg-key',
91 + key: bob_keys2.public
92 + }, function (err, data) {
93 + if(err) throw err
94 + t.ok(data.key)
95 +
96 + var content = { type: 'private', text: 'hello again, alice!' }
97 + var ptxt = Buffer.from(JSON.stringify(content))
98 + var nonce = u.id2Buffer(data.key)
99 + var keys = [bob_keys2, alice_keys].map(function (key) {
100 + return scalarmult(bob_keys2.private, key.public)
80101 })
102 + var ctxt = group_box.box(ptxt, nonce, keys)
103 + var _key = group_box.unboxKey(ctxt, nonce, keys, 8)
104 + t.ok(_key, 'message can be decrypted')
105 + bob.publish(
106 + ctxt.toString('base64')+'.box2',
107 + function (err, data) {
108 + if(err) throw err
109 + t.ok(data)
110 + alice.get({id: data.key, private: true}, function (err, msg) {
111 + if(err) throw err
112 + console.log(msg)
113 + t.deepEqual(msg.content, content)
114 + t.end()
115 + })
116 + }
117 + )
81118 })
82119 })
83120
121 +//test that alice can decrypt messages after bob has switched
122 +//keys again.
123 +
84124 tape('cleanup', function (t) {
85125 alice.close()
86126 t.end()
87127 })

Built with git-ssb-web