git ssb

0+

Dominic / ssb-peer-invites



Commit 81202b9f139b941aa38f6d73effefc40e2a7c378

much more tests for various error cases

Dominic Tarr committed on 3/26/2018, 4:26:28 AM
Parent: 4b01dccf7446ceaacbb44af829f67f0739b9c46d

Files changed

test/invalid.jschanged
test/invalid.jsView
@@ -54,12 +54,13 @@
5454
5555 //construct a message where host does not match
5656 var seed = hash('seed2')
5757 var keys = ssbKeys.generate(null, seed)
58 + var wrong_seed = hash('wrong_seed')
5859 var invalid = ssbKeys.signObj(keys, invite_key, {
5960 type: 'invite',
6061 invite: keys.id, //correct key
61- reveal: u.box('cannot be decrypted due to wrong key', u.hash('wrong key')),
62 + reveal: u.box({hidden: true}, u.hash(u.hash(wrong_seed))),
6263 host: alice.id
6364 })
6465 var invite_msg = v.create(null, alice, null, invalid, new Date('2018-03-26T06:14:18.377Z'))
6566
@@ -70,8 +71,11 @@
7071 }, 'user-invites:decrypt-reveal-failed')
7172
7273 //say if the invitee creates a accept message anyway.
7374
75 + throws(t, function () {
76 + i.createAccept(invite_msg, wrong_seed, bob.id)
77 + }, 'user-invites:seed-must-match-invite')
7478
7579
7680 throws(t, function () {
7781 i.createAccept(invite_msg, seed, bob.id)
@@ -90,6 +94,88 @@
9094 throws(t, function () {
9195 i.verifyAccept(accept_msg, invite_msg)
9296 }, 'user-invites:decrypt-accept-reveal-failed')
9397
98 + var accept2 = ssbKeys.signObj(ssbKeys.generate(null, seed), invite_key, {
99 + type: 'invite/accept',
100 + receipt: '%'+ssbKeys.hash(JSON.stringify(invite_msg, null, 2)),
101 + id: bob.id,
102 + key: u.hash('not the key') //what the reveal key should be.
103 + })
104 +
105 + throws(t, function () {
106 + i.verifyAccept(accept_msg, invite_msg)
107 + }, 'user-invites:decrypt-accept-reveal-failed')
108 +
94109 t.end()
95110 })
111 +
112 +tape('wrong invite', function (t) {
113 + var seed = hash('seed1')
114 +
115 + var invite1 = v.create(null, alice, null, i.createInvite(seed, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}), new Date('2018-03-14T06:14:18.377Z'))
116 +
117 + t.deepEqual({
118 + reveal: {name: 'bob'},
119 + private: {text: 'welcome to ssb!'}
120 + }, i.verifyInvitePrivate(invite1, seed))
121 +
122 +
123 + var accept_content = i.createAccept(invite1, seed, bob.id)
124 + var accept = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
125 +
126 + var seed2 = hash('seed2')
127 + var invite2 = v.create(null, alice, null, i.createInvite(seed2, alice.id, {name: 'bob'}, {text: 'welcome to ssb!'}), new Date('2018-03-14T06:14:18.377Z'))
128 +
129 + //just test we do not verify the incorrect invite
130 + throws(t, function () {
131 + i.verifyAccept(accept, invite2)
132 + }, 'user-invites:accept-wrong-invite')
133 +
134 + t.end()
135 +
136 +})
137 +
138 +tape('wrong invite', function (t) {
139 + var seed = hash('seed1')
140 +
141 + var invite = v.create(null, alice, null, i.createInvite(seed, alice.id), new Date('2018-03-14T06:14:18.377Z'))
142 + var seed2 = hash('seed2')
143 + var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed2), invite_key, {
144 + type: 'invite/accept',
145 + receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)),
146 + id: bob.id,
147 + })
148 + var accept2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
149 +
150 +
151 + //just test we do not verify the incorrect invite
152 + throws(t, function () {
153 + i.verifyAccept(accept2, invite)
154 + }, 'user-invites:accept-invite-signature-failed')
155 +
156 + t.end()
157 +})
158 +
159 +
160 +tape('wrong invite', function (t) {
161 + var seed = hash('seed1')
162 +
163 + var invite = v.create(null, alice, null, i.createInvite(seed, alice.id, 'REVEAL'), new Date('2018-03-14T06:14:18.377Z'))
164 + var accept_content = ssbKeys.signObj(ssbKeys.generate(null, seed), invite_key, {
165 + type: 'invite/accept',
166 + receipt: '%'+ssbKeys.hash(JSON.stringify(invite, null, 2)),
167 + id: bob.id,
168 + //key is missing!
169 + })
170 + var accept2 = v.create(null, bob, null, accept_content, new Date('2018-03-14T06:32:18.377Z'))
171 +
172 +
173 + //just test we do not verify the incorrect invite
174 + throws(t, function () {
175 + i.verifyAccept(accept2, invite)
176 + }, 'user-invites:accept-must-reveal-key')
177 +
178 + t.end()
179 +})
180 +
181 +

Built with git-ssb-web