git ssb

0+

Dominic / ssb-peer-invites



Commit d8e63bc4e3cc6ca4565996990f626ed2a9742fd6

be more explicit about buffer encodings

Dominic Tarr committed on 12/20/2018, 10:16:48 PM
Parent: 6da1ed2b81fa01cf82a1cb23f61b7ba7434a8770

Files changed

valid.jschanged
valid.jsView
@@ -21,8 +21,21 @@
2121 function toMsgId(msg) {
2222 return '%'+ssbKeys.hash(JSON.stringify(msg, null, 2))
2323 }
2424
25 +//derive key for private field
26 +function hash (seed) {
27 + if(!Buffer.isBuffer(seed)) throw new Error('expected seed as buffer')
28 + return u.hash(seed)
29 +}
30 +
31 +//derive key for reveal field
32 +function hash2 (seed) {
33 + if(!Buffer.isBuffer(seed)) throw new Error('expected seed as buffer')
34 + return u.hash(u.hash(seed))
35 +}
36 +
37 +
2538 exports.createInvite = function (seed, host, reveal, private, caps) {
2639 if(!isObject(caps)) throw new Error('caps *must* be provided')
2740
2841 seed = toBuffer(seed)
@@ -32,10 +45,10 @@
3245 return ssbKeys.signObj(keys, caps.userInvite, {
3346 type: 'user-invite',
3447 invite: keys.id,
3548 host: host, //sign our own key, to prove we created K
36- reveal: reveal ? u.box(reveal, u.hash(u.hash(seed))) : undefined,
37- private: private ? u.box(private, u.hash(seed)) : undefined
49 + reveal: reveal ? u.box(reveal, hash2(seed)) : undefined,
50 + private: private ? u.box(private, hash(seed)) : undefined
3851 })
3952 }
4053
4154 exports.verifyInvitePublic = function (msg, caps) {
@@ -58,13 +71,13 @@
5871
5972 seed = toBuffer(seed)
6073 exports.verifyInvitePublic(msg, caps)
6174 if(msg.content.reveal) {
62- var reveal = u.unbox(msg.content.reveal, u.hash(u.hash(seed)))
75 + var reveal = u.unbox(msg.content.reveal, hash2(seed))
6376 if(!reveal) throw code(new Error('could not decrypt reveal field'), 'decrypt-reveal-failed')
6477 }
6578 if(msg.content.private) {
66- var private = u.unbox(msg.content.private, u.hash(seed))
79 + var private = u.unbox(msg.content.private, hash(seed))
6780 if(!private) throw code(new Error('could not decrypt private field'), 'decrypt-private-failed')
6881 }
6982
7083 return {reveal: reveal, private: private}
@@ -84,9 +97,9 @@
8497 receipt: inviteId,
8598 id: id
8699 }
87100 if(msg.content.reveal)
88- content.key = u.hash(u.hash(seed)).toString('base64')
101 + content.key = hash2(seed).toString('base64')
89102 return ssbKeys.signObj(keys, caps.userInvite, content)
90103 }
91104
92105 exports.verifyAcceptOnly = function (accept, caps) {
@@ -119,9 +132,9 @@
119132 throw code(new Error('guest must use a new key, not the same seed'), 'guest-key-reuse')
120133 if(invite_msg.content.reveal) {
121134 if(!accept.content.key)
122135 throw code(new Error('accept missing reveal key, when invite has it'), 'accept-must-reveal-key')
123- reveal = u.unbox(invite_msg.content.reveal, Buffer.from(accept.content.key, 'base64'))
136 + reveal = u.unbox(invite_msg.content.reveal, toBuffer(accept.content.key))
124137 if(!reveal) throw code(new Error('accept did not correctly reveal invite'), 'decrypt-accept-reveal-failed')
125138 }
126139
127140 if(!ssbKeys.verifyObj(invite_msg.content.invite, caps.userInvite, accept.content))

Built with git-ssb-web