-
Notifications
You must be signed in to change notification settings - Fork 897
Implement a fast lookup for wildcard certificates #2815
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
base: main
Are you sure you want to change the base?
Implement a fast lookup for wildcard certificates #2815
Conversation
5540ac3 to
d979058
Compare
gfoidl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: there are quite a few blank lines that could be removed too.
| var charA = x[^i] & 0x5F; | ||
| var charB = y[^i] & 0x5F; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You compare it backwards?
Is it better then, to write the loop backwards and have normal index access?
| var length = Math.Min(x.Length, y.Length); | ||
|
|
||
| for (var i = 1; i <= length; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the JIT can't elide the bound-check for indexing into the spans.
I think it's better to slice the spans to the common (= min) length and use one span in the loop, in order to elide at least one bound check (the JIT should handle the downward loop (see other comment) in a recent version).
Roughly:
| var length = Math.Min(x.Length, y.Length); | |
| for (var i = 1; i <= length; i++) | |
| if (x.Length < y.Length) | |
| { | |
| y = y.Slice(0, x.Length); | |
| } | |
| else if (y.Length < x.Length) | |
| { | |
| x = x.Slice(0, y.Length); | |
| } | |
| for (var i = x.Length; i >= 1; --i) |
| _hasBeenUpdated = true; | ||
| } | ||
|
|
||
| public X509Certificate2 GetCertificate(ConnectionContext connectionContext, string domainName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domainName CAN BE NULL!
when SNI is not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well poop, forgot about SNI. I would expect that everything supports SNI by now. But yes, get your point...sigh...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would suggest skipping certificate lookups and immediately fallback to the default cert when string.IsNullOrEmpty
you WILL get this traffic anytime someone runs ssllabs server test, or some other kind of auditing tool
or for the handful of people running this on their own internal network and connecting with some kind of weird legacy system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to handle non SNI TLS hand shake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
If this pull also needs to work for the Kubernetes.Controller the following needs to be modified also note: i don't work for MS but i have this code running right now with those lines patched out. |
e56abc3 to
0d20eac
Compare
Thanks for that |
No description provided.