lib/connections, lib/tlsutil: Handle certName in Go 1.15 (fixes #6867) (#6868)

Our authentication is based on device ID (certificate fingerprint) but
we also check the certificate name for ... historical extra security
reasons. (I don't think this adds anything but it is what it is.) Since
that check breaks in Go 1.15 this change does two things:

- Adds a manual check for the peer certificate CommonName, and if they
  are equal we are happy and don't call the more advanced
  VerifyHostname() function. This allows our old style certificates to
  still pass the check.

- Adds the cert name "syncthing" as a DNS SAN when generating the
  certificate. This is the correct way nowadays and makes VerifyHostname()
  happy in Go 1.15 as well, even without the above patch.
This commit is contained in:
Jakob Borg
2020-07-30 13:36:11 +02:00
committed by GitHub
parent d53a2567a4
commit 2dc2aa5d21
4 changed files with 28 additions and 10 deletions

View File

@@ -1136,7 +1136,7 @@ func TestPrefixMatch(t *testing.T) {
}
}
func TestCheckExpiry(t *testing.T) {
func TestShouldRegenerateCertificate(t *testing.T) {
dir, err := ioutil.TempDir("", "syncthing-test")
if err != nil {
t.Fatal(err)
@@ -1149,7 +1149,7 @@ func TestCheckExpiry(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := checkExpiry(crt); err == nil {
if err := shouldRegenerateCertificate(crt); err == nil {
t.Error("expected expiry error")
}
@@ -1158,7 +1158,7 @@ func TestCheckExpiry(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := checkExpiry(crt); err != nil {
if err := shouldRegenerateCertificate(crt); err != nil {
t.Error("expected no error:", err)
}
@@ -1168,7 +1168,7 @@ func TestCheckExpiry(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err := checkExpiry(crt); err == nil {
if err := shouldRegenerateCertificate(crt); err == nil {
t.Error("expected expiry error")
}
}