Skip to content

Commit cea873b

Browse files
committed
tests: adding custom TLS verification tests
[ci skip]
1 parent 6009eb2 commit cea873b

File tree

3 files changed

+270
-60
lines changed

3 files changed

+270
-60
lines changed

src/QUICConnection.ts

+32-28
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ class QUICConnection extends EventTarget {
682682
// If short frame
683683
if (header.ty === 5) {
684684
this.shortReceived = true;
685-
this.conn.sendAckEliciting();
686685
}
687686
}
688687

@@ -845,34 +844,39 @@ class QUICConnection extends EventTarget {
845844
sendInfo.to.host,
846845
);
847846
this.logger.debug(`sent ${sendLength} bytes`);
848-
}
849-
// Handling custom TLS verification, this must be done after the following conditions.
850-
// 1. Connection established.
851-
// 2. Certs available.
852-
// 3. Sent after connection has established.
853-
if (
854-
!this.customVerified &&
855-
this.conn.isEstablished() &&
856-
this.conn.peerCertChain() != null
857-
) {
858-
this.customVerified = true;
859-
const peerCerts = this.conn.peerCertChain();
860-
if (peerCerts == null) never();
861-
const peerCertsPem = peerCerts.map((c) => utils.certificateDERToPEM(c));
862-
// Dispatching certs available event
863-
// this.dispatchEvent(new events.QUICConnectionRemoteCertEvent()); TODO
864-
try {
865-
if (this.verifyCallback != null) this.verifyCallback(peerCertsPem);
866-
this.conn.sendAckEliciting();
867-
} catch (e) {
868-
// Force the connection to end.
869-
// Error 304 indicates cert chain failed verification.
870-
// Error 372 indicates cert chain was missing.
871-
this.conn.close(
872-
false,
873-
304,
874-
Buffer.from(`Custom TLSFail: ${e.message}`),
847+
848+
// Handling custom TLS verification, this must be done after the following conditions.
849+
// 1. Connection established.
850+
// 2. Certs available.
851+
// 3. Sent after connection has established.
852+
if (
853+
!this.customVerified &&
854+
this.conn.isEstablished() &&
855+
this.conn.peerCertChain() != null
856+
) {
857+
this.customVerified = true;
858+
const peerCerts = this.conn.peerCertChain();
859+
if (peerCerts == null) never();
860+
const peerCertsPem = peerCerts.map((c) =>
861+
utils.certificateDERToPEM(c),
875862
);
863+
try {
864+
if (this.verifyCallback != null) this.verifyCallback(peerCertsPem);
865+
this.logger.warn('TLS verification succeeded');
866+
this.conn.sendAckEliciting();
867+
} catch (e) {
868+
// Force the connection to end.
869+
// Error 304 indicates cert chain failed verification.
870+
// Error 372 indicates cert chain was missing.
871+
this.logger.warn(
872+
`TLS fail due to [${e.message}], closing connection`,
873+
);
874+
this.conn.close(
875+
false,
876+
304,
877+
Buffer.from(`Custom TLSFail: ${e.message}`),
878+
);
879+
}
876880
}
877881
}
878882

src/QUICServer.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,7 @@ class QUICServer extends EventTarget {
8484
}: {
8585
crypto: {
8686
key: ArrayBuffer;
87-
ops: {
88-
sign(key: ArrayBuffer, data: ArrayBuffer): Promise<ArrayBuffer>;
89-
verify(
90-
key: ArrayBuffer,
91-
data: ArrayBuffer,
92-
sig: ArrayBuffer,
93-
): Promise<boolean>;
94-
};
87+
ops: ServerCrypto;
9588
};
9689
config: Partial<QUICConfig> & {
9790
key: string | Array<string> | Uint8Array | Array<Uint8Array>;

0 commit comments

Comments
 (0)