Go: x509: certificate relies on legacy Common Name field
1. What the error actually means
Go’s crypto/x509 package returns this exact string when a server certificate has no Subject Alternative Name (SAN) extension and carries the hostname only in the legacy subject: CN= field:
x509: certificate relies on legacy Common Name field, use SANs instead
In an HTTP client it usually arrives wrapped:
Get "https://a.internal/health": tls: failed to verify certificate: x509: certificate relies on legacy Common Name field, use SANs instead
The behaviour changed in two steps. Go 1.15 (August 2020) stopped using CN when SAN was absent, leaving a temporary GODEBUG=x509ignoreCN=0 escape hatch; Go 1.17 removed that hatch entirely. Anything built with a modern toolchain therefore rejects CN-only certificates — as does Chrome (since Chrome 58, 2017) and Apple platforms (iOS 13 / macOS 10.15 and later).
Two structural limits make CN unusable as an identity field: it is capped at 64 characters, and it cannot express more than one name or any IP address. A SAN extension carries many dNSName and iPAddress entries, which is why it replaced CN for hostname verification everywhere.
In practice this is nearly always an internal, self-signed or private-CA certificate produced by an old script, an appliance, or a hand-rolled openssl req -subj "/CN=..." call that never added -addext. Public CAs have written SANs by default for years, so if a public certificate triggers this, you are probably connecting to a stale certificate on disk or an old device, not to the CA’s current output.
2. Diagnose it in 60 seconds
Confirm what the server is actually sending before changing anything. Always pass -servername so SNI selects the right certificate:
echo | openssl s_client -connect a.internal:443 -servername a.internal -showcerts 2>/dev/null
| openssl x509 -noout -subject -issuer -dates -ext subjectAltName
If there is no subjectAltName block, you have found the problem. A healthy result looks like this:
subject=CN = a.internal
issuer=CN = Internal Root CA
notBefore=Feb 1 00:00:00 2026 GMT
notAfter=May 2 00:00:00 2026 GMT
X509v3 Subject Alternative Name:
DNS:a.internal, DNS:*.a.internal, IP Address:10.0.0.5
To inspect a file rather than a live endpoint:
openssl x509 -in a.crt -noout -text | grep -A2 "Subject Alternative Name"
To see exactly what a Go client sees — including the remaining lifetime, which matters once the 200/100/47-day caps land — drop this into cmd/peercert/main.go:
package main
import (
"crypto/tls"
"fmt"
"os"
)
func main() {
conn, err := tls.Dial("tcp", os.Args[1], &tls.Config{ServerName: os.Args[2], MinVersion: tls.VersionTLS12})
if err != nil {
fmt.Println("handshake:", err)
os.Exit(1)
}
defer conn.Close()
leaf := conn.ConnectionState().PeerCertificates[0]
fmt.Println("subject: ", leaf.Subject)
fmt.Println("dnsNames: ", leaf.DNSNames)
fmt.Println("ipAddresses:", leaf.IPAddresses)
fmt.Println("notBefore: ", leaf.NotBefore.UTC())
fmt.Println("notAfter: ", leaf.NotAfter.UTC())
fmt.Printf("lifetime: %.1f daysn", leaf.NotAfter.Sub(leaf.NotBefore).Hours()/24)
}
Run it with go run ./cmd/peercert a.internal:443 a.internal.
3. The validity caps you must design for now (2026 → 2029)
Older versions of this article quoted 825 days, then 398 days. Both are historical. The current schedule comes from CA/Browser Forum ballot SC-081, which phases in three reductions for publicly trusted TLS server certificates, measured as notAfter − notBefore:
| Certificate issued on or after | Max public TLS validity | Max DV/OV/EV data reuse | Recommended renewal target |
|---|---|---|---|
| 2020-09-01 (still current) | 398 days | 398 days | 60–90 days, ACME |
| 2026-03-15 | 200 days | 200 days | 60 days |
| 2027-03-15 | 100 days | 100 days | 30–45 days |
| 2029-03-15 | 47 days | 47 days | ~20 days, ARI-driven |
What this changes operationally:
- Manual renewal stops being viable. A 47-day certificate behind a two-week human approval cycle is a 30-day certificate with a 17-day outage risk.
- Automation becomes the only supported model: ACME (Let’s Encrypt, Buypass, Google Trust Services, ZeroSSL),
cert-managerin Kubernetes, or a built-in ACME client such as Caddy’s. - Jitter and ARI matter. With 47-day lifetimes, thousands of clients renewing at the same second is an availability risk. Prefer ACME Renewal Information (ARI, RFC 9773) over a fixed cron window.
- Existing certificates are not revoked by the schedule. A 398-day certificate issued before 2026-03-15 remains valid until its own
notAfter; each cap applies only to certificates issued on or after its date. - Internal CA and mTLS client certificates are outside these caps, but running them on the same short cadence keeps your automation honest.
For the record: Ballot 193 set 825 days from 2018-03-01, and SC-042 set 398 days from 2020-09-01. Any guide still presenting 825 or 398 days as the current maximum is out of date.
4. Fix internal certificates: reissue with SAN
OpenSSL 1.1.1 and later support -addext, which is the fastest path. Check with openssl version first.
Self-signed certificate for a service (90 days is a sane internal default):
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 90
-keyout a.key -out a.crt
-subj "/CN=a.internal"
-addext "subjectAltName=DNS:a.internal,DNS:*.a.internal,IP:10.0.0.5,IP:127.0.0.1"
-addext "basicConstraints=critical,CA:FALSE"
-addext "keyUsage=critical,digitalSignature,keyEncipherment"
-addext "extendedKeyUsage=serverAuth"
CSR for a private CA — the SAN must be in the request, and the CA must copy it into the certificate it signs:
openssl req -new -newkey rsa:2048 -nodes -sha256
-keyout a.key -out a.csr
-subj "/CN=a.internal"
-addext "subjectAltName=DNS:a.internal,DNS:*.a.internal,IP:10.0.0.5"
Verify the request before submitting it:
openssl req -in a.csr -noout -text | grep -A2 "Subject Alternative Name"
On OpenSSL older than 1.1.1, or when you want a repeatable, reviewable profile, use a config file:
[req]
distinguished_name = dn
req_extensions = v3_req
prompt = no
[dn]
CN = a.internal
[v3_req]
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt
[alt]
DNS.1 = a.internal
DNS.2 = *.a.internal
IP.1 = 10.0.0.5
openssl req -new -config a.cnf -key a.key -out a.csr
openssl x509 -req -in a.csr -CA ca.crt -CAkey ca.key -CAcreateserial
-days 90 -sha256 -extfile a.cnf -extensions v3_req -out a.crt
openssl verify -CAfile ca.crt -verify_hostname a.internal a.crt
For local development, do not hand-roll anything — use mkcert, which installs a local CA into the system trust store and always writes SANs:
mkcert -install
mkcert a.internal "*.a.internal" localhost 127.0.0.1 ::1
If your Go service must trust a private CA, load it explicitly instead of disabling verification:
pool, _ := x509.SystemCertPool()
pem, err := os.ReadFile("/etc/ssl/internal-ca.crt")
if err != nil {
log.Fatal(err)
}
if !pool.AppendCertsFromPEM(pem) {
log.Fatal("no certificates parsed from internal-ca.crt")
}
client := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{
RootCAs: pool,
MinVersion: tls.VersionTLS12,
}}}
On Linux, Go also honours SSL_CERT_FILE and SSL_CERT_DIR, which is often the cleanest container fix: mount the bundle and set SSL_CERT_FILE=/etc/ssl/certs/internal-ca.crt. Never “fix” this with InsecureSkipVerify: true — that discards the very hostname check this error is about.
Names to put in the SAN every time: the FQDN clients use, any short name still present in configs, the wildcard if you depend on one, and every IP address and loopback literal used by health checks. Wildcards match exactly one label: *.a.internal covers api.a.internal, but not a.internal and not eu.api.a.internal.
5. Public certificates: let the CA write SANs and automate renewal
For anything under a public suffix, use ACME. The CA writes SANs automatically and enforces the validity cap server-side — your requested duration is a hint, not a guarantee:
certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
certbot renew --dry-run
In Kubernetes, cert-manager expresses SANs as dnsNames and ipAddresses; set renewBefore to at least a third of duration:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: a-internal
namespace: default
spec:
secretName: a-internal-tls
duration: 2160h # 90 days; public CAs may shorten this
renewBefore: 720h # renew with 60 days remaining
commonName: a.internal
dnsNames:
- a.internal
- "*.a.internal"
ipAddresses:
- 10.0.0.5
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
kubectl get certificate a-internal -o wide
cmctl renew a-internal -n default
Two naming notes. First, .internal is a reserved TLD (ICANN reserved it in 2024) and public CAs will not issue for it — use your private CA, or a subdomain of a name you genuinely control. Second, if the old certificate’s CN exceeds 64 characters, Go may instead report x509: "..." certificate is not standards compliant; reissuing with a short CN and a complete SAN list clears both errors at once.
6. Comparison: what each certificate type actually gives you
| Certificate shape | Field used for verification | Accepted by Go 1.17+ / Chrome / iOS 13+ | IP addresses | Multiple names |
|---|---|---|---|---|
| CN-only (legacy) | subject:CN |
No | No | No (CN ≤ 64 chars) |
| CN + SAN | SAN (CN ignored) | Yes | Yes, via iPAddress |
Yes |
| SAN only, no CN | SAN | Yes | Yes | Yes |
| Type | What the CA validates | Browser UI | Max validity from 2026-03-15 | Use it for |
|---|---|---|---|---|
| DV | Domain control only (DNS-01, HTTP-01, TLS-ALPN-01) | Generic padlock, no organisation info | 200 days | Public sites, APIs, anything automatable |
| OV | Domain control plus verified organisation identity in subject:O |
Identical to DV — no org name shown | 200 days | B2B and partner-facing services, procurement checklists |
| EV | Domain control plus extended validation per the CA/B EV Guidelines; policy OIDs and CT entries | Identical to DV — no green bar, no company name (removed in 2019) | 200 days | Regulatory or contractual requirements, not UI |
On EV specifically: the organisation name is not displayed in browser UI any more. Chrome removed the EV treatment from the address bar in 2019 and Safari and Firefox followed, so a DV, OV and EV certificate look the same to a user today. EV survives as certificate-policy OIDs, Certificate Transparency evidence and a stronger audit trail — valuable for procurement and compliance, not for phishing resistance. If your business case for EV was “users will see our company name”, that case is dead; if it was “our regulator requires extended validation”, it still stands.
7. Troubleshooting: real messages and what they mean
| Message | Cause | Fix |
|---|---|---|
x509: certificate relies on legacy Common Name field, use SANs instead |
Certificate has no SAN extension | Reissue with SANs (section 4) |
x509: certificate is valid for a.internal, not b.internal |
SAN exists but lacks the requested name | Add the name to the SAN, or correct the client’s ServerName |
x509: cannot validate certificate for 10.0.0.5 because it doesn't contain any IP SANs |
IP literal missing, or placed in a dNSName |
Add IP:10.0.0.5 to the SAN |
x509: certificate signed by unknown authority |
Private CA not in the process trust store | Mount the CA, set SSL_CERT_FILE, or use SystemCertPool + AppendCertsFromPEM |
x509: certificate has expired or is not yet valid: current time 2026-03-15T10:00:00Z is after 2026-01-01T00:00:00Z |
Expired certificate, or clock skew in a container | Rotate; verify NTP and container time |
x509: SAN dNSName is malformed |
IP literal inside a DNS SAN, or a double wildcard like *.*.a.internal |
Move the IP to iPAddress; use single-label wildcards |
x509: certificate specifies an incompatible key usage |
EKU lacks serverAuth (or clientAuth for mTLS) |
Reissue with the correct extendedKeyUsage |
x509: invalid signature: parent certificate cannot sign this kind of certificate |
Intermediate is missing CA:TRUE or keyUsage=keyCertSign |
Fix the CA profile and re-sign the chain |
x509: "..." certificate is not standards compliant |
CN longer than 64 characters | Shorten or drop the CN; rely on the SAN |
tls: failed to verify certificate: x509: ... |
Go 1.20+ error wrapping | Read the cause after the final colon |
remote error: tls: bad certificate |
Server rejects the client certificate in mTLS | Check the client cert’s SAN, EKU clientAuth and CA chain |
You can reproduce a hostname failure offline, without a network round trip:
openssl verify -CAfile ca.crt -verify_hostname b.internal a.crt
# CN = a.internal
error 62 at 0 depth lookup: hostname mismatch
That error 62 is the OpenSSL equivalent of Go’s SAN mismatch, and it confirms the certificate itself is the problem rather than DNS or firewalling.
8. Rotation checklist for the short-lifetime era
- Inventory. Enumerate every endpoint, including internal ones, and record issuer, SANs and
notAfter. A loop is enough to start:for h in api.internal web.internal example.com; do echo "== $h" echo | openssl s_client -connect "$h:443" -servername "$h" 2>/dev/null | openssl x509 -noout -subject -dates -ext subjectAltName done - Move everything to SAN-bearing certificates before touching renewal cadence; the CN error and the lifetime crunch are separate problems that are cheapest to fix together.
- Automate issuance and deployment. ACME or
cert-manager, with the reload step (nginx-s reload, Envoy SDS, or a file watcher) tested in staging. - Alert on percentage of lifetime left, not on days. Thresholds at 50%, 25% and 10% of
notAfter − notBeforekeep working as lifetimes shrink to 47 days. - Prefer ARI over fixed schedules, and add jitter if your client does not support it.
- Keep OCSP out of the critical path. OCSP is being retired across the ecosystem (Let’s Encrypt ended its OCSP service in 2025) and short lifetimes plus CRLs replace it — do not build monitoring or gating on OCSP responses.
- Test the failure mode. Expire a certificate deliberately in staging and confirm the alert fires before the outage does.
9. FAQ
Can I just set GODEBUG=x509ignoreCN=0?
No. The escape hatch existed only in Go 1.15 and 1.16 and was removed in Go 1.17. No environment variable or build flag restores CN matching, and the same certificate would fail in Chrome and on iOS regardless.
Can I add a SAN to an existing certificate without reissuing?
No. The SAN lives inside the signed tbsCertificate; changing it invalidates the signature. Reissue — the key pair can often be reused, so only the CSR and signature change.
Will my 398-day certificate be revoked on 2026-03-15?
No. The 200-day cap applies to certificates issued on or after 2026-03-15. Certificates already issued keep running to their own notAfter; the schedule only constrains new issuance from each date.
Do I need an EV certificate so users see my company name?
No — browsers no longer display it. Chrome dropped the EV indicator in 2019 and Safari and Firefox followed; DV, OV and EV are visually identical. Buy EV only if a contract or regulator requires extended validation, and expect the evidence to live in policy OIDs and CT logs rather than the address bar.
Does a wildcard SAN cover the apex domain?
No. *.a.internal matches exactly one label, so api.a.internal is covered but a.internal and eu.api.a.internal are not. List the apex explicitly.
Why does curl succeed while Go fails on the same host?
Some OpenSSL builds and curl configurations still fall back to CN when SAN is absent; Go does not. Treat curl as a transport test, not an identity test, and confirm with openssl x509 -noout -ext subjectAltName or the Go snippet in section 2.
How do I get a publicly trusted certificate for a .internal name?
You cannot. .internal is reserved and not publicly resolvable, so no public CA can validate it. Use a private CA with a distributed root, or use a subdomain of a public name you own with DNS-01 validation and split-horizon DNS.
Is the 47-day limit really happening?
Yes — SC-081 sets 47 days for certificates issued on or after 2029-03-15, following 200 days from 2026-03-15 and 100 days from 2027-03-15. Treat 2029 as a planning deadline today: anything that cannot renew unattended will not survive it.