1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-26 03:09:37 +02:00

Certificates are PEM encoded by default now

This commit is contained in:
xenolf 2015-10-18 03:10:46 +02:00
parent caa6e78289
commit dcdcde03aa
2 changed files with 6 additions and 3 deletions

View File

@ -151,7 +151,7 @@ func (c *Client) AgreeToTos() error {
// ObtainCertificates tries to obtain certificates from the CA server // ObtainCertificates tries to obtain certificates from the CA server
// using the challenges it has configured. The returned certificates are // using the challenges it has configured. The returned certificates are
// DER encoded byte slices. // PEM encoded byte slices.
func (c *Client) ObtainCertificates(domains []string) ([]CertificateResource, error) { func (c *Client) ObtainCertificates(domains []string) ([]CertificateResource, error) {
logger().Print("Obtaining certificates...") logger().Print("Obtaining certificates...")
challenges := c.getChallenges(domains) challenges := c.getChallenges(domains)
@ -165,7 +165,7 @@ func (c *Client) ObtainCertificates(domains []string) ([]CertificateResource, er
return c.requestCertificates(challenges) return c.requestCertificates(challenges)
} }
// RevokeCertificate takes a DER encoded certificate and tries to revoke it at the CA. // RevokeCertificate takes a PEM encoded certificate and tries to revoke it at the CA.
func (c *Client) RevokeCertificate(certificate []byte) error { func (c *Client) RevokeCertificate(certificate []byte) error {
encodedCert := base64.URLEncoding.EncodeToString(certificate) encodedCert := base64.URLEncoding.EncodeToString(certificate)
@ -357,7 +357,7 @@ func (c *Client) requestCertificate(authz *authorizationResource, result chan Ce
// Otherwise the body is the certificate. // Otherwise the body is the certificate.
if len(cert) > 0 { if len(cert) > 0 {
cerRes.CertStableURL = resp.Header.Get("Content-Location") cerRes.CertStableURL = resp.Header.Get("Content-Location")
cerRes.Certificate = cert cerRes.Certificate = pemEncode(cert)
result <- cerRes result <- cerRes
} else { } else {
// The certificate was granted but is not yet issued. // The certificate was granted but is not yet issued.

View File

@ -29,6 +29,9 @@ func pemEncode(data interface{}) []byte {
switch key := data.(type) { switch key := data.(type) {
case *rsa.PrivateKey: case *rsa.PrivateKey:
pemBlock = &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)} pemBlock = &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)}
break
case []byte:
pemBlock = &pem.Block{Type: "CERTIFICATE", Bytes: data.([]byte)}
} }
return pem.EncodeToMemory(pemBlock) return pem.EncodeToMemory(pemBlock)