mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-01 21:24:23 +08:00
lego provides PEM-encoded certificate bytes for us
This commit is contained in:
parent
7568b0e215
commit
9f9de389d5
|
@ -8,19 +8,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// saveCertificate saves a DER-encoded (binary format) certificate
|
|
||||||
// to file.
|
|
||||||
func saveCertificate(certBytes []byte, file string) error {
|
|
||||||
pemCert := pem.Block{Type: "CERTIFICATE", Bytes: certBytes}
|
|
||||||
certOut, err := os.Create(file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pem.Encode(certOut, &pemCert)
|
|
||||||
certOut.Close()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadRSAPrivateKey loads a PEM-encoded RSA private key from file.
|
// loadRSAPrivateKey loads a PEM-encoded RSA private key from file.
|
||||||
func loadRSAPrivateKey(file string) (*rsa.PrivateKey, error) {
|
func loadRSAPrivateKey(file string) (*rsa.PrivateKey, error) {
|
||||||
keyBytes, err := ioutil.ReadFile(file)
|
keyBytes, err := ioutil.ReadFile(file)
|
||||||
|
|
|
@ -144,7 +144,7 @@ func saveCertsAndKeys(certificates []acme.CertificateResource) error {
|
||||||
os.MkdirAll(storage.Site(cert.Domain), 0700)
|
os.MkdirAll(storage.Site(cert.Domain), 0700)
|
||||||
|
|
||||||
// Save cert
|
// Save cert
|
||||||
err := saveCertificate(cert.Certificate, storage.SiteCertFile(cert.Domain))
|
err := ioutil.WriteFile(storage.SiteCertFile(cert.Domain), cert.Certificate, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user