ScuttlebuttPeer.tsView |
---|
14 | 14 … | import { advertise } from "./udpPeerDiscoverer.ts"; |
15 | 15 … | |
16 | 16 … | |
17 | 17 … | export default class ScuttlebuttPeer extends EventTarget { |
18 | | - network_identifier = fromBase64( |
19 | | - "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=", |
20 | | - ); |
| 18 … | + network_identifier = config.networkIdentifier; |
21 | 19 … | keyPair = getClientKeyPair(); |
22 | 20 … | id = "@" + |
23 | 21 … | toBase64( |
24 | 22 … | this.keyPair.publicKey, |
147 | 145 … | if (!verification2) { |
148 | 146 … | throw new Error("Verification of the server's second response failed"); |
149 | 147 … | } |
150 | 148 … | |
151 | | - const serverToClientKey = sodium.crypto_hash_sha256( |
| 149 … | + const combinedSharedSecret = sodium.crypto_hash_sha256( |
152 | 150 … | concat( |
153 | | - sodium.crypto_hash_sha256(sodium.crypto_hash_sha256( |
154 | | - concat( |
155 | | - this.network_identifier, |
156 | | - shared_secret_ab, |
157 | | - shared_secret_aB, |
158 | | - shared_secret_Ab, |
159 | | - ), |
160 | | - )), |
161 | | - this.keyPair.publicKey, |
| 151 … | + this.network_identifier, |
| 152 … | + shared_secret_ab, |
| 153 … | + shared_secret_aB, |
| 154 … | + shared_secret_Ab, |
162 | 155 … | ), |
163 | 156 … | ); |
164 | 157 … | |
165 | | - const clientToServerKey = sodium.crypto_hash_sha256( |
166 | | - concat( |
167 | | - sodium.crypto_hash_sha256(sodium.crypto_hash_sha256( |
168 | | - concat( |
169 | | - this.network_identifier, |
170 | | - shared_secret_ab, |
171 | | - shared_secret_aB, |
172 | | - shared_secret_Ab, |
173 | | - ), |
174 | | - )), |
175 | | - server_longterm_pk, |
176 | | - ), |
177 | | - ); |
178 | | - |
179 | | - const network_identifier = this.network_identifier; |
180 | | - const serverToClientNonce = sodium.crypto_auth( |
| 158 … | + const connection = new BoxConnection( |
| 159 … | + conn, |
| 160 … | + combinedSharedSecret, |
| 161 … | + this.keyPair.publicKey, |
| 162 … | + server_longterm_pk, |
181 | 163 … | clientEphemeralKeyPair.publicKey, |
182 | | - network_identifier, |
183 | | - ).slice(0, 24); |
184 | | - const clientToServerNonce = sodium.crypto_auth( |
185 | 164 … | server_ephemeral_pk, |
186 | | - network_identifier, |
187 | | - ).slice(0, 24); |
188 | | - |
189 | | - const connection = new BoxConnection( |
190 | | - conn, |
191 | | - serverToClientKey, |
192 | | - serverToClientNonce, |
193 | | - clientToServerKey, |
194 | | - clientToServerNonce, |
195 | 165 … | ); |
196 | 166 … | this.connections.push(connection); |
197 | 167 … | connection.addEventListener("close", () => { |
198 | 168 … | log.debug( |
299 | 269 … | ), |
300 | 270 … | ); |
301 | 271 … | await conn.write(completionMsg); |
302 | 272 … | |
303 | | - |
304 | | - const serverToClientKey = sodium.crypto_hash_sha256( |
| 273 … | + const combinedSharedSecret = sodium.crypto_hash_sha256( |
305 | 274 … | concat( |
306 | | - sodium.crypto_hash_sha256(sodium.crypto_hash_sha256( |
307 | | - concat( |
308 | | - this.network_identifier, |
309 | | - shared_secret_ab, |
310 | | - shared_secret_aB, |
311 | | - shared_secret_Ab, |
312 | | - ), |
313 | | - )), |
314 | | - client_longterm_pk, |
| 275 … | + this.network_identifier, |
| 276 … | + shared_secret_ab, |
| 277 … | + shared_secret_aB, |
| 278 … | + shared_secret_Ab, |
315 | 279 … | ), |
316 | 280 … | ); |
317 | 281 … | |
318 | | - const clientToServerKey = sodium.crypto_hash_sha256( |
319 | | - concat( |
320 | | - sodium.crypto_hash_sha256(sodium.crypto_hash_sha256( |
321 | | - concat( |
322 | | - this.network_identifier, |
323 | | - shared_secret_ab, |
324 | | - shared_secret_aB, |
325 | | - shared_secret_Ab, |
326 | | - ), |
327 | | - )), |
328 | | - this.keyPair.publicKey, |
329 | | - ), |
330 | | - ); |
331 | | - |
332 | | - const serverToClientNonce = sodium.crypto_auth( |
333 | | - client_ephemeral_pk, |
334 | | - this.network_identifier, |
335 | | - ).slice(0, 24); |
336 | | - const clientToServerNonce = sodium.crypto_auth( |
337 | | - serverEphemeralKeyPair.publicKey, |
338 | | - this.network_identifier, |
339 | | - ).slice(0, 24); |
340 | | - |
341 | 282 … | const connection = new BoxConnection( |
342 | 283 … | conn, |
343 | | - clientToServerKey, |
344 | | - clientToServerNonce, |
345 | | - serverToClientKey, |
346 | | - serverToClientNonce, |
| 284 … | + combinedSharedSecret, |
| 285 … | + this.keyPair.publicKey, |
| 286 … | + client_longterm_pk, |
| 287 … | + serverEphemeralKeyPair.publicKey, |
| 288 … | + client_ephemeral_pk, |
347 | 289 … | ); |
348 | 290 … | this.connections.push(connection); |
349 | 291 … | connection.addEventListener("close", () => { |
350 | 292 … | log.debug( |