11import Logger , { formatting , LogLevel , StreamHandler } from '@matrixai/logger' ;
2- import * as events from '../dist/events.js' ;
3- import * as utils from '../dist/utils.js' ;
42import * as peculiarWebcrypto from '@peculiar/webcrypto' ;
53import * as x509 from '@peculiar/x509' ;
4+ import * as events from '../dist/events.js' ;
5+ import * as utils from '../dist/utils.js' ;
66import QUICServer from '../dist/QUICServer.js' ;
77import QUICClient from '../dist/QUICClient.js' ;
88import QUICStream from '../dist/QUICStream.js' ;
@@ -21,10 +21,7 @@ const extendedKeyUsageFlags = {
2121
2222async function generateKeyHMAC ( ) {
2323 const cryptoKey = await webcrypto . subtle . generateKey (
24- {
25- name : 'HMAC' ,
26- hash : 'SHA-256' ,
27- } ,
24+ { name : 'HMAC' , hash : 'SHA-256' } ,
2825 true ,
2926 [ 'sign' , 'verify' ] ,
3027 ) ;
@@ -51,10 +48,7 @@ async function signHMAC(key, data) {
5148 const cryptoKey = await webcrypto . subtle . importKey (
5249 'raw' ,
5350 key ,
54- {
55- name : 'HMAC' ,
56- hash : 'SHA-256' ,
57- } ,
51+ { name : 'HMAC' , hash : 'SHA-256' } ,
5852 true ,
5953 [ 'sign' , 'verify' ] ,
6054 ) ;
@@ -65,10 +59,7 @@ async function verifyHMAC(key, data, sig) {
6559 const cryptoKey = await webcrypto . subtle . importKey (
6660 'raw' ,
6761 key ,
68- {
69- name : 'HMAC' ,
70- hash : 'SHA-256' ,
71- } ,
62+ { name : 'HMAC' , hash : 'SHA-256' } ,
7263 true ,
7364 [ 'sign' , 'verify' ] ,
7465 ) ;
@@ -81,22 +72,13 @@ async function importPublicKey(publicKey) {
8172 case 'RSA' :
8273 switch ( publicKey . alg ) {
8374 case 'RS256' :
84- algorithm = {
85- name : 'RSASSA-PKCS1-v1_5' ,
86- hash : 'SHA-256' ,
87- } ;
75+ algorithm = { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-256' } ;
8876 break ;
8977 case 'RS384' :
90- algorithm = {
91- name : 'RSASSA-PKCS1-v1_5' ,
92- hash : 'SHA-384' ,
93- } ;
78+ algorithm = { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-384' } ;
9479 break ;
9580 case 'RS512' :
96- algorithm = {
97- name : 'RSASSA-PKCS1-v1_5' ,
98- hash : 'SHA-512' ,
99- } ;
81+ algorithm = { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-512' } ;
10082 break ;
10183 default :
10284 throw new Error ( `Unsupported algorithm ${ publicKey . alg } ` ) ;
@@ -110,32 +92,19 @@ async function importPublicKey(publicKey) {
11092 ] ) ;
11193}
11294
113- /**
114- * Imports private key.
115- * This uses `@peculiar/webcrypto` API for Ed25519 keys.
116- */
11795async function importPrivateKey ( privateKey ) {
11896 let algorithm ;
11997 switch ( privateKey . kty ) {
12098 case 'RSA' :
12199 switch ( privateKey . alg ) {
122100 case 'RS256' :
123- algorithm = {
124- name : 'RSASSA-PKCS1-v1_5' ,
125- hash : 'SHA-256' ,
126- } ;
101+ algorithm = { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-256' } ;
127102 break ;
128103 case 'RS384' :
129- algorithm = {
130- name : 'RSASSA-PKCS1-v1_5' ,
131- hash : 'SHA-384' ,
132- } ;
104+ algorithm = { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-384' } ;
133105 break ;
134106 case 'RS512' :
135- algorithm = {
136- name : 'RSASSA-PKCS1-v1_5' ,
137- hash : 'SHA-512' ,
138- } ;
107+ algorithm = { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-512' } ;
139108 break ;
140109 default :
141110 throw new Error ( `Unsupported algorithm ${ privateKey . alg } ` ) ;
@@ -226,11 +195,8 @@ async function generateCertificate({
226195 if ( duration < 0 ) {
227196 throw new RangeError ( '`duration` must be positive' ) ;
228197 }
229- // X509 `UTCTime` format only has resolution of seconds
230- // this truncates to second resolution
231198 const notBeforeDate = new Date ( now . getTime ( ) - ( now . getTime ( ) % 1000 ) ) ;
232199 const notAfterDate = new Date ( now . getTime ( ) - ( now . getTime ( ) % 1000 ) ) ;
233- // If the duration is 0, then only the `now` is valid
234200 notAfterDate . setSeconds ( notAfterDate . getSeconds ( ) + duration ) ;
235201 if ( notBeforeDate < new Date ( 0 ) ) {
236202 throw new RangeError (
@@ -253,26 +219,12 @@ async function generateCertificate({
253219 const serialNumber = certId ;
254220 const subjectNodeIdEncoded = Buffer . from ( subjectNodeId ) . toString ( 'hex' ) ;
255221 const issuerNodeIdEncoded = Buffer . from ( issuerNodeId ) . toString ( 'hex' ) ;
256- // The entire subject attributes and issuer attributes
257- // is constructed via `x509.Name` class
258- // By default this supports on a limited set of names:
259- // CN, L, ST, O, OU, C, DC, E, G, I, SN, T
260- // If custom names are desired, this needs to change to constructing
261- // `new x509.Name('FOO=BAR', { FOO: '1.2.3.4' })` manually
262- // And each custom attribute requires a registered OID
263- // Because the OID is what is encoded into ASN.1
264222 const subjectAttrs = [
265- {
266- CN : [ subjectNodeIdEncoded ] ,
267- } ,
268- // Filter out conflicting CN attributes
223+ { CN : [ subjectNodeIdEncoded ] } ,
269224 ...subjectAttrsExtra . filter ( ( attr ) => ! ( 'CN' in attr ) ) ,
270225 ] ;
271226 const issuerAttrs = [
272- {
273- CN : [ issuerNodeIdEncoded ] ,
274- } ,
275- // Filter out conflicting CN attributes
227+ { CN : [ issuerNodeIdEncoded ] } ,
276228 ...issuerAttrsExtra . filter ( ( attr ) => ! ( 'CN' in attr ) ) ,
277229 ] ;
278230 const signingAlgorithm = issuerPrivateCryptoKey . algorithm ;
@@ -305,34 +257,12 @@ async function generateCertificate({
305257 extendedKeyUsageFlags . ocspSigning ,
306258 ] ) ,
307259 new x509 . SubjectAlternativeNameExtension ( [
308- {
309- type : 'dns' ,
310- value : subjectNodeIdEncoded ,
311- } ,
312- {
313- type : 'dns' ,
314- value : 'localhost' ,
315- } ,
316- // Quiche doesn't support IP SANs,
317- // instead we hack these in as DNS SANs for testing purposes
318- {
319- type : 'dns' ,
320- value : '127.0.0.1' ,
321- } ,
322- // Quiche doesn't support IP SANs,
323- // instead we hack these in as DNS SANs for testing purposes
324- {
325- type : 'dns' ,
326- value : '::1' ,
327- } ,
328- {
329- type : 'ip' ,
330- value : '127.0.0.1' ,
331- } ,
332- {
333- type : 'ip' ,
334- value : '::1' ,
335- } ,
260+ { type : 'dns' , value : subjectNodeIdEncoded } ,
261+ { type : 'dns' , value : 'localhost' } ,
262+ { type : 'dns' , value : '127.0.0.1' } ,
263+ { type : 'dns' , value : '::1' } ,
264+ { type : 'ip' , value : '127.0.0.1' } ,
265+ { type : 'ip' , value : '::1' } ,
336266 ] ) ,
337267 await x509 . SubjectKeyIdentifierExtension . create ( subjectPublicCryptoKey ) ,
338268 ] ,
@@ -376,6 +306,7 @@ async function generateTLSConfig() {
376306 } ;
377307}
378308
309+ /* eslint-disable no-console */
379310const main = async ( ) => {
380311 const logger = new Logger ( `${ QUICStream . name } Test` , LogLevel . WARN , [
381312 new StreamHandler (
@@ -428,7 +359,6 @@ const main = async () => {
428359 } ) ;
429360 socketCleanMethods . extractSocket ( client ) ;
430361 const conn = ( await connectionEventProm . p ) . detail ;
431- // Do the test
432362 const activeServerStreams = [ ] ;
433363 conn . addEventListener (
434364 events . EventQUICConnectionStream . name ,
@@ -439,7 +369,6 @@ const main = async () => {
439369 } ,
440370 ) ;
441371
442- // Let's make a new streams.
443372 for ( let i = 0 ; i < 1000 ; i ++ ) {
444373 console . error ( 'loop' ) ;
445374 const stream = client . connection . newStream ( ) ;
0 commit comments