Wrap []byte for DER certificates in its own type.

This commit is contained in:
xenolf 2015-10-18 03:29:26 +02:00
parent 141900789d
commit 7f6f790253
2 changed files with 4 additions and 2 deletions

View file

@ -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 = pemEncode(cert) cerRes.Certificate = pemEncode(derCertificateBytes(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

@ -10,6 +10,8 @@ import (
"time" "time"
) )
type derCertificateBytes []byte
func generatePrivateKey(keyLength int) (*rsa.PrivateKey, error) { func generatePrivateKey(keyLength int) (*rsa.PrivateKey, error) {
return rsa.GenerateKey(rand.Reader, keyLength) return rsa.GenerateKey(rand.Reader, keyLength)
} }
@ -30,7 +32,7 @@ func pemEncode(data interface{}) []byte {
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 break
case []byte: case derCertificateBytes:
pemBlock = &pem.Block{Type: "CERTIFICATE", Bytes: data.([]byte)} pemBlock = &pem.Block{Type: "CERTIFICATE", Bytes: data.([]byte)}
} }