gRPC asks the standard health service, optionally about one service. SMTP waits for the greeting, says EHLO and, unless disabled, requires STARTTLS or connects with implicit TLS. RADIUS sends an Access-Request signed with a Message-Authenticator and tells a rejected login from a wrong shared secret. SNMP v1/v2c reads one OID and compares its value textually or numerically, hinting at the community when the agent stays silent. All go through the network guard. Errors from dialing are no longer passed through redaction, and secrets shorter than four characters are left in messages instead of garbling them. Refs #95 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package check
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"errors"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
// TLS modes of services with optional encryption: "require" encrypts
|
|
// without verifying the certificate, "verify" also verifies it.
|
|
func validTLSMode(m string) bool { return m == "disable" || m == "require" || m == "verify" }
|
|
|
|
// tlsFor returns the client TLS settings for mode, or nil for "disable".
|
|
func tlsFor(mode, target string) *tls.Config {
|
|
if mode == "disable" {
|
|
return nil
|
|
}
|
|
host, _, _ := net.SplitHostPort(target)
|
|
return &tls.Config{ServerName: host, InsecureSkipVerify: mode == "require"} //nolint:gosec // "require" encrypts without verifying, as chosen per monitor
|
|
}
|
|
|
|
// redact shortens err for customers and removes secrets some clients
|
|
// repeat in their errors. Secrets shorter than four characters are left:
|
|
// replacing them would garble the message while hiding little.
|
|
func redact(err error, secrets ...string) string {
|
|
var op *net.OpError
|
|
if errors.As(err, &op) && op.Op == "dial" {
|
|
return describeNetErr(err)
|
|
}
|
|
msg := err.Error()
|
|
for _, s := range secrets {
|
|
if len(s) >= 4 {
|
|
msg = strings.ReplaceAll(msg, s, "***")
|
|
}
|
|
}
|
|
return truncate(msg, 300)
|
|
}
|