Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(devtools-proxy-support): push expired certs to the bottom of the system CA list COMPASS-8322 #474

Merged
merged 5 commits into from
Sep 24, 2024

Conversation

gribnoysup
Copy link
Collaborator

@gribnoysup gribnoysup commented Sep 20, 2024

We ran into more weird issues with CA cert validation failing in unexpected cases (see COMPASS-8322 for more details) affecting users because system CAs are now added to the CA list by default. To work around this particular one we're sorting a list of CAs returned from system store by expiration date to make sure that the ones that will expire sooner or expired already have less of a chance to get picked up from the CA list

}
}
return [...ca].join('\n');
}

const pemWithParsedCache = new WeakMap<
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cache is still here, just got moved down with the function and renamed to clarify the purpose

* Safely parse provided certs, push any encountered errors to the provided
* messages array
*/
export function parseCACerts(
Copy link
Collaborator Author

@gribnoysup gribnoysup Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split parsing out of removing function so that I can parse once, then optionally remove the ones with missing issuer, then use the same parsed certs when sorting without loosing the parsed certs inside the "removing" function

@gribnoysup gribnoysup marked this pull request as draft September 20, 2024 14:13
@gribnoysup gribnoysup force-pushed the compass-8322-sort-by-expired branch from c58fbfd to bfffacd Compare September 23, 2024 15:57
const reducedList = removeCertificatesWithoutIssuer(systemCerts);
systemCerts = reducedList.ca;
messages = messages.concat(reducedList.messages);
systemCerts = removeCertificatesWithoutIssuer(systemCerts, messages);
}

return {
ca: mergeCA(
Copy link
Collaborator Author

@gribnoysup gribnoysup Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something I'm planning to pursue right now, but assuming openssl doesn't fail when using the same CA list that we used to repro the issue because it is doing the sorting somewhere internally and Node.js doesn't, it seems like we might want to sort all the options combined, and not only the ones coming from system CA, but I'm not feeling confident enough to do this change right now, would like to confirm exactly why this is not happening when trying the same connection with openssl directly and not with Node.js tls module

@gribnoysup gribnoysup marked this pull request as ready for review September 24, 2024 05:47
messages.push(
}

function doesCertificateHasMatchingIssuer(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar nit: have, not has :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY! Will fix

Copy link
Collaborator

@lerouxb lerouxb Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so either doesCertificateHaveMatchingIssuer or certificateHasMatchingIssuer.

certs: ParsedX509Cert[]
) {
return (
!parsed ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if parsed is falsey we return that it does have a matching issuer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that's old code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm just keeping it as-is, but FWIW Annas reasoning in the PR that introduced it seems fair to me. I'll add it as a comment here so that we don't need to track down the PR every time

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up moving the !parsed check outside of the method just so this function name clearly describes and matches what it does. Moved the not parsed check to the filter itself and added a comment, seems a bit cleaner that way?

// be generally very rare, but in case it happens and this cert will affect
// the TLS handshake, it will show up in the logs as the connection error
// anyway, so it's safe to keep it
const keep = !cert.parsed || certificateHasMatchingIssuer(cert.parsed, ca);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@gribnoysup gribnoysup merged commit 3039562 into main Sep 24, 2024
5 checks passed
@gribnoysup gribnoysup deleted the compass-8322-sort-by-expired branch September 24, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants