aboutsummaryrefslogtreecommitdiff
path: root/crypto.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-03-18 19:35:41 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-03-18 19:35:41 +0100
commit767868108a78b0c62b6613dba22e81b9134739b2 (patch)
tree456804a8348e184b47dff54ebf5b18da9e4d1ad8 /crypto.go
parent40a9ef230ee6112e6e8bf5981a4e18a17f34e307 (diff)
wip
Diffstat (limited to 'crypto.go')
-rw-r--r--crypto.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/crypto.go b/crypto.go
index a8ecb41..d7b3b10 100644
--- a/crypto.go
+++ b/crypto.go
@@ -19,6 +19,7 @@ const (
pemRSA = `RSA PRIVATE KEY`
pemEC = `EC PRIVATE KEY`
pemCRT = `CERTIFICATE`
+ pemCSR = `CERTIFICATE REQUEST`
)
var (
@@ -26,6 +27,11 @@ var (
ErrKeySize = errors.New("insufficient key size")
)
+func DumpCSR(w io.Writer, csr []byte) error {
+ block := &pem.Block{Type: pemCSR, Bytes: csr}
+ return pem.Encode(w, block)
+}
+
func SaveKey(w io.Writer, key crypto.PrivateKey) error {
var block *pem.Block
switch k := key.(type) {
@@ -59,10 +65,7 @@ func LoadKey(r io.Reader) (crypto.PrivateKey, error) {
}
func SaveCert(w io.Writer, cert []byte) error {
- block := &pem.Block{
- Type: pemCRT,
- Bytes: cert,
- }
+ block := &pem.Block{Type: pemCRT, Bytes: cert}
return pem.Encode(w, block)
}
@@ -100,12 +103,13 @@ func NewCSR(key crypto.PrivateKey, altnames, emails []string) (string, error) {
if len(altnames) > 1 {
tmpl.DNSNames = altnames
}
- if len(emails) > 1 {
+ if len(emails) > 0 {
tmpl.EmailAddresses = emails
}
der, err := x509.CreateCertificateRequest(rand.Reader, &tmpl, key)
if err != nil {
return "", err
}
+ //DumpCSR(os.Stdout, der)
return base64.RawURLEncoding.EncodeToString(der), nil
}