You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: add signal handler for SIGHUP to reload the HTTP and NATS servers
log.Fatalf("Error closing key.pem: %v", err)
}
log.Debug("wrote key.pem")
ifconfig.NoRotateCerts {
log.Debug("Not rotating certs, as per config")
return
}
gorotateTLSCerts()
}
funcrotateTLSCerts() {
log.Debug("Rotating TLS certificates...")
CertFile:=config.CertFile// open the cert file and determine the notbefore date and the notafter date// if the notafter date is within 33% of the config.CertificateValidTime, then// generate a new cert// otherwise sleep for 1 day and check againneedsRotation:=func() (bool, error) {
file, err:=os.Open(CertFile)
iferr!=nil {
returnfalse, errors.Join(err, errors.New("could not open cert file"))
}
deferfile.Close()
stats, statsErr:=file.Stat()
ifstatsErr!=nil {
returnfalse, errors.Join(statsErr, errors.New("could not stat cert file"))
}
size:=stats.Size()
bytes:=make([]byte, size)
bufr:=bufio.NewReader(file)
_, err=bufr.Read(bytes)
iferr!=nil {
returnfalse, errors.Join(err, errors.New("could not read cert file into buffer"))
}
block, _:=pem.Decode(bytes)
cert, err:=x509.ParseCertificate(block.Bytes)
iferr!=nil {
returnfalse, errors.Join(err, errors.New("could not parse cert"))
}
returntime.Now().After(cert.NotAfter.Add(-config.CertificateValidTime/3)), nil
}
reloadHttpServer:=func() {
shutdownTimeout, cancel:=context.WithTimeout(context.Background(), 15*time.Second)
defercancel()
httpServer.Shutdown(shutdownTimeout)
SetHttpServer(server.StartAPIServer())
}
for {
shouldRotate, err:=needsRotation()
iferr!=nil {
log.Error(err)
time.Sleep(time.Minute)
continue
}
ifshouldRotate {
genCert(true)
pki.ReloadNatsServer()
reloadHttpServer()
// TODO: add signal handler for SIGHUP to reload the HTTP and NATS servers
}
time.Sleep(24*time.Hour)
}
}
funcSetHttpServer(s*http.Server) {
httpServer=s
}
The text was updated successfully, but these errors were encountered:
grlx/certs/tls.go
Line 305 in e997e0a
The text was updated successfully, but these errors were encountered: