Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed May 24, 2023
1 parent fb062ad commit 997f395
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 132 deletions.
2 changes: 1 addition & 1 deletion src/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function main(_argv = process.argv): Promise<number> {
privKeyFromPemFile: './tests/fixtures/certs/okp1.key',
certChainFromPemFile: './tests/fixtures/certs/okp1.crt',
},
}
},
});

await server.start({
Expand Down
16 changes: 11 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,19 @@ const textEncoder = new TextEncoder();

function buildQuicheConfig(config: QUICConfig): QuicheConfig {
if (config.key != null && config.cert == null) {
throw new errors.ErrorQUICConfig('The cert option must be set when key is set');
throw new errors.ErrorQUICConfig(
'The cert option must be set when key is set',
);
} else if (config.key == null && config.cert != null) {
throw new errors.ErrorQUICConfig('The key option must be set when cert is set');
throw new errors.ErrorQUICConfig(
'The key option must be set when cert is set',
);
} else if (config.key != null && config.cert != null) {
if (Array.isArray(config.key) && Array.isArray(config.cert)) {
if (config.key.length !== config.cert.length) {
throw new errors.ErrorQUICConfig('The number of keys must match the number of certs');
throw new errors.ErrorQUICConfig(
'The number of keys must match the number of certs',
);
}
}
}
Expand All @@ -166,7 +172,7 @@ function buildQuicheConfig(config: QUICConfig): QuicheConfig {
// This is an array of private keys in PEM format
let keyPEMBuffers: Array<Uint8Array> | undefined;
if (config.key != null) {
let keyPEMs: Array<string> = [];
const keyPEMs: Array<string> = [];
if (typeof config.key === 'string') {
keyPEMs.push(config.key.trim() + '\n');
} else if (config.key instanceof Uint8Array) {
Expand All @@ -185,7 +191,7 @@ function buildQuicheConfig(config: QUICConfig): QuicheConfig {
// This is an array of certificate chains in PEM format
let certChainPEMBuffers: Array<Uint8Array> | undefined;
if (config.cert != null) {
let certChainPEMs: Array<string> = [];
const certChainPEMs: Array<string> = [];
if (typeof config.cert === 'string') {
certChainPEMs.push(config.cert.trim() + '\n');
} else if (config.cert instanceof Uint8Array) {
Expand Down
22 changes: 7 additions & 15 deletions tests/QUICServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe(QUICServer.name, () => {
tlsConfig: {
privKeyPem: keyPairRSAPEM.privateKey,
certChainPem: certRSAPEM,
}
},
},
logger: logger.getChild('QUICServer'),
});
Expand All @@ -117,7 +117,7 @@ describe(QUICServer.name, () => {
tlsConfig: {
privKeyPem: keyPairECDSAPEM.privateKey,
certChainPem: certECDSAPEM,
}
},
},
logger: logger.getChild('QUICServer'),
});
Expand All @@ -134,7 +134,7 @@ describe(QUICServer.name, () => {
tlsConfig: {
privKeyPem: keyPairEd25519PEM.privateKey,
certChainPem: certEd25519PEM,
}
},
},
logger: logger.getChild('QUICServer'),
});
Expand All @@ -152,26 +152,24 @@ describe(QUICServer.name, () => {
tlsConfig: {
privKeyPem: keyPairEd25519PEM.privateKey,
certChainPem: certEd25519PEM,
}
},
},
logger: logger.getChild('QUICServer'),
});
await quicServer.start();



const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
await crypto.ops.randomBytes(scidBuffer);
const scid = new QUICConnectionId(scidBuffer);

const socket = new QUICSocket({
crypto,
resolveHostname: utils.resolveHostname,
logger: logger.getChild(QUICSocket.name)
logger: logger.getChild(QUICSocket.name),
});
await socket.start();

// const config = buildQuicheConfig({
// Const config = buildQuicheConfig({
// ...clientDefault
// });
// Here we want to VERIFY the peer
Expand All @@ -180,10 +178,9 @@ describe(QUICServer.name, () => {

const quicConfig: QUICConfig = {
...clientDefault,
verifyPeer: true
verifyPeer: true,
};


const connection = await QUICConnection.connectQUICConnection({
scid,
socket,
Expand All @@ -194,19 +191,14 @@ describe(QUICServer.name, () => {
},

config: quicConfig,

});


await socket.stop();
await quicServer.stop();

// We can run with several rsa keypairs and certificates

});
describe('updating configuration', () => {

// We want to test changing the configuration over time

});
});
Loading

0 comments on commit 997f395

Please sign in to comment.