Skip to content

Commit d7c31c3

Browse files
committedOct 25, 2018
Properly fill CSR DNSNames or IPAddresses
1 parent 1c1ac1b commit d7c31c3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎ca/client.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"encoding/pem"
1616
"io"
1717
"io/ioutil"
18+
"net"
1819
"net/http"
1920
"net/url"
2021
"strings"
@@ -353,8 +354,14 @@ func CreateSignRequest(ott string) (*api.SignRequest, crypto.PrivateKey, error)
353354
CommonName: claims.Subject,
354355
},
355356
SignatureAlgorithm: x509.ECDSAWithSHA256,
356-
DNSNames: []string{claims.Subject},
357357
}
358+
359+
if ip := net.ParseIP(claims.Subject); ip != nil {
360+
template.IPAddresses = append(template.IPAddresses, ip)
361+
} else {
362+
template.DNSNames = append(template.DNSNames, claims.Subject)
363+
}
364+
358365
csr, err := x509.CreateCertificateRequest(rand.Reader, template, pk)
359366
if err != nil {
360367
return nil, nil, errors.Wrap(err, "error creating certificate request")

0 commit comments

Comments
 (0)