Domain Controller auf Windows Server 2012 R2 koennen TLS 1.2 per Registry deaktiviert haben. ad.min_tls_version (Default 1.2) erlaubt es, fuer solche Altsysteme auf 1.0/1.1 herunterzugehen; das Portal warnt dann bei jedem Start. Die Zertifikatspruefung bleibt in jedem Fall aktiv — fuer LDAP gibt es weiterhin keine Insecure-Option. Im Legacy-Modus kommen lediglich die CBC-SHA256-Suiten hinzu, die Go als unsicher einstuft; RC4, 3DES und Suiten ohne Forward Secrecy werden nie angeboten. README dokumentiert zusaetzlich die beiden anderen 2012-R2-Stolpersteine: SHA-1-signierte DC-Zertifikate (seit Go 1.24 nicht mehr umgehbar) und RSA-Schluesselaustausch (nur ueber GODEBUG=tlsrsakex=1). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBHF4R9EAejDJUMdwr6C68
98 lines
3 KiB
Go
98 lines
3 KiB
Go
package auth
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseTLSVersion(t *testing.T) {
|
|
cases := map[string]uint16{
|
|
"1.0": tls.VersionTLS10,
|
|
"1.1": tls.VersionTLS11,
|
|
"1.2": tls.VersionTLS12,
|
|
"1.3": tls.VersionTLS13,
|
|
}
|
|
for in, want := range cases {
|
|
if got := ParseTLSVersion(in); got != want {
|
|
t.Errorf("ParseTLSVersion(%q) = %#04x, want %#04x", in, got, want)
|
|
}
|
|
}
|
|
// Unbekanntes oder leeres Eingaben fallen auf das Sichere zurück.
|
|
for _, in := range []string{"", "1.4", "unsinn", "TLSv1"} {
|
|
if got := ParseTLSVersion(in); got != tls.VersionTLS12 {
|
|
t.Errorf("ParseTLSVersion(%q) = %#04x, want TLS 1.2", in, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTLSConfigDefaultsToTLS12(t *testing.T) {
|
|
cfg, err := tlsConfigFor("dc01.firma.local", "", 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.MinVersion != tls.VersionTLS12 {
|
|
t.Errorf("MinVersion = %#04x, want TLS 1.2", cfg.MinVersion)
|
|
}
|
|
if cfg.ServerName != "dc01.firma.local" {
|
|
t.Errorf("ServerName = %q", cfg.ServerName)
|
|
}
|
|
if cfg.InsecureSkipVerify {
|
|
t.Error("die Zertifikatspruefung darf fuer LDAP niemals abschaltbar sein")
|
|
}
|
|
if cfg.CipherSuites != nil {
|
|
t.Error("bei TLS 1.2+ sollen Gos sichere Vorgaben gelten, keine eigene Liste")
|
|
}
|
|
}
|
|
|
|
func TestTLSConfigLegacyAddsCBCSuites(t *testing.T) {
|
|
cfg, err := tlsConfigFor("dc01.firma.local", "", tls.VersionTLS10)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.MinVersion != tls.VersionTLS10 {
|
|
t.Errorf("MinVersion = %#04x, want TLS 1.0", cfg.MinVersion)
|
|
}
|
|
if cfg.InsecureSkipVerify {
|
|
t.Error("auch im Legacy-Modus bleibt die Zertifikatspruefung aktiv")
|
|
}
|
|
has := func(id uint16) bool {
|
|
for _, got := range cfg.CipherSuites {
|
|
if got == id {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Die CBC-SHA256-Suite fuehrt Go als unsicher und bietet sie sonst nicht an.
|
|
if !has(tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) {
|
|
t.Error("ECDHE_RSA_AES_128_CBC_SHA256 fehlt in der Legacy-Liste")
|
|
}
|
|
// Die CBC-SHA1-Suiten eines 2012 R2 stecken schon in Gos Vorgaben.
|
|
if !has(tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) {
|
|
t.Error("ECDHE_RSA_AES_256_CBC_SHA fehlt — die braucht ein 2012 R2 unter TLS 1.0")
|
|
}
|
|
// Die modernen Suiten duerfen im Legacy-Modus nicht wegfallen.
|
|
if !has(tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) {
|
|
t.Error("die modernen Suiten duerfen im Legacy-Modus nicht wegfallen")
|
|
}
|
|
// Kein reiner RSA-Schluesselaustausch: keine Forward Secrecy, und Go
|
|
// filtert die Suiten ohnehin weg.
|
|
for _, id := range []uint16{tls.TLS_RSA_WITH_AES_128_CBC_SHA, tls.TLS_RSA_WITH_AES_256_CBC_SHA} {
|
|
if has(id) {
|
|
t.Errorf("Suite %#04x ohne Forward Secrecy gehoert nicht in die Liste", id)
|
|
}
|
|
}
|
|
// RC4 und 3DES niemals.
|
|
for _, id := range []uint16{tls.TLS_RSA_WITH_RC4_128_SHA, tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA} {
|
|
if has(id) {
|
|
t.Errorf("veraltete Suite %#04x darf nie angeboten werden", id)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTLSConfigRejectsBadCAFile(t *testing.T) {
|
|
if _, err := tlsConfigFor("dc01", "/gibt/es/nicht.pem", tls.VersionTLS12); err == nil {
|
|
t.Fatal("fehlende CA-Datei muss abgelehnt werden")
|
|
}
|
|
}
|