Commit f57b58569dafb4a037a0648c9e7731063a14b691
get dencrypting private-message keys to work!
Dominic Tarr committed on 12/27/2018, 8:28:16 PMParent: d62aabe95512e6a3e72bd54fe3021aa77a550401
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -44,11 +44,12 @@ | ||
44 | 44 … | |
45 | 45 … | //state: |
46 | 46 … | /* |
47 | 47 … | { |
48 | - <author>: { | |
48 … | + <author>: [{ | |
49 … | + sequence: <sequence at which author set this key>, | |
49 | 50 … | key: <author's latest privacy key> |
50 | - } | |
51 … | + }] | |
51 | 52 … | } |
52 | 53 … | */ |
53 | 54 … | |
54 | 55 … | var keyState = null |
@@ -56,23 +57,20 @@ | ||
56 | 57 … | //cache: {<author>: [scalar_mult(msg_keys[i], <author's latest privacy key>)] |
57 | 58 … | var cache = {} |
58 | 59 … | |
59 | 60 … | |
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) { | |
61 | 62 … | state = acc = acc || {} |
62 | 63 … | var msg = data.value |
63 | 64 … | if(msg.content.type === 'private-msg-key') { |
65 … | + console.log('index msg:', msg) | |
64 | 66 … | acc[msg.author] = [{sequence: msg.sequence, key: msg.content.key}] |
67 … | + console.log('indexed', acc) | |
65 | 68 … | cache[msg.author] = null |
66 | 69 … | } |
70 … | + return acc | |
67 | 71 … | })) |
68 | 72 … | |
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 | - | |
75 | 73 … | sbot.addMap(function (data, cb) { |
76 | 74 … | if(!u.isBox2(data.value.content)) return cb(null, data) |
77 | 75 … | //the views and keyState have not been loaded |
78 | 76 … | //delay processing any box2 messages until they are. |
@@ -82,15 +80,16 @@ | ||
82 | 80 … | }) |
83 | 81 … | }) |
84 | 82 … | |
85 | 83 … | sbot.addUnboxer({ |
84 … | + name: 'private-msg-key', | |
86 | 85 … | key: function (content, value) { |
87 | 86 … | if(!u.isBox2(content)) return |
88 | 87 … | //a_state is reverse chrono list of author's private-msg-keys |
89 | 88 … | //take the latest key that has sequence less than message |
90 | 89 … | //to decrypt |
91 | 90 … | var a_state = state[value.author] |
92 | - if(!a_state) return | |
91 … | + if(!a_state) return console.log('no author state') | |
93 | 92 … | |
94 | 93 … | var keys_to_try = cache[value.author] |
95 | 94 … | var a_key |
96 | 95 … | for(var i = 0; i < a_state.length; i++) { |
@@ -98,9 +97,9 @@ | ||
98 | 97 … | a_key = a_state[i].key |
99 | 98 … | break; |
100 | 99 … | } |
101 | 100 … | } |
102 | - if(!a_key) return | |
101 … | + if(!a_key) return console.log('no author key') | |
103 | 102 … | |
104 | 103 … | if(!keys_to_try) |
105 | 104 … | keys_to_try = cache[value.author] = keyState.msgKeys.map(function (curve) { |
106 | 105 … | console.log("A_KEY", a_key, curve) |
@@ -110,16 +109,12 @@ | ||
110 | 109 … | ) |
111 | 110 … | }) |
112 | 111 … | |
113 | 112 … | 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) | |
121 | 114 … | |
115 … | + /* | |
116 … | + //should group keys be included in this plugin? | |
122 | 117 … | var group_keys = [] |
123 | 118 … | for(var id in keyState.groupKeys) |
124 | 119 … | group_keys.push(getGroupMsgKey(nonce, keyState.groupKeys[id])) |
125 | 120 … | //note: if we only allow groups in the first 4 slots |
@@ -127,36 +122,22 @@ | ||
127 | 122 … | key = group_box.unboxKey( //groups we are in |
128 | 123 … | ctxt, nonce, group_keys, 4 |
129 | 124 … | ) |
130 | 125 … | if(key) return key |
126 … | + */ | |
131 | 127 … | }, |
132 | 128 … | value: function (content, key, value) { |
133 | 129 … | if(!u.isBox2(content)) return |
134 | - console.log() | |
135 | - console.log('-------------:', value) | |
136 | 130 … | var ctxt = u.ctxt2Buffer(content) |
137 | 131 … | 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 (_) {} | |
155 | 135 … | } |
156 | 136 … | }) |
157 | 137 … | |
158 | 138 … | return { |
139 … | + get: remoteKeys.get, | |
159 | 140 … | // addGroupKey: function (group, cb) { |
160 | 141 … | // af.get(function () { |
161 | 142 … | // keyState.groupKeys[hmac(group.id, group.unbox)] = group) |
162 | 143 … | // af.set(keys, cb) |
@@ -187,9 +168,4 @@ | ||
187 | 168 … | } |
188 | 169 … | } |
189 | 170 … | } |
190 | 171 … | |
191 | - | |
192 | - | |
193 | - | |
194 | - | |
195 | - |
Built with git-ssb-web