cloudflare / cfssl

CFSSL: Cloudflare's PKI and TLS toolkit
https://cfssl.org/
BSD 2-Clause "Simplified" License
8.67k stars 1.1k forks source link

Issue with SANs Storage in Database: Only Domain Names are Saved #1389

Open thebluesoul opened 1 month ago

thebluesoul commented 1 month ago

When issuing client certificates, I configure the CN (Common Name) as the User ID and SANs (Subject Alternative Names) as the User email. However, in the database, only the Domain Name (DNSName) is saved in the SANs field, ignoring other types like Email, IP Address, and URI. The issue seems to originate from the following code snippet in local.go:

$ git diff signer/local/local.go
diff --git a/signer/local/local.go b/signer/local/local.go
index 091ce79c..c5c85d9a 100644
--- a/signer/local/local.go
+++ b/signer/local/local.go
@@ -525,7 +525,22 @@ func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
                if err := certRecord.SetMetadata(req.Metadata); err != nil {
                        return nil, err
                }
-               if err := certRecord.SetSANs(certTBS.DNSNames); err != nil {
+
+               var ipStrings []string
+               for _, ip := range certTBS.IPAddresses {
+                       ipStrings = append(ipStrings, ip.String())
+               }
+
+               var uriStrings []string
+               for _, uri := range certTBS.URIs {
+                       uriStrings = append(uriStrings, uri.String())
+               }
+
+               allSANs := append(certTBS.DNSNames, certTBS.EmailAddresses...)
+               allSANs = append(allSANs, ipStrings...)
+               allSANs = append(allSANs, uriStrings...)
+
+               if err := certRecord.SetSANs(allSANs); err != nil {
                        return nil, err
                }

$ 

Please advise on how to modify the code to include all SANs types.

thebluesoul commented 1 week ago

Here is the related PR. #1390