fix: Fix username extraction in the TLS handler

This commit is contained in:
2024-01-11 22:10:32 +01:00
parent 352f8bb4ce
commit 9b971daf28
4 changed files with 22 additions and 25 deletions

View File

@@ -44,7 +44,6 @@ func unlockDomain(domain string) {
}
func buildDomainList(domain, pagesDomain string) []string {
// TODO: For wildcards, we MUST use DNS01
if domain == pagesDomain || strings.HasSuffix(domain, pagesDomain) {
return []string{
pagesDomain,
@@ -56,7 +55,6 @@ func buildDomainList(domain, pagesDomain string) []string {
}
func getDomainKey(domain, pagesDomain string) string {
// TODO: For wildcards, we MUST use DNS01
if domain == pagesDomain || strings.HasSuffix(domain, pagesDomain) {
return "*." + pagesDomain
}
@@ -64,10 +62,6 @@ func getDomainKey(domain, pagesDomain string) string {
return domain
}
func usernameFromDomain(domain string) string {
return strings.Split(domain, ".")[0]
}
func getUsername(sni, pagesDomain string) (string, error) {
if !strings.HasSuffix(sni, pagesDomain) {
log.Debugf("'%s' is not a subdomain of '%s'", sni, pagesDomain)
@@ -81,10 +75,10 @@ func getUsername(sni, pagesDomain string) (string, error) {
return "", errors.New("CNAME does not resolve to subdomain of pages domain")
}
return usernameFromDomain(query), nil
return dns.ExtractUsername(pagesDomain, query), nil
}
return usernameFromDomain(sni), nil
return dns.ExtractUsername(pagesDomain, sni), nil
}
func MakeTlsConfig(pagesDomain, cachePath string, cache *certificates.CertificatesCache, acmeClient *lego.Client, giteaClient *repo.GiteaClient) *tls.Config {