Skip to content

Commit aa51a92

Browse files
committed
chore(proxy-support): naming fixes and more comments
1 parent 30c3ab1 commit aa51a92

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/devtools-proxy-support/src/system-ca.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export function parseCACerts(
6868
try {
6969
parsed = new X509Certificate(pem);
7070
} catch (err: unknown) {
71+
// Most definitely should happen never or extremely rarely, in case it
72+
// does, if this cert will affect the TLS connection verification, the
73+
// connection will most definitely fail and we'll se it in the logs. For
74+
// that reason we're just logging, but not throwing an error here
7175
messages.push(
7276
`Unable to parse certificate: ${
7377
err && typeof err === 'object' && 'message' in err
@@ -80,15 +84,14 @@ export function parseCACerts(
8084
});
8185
}
8286

83-
function doesCertificateHasMatchingIssuer(
84-
{ parsed }: ParsedX509Cert,
87+
function certificateHasMatchingIssuer(
88+
cert: X509Certificate,
8589
certs: ParsedX509Cert[]
8690
) {
8791
return (
88-
!parsed ||
89-
parsed.checkIssued(parsed) ||
92+
cert.checkIssued(cert) ||
9093
certs.some(({ parsed: issuer }) => {
91-
return issuer && parsed.checkIssued(issuer);
94+
return issuer && cert.checkIssued(issuer);
9295
})
9396
);
9497
}
@@ -123,7 +126,11 @@ export function removeCertificatesWithoutIssuer(
123126

124127
const _messages: string[] = [];
125128
const filteredCAlist = ca.filter((cert) => {
126-
const keep = doesCertificateHasMatchingIssuer(cert, ca);
129+
// If cert was not parsed, we want to keep it in the list. The case should
130+
// be generally very rare, but in case it happens and this cert will affect
131+
// the TLS handshake, it will show up in the logs as the connection error
132+
// anyway, so it's safe to keep it
133+
const keep = !cert.parsed || certificateHasMatchingIssuer(cert.parsed, ca);
127134
if (!keep && cert.parsed) {
128135
const { parsed } = cert;
129136
_messages.push(

0 commit comments

Comments
 (0)