aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-24 18:39:18 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-24 18:39:18 +0100
commit88533d6843eee95763c8e4782b60c4da17fc7609 (patch)
treeefdd6137717733ec2e3913e5d6942ce4fc93ccc0 /crypto.go
parentc7e20e280579bcabcb7b122ec11c88ccd057c4e2 (diff)
Add CSR request
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
}