aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-03-06 02:49:32 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-03-06 02:49:32 +0100
commit545a6a4999f1a42353a8e90b9fada6fbfccea38d (patch)
tree9238cbfdb6a9bdb8c18fbf696cadae9b36c2904c /crypto.go
parentc9ef855f5a3a46c8ec8106cf9b62fd12fc03268b (diff)
Refactor NewCSR
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto.go b/crypto.go
index eb859c2..220becd 100644
--- a/crypto.go
+++ b/crypto.go
@@ -6,7 +6,10 @@ import (
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
+ "crypto/tls"
"crypto/x509"
+ "crypto/x509/pkix"
+ "encoding/base64"
"encoding/pem"
"errors"
"io"
@@ -78,3 +81,17 @@ func NewKey(size int) (crypto.PrivateKey, error) {
return rsa.GenerateKey(rand.Reader, size)
}
}
+
+func NewCSR(cert tls.Certificate, altnames []string) (string, error) {
+ tmpl := x509.CertificateRequest{
+ Subject: pkix.Name{CommonName: altnames[0]},
+ }
+ if len(altnames) > 1 {
+ tmpl.DNSNames = altnames
+ }
+ der, err := x509.CreateCertificateRequest(rand.Reader, &tmpl, cert.PrivateKey)
+ if err != nil {
+ return "", err
+ }
+ return base64.RawURLEncoding.EncodeToString(der), nil
+}