aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
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
+}