V2Ray TLS Handshake Failures and Certificate Errors: System Time, SNI, and allowInsecure Explained

TLS certificate errors are one of the most common reasons V2Ray connections fail. Checking system time, SNI matching, certificate chain completeness, and allowInsecure in that order will pinpoint the issue in both v2rayN and v2rayNG.

In this article

For users hitting the three main TLS errors — "certificate expired", "certificate name mismatch", and "unknown authority" — this guide walks through four checks in order: system time, SNI/domain match, certificate chain completeness, and allowInsecure, with exact steps for v2rayN and v2rayNG.

Common TLS handshake errors and the order to troubleshoot them

The TLS handshake is the first step in establishing a V2Ray connection. The client sends a ClientHello, the server returns its certificate chain, and the local core then verifies the certificate validity period, domain match, and issuing chain. If any step fails, the connection is terminated during the handshake, showing up as "connected but immediately disconnected" or a certificate error in the core log. v2rayN and v2rayNG use the same Xray core, so the error format is identical.

A fixed troubleshooting order works best: read the exact error message first, then check system time, then domain/SNI match, and finally the certificate chain. Skipping around most often leads to endlessly switching servers while the real problem stays unchanged.

Error: tls: failed to verify certificate: x509: certificate has expired or is not yet valid

Cause and fix: The device clock is too far off from real time, putting it outside the certificate's validity window — enable automatic system time sync, restart the core, and retry.

Error: tls: failed to verify certificate: x509: certificate is valid for v2.example.com, not 203.0.113.10

Cause and fix: The server address is set to an IP, but the certificate was issued for a domain — change the address back to the domain, or enter the certificate's domain in the SNI field.

Error: tls: failed to verify certificate: x509: certificate signed by unknown authority

Cause and fix: The server isn't sending the intermediate certificate, so the client can't build a trust chain — use a full certificate chain file on the server side; on the client you can temporarily enable allowInsecure to confirm the diagnosis.

These three errors map to three independent checkpoints. The following sections cover them in this order, with the exact v2rayN and v2rayNG steps at the end of each section.

System time skew: the first source of expired and not yet valid

Certificate validation uses the device's local time. A certificate contains NotBefore and NotAfter boundaries; if the local time falls outside them, you get an "expired" or "not yet valid" error. v2rayN's core log panel prints a local timestamp for every handshake — compare that with real time. A difference of more than a few minutes is enough to confirm a clock issue.

90 days
Typical free certificate validity
443
Default TLS port
2 devices
Devices to check for time sync

Syncing time takes two steps: turn on automatic time, then tap sync now once. Virtual machine and dual-boot users should also make sure the guest OS refreshes its time after resuming — time freezes while suspended.

Time sync paths on Windows and Android

After syncing, restart the core and try again. In v2rayN, use "Core" → "Restart Core"; in v2rayNG, toggle the connection switch off and on. If the error is gone, the problem was time skew.

SNI and domain matching: pinpointing the certificate name mismatch error

Domain matching is the second step of certificate validation. The client compares the certificate's CN and SAN list against the "server address" or a separate SNI field. When the address is an IP but the certificate is only issued for a domain, the log shows valid for xxx, not yyy. In the Xray core this field is called serverName; the GUI shows it as SNI.

{
  "streamSettings": {
    "network": "tcp",
    "security": "tls",
    "tlsSettings": {
      "allowInsecure": false,
      "serverName": "v2.example.com"
    }
  }
}
Server addressSNI fieldHandshake result
v2.example.comLeave emptyOK — SNI automatically uses the address domain
203.0.113.10v2.example.comOK — connection goes over IP, certificate checked against SNI
203.0.113.10Leave emptyCertificate name mismatch, handshake terminated

There are only two fixes: change the address back to the domain, or keep the IP and enter the certificate's domain in the SNI field. The first works when the domain resolves; the second is for when the domain is polluted and you need to connect by IP. In v2rayN, SNI is in the TLS group of the server edit window; in v2rayNG, it's under the TLS settings on the server edit page.

Missing certificate chains and the correct use of allowInsecure

A certificate chain consists of a leaf certificate, intermediate certificates, and a root certificate. The server must send the leaf and intermediate certificates; the root comes from the client system's trust store. If the intermediate certificate is missing, the client can't build a trust chain and reports unknown authority. This is a server-side configuration issue, most often caused by writing only the leaf certificate into the deployment file.

Client initiates handshakeServer sends certificate chainLocal root certificate validationTLS session established

allowInsecure skips the entire certificate validation chain — validity period, domain, and issuer. It doesn't fix the certificate itself; it just lets the handshake pass. If enabling it temporarily makes the connection succeed, the problem is indeed on the certificate side. Fix the certificate on the server afterward instead of leaving this option on permanently.

In v2rayN, allowInsecure is in the TLS group of the server edit window; you need to restart the core for it to take effect. In v2rayNG, it's the allowInsecure toggle on the server edit page; toggle it off and reconnect. Traffic is still TLS-encrypted, but the certificate identity is no longer verified, allowing a man-in-the-middle to substitute the certificate.

v2rayN and v2rayNG TLS settings comparison

The table below summarizes where to find the four checkpoints in both clients. Following this order covers the vast majority of certificate-related errors.

Check itemv2rayNv2rayNG
Core logLog panel at the bottom of the main windowLog entry on the main screen
Server addressEdit server → AddressEdit server → Address
SNIEdit server → TLS → SNIEdit server → TLS group → SNI
allowInsecureEdit server → TLS → allowInsecureEdit server → allowInsecure toggle
Restart connectionCore → Restart CoreToggle the connection switch off and on

Getting "certificate has expired" even though the phone shows the correct time

First check the handshake timestamp in v2rayN's log panel to see what local time the core is reading; then check whether the Windows Time service is running, and run w32tm /resync in an elevated command prompt to force a sync.

I entered the domain but still get "not valid for"

Make sure the domain exactly matches one of the certificate's SAN entries — the www prefix counts as a mismatch. Open the domain directly in a browser over HTTPS and compare the "Subject Alternative Name" list in the certificate details one by one.

allowInsecure makes it work — can I just leave it on?

Not recommended. It only skips validation; it doesn't fix the certificate. For long-term use, complete the server's certificate chain and turn allowInsecure back off.

Certificate errors only appear on one server

That server's certificate is misconfigured. Switching to another server restores service temporarily; also check whether the server address was mistakenly set to an IP while the certificate is only issued for a domain.

Same error after restarting the core

Make sure the modified server is the one selected in the server list, and re-fetch the subscription in v2rayNG before retrying. On some devices you also need to sync the system time first, then disconnect and reconnect.

v2rayN download