Skip to content

Commit 9ff0957

Browse files
committed
ca: Profile tweaks (default, promote CA flag)
This adds the ability to flag a profile to promote the first domain/IP to the common name. This was previously removed when promotion was deprecated, but is still allowed in the Let's Encrypt "classic" profile, so this helps mock this behavior (and also allows it to be mocked in CAs that still do the same).
1 parent dc9bf9d commit 9ff0957

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

ca/ca.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ type chain struct {
4545
}
4646

4747
type Profile struct {
48-
Description string
49-
ValidityPeriod uint64
48+
Description string
49+
PromoteCommonName bool
50+
ValidityPeriod uint64
5051
}
5152

5253
func (c *chain) String() string {
@@ -309,6 +310,22 @@ func (ca *CAImpl) newCertificate(domains []string, ips []net.IP, key crypto.Publ
309310
IsCA: false,
310311
}
311312

313+
// Check to see if the profile allows for the promotion of first domain to
314+
// the common name. This helps emulate the Let's Encrypt "classic" profile or
315+
// other CAs that follow similar behavior.
316+
if prof.PromoteCommonName {
317+
var cn string
318+
switch {
319+
case len(domains) > 0:
320+
cn = domains[0]
321+
case len(ips) > 0:
322+
cn = ips[0].String()
323+
}
324+
if cn != "" {
325+
template.Subject.CommonName = cn
326+
}
327+
}
328+
312329
if ca.ocspResponderURL != "" {
313330
template.OCSPServer = []string{ca.ocspResponderURL}
314331
}
@@ -375,7 +392,12 @@ func New(log *log.Logger, db *db.MemoryStore, ocspResponderURL string, alternate
375392
prof.ValidityPeriod = defaultValidityPeriod
376393
}
377394
ca.profiles[name] = &prof
378-
ca.log.Printf("Loaded profile %q with certificate validity period of %d seconds", name, prof.ValidityPeriod)
395+
ca.log.Printf(
396+
"Loaded profile %q with certificate validity period of %d seconds (promote CN=%t)",
397+
name,
398+
prof.ValidityPeriod,
399+
prof.PromoteCommonName,
400+
)
379401
}
380402

381403
return ca

0 commit comments

Comments
 (0)