in evReady/cmd/web/certificates.go [70:101]
func (app *application) pemCreator(hostname, rootCert string) (string, error) {
certs, ip, err := getCertFromHost(hostname, "443", true)
if err != nil || certs == nil {
app.logger.Error("Unable to retrieve cert from host.", "hostname", hostname, "error", err.Error())
}
certChain := CertChain{
Hostname: hostname,
IP: ip,
}
f, err := os.Create("/tmp/" + xid.New().String() + ".pem")
if err != nil {
app.logger.Error("Unable to create certs file.", "error", err.Error())
}
defer f.Close()
for _, cert := range certs {
_, err := f.WriteString(certConvert(cert.Raw))
if err != nil {
app.logger.Error("Unable to write certs to file.", "error", err.Error())
}
certChain.Certs = append(certChain.Certs, base64.StdEncoding.EncodeToString(cert.Raw))
}
_, err = f.WriteString(rootCert)
if err != nil {
app.logger.Error("Unable to write cert to PEM chain file.", "error", err.Error())
}
return f.Name(), f.Sync()
}