git ssb

1+

Dominic / ssb-private-groups



Commit 128131cbfd2df26649597c787fbf851b2c81a79d

enable groups

Dominic Tarr committed on 12/29/2018, 5:18:53 AM
Parent: 56bb6630cc8a69ba81b64ae16b943768e2708080

Files changed

index.jschanged
index.jsView
@@ -56,16 +56,14 @@
5656 var state = null
5757 //cache: {<author>: [scalar_mult(msg_keys[i], <author's latest privacy key>)]
5858 var cache = {}
5959
60-
60 + //maybe in the future, use a level db here.
6161 var remoteKeys = sbot._flumeUse('private-groups/remote-keys', Reduce(1, function (acc, data) {
6262 state = acc = acc || {}
6363 var msg = data.value
6464 if(msg.content.type === 'private-msg-key') {
65- console.log('index msg:', msg)
6665 acc[msg.author] = [{sequence: msg.sequence, key: msg.content.key}]
67- console.log('indexed', acc)
6866 cache[msg.author] = null
6967 }
7068 return acc
7169 }))
@@ -101,30 +99,35 @@
10199 if(!a_key) return console.log('no author key')
102100
103101 if(!keys_to_try)
104102 keys_to_try = cache[value.author] = keyState.msgKeys.map(function (curve) {
105- console.log("A_KEY", a_key, curve)
106103 return cl.crypto_scalarmult(
107104 Buffer.from(curve.private, 'base64'),
108105 Buffer.from(a_key, 'base64')
109106 )
110107 })
111108
112- var ctxt = u.ctxt2Buffer(content), nonce = u.id2Buffer(value.previous)
113- return group_box.unboxKey(ctxt, nonce, keys_to_try, 8)
109 + //the very first message cannot be a group_box.
110 + if(value.previous == null) return
111 + var ctxt = u.ctxt2Buffer(content)
112 + var nonce = u.id2Buffer(value.previous)
114113
115- /*
114 + var key = group_box.unboxKey(ctxt, nonce, keys_to_try, 8)
115 + if(key) return key
116 +
116117 //should group keys be included in this plugin?
118 + //yes, because box2 supports both direct keys and group keys.
117119 var group_keys = []
118120 for(var id in keyState.groupKeys)
119121 group_keys.push(getGroupMsgKey(nonce, keyState.groupKeys[id]))
122 +
120123 //note: if we only allow groups in the first 4 slots
121124 //that means better sort them before any individuals
122125 key = group_box.unboxKey( //groups we are in
123126 ctxt, nonce, group_keys, 4
124127 )
125128 if(key) return key
126- */
129 +
127130 },
128131 value: function (content, key, value) {
129132 if(!u.isBox2(content)) return
130133 var ctxt = u.ctxt2Buffer(content)
@@ -136,14 +139,14 @@
136139 })
137140
138141 return {
139142 get: remoteKeys.get,
140-// addGroupKey: function (group, cb) {
141-// af.get(function () {
142-// keyState.groupKeys[hmac(group.id, group.unbox)] = group)
143-// af.set(keys, cb)
144-// })
145-// },
143 + addGroupKey: function (group, cb) {
144 + af.get(function () {
145 + keyState.groupKeys[hmac(group.id, group.unbox)] = group)
146 + af.set(keys, cb)
147 + })
148 + },
146149 addCurvePair: function (curve_keys, cb) {
147150 onReady(function () {
148151 if(!u.isCurvePair(curve_keys))
149152 return cb(new Error('expected a pair of curve25519 keys'))

Built with git-ssb-web