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

Fixes #292 #293

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions transport/httpcommon/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"net/http/httptrace"
"net/textproto"
"net/url"
"strings"

"github.com/elastic/elastic-agent-libs/transport/tlscommon"
)
Expand Down Expand Up @@ -181,15 +182,19 @@ func diagError(err error) string {
// keep unwrapping to url.Error as the last error as other failures can be embedded in a url.Error
// Can detect if an HTTPS request is made to an HTTP server
var uErr *url.Error

if errors.As(err, &uErr) {
switch uErr.Err.Error() {
case "http: server gave HTTP response to HTTPS client":
errString := uErr.Err.Error()
if strings.Contains(errString, "http: server gave HTTP response to HTTPS client") {
return fmt.Sprintf("%v: caused by using HTTPS schema on HTTP server.", uErr)
case "remote error: tls: certificate required":
return fmt.Sprintf("%v: caused by missing mTLS client cert.", uErr)
case "remote error: tls: expired certificate":
}
if strings.Contains(errString, "remote error: tls: certificate required") {
return fmt.Sprintf("%v: caused by missing mTLS client cert.", uErr)
}
if strings.Contains(errString, "remote error: tls: expired certificate") {
return fmt.Sprintf("%v: caused by expired mTLS client cert.", uErr)
case "remote error: tls: bad certificate":
}
if strings.Contains(errString, "remote error: tls: bad certificate") {
return fmt.Sprintf("%v: caused by invalid mTLS client cert, does the server trust the CA used for the client cert?.", uErr)
}
}
Expand Down
Loading