Line 0
Link Here
|
|
|
1 |
--- syncthing/lib/api/api.go.orig 2020-08-11 08:56:46 UTC |
2 |
+++ syncthing/lib/api/api.go |
3 |
@@ -149,7 +149,7 @@ func (s *service) getListener(guiCfg config.GUIConfigu |
4 |
// If the certificate has expired or will expire in the next month, fail |
5 |
// it and generate a new one. |
6 |
if err == nil { |
7 |
- err = checkExpiry(cert) |
8 |
+ err = shouldRegenerateCertificate(cert) |
9 |
} |
10 |
if err != nil { |
11 |
l.Infoln("Loading HTTPS certificate:", err) |
12 |
@@ -1736,7 +1736,11 @@ func addressIsLocalhost(addr string) bool { |
13 |
} |
14 |
} |
15 |
|
16 |
-func checkExpiry(cert tls.Certificate) error { |
17 |
+// shouldRegenerateCertificate checks for certificate expiry or other known |
18 |
+// issues with our API/GUI certificate and returns either nil (leave the |
19 |
+// certificate alone) or an error describing the reason the certificate |
20 |
+// should be regenerated. |
21 |
+func shouldRegenerateCertificate(cert tls.Certificate) error { |
22 |
leaf := cert.Leaf |
23 |
if leaf == nil { |
24 |
// Leaf can be nil or not, depending on how parsed the certificate |
25 |
@@ -1752,10 +1756,19 @@ func checkExpiry(cert tls.Certificate) error { |
26 |
} |
27 |
} |
28 |
|
29 |
- if leaf.Subject.String() != leaf.Issuer.String() || |
30 |
- len(leaf.DNSNames) != 0 || len(leaf.IPAddresses) != 0 { |
31 |
- // The certificate is not self signed, or has DNS/IP attributes we don't |
32 |
+ if leaf.Subject.String() != leaf.Issuer.String() || len(leaf.IPAddresses) != 0 { |
33 |
+ // The certificate is not self signed, or has IP attributes we don't |
34 |
// add, so we leave it alone. |
35 |
+ return nil |
36 |
+ } |
37 |
+ if len(leaf.DNSNames) > 1 { |
38 |
+ // The certificate has more DNS SANs attributes than we ever add, so |
39 |
+ // we leave it alone. |
40 |
+ return nil |
41 |
+ } |
42 |
+ if len(leaf.DNSNames) == 1 && leaf.DNSNames[0] != leaf.Issuer.CommonName { |
43 |
+ // The one SAN is different from the issuer, so it's not one of our |
44 |
+ // newer self signed certificates. |
45 |
return nil |
46 |
} |
47 |
|