@@ -562,7 +562,7 @@ func (cfg *Config) obtainCert(ctx context.Context, name string, interactive bool
562
562
}
563
563
}
564
564
565
- csr , err := cfg .generateCSR (privKey , []string {name })
565
+ csr , err := cfg .generateCSR (privKey , []string {name }, false )
566
566
if err != nil {
567
567
return err
568
568
}
@@ -584,7 +584,19 @@ func (cfg *Config) obtainCert(ctx context.Context, name string, interactive bool
584
584
}
585
585
}
586
586
587
- issuedCert , err = issuer .Issue (ctx , csr )
587
+ // TODO: ZeroSSL's API currently requires CommonName to be set, and requires it be
588
+ // distinct from SANs. If this was a cert it would violate the BRs, but their certs
589
+ // are compliant, so their CSR requirements just needlessly add friction, complexity,
590
+ // and inefficiency for clients. CommonName has been deprecated for 25+ years.
591
+ useCSR := csr
592
+ if _ , ok := issuer .(* ZeroSSLIssuer ); ok {
593
+ useCSR , err = cfg .generateCSR (privKey , []string {name }, true )
594
+ if err != nil {
595
+ return err
596
+ }
597
+ }
598
+
599
+ issuedCert , err = issuer .Issue (ctx , useCSR )
588
600
if err == nil {
589
601
issuerUsed = issuer
590
602
break
@@ -808,7 +820,7 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
808
820
}
809
821
}
810
822
811
- csr , err := cfg .generateCSR (privateKey , []string {name })
823
+ csr , err := cfg .generateCSR (privateKey , []string {name }, false )
812
824
if err != nil {
813
825
return err
814
826
}
@@ -818,6 +830,18 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
818
830
var issuerUsed Issuer
819
831
var issuerKeys []string
820
832
for _ , issuer := range cfg .Issuers {
833
+ // TODO: ZeroSSL's API currently requires CommonName to be set, and requires it be
834
+ // distinct from SANs. If this was a cert it would violate the BRs, but their certs
835
+ // are compliant, so their CSR requirements just needlessly add friction, complexity,
836
+ // and inefficiency for clients. CommonName has been deprecated for 25+ years.
837
+ useCSR := csr
838
+ if _ , ok := issuer .(* ZeroSSLIssuer ); ok {
839
+ useCSR , err = cfg .generateCSR (privateKey , []string {name }, true )
840
+ if err != nil {
841
+ return err
842
+ }
843
+ }
844
+
821
845
issuerKeys = append (issuerKeys , issuer .IssuerKey ())
822
846
if prechecker , ok := issuer .(PreChecker ); ok {
823
847
err = prechecker .PreCheck (ctx , []string {name }, interactive )
@@ -826,7 +850,7 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
826
850
}
827
851
}
828
852
829
- issuedCert , err = issuer .Issue (ctx , csr )
853
+ issuedCert , err = issuer .Issue (ctx , useCSR )
830
854
if err == nil {
831
855
issuerUsed = issuer
832
856
break
@@ -898,10 +922,16 @@ func (cfg *Config) renewCert(ctx context.Context, name string, force, interactiv
898
922
return err
899
923
}
900
924
901
- func (cfg * Config ) generateCSR (privateKey crypto.PrivateKey , sans []string ) (* x509.CertificateRequest , error ) {
925
+ // generateCSR generates a CSR for the given SANs. If useCN is true, CommonName will get the first SAN (TODO: this is only a temporary hack for ZeroSSL API support).
926
+ func (cfg * Config ) generateCSR (privateKey crypto.PrivateKey , sans []string , useCN bool ) (* x509.CertificateRequest , error ) {
902
927
csrTemplate := new (x509.CertificateRequest )
903
928
904
929
for _ , name := range sans {
930
+ // TODO: This is a temporary hack to support ZeroSSL API...
931
+ if useCN && csrTemplate .Subject .CommonName == "" && len (name ) <= 64 {
932
+ csrTemplate .Subject .CommonName = name
933
+ continue
934
+ }
905
935
if ip := net .ParseIP (name ); ip != nil {
906
936
csrTemplate .IPAddresses = append (csrTemplate .IPAddresses , ip )
907
937
} else if strings .Contains (name , "@" ) {
0 commit comments