Skip to content

Commit 731a41b

Browse files
committed
wip: tls handshake testing
1 parent b31855f commit 731a41b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type TlsConfig = {
1515

1616
type QUICConfig = {
1717
tlsConfig: TlsConfig | undefined;
18+
verifyFromPemFile: string | undefined;
1819
supportedPrivateKeyAlgos: string | undefined;
1920
verifyPeer: boolean;
2021
logKeys: string | undefined;
@@ -34,9 +35,10 @@ type QUICConfig = {
3435

3536
const clientDefault: QUICConfig = {
3637
tlsConfig: undefined,
38+
verifyFromPemFile: undefined,
3739
supportedPrivateKeyAlgos: supportedPrivateKeyAlgosDefault,
3840
logKeys: undefined,
39-
verifyPeer: false,
41+
verifyPeer: true,
4042
grease: true,
4143
maxIdleTimeout: 5000,
4244
maxRecvUdpPayloadSize: quiche.MAX_DATAGRAM_SIZE,
@@ -59,6 +61,7 @@ const clientDefault: QUICConfig = {
5961

6062
const serverDefault: QUICConfig = {
6163
tlsConfig: undefined,
64+
verifyFromPemFile: undefined,
6265
supportedPrivateKeyAlgos: supportedPrivateKeyAlgosDefault,
6366
logKeys: undefined,
6467
verifyPeer: false,
@@ -102,6 +105,9 @@ function buildQuicheConfig(config: QUICConfig): QuicheConfig {
102105
quicheConfig.loadPrivKeyFromPemFile(config.tlsConfig.privKeyFromPemFile);
103106
}
104107
}
108+
if (config.verifyFromPemFile != null) {
109+
quicheConfig.loadVerifyLocationsFromFile(config.verifyFromPemFile);
110+
}
105111
if (config.logKeys != null) {
106112
quicheConfig.logKeys();
107113
}

tests/QUICClient.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as errors from '@/errors';
99
import { fc } from '@fast-check/jest';
1010
import * as tlsUtils from './tlsUtils';
1111
import * as certFixtures from './fixtures/certFixtures';
12+
import { promise } from "@/utils";
1213

1314
const tlsArb = fc.oneof(
1415
certFixtures.tlsConfigExampleArb,
@@ -243,6 +244,43 @@ describe(QUICClient.name, () => {
243244
await server.stop();
244245
});
245246
})
247+
describe('graceful tls handshake', () => {
248+
test('handshake succeeds', async () => {
249+
const server = new QUICServer({
250+
crypto,
251+
logger: logger.getChild(QUICServer.name),
252+
config: {
253+
tlsConfig: certFixtures.tlsConfigFileRSA1,
254+
verifyPeer: true,
255+
verifyFromPemFile: certFixtures.tlsConfigFileRSA2.certChainFromPemFile
256+
}
257+
});
258+
const handleConnectionEventProm = promise<any>()
259+
server.addEventListener('connection', handleConnectionEventProm.resolveP);
260+
await server.start({
261+
host: '127.0.0.1' as Host,
262+
});
263+
// Connection should succeed
264+
const client = await QUICClient.createQUICClient({
265+
host: '::ffff:127.0.0.1' as Host,
266+
port: server.port,
267+
localHost: '::' as Host,
268+
crypto,
269+
logger: logger.getChild(QUICClient.name),
270+
config: {
271+
verifyPeer: false,
272+
tlsConfig: certFixtures.tlsConfigFileRSA2,
273+
verifyFromPemFile: certFixtures.tlsConfigFileRSA2.certChainFromPemFile
274+
}
275+
});
276+
await handleConnectionEventProm.p
277+
await client.destroy();
278+
await server.stop();
279+
})
280+
test.todo('handshake fails validation for server')
281+
test.todo('handshake fails validation for client')
282+
test.todo('handshake fails validation for both')
283+
})
246284

247285
// test('dual stack to dual stack', async () => {
248286

0 commit comments

Comments
 (0)