Skip to content

Commit c0e6455

Browse files
committed
feat: verifyPeer now rejects if no client certificate provided
* Related #9 [ci skip]
1 parent 0f0a95a commit c0e6455

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function retry(scid: Uint8Array, dcid: Uint8Array, newScid: Uint8Array, t
132132
export function versionIsSupported(version: number): boolean
133133
export class Config {
134134
constructor()
135-
static withBoringSslCtx(certPem?: Uint8Array | undefined | null, keyPem?: Uint8Array | undefined | null, supportedKeyAlgos?: string | undefined | null, caCertPem?: Uint8Array | undefined | null): Config
135+
static withBoringSslCtx(certPem: Uint8Array | undefined | null, keyPem: Uint8Array | undefined | null, supportedKeyAlgos: string | undefined | null, caCertPem: Uint8Array | undefined | null, verifyPeer: boolean): Config
136136
loadCertChainFromPemFile(file: string): void
137137
loadPrivKeyFromPemFile(file: string): void
138138
loadVerifyLocationsFromFile(file: string): void

src/QUICConnection.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class QUICConnection extends EventTarget {
4747
public readonly establishedP: Promise<void>;
4848
protected resolveEstablishedP: () => void;
4949
protected rejectEstablishedP: (reason?: any) => void;
50+
public readonly handshakeP: Promise<void>;
51+
protected resolveHandshakeP: () => void;
5052

5153
protected logger: Logger;
5254
protected socket: QUICSocket;
@@ -224,6 +226,9 @@ class QUICConnection extends EventTarget {
224226
const { p: closedP, resolveP: resolveClosedP } = utils.promise();
225227
this.resolveCloseP = resolveClosedP;
226228
this.closedP = closedP;
229+
const { p: handshakeP, resolveP: resolveHandshakeP } = utils.promise();
230+
this.handshakeP = handshakeP;
231+
this.resolveHandshakeP = resolveHandshakeP;
227232
}
228233

229234
// Immediately call this after construction
@@ -262,6 +267,8 @@ class QUICConnection extends EventTarget {
262267
errorMessage?: string;
263268
} = {}) {
264269
this.logger.info(`Destroy ${this.constructor.name}`);
270+
// Console.log(this.conn.localError())
271+
// console.log(this.conn.peerError())
265272
for (const stream of this.streamMap.values()) {
266273
await stream.destroy();
267274
}
@@ -341,6 +348,7 @@ class QUICConnection extends EventTarget {
341348
this.logger.debug(`Did a recv ${data.byteLength}`);
342349
this.conn.recv(data, recvInfo);
343350
} catch (e) {
351+
console.error(e);
344352
this.logger.error(e.message);
345353
// Depending on the exception, the `this.conn.recv`
346354
// may have automatically started closing the connection
@@ -415,6 +423,9 @@ class QUICConnection extends EventTarget {
415423
}
416424
} finally {
417425
this.logger.debug('RECV FINALLY');
426+
this.logger.debug(
427+
` ________ ED: ${this.conn.isInEarlyData()} TO: ${this.conn.isTimedOut()} EST: ${this.conn.isEstablished()}`,
428+
);
418429

419430
// Set the timeout
420431
this.checkTimeout();
@@ -534,6 +545,9 @@ class QUICConnection extends EventTarget {
534545
}
535546
} finally {
536547
this.logger.debug('SEND FINALLY');
548+
this.logger.debug(
549+
` ________ ED: ${this.conn.isInEarlyData()} TO: ${this.conn.isTimedOut()} EST: ${this.conn.isEstablished()}`,
550+
);
537551
this.checkTimeout();
538552
this.logger.debug(
539553
`state are draining: ${this.conn.isDraining()}, closed: ${this.conn.isClosed()}`,

src/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function buildQuicheConfig(config: QUICConfig): QuicheConfig {
9494
privKeyPem,
9595
config.supportedPrivateKeyAlgos ?? null,
9696
config.verifyPem != null ? Buffer.from(config.verifyPem) : null,
97+
config.verifyPeer,
9798
);
9899
if (config.tlsConfig != null && 'certChainFromPemFile' in config.tlsConfig) {
99100
if (config.tlsConfig?.certChainFromPemFile != null) {
@@ -114,8 +115,6 @@ function buildQuicheConfig(config: QUICConfig): QuicheConfig {
114115
if (config.enableEarlyData) {
115116
quicheConfig.enableEarlyData();
116117
}
117-
118-
quicheConfig.verifyPeer(config.verifyPeer);
119118
quicheConfig.grease(config.grease);
120119
quicheConfig.setMaxIdleTimeout(config.maxIdleTimeout);
121120
quicheConfig.setMaxRecvUdpPayloadSize(config.maxRecvUdpPayloadSize);

src/native/napi/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ impl Config {
5252
key_pem: Option<Uint8Array>,
5353
supported_key_algos: Option<String>,
5454
ca_cert_pem: Option<Uint8Array>,
55+
verify_peer: bool,
5556
) -> Result<Self> {
5657
let mut ssl_ctx_builder = boring::ssl::SslContextBuilder::new(
5758
boring::ssl::SslMethod::tls(),
5859
).or_else(
5960
|err| Err(Error::from_reason(err.to_string()))
6061
)?;
62+
let verify_value = if verify_peer {boring::ssl::SslVerifyMode::PEER | boring::ssl::SslVerifyMode::FAIL_IF_NO_PEER_CERT }
63+
else { boring::ssl::SslVerifyMode::NONE };
64+
ssl_ctx_builder.set_verify(verify_value);
6165
// Processing and adding the cert chain
6266
if let Some(cert_pem) = cert_pem {
6367
let x509_cert_chain = boring::x509::X509::stack_from_pem(

src/native/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface ConfigConstructor {
4848
keyPem: Uint8Array | null,
4949
supportedKeyAlgos: string | null,
5050
ca_cert_pem: Uint8Array | null,
51+
verify_peer: boolean,
5152
): Config;
5253
}
5354

tests/QUICClient.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ describe(QUICClient.name, () => {
397397
verifyPeer: false,
398398
},
399399
});
400-
await handleConnectionEventProm.p;
401400
await client.destroy();
402401
await server.stop();
403402
},

0 commit comments

Comments
 (0)