-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Use hostname check from verify.go to handle patterns in TLS certs #23661
Conversation
Pinging @elastic/agent (Team:Agent) |
testing |
func matchHostnames(pattern, host string) bool { | ||
pattern = toLowerCaseASCII(pattern) | ||
host = toLowerCaseASCII(strings.TrimSuffix(host, ".")) | ||
|
||
if len(pattern) == 0 || len(host) == 0 { | ||
return false | ||
} | ||
|
||
patternParts := strings.Split(pattern, ".") | ||
hostParts := strings.Split(host, ".") | ||
|
||
if len(patternParts) != len(hostParts) { | ||
return false | ||
} | ||
|
||
for i, patternPart := range patternParts { | ||
if i == 0 && patternPart == "*" { | ||
continue | ||
} | ||
if patternPart != hostParts[i] { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
// toLowerCaseASCII returns a lower-case version of in. See RFC 6125 6.4.1. We use | ||
// an explicitly ASCII function to avoid any sharp corners resulting from | ||
// performing Unicode operations on DNS labels. | ||
func toLowerCaseASCII(in string) string { |
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.
It seems fairly easy to add unit tests for for these two methods. Could we add them too?
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 am adding tests ATM, but not for these specific function, but for the whole VerifyConnection callback.
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.
Great, thanks! If possible, I'd add unit tests for the calculation and verification of the lowerCaseASCII hostname, just in case we missed any edge case for the conditional branches inside both methods.
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.
worked for agent enroll
💔 Build Failed
Expand to view the summary
Build stats
Test stats 🧪
Steps errorsExpand to view the steps failures
`x-pack/packetbeat-Lint - mage check;mage update;`
|
Test | Results |
---|---|
Failed | 0 |
Passed | 17362 |
Skipped | 1346 |
Total | 18708 |
jenkins run tests |
Failing test are unrelated. |
💔 Build Failed
Expand to view the summary
Build stats
Test stats 🧪
Steps errorsExpand to view the steps failures
`x-pack/packetbeat-Lint - mage check;mage update;`
|
Test | Results |
---|---|
Failed | 0 |
Passed | 17362 |
Skipped | 1346 |
Total | 18708 |
/packaging |
…astic#23661) Previously, DNSNames in x509 certs with wildcards were not accepted. The function from Golang's `verify.go` is taken, so the check remains the same between Golang versions. (cherry picked from commit 6291419)
…pack-when-oss-changes * upstream/master: [DOCS] Add setup content to Kubernetes and Cloud Foundry docs (elastic#23580) [CI] Mandatory windows support for all the versions (elastic#23615) Add check when retrieving the worker process id using performance counters (elastic#23647) Remove 4912 evtx from testing (elastic#23669) Add missing SSL settings (elastic#23632) Update X-Pack Packetbeat config (elastic#23666) Use hostname check from verify.go to handle patterns in TLS certs (elastic#23661) Fix: Dissect Cisco ASA 302013 message usernames (elastic#21196) Add FAQ entry for MADV settings in older versions (elastic#23429) Sync fixes from Integration Package Testing (elastic#23424) [Filebeat] Add Cisco ASA message '302023' parsing (elastic#23092) [Elastic Log Driver] Change hosts config flag (elastic#23628) Audit and Authentication Policy Change Events (elastic#20684)
What does this PR do?
Previously, DNSNames in x509 certs with wildcards were not accepted. The function from Golang's
verify.go
is taken, so the check remains the same between Golang versions.Why is it important?
Wildcards in DNSNames were not accepted. Now the are.
Checklist
- [ ] I have made corresponding changes to the documentation- [ ] I have made corresponding change to the default configuration files- [ ] I have added an entry inCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.