git ssb

1+

Dominic / ssb-private-groups



Commit f57b58569dafb4a037a0648c9e7731063a14b691

get dencrypting private-message keys to work!

Dominic Tarr committed on 12/27/2018, 8:28:16 PM
Parent: d62aabe95512e6a3e72bd54fe3021aa77a550401

Files changed

index.jschanged
index.jsView
@@ -44,11 +44,12 @@
4444
4545 //state:
4646 /*
4747 {
48- <author>: {
48 + <author>: [{
49 + sequence: <sequence at which author set this key>,
4950 key: <author's latest privacy key>
50- }
51 + }]
5152 }
5253 */
5354
5455 var keyState = null
@@ -56,23 +57,20 @@
5657 //cache: {<author>: [scalar_mult(msg_keys[i], <author's latest privacy key>)]
5758 var cache = {}
5859
5960
60- sbot._flumeUse('private-groups/remote-keys', Reduce(1, function (acc, data) {
61 + var remoteKeys = sbot._flumeUse('private-groups/remote-keys', Reduce(1, function (acc, data) {
6162 state = acc = acc || {}
6263 var msg = data.value
6364 if(msg.content.type === 'private-msg-key') {
65 + console.log('index msg:', msg)
6466 acc[msg.author] = [{sequence: msg.sequence, key: msg.content.key}]
67 + console.log('indexed', acc)
6568 cache[msg.author] = null
6669 }
70 + return acc
6771 }))
6872
69- //sbot._flumeUse('private-groups/old-remote-keys', Level(1, function (data) {
70- // if(msg.content.type === 'private-msg-key') {
71- // return [msg.author, msg.sequence, msg.content.type]
72- // }
73- //})
74-
7573 sbot.addMap(function (data, cb) {
7674 if(!u.isBox2(data.value.content)) return cb(null, data)
7775 //the views and keyState have not been loaded
7876 //delay processing any box2 messages until they are.
@@ -82,15 +80,16 @@
8280 })
8381 })
8482
8583 sbot.addUnboxer({
84 + name: 'private-msg-key',
8685 key: function (content, value) {
8786 if(!u.isBox2(content)) return
8887 //a_state is reverse chrono list of author's private-msg-keys
8988 //take the latest key that has sequence less than message
9089 //to decrypt
9190 var a_state = state[value.author]
92- if(!a_state) return
91 + if(!a_state) return console.log('no author state')
9392
9493 var keys_to_try = cache[value.author]
9594 var a_key
9695 for(var i = 0; i < a_state.length; i++) {
@@ -98,9 +97,9 @@
9897 a_key = a_state[i].key
9998 break;
10099 }
101100 }
102- if(!a_key) return
101 + if(!a_key) return console.log('no author key')
103102
104103 if(!keys_to_try)
105104 keys_to_try = cache[value.author] = keyState.msgKeys.map(function (curve) {
106105 console.log("A_KEY", a_key, curve)
@@ -110,16 +109,12 @@
110109 )
111110 })
112111
113112 var ctxt = u.ctxt2Buffer(content), nonce = u.id2Buffer(value.previous)
114- // console.log('-CTXT', ctxt)
115- // console.log('-NONCE', nonce)
116-// console.log('-KEYS', keys_to_try)
117- var key = group_box.unboxKey( //direct recipients
118- ctxt, nonce, keys_to_try, 8
119- )
120- if(key) return key
113 + return group_box.unboxKey(ctxt, nonce, keys_to_try, 8)
121114
115 + /*
116 + //should group keys be included in this plugin?
122117 var group_keys = []
123118 for(var id in keyState.groupKeys)
124119 group_keys.push(getGroupMsgKey(nonce, keyState.groupKeys[id]))
125120 //note: if we only allow groups in the first 4 slots
@@ -127,36 +122,22 @@
127122 key = group_box.unboxKey( //groups we are in
128123 ctxt, nonce, group_keys, 4
129124 )
130125 if(key) return key
126 + */
131127 },
132128 value: function (content, key, value) {
133129 if(!u.isBox2(content)) return
134- console.log()
135- console.log('-------------:', value)
136130 var ctxt = u.ctxt2Buffer(content)
137131 var nonce = u.id2Buffer(value.previous)
138- console.log("INPUT", {
139- ctxt: ctxt.toString('hex'),
140- nonce: nonce,
141- key: key
142- })
143- console.log(
144- 'INPUT_VALUE',
145- cl.crypto_hash_sha256(Buffer.concat([ctxt, nonce, key])),
146- group_box.unboxBody(ctxt, nonce, key)
147- )
148- var ptxt = group_box.unboxBody(ctxt, nonce, key)
149- if(ptxt) {
150- try {
151- console.log("CONTENT", JSON.parse(ptxt.toString()))
152- return JSON.parse(ptxt.toString())
153- } catch (_) {}
154- }
132 + try {
133 + return JSON.parse(group_box.unboxBody(ctxt, nonce, key).toString())
134 + } catch (_) {}
155135 }
156136 })
157137
158138 return {
139 + get: remoteKeys.get,
159140 // addGroupKey: function (group, cb) {
160141 // af.get(function () {
161142 // keyState.groupKeys[hmac(group.id, group.unbox)] = group)
162143 // af.set(keys, cb)
@@ -187,9 +168,4 @@
187168 }
188169 }
189170 }
190171
191-
192-
193-
194-
195-

Built with git-ssb-web