Skip to content

Commit

Permalink
fix error on cname lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Jul 16, 2023
1 parent b4a03ae commit 0b6dae9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/pkg/web/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func isValidHostName(ctx context.Context, host string) error {

cname, err := net.DefaultResolver.LookupCNAME(ctx, host)
if err != nil {
return errors.Wrap(err, "failed to lookup CNAME")
return errors.Wrap(errInvalidHostName, "failed to lookup CNAME")
}

if cname == "" {
Expand All @@ -86,15 +86,15 @@ func isValidHostName(ctx context.Context, host string) error {
return nil
}

//CertificateManager is used to manage SSL certificates
// CertificateManager is used to manage SSL certificates
type CertificateManager struct {
ctx context.Context
cert tls.Certificate
leaf *x509.Certificate
autotls autocert.Manager
}

//NewCertificateManager creates a new CertificateManager
// NewCertificateManager creates a new CertificateManager
func NewCertificateManager(ctx context.Context, certFile, keyFile string) (*CertificateManager, error) {
manager := &CertificateManager{
ctx: ctx,
Expand Down Expand Up @@ -122,9 +122,9 @@ func NewCertificateManager(ctx context.Context, certFile, keyFile string) (*Cert
return manager, nil
}

//GetCertificate decides which certificate to use
//It first tries to use loaded certificate for incoming request if it's compatible
//Otherwise fallsback to a automatically generated certificate by Let's Encrypt
// GetCertificate decides which certificate to use
// It first tries to use loaded certificate for incoming request if it's compatible
// Otherwise fallsback to a automatically generated certificate by Let's Encrypt
func (m *CertificateManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
if m.leaf != nil {
serverName, err := idna.Lookup.ToASCII(hello.ServerName)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (m *CertificateManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Ce
return cert, err
}

//StartHTTPServer creates a new HTTP server on port 80 that is used for the ACME HTTP Challenge
// StartHTTPServer creates a new HTTP server on port 80 that is used for the ACME HTTP Challenge
func (m *CertificateManager) StartHTTPServer() {
err := http.ListenAndServe(":80", m.autotls.HTTPHandler(nil))
if err != nil {
Expand Down

0 comments on commit 0b6dae9

Please sign in to comment.