1
1
import type { X509Certificate } from '@peculiar/x509' ;
2
- import type { QUICConfig , Crypto , Host , Hostname , Port } from '@/types' ;
2
+ import type {
3
+ QUICConfig ,
4
+ Host ,
5
+ Hostname ,
6
+ Port ,
7
+ ClientCrypto ,
8
+ ServerCrypto ,
9
+ } from '@/types' ;
3
10
import dgram from 'dgram' ;
4
11
import Logger , { LogLevel , StreamHandler , formatting } from '@matrixai/logger' ;
5
12
import QUICServer from '@/QUICServer' ;
@@ -77,24 +84,26 @@ describe(QUICServer.name, () => {
77
84
certEd25519PEM = testsUtils . certToPEM ( certEd25519 ) ;
78
85
} ) ;
79
86
// This has to be setup asynchronously due to key generation
80
- let crypto : {
81
- key : ArrayBuffer ;
82
- ops : Crypto ;
83
- } ;
87
+ let clientCrypto : ClientCrypto ;
88
+ let serverCrypto : ServerCrypto ;
89
+ let key : ArrayBuffer ;
84
90
beforeEach ( async ( ) => {
85
- crypto = {
86
- key : await testsUtils . generateKeyHMAC ( ) ,
87
- ops : {
88
- sign : testsUtils . signHMAC ,
89
- verify : testsUtils . verifyHMAC ,
90
- randomBytes : testsUtils . randomBytes ,
91
- } ,
91
+ key = await testsUtils . generateKeyHMAC ( ) ;
92
+ clientCrypto = {
93
+ randomBytes : testsUtils . randomBytes ,
94
+ } ;
95
+ serverCrypto = {
96
+ sign : testsUtils . signHMAC ,
97
+ verify : testsUtils . verifyHMAC ,
92
98
} ;
93
99
} ) ;
94
100
describe ( 'start and stop' , ( ) => {
95
101
test ( 'with RSA' , async ( ) => {
96
102
const quicServer = new QUICServer ( {
97
- crypto,
103
+ crypto : {
104
+ key,
105
+ ops : serverCrypto ,
106
+ } ,
98
107
config : {
99
108
key : keyPairRSAPEM . privateKey ,
100
109
cert : certRSAPEM ,
@@ -109,7 +118,10 @@ describe(QUICServer.name, () => {
109
118
} ) ;
110
119
test ( 'with ECDSA' , async ( ) => {
111
120
const quicServer = new QUICServer ( {
112
- crypto,
121
+ crypto : {
122
+ key,
123
+ ops : serverCrypto ,
124
+ } ,
113
125
config : {
114
126
key : keyPairECDSAPEM . privateKey ,
115
127
cert : certECDSAPEM ,
@@ -124,7 +136,10 @@ describe(QUICServer.name, () => {
124
136
} ) ;
125
137
test ( 'with Ed25519' , async ( ) => {
126
138
const quicServer = new QUICServer ( {
127
- crypto,
139
+ crypto : {
140
+ key,
141
+ ops : serverCrypto ,
142
+ } ,
128
143
config : {
129
144
key : keyPairEd25519PEM . privateKey ,
130
145
cert : certEd25519PEM ,
@@ -141,7 +156,10 @@ describe(QUICServer.name, () => {
141
156
describe ( 'binding to host and port' , ( ) => {
142
157
test ( 'listen on IPv4' , async ( ) => {
143
158
const quicServer = new QUICServer ( {
144
- crypto,
159
+ crypto : {
160
+ key,
161
+ ops : serverCrypto ,
162
+ } ,
145
163
config : {
146
164
key : keyPairEd25519PEM . privateKey ,
147
165
cert : certEd25519PEM ,
@@ -157,7 +175,10 @@ describe(QUICServer.name, () => {
157
175
} ) ;
158
176
test ( 'listen on IPv6' , async ( ) => {
159
177
const quicServer = new QUICServer ( {
160
- crypto,
178
+ crypto : {
179
+ key,
180
+ ops : serverCrypto ,
181
+ } ,
161
182
config : {
162
183
key : keyPairEd25519PEM . privateKey ,
163
184
cert : certEd25519PEM ,
@@ -173,7 +194,10 @@ describe(QUICServer.name, () => {
173
194
} ) ;
174
195
test ( 'listen on dual stack' , async ( ) => {
175
196
const quicServer = new QUICServer ( {
176
- crypto,
197
+ crypto : {
198
+ key,
199
+ ops : serverCrypto ,
200
+ } ,
177
201
config : {
178
202
key : keyPairEd25519PEM . privateKey ,
179
203
cert : certEd25519PEM ,
@@ -191,7 +215,10 @@ describe(QUICServer.name, () => {
191
215
// NOT RECOMMENDED, because send addresses will have to be mapped
192
216
// addresses, which means you can ONLY connect to mapped addresses
193
217
const quicServer = new QUICServer ( {
194
- crypto,
218
+ crypto : {
219
+ key,
220
+ ops : serverCrypto ,
221
+ } ,
195
222
config : {
196
223
key : keyPairEd25519PEM . privateKey ,
197
224
cert : certEd25519PEM ,
@@ -214,7 +241,10 @@ describe(QUICServer.name, () => {
214
241
} ) ;
215
242
test ( 'listen on hostname' , async ( ) => {
216
243
const quicServer = new QUICServer ( {
217
- crypto,
244
+ crypto : {
245
+ key,
246
+ ops : serverCrypto ,
247
+ } ,
218
248
config : {
219
249
key : keyPairEd25519PEM . privateKey ,
220
250
cert : certEd25519PEM ,
@@ -232,7 +262,10 @@ describe(QUICServer.name, () => {
232
262
} ) ;
233
263
test ( 'listen on hostname and custom resolver' , async ( ) => {
234
264
const quicServer = new QUICServer ( {
235
- crypto,
265
+ crypto : {
266
+ key,
267
+ ops : serverCrypto ,
268
+ } ,
236
269
config : {
237
270
key : keyPairEd25519PEM . privateKey ,
238
271
cert : certEd25519PEM ,
@@ -248,83 +281,84 @@ describe(QUICServer.name, () => {
248
281
await quicServer . stop ( ) ;
249
282
} ) ;
250
283
} ) ;
251
- describe . only ( 'connection bootstrap' , ( ) => {
252
- // Test without peer verification
253
- test . only ( '' , async ( ) => {
254
- const quicServer = new QUICServer ( {
255
- crypto,
256
- config : {
257
- // Key: keyPairRSAPEM.privateKey,
258
- // cert: certRSAPEM,
259
- key : keyPairECDSAPEM . privateKey ,
260
- cert : certECDSAPEM ,
261
- verifyPeer : false ,
262
- } ,
263
- logger : logger . getChild ( 'QUICServer' ) ,
264
- } ) ;
265
- await quicServer . start ( {
266
- host : '127.0.0.1' as Host ,
267
- } ) ;
268
-
269
- const scidBuffer = new ArrayBuffer ( quiche . MAX_CONN_ID_LEN ) ;
270
- await crypto . ops . randomBytes ( scidBuffer ) ;
271
- const scid = new QUICConnectionId ( scidBuffer ) ;
272
-
273
- // Verify peer
274
- // Note that you cannot send to IPv4 from dual stack socket
275
- // It must be sent as IPv4 mapped IPv6
276
-
277
- const socket = new QUICSocket ( {
278
- crypto,
279
- logger : logger . getChild ( QUICSocket . name ) ,
280
- } ) ;
281
- await socket . start ( {
282
- host : '127.0.0.1' as Host ,
283
- } ) ;
284
-
285
- // ???
286
- const clientConfig : QUICConfig = {
287
- ...clientDefault ,
288
- verifyPeer : false ,
289
- } ;
290
-
291
- // This creates a connection state
292
- // We now need to trigger it
293
- const connection = await QUICConnection . connectQUICConnection ( {
294
- scid,
295
- socket,
296
- remoteInfo : {
297
- host : quicServer . host ,
298
- port : quicServer . port ,
299
- } ,
300
- config : clientConfig ,
301
- logger : logger . getChild ( QUICConnection . name ) ,
302
- } ) ;
303
-
304
- connection . addEventListener ( 'error' , ( e ) => {
305
- console . log ( 'error' , e ) ;
306
- } ) ;
307
-
308
- // Trigger the connection
309
- await connection . send ( ) ;
310
-
311
- // Wait till it is established
312
- console . log ( 'BEFORE ESTABLISHED P' ) ;
313
- await connection . establishedP ;
314
- console . log ( 'AFTER ESTABLISHED P' ) ;
315
-
316
- // You must destroy the connection
317
- console . log ( 'DESTROY CONNECTION' ) ;
318
- await connection . destroy ( ) ;
319
- console . log ( 'DESTROYED CONNECTION' ) ;
320
-
321
- console . log ( 'STOP SOCKET' ) ;
322
- await socket . stop ( ) ;
323
- console . time ( 'STOPPED SOCKET' ) ;
324
- await quicServer . stop ( ) ;
325
- console . timeEnd ( 'STOPPED SOCKET' ) ;
326
- } ) ;
327
- } ) ;
284
+ // Describe.only('connection bootstrap', () => {
285
+ // // Test without peer verification
286
+ // test.only('', async () => {
287
+ // const quicServer = new QUICServer({
288
+ // crypto: {
289
+ // key,
290
+ // ops: serverCrypto,
291
+ // },
292
+ // config: {
293
+ // key: keyPairECDSAPEM.privateKey,
294
+ // cert: certECDSAPEM,
295
+ // verifyPeer: false,
296
+ // },
297
+ // logger: logger.getChild('QUICServer'),
298
+ // });
299
+ // await quicServer.start({
300
+ // host: '127.0.0.1' as Host,
301
+ // });
302
+ //
303
+ // const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
304
+ // await clientCrypto.randomBytes(scidBuffer);
305
+ // const scid = new QUICConnectionId(scidBuffer);
306
+ //
307
+ // // Verify peer
308
+ // // Note that you cannot send to IPv4 from dual stack socket
309
+ // // It must be sent as IPv4 mapped IPv6
310
+ //
311
+ // const socket = new QUICSocket({
312
+ // logger: logger.getChild(QUICSocket.name),
313
+ // });
314
+ // await socket.start({
315
+ // host: '127.0.0.1' as Host,
316
+ // });
317
+ //
318
+ // // ???
319
+ // const clientConfig: QUICConfig = {
320
+ // ...clientDefault,
321
+ // verifyPeer: false,
322
+ // };
323
+ //
324
+ // // This creates a connection state
325
+ // // We now need to trigger it
326
+ // const connection = await QUICConnection.createQUICConnection({
327
+ // type: 'client',
328
+ // scid,
329
+ // socket,
330
+ // remoteInfo: {
331
+ // host: quicServer.host,
332
+ // port: quicServer.port,
333
+ // },
334
+ // config: clientConfig,
335
+ // logger: logger.getChild(QUICConnection.name),
336
+ // });
337
+ //
338
+ // connection.addEventListener('error', (e) => {
339
+ // console.log('error', e);
340
+ // });
341
+ //
342
+ // // Trigger the connection
343
+ // await connection.send();
344
+ //
345
+ // // Wait till it is established
346
+ // console.log('BEFORE ESTABLISHED P');
347
+ // await connection.establishedP;
348
+ // console.log('AFTER ESTABLISHED P');
349
+ //
350
+ // // You must destroy the connection
351
+ // console.log('DESTROY CONNECTION');
352
+ // await connection.stop();
353
+ // console.log('DESTROYED CONNECTION');
354
+ //
355
+ // console.log('STOP SOCKET');
356
+ // await socket.stop();
357
+ // console.time('STOPPED SOCKET');
358
+ // await quicServer.stop();
359
+ // console.timeEnd('STOPPED SOCKET');
360
+ // });
361
+ // });
328
362
// Test('bootstrapping a new connection', async () => {
329
363
// const quicServer = new QUICServer({
330
364
// crypto,
@@ -335,50 +369,50 @@ describe(QUICServer.name, () => {
335
369
// logger: logger.getChild('QUICServer'),
336
370
// });
337
371
// await quicServer.start();
338
-
372
+ //
339
373
// const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
340
374
// await crypto.ops.randomBytes(scidBuffer);
341
375
// const scid = new QUICConnectionId(scidBuffer);
342
-
376
+ //
343
377
// const socket = new QUICSocket({
344
378
// crypto,
345
379
// resolveHostname: utils.resolveHostname,
346
380
// logger: logger.getChild(QUICSocket.name),
347
381
// });
348
382
// await socket.start();
349
-
383
+ //
350
384
// // Const config = buildQuicheConfig({
351
385
// // ...clientDefault
352
386
// // });
353
387
// // Here we want to VERIFY the peer
354
388
// // If we use the same certificate
355
389
// // then it should be consider as if it is trusted!
356
-
390
+ //
357
391
// const quicConfig: QUICConfig = {
358
392
// ...clientDefault,
359
393
// verifyPeer: true,
360
394
// };
361
-
395
+ //
362
396
// const connection = await QUICConnection.connectQUICConnection({
363
397
// scid,
364
398
// socket,
365
-
399
+ //
366
400
// remoteInfo: {
367
401
// host: utils.resolvesZeroIP(quicServer.host),
368
402
// port: quicServer.port,
369
403
// },
370
-
404
+ //
371
405
// config: quicConfig,
372
406
// });
373
-
407
+ //
374
408
// await socket.stop();
375
409
// await quicServer.stop();
376
-
410
+ //
377
411
// // We can run with several rsa keypairs and certificates
378
412
// });
379
- describe ( 'updating configuration' , ( ) => {
380
- // We want to test changing the configuration over time
381
- } ) ;
413
+ // describe('updating configuration', () => {
414
+ // // We want to test changing the configuration over time
415
+ // });
382
416
// Test hole punching, there's an initiation function
383
417
// We can make it start doing this, but technically it's the socket's duty to do this
384
418
// not just the server side
0 commit comments