]> Sergey Matveev's repositories - godlighty.git/blobdiff - tls.go
Ability to work without ECDSA
[godlighty.git] / tls.go
diff --git a/tls.go b/tls.go
index 51470f37bb802ebe1f45cb10eefe0c1b2d24e74b..b2ad433d6ddc0bb3d16c2c0b391b4ae0fadfa8cb 100644 (file)
--- a/tls.go
+++ b/tls.go
@@ -1,6 +1,6 @@
 /*
 godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server
-Copyright (C) 2021-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -67,12 +67,17 @@ func GetCertificate(chi *tls.ClientHelloInfo) (*tls.Certificate, error) {
                        return cert, nil
                }
        }
-       if CHIHasEdDSA(chi) {
-               if cert := HostToEdDSACertificate[chi.ServerName]; cert != nil {
-                       return cert, nil
+       var cert *tls.Certificate
+       if len(HostToECDSACertificate) == 0 {
+               cert = HostToEdDSACertificate[chi.ServerName]
+       } else {
+               if CHIHasEdDSA(chi) {
+                       if cert := HostToEdDSACertificate[chi.ServerName]; cert != nil {
+                               return cert, nil
+                       }
                }
+               cert = HostToECDSACertificate[chi.ServerName]
        }
-       cert := HostToECDSACertificate[chi.ServerName]
        if cert == nil {
                return nil, errors.New("no certificate found")
        }
@@ -84,7 +89,7 @@ func GetConfigForClient(chi *tls.ClientHelloInfo) (*tls.Config, error) {
        if CHIHasGOST(chi) {
                pool = HostGOSTClientAuth[chi.ServerName]
        }
-       if pool == nil && CHIHasEdDSA(chi) {
+       if pool == nil && (CHIHasEdDSA(chi) || len(HostECDSAClientAuth) == 0) {
                pool = HostEdDSAClientAuth[chi.ServerName]
        }
        if pool == nil {
@@ -149,11 +154,9 @@ func loadCertificates(
                                log.Fatalln(err)
                        }
                        pool.AddCert(ca)
+                       (*hostClientAuth)[host] = pool
                }
        }
-       if len(pool.Subjects()) > 0 {
-               (*hostClientAuth)[host] = pool
-       }
 }
 
 func LoadCertificates() {