aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/crypto.go b/crypto.go
index 619cccc..bb1dd6a 100644
--- a/crypto.go
+++ b/crypto.go
@@ -35,7 +35,7 @@ func NewKey(w io.Writer, size int) (*rsa.PrivateKey, error) {
return key, pem.Encode(w, block)
}
-func NewCSR(altnames []string, key *rsa.PrivateKey) ([]byte, error) {
+func NewCSR(altnames []string, key *rsa.PrivateKey) (string, error) {
tmpl := x509.CertificateRequest{
Subject: pkix.Name{
CommonName: altnames[0],
@@ -44,14 +44,18 @@ func NewCSR(altnames []string, key *rsa.PrivateKey) ([]byte, error) {
if len(altnames) > 1 {
tmpl.DNSNames = altnames
}
- return x509.CreateCertificateRequest(rand.Reader, &tmpl, key)
+ der, err := x509.CreateCertificateRequest(rand.Reader, &tmpl, key)
+ if err != nil {
+ return "", err
+ }
+ return base64.RawURLEncoding.EncodeToString(der), nil
}
func Thumb(token string, key crypto.PublicKey) (string, error) {
k := &jose.JsonWebKey{Key: key, Algorithm: "RSA"}
- t, err := k.Thumbprint(crypto.SHA256)
+ thumb, err := k.Thumbprint(crypto.SHA256)
if err != nil {
return "", err
}
- return token + "." + base64.RawURLEncoding.EncodeToString(t), nil
+ return token + "." + base64.RawURLEncoding.EncodeToString(thumb), nil
}