Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Update ZeroSSL to successfully shutdown cert server on failure and pa…
Browse files Browse the repository at this point in the history
…rse revoke response
  • Loading branch information
gkrizek committed Mar 12, 2021
1 parent 755117e commit edc3933
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions certprovider/zerossl.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ZeroSSLCertResponse struct {
}

type ZeroSSLCertRevoke struct {
Success string `json:"success"`
Success int `json:"success"`
}

func ZeroSSLGenerateCsr(keyBytes []byte, domain string) (csrBuffer bytes.Buffer, err error) {
Expand Down Expand Up @@ -281,7 +281,7 @@ func ZeroSSLRevokeCert(certificateId string) (err error) {
}
return fmt.Errorf("There was a problem requesting a certificate: %s", apiError.Error.Type)
}
if revokeCert.Success != "1" {
if revokeCert.Success != 1 {
fmt.Printf("Unknown error occured: %v\n", string(body))
return fmt.Errorf("There was a problem requesting a certificate: %s", revokeCert)
}
Expand Down
10 changes: 9 additions & 1 deletion lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ func createExternalCert(cfg *Config, keyBytes []byte, certLocation string) (retu
}()
err = certprovider.ZeroSSLValidateCert(externalCert)
if err != nil {
certServer.Close()
return returnCert, certId, err
}
rpcsLog.Debug("requested certificate to be validated")
Expand All @@ -861,6 +862,7 @@ func createExternalCert(cfg *Config, keyBytes []byte, certLocation string) (retu
for {
newCert, err := certprovider.ZeroSSLGetCert(externalCert)
if err != nil {
certServer.Close()
return returnCert, certId, err
}
status := newCert.Status
Expand All @@ -871,17 +873,20 @@ func createExternalCert(cfg *Config, keyBytes []byte, certLocation string) (retu
} else if status == "draft" {
err = certprovider.ZeroSSLValidateCert(externalCert)
if err != nil {
certServer.Close()
return returnCert, certId, err
}
}
if retries > 3 {
rpcsLog.Error("Still can't get a certificate after 3 retries. Failing...")
certServer.Close()
return returnCert, "", fmt.Errorf("Timed out trying to create SSL Certificate")
}
if checkCount > 15 {
rpcsLog.Warn("Timed out waiting for cert. Requesting a new one.")
externalCert, err = certprovider.ZeroSSLRequestCert(csr, cfg.ExternalSSLDomain)
if err != nil {
certServer.Close()
return returnCert, certId, err
}
rpcsLog.Infof("received cert request with id %s", externalCert.Id)
Expand All @@ -894,10 +899,12 @@ func createExternalCert(cfg *Config, keyBytes []byte, certLocation string) (retu
certId = externalCert.Id
certificate, caBundle, err := certprovider.ZeroSSLDownloadCert(externalCert)
if err != nil {
certServer.Close()
return returnCert, certId, err
}
externalCertBytes := []byte(certificate + "\n" + caBundle)
if err = ioutil.WriteFile(certLocation, externalCertBytes, 0644); err != nil {
certServer.Close()
return returnCert, certId, err
}
rpcsLog.Infof("successfully wrote external SSL certificate to %s",
Expand All @@ -906,6 +913,7 @@ func createExternalCert(cfg *Config, keyBytes []byte, certLocation string) (retu
externalCertBytes, keyBytes,
)
if err != nil {
certServer.Close()
return returnCert, certId, err
}
rpcsLog.Info("shutting down certificate validator server")
Expand Down Expand Up @@ -952,7 +960,7 @@ func getEphemeralTLSConfig(cfg *Config, keyRing keychain.KeyRing) (*tls.Config,
cfg, keyBytes, externalSSLCertPath,
)
if err != nil {
rpcsLog.Info(err)
rpcsLog.Warn(err)
failedProvision = true
}
}
Expand Down

0 comments on commit edc3933

Please sign in to comment.