@@ -16,6 +16,7 @@ import (
1616 "net"
1717 "net/http"
1818 "net/mail"
19+ "net/url"
1920 "os"
2021
2122 "github.com/cloudflare/cfssl/certdb"
@@ -105,6 +106,7 @@ func (s *Signer) sign(template *x509.Certificate) (cert []byte, err error) {
105106 }
106107 template .DNSNames = nil
107108 template .EmailAddresses = nil
109+ template .URIs = nil
108110 s .ca = template
109111 initRoot = true
110112 }
@@ -159,20 +161,23 @@ func PopulateSubjectFromCSR(s *signer.Subject, req pkix.Name) pkix.Name {
159161 return name
160162}
161163
162- // OverrideHosts fills template's IPAddresses, EmailAddresses, and DNSNames with the
164+ // OverrideHosts fills template's IPAddresses, EmailAddresses, DNSNames, and URIs with the
163165// content of hosts, if it is not nil.
164166func OverrideHosts (template * x509.Certificate , hosts []string ) {
165167 if hosts != nil {
166168 template .IPAddresses = []net.IP {}
167169 template .EmailAddresses = []string {}
168170 template .DNSNames = []string {}
171+ template .URIs = []* url.URL {}
169172 }
170173
171174 for i := range hosts {
172175 if ip := net .ParseIP (hosts [i ]); ip != nil {
173176 template .IPAddresses = append (template .IPAddresses , ip )
174177 } else if email , err := mail .ParseAddress (hosts [i ]); err == nil && email != nil {
175178 template .EmailAddresses = append (template .EmailAddresses , email .Address )
179+ } else if uri , err := url .ParseRequestURI (hosts [i ]); err == nil && uri != nil {
180+ template .URIs = append (template .URIs , uri )
176181 } else {
177182 template .DNSNames = append (template .DNSNames , hosts [i ])
178183 }
@@ -232,6 +237,9 @@ func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
232237 if profile .CSRWhitelist .EmailAddresses {
233238 safeTemplate .EmailAddresses = csrTemplate .EmailAddresses
234239 }
240+ if profile .CSRWhitelist .URIs {
241+ safeTemplate .URIs = csrTemplate .URIs
242+ }
235243 }
236244
237245 if req .CRLOverride != "" {
@@ -277,6 +285,11 @@ func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
277285 return nil , cferr .New (cferr .PolicyError , cferr .UnmatchedWhitelist )
278286 }
279287 }
288+ for _ , name := range safeTemplate .URIs {
289+ if profile .NameWhitelist .Find ([]byte (name .String ())) == nil {
290+ return nil , cferr .New (cferr .PolicyError , cferr .UnmatchedWhitelist )
291+ }
292+ }
280293 }
281294
282295 if profile .ClientProvidesSerialNumbers {
@@ -467,17 +480,17 @@ func (s *Signer) SignFromPrecert(precert *x509.Certificate, scts []ct.SignedCert
467480 // Create the new tbsCert from precert. Do explicit copies of any slices so that we don't
468481 // use memory that may be altered by us or the caller at a later stage.
469482 tbsCert := x509.Certificate {
470- SignatureAlgorithm : precert .SignatureAlgorithm ,
471- PublicKeyAlgorithm : precert .PublicKeyAlgorithm ,
472- PublicKey : precert .PublicKey ,
473- Version : precert .Version ,
474- SerialNumber : precert .SerialNumber ,
475- Issuer : precert .Issuer ,
476- Subject : precert .Subject ,
477- NotBefore : precert .NotBefore ,
478- NotAfter : precert .NotAfter ,
479- KeyUsage : precert .KeyUsage ,
480- BasicConstraintsValid : precert .BasicConstraintsValid ,
483+ SignatureAlgorithm : precert .SignatureAlgorithm ,
484+ PublicKeyAlgorithm : precert .PublicKeyAlgorithm ,
485+ PublicKey : precert .PublicKey ,
486+ Version : precert .Version ,
487+ SerialNumber : precert .SerialNumber ,
488+ Issuer : precert .Issuer ,
489+ Subject : precert .Subject ,
490+ NotBefore : precert .NotBefore ,
491+ NotAfter : precert .NotAfter ,
492+ KeyUsage : precert .KeyUsage ,
493+ BasicConstraintsValid : precert .BasicConstraintsValid ,
481494 IsCA : precert .IsCA ,
482495 MaxPathLen : precert .MaxPathLen ,
483496 MaxPathLenZero : precert .MaxPathLenZero ,
0 commit comments