Home >Backend Development >Golang >Why Am I Getting an \'Incomplete Certificate Chain\' Error with GoDaddy\'s SSL Certificate in Go?
SSL Issue: Incomplete Certificate Chain with GoDaddy's Certificate
When setting up an HTTPS web server using GoDaddy's SSL certificates, you may encounter the error "This server's certificate chain is incomplete." This can be caused by a misconfiguration in your Go code.
Solution:
To resolve this issue, ensure that the certificate file used in ListenAndServeTLS() contains the complete certificate chain. This includes the server's certificate, intermediate certificates (if any), and the root CA certificate.
In your code, you're currently loading the main certificate file and private key, but you're missing the bundle file, which typically contains the intermediate certificates.
Replace the following line:
err := srv.ListenAndServeTLS("cert/myalcoholist.pem","cert/myalcoholist.key")
with this:
cert, err := tls.LoadX509KeyPair("cert/myalcoholist.pem","cert/myalcoholist.key") if err != nil { log.Fatalf("server: loadkeys: %s", err) } pem, err := ioutil.ReadFile("cert/cert/sf_bundle-g2-g1.crt") if err != nil { log.Fatalf("Failed to read client certificate authority: %v", err) } if !certpool.AppendCertsFromPEM(pem) { log.Fatalf("Can't parse client certificate authority") } tlsConfig := &tls.Config{ ClientCAs: certpool, Certificates: []tls.Certificate{cert}, } srv := &http.Server{ Addr: "myalcoholist.com:443", Handler: n, ReadTimeout: time.Duration(5) * time.Second, WriteTimeout: time.Duration(5) * time.Second, TLSConfig: tlsConfig, } err := srv.ListenAndServeTLS("cert/myalcoholist.pem","cert/myalcoholist.key")
This will load the complete certificate chain and configure the TLSConfig accordingly.
Additional Tips:
The above is the detailed content of Why Am I Getting an \'Incomplete Certificate Chain\' Error with GoDaddy\'s SSL Certificate in Go?. For more information, please follow other related articles on the PHP Chinese website!