diff options
Diffstat (limited to 'crypto.go')
-rw-r--r-- | crypto.go | 26 |
1 files changed, 10 insertions, 16 deletions
@@ -98,23 +98,17 @@ func NewKey(size int) (crypto.PrivateKey, error) { var oidMailAddress = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1} -func mailAttr(mail string) pkix.AttributeTypeAndValue { - return pkix.AttributeTypeAndValue{ - Type: oidMailAddress, - Value: mail, - } -} - -func NewCSR(key crypto.PrivateKey, altnames, emails []string) (string, error) { - mail := mailAttr(emails[0]) - subj := pkix.Name{ - CommonName: altnames[0], - Names: []pkix.AttributeTypeAndValue{mail}, - } +func NewCSR(key crypto.PrivateKey, altnames []string, email string) (string, error) { tmpl := x509.CertificateRequest{ - Subject: subj, - DNSNames: altnames, - EmailAddresses: emails, + Subject: pkix.Name{CommonName: altnames[0]}, + DNSNames: altnames, + } + if email != "" { + m := pkix.AttributeTypeAndValue{ + Type: oidMailAddress, + Value: email, + } + tmpl.Subject.ExtraNames = append(tmpl.Subject.ExtraNames, m) } der, err := x509.CreateCertificateRequest(rand.Reader, &tmpl, key) if err != nil { |