Fix logical conflicts with CA refactor

pull/4275/head
Paul Banks 7 years ago committed by Mitchell Hashimoto
parent c58d47ba59
commit 140f3f5a44
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A

@ -3,12 +3,9 @@ package connect
import ( import (
"bytes" "bytes"
"crypto" "crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand" "crypto/rand"
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"fmt"
"net/url" "net/url"
) )
@ -34,26 +31,3 @@ func CreateCSR(uri CertURI, privateKey crypto.Signer) (string, error) {
return csrBuf.String(), nil return csrBuf.String(), nil
} }
// GeneratePrivateKey generates a new Private key
func GeneratePrivateKey() (crypto.Signer, string, error) {
var pk *ecdsa.PrivateKey
pk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return nil, "", fmt.Errorf("error generating private key: %s", err)
}
bs, err := x509.MarshalECPrivateKey(pk)
if err != nil {
return nil, "", fmt.Errorf("error generating private key: %s", err)
}
var buf bytes.Buffer
err = pem.Encode(&buf, &pem.Block{Type: "EC PRIVATE KEY", Bytes: bs})
if err != nil {
return nil, "", fmt.Errorf("error encoding private key: %s", err)
}
return pk, buf.String(), nil
}

@ -2,6 +2,7 @@ package connect
import ( import (
"bytes" "bytes"
"crypto"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/elliptic" "crypto/elliptic"
"crypto/rand" "crypto/rand"
@ -10,25 +11,25 @@ import (
"fmt" "fmt"
) )
// GeneratePrivateKey returns a new private key // GeneratePrivateKey generates a new Private key
func GeneratePrivateKey() (string, error) { func GeneratePrivateKey() (crypto.Signer, string, error) {
var pk *ecdsa.PrivateKey var pk *ecdsa.PrivateKey
pk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) pk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil { if err != nil {
return "", fmt.Errorf("error generating private key: %s", err) return nil, "", fmt.Errorf("error generating private key: %s", err)
} }
bs, err := x509.MarshalECPrivateKey(pk) bs, err := x509.MarshalECPrivateKey(pk)
if err != nil { if err != nil {
return "", fmt.Errorf("error generating private key: %s", err) return nil, "", fmt.Errorf("error generating private key: %s", err)
} }
var buf bytes.Buffer var buf bytes.Buffer
err = pem.Encode(&buf, &pem.Block{Type: "EC PRIVATE KEY", Bytes: bs}) err = pem.Encode(&buf, &pem.Block{Type: "EC PRIVATE KEY", Bytes: bs})
if err != nil { if err != nil {
return "", fmt.Errorf("error encoding private key: %s", err) return nil, "", fmt.Errorf("error encoding private key: %s", err)
} }
return buf.String(), nil return pk, buf.String(), nil
} }

Loading…
Cancel
Save