TLS mode is the most powerful crypto mode of OpenVPN in both security and flexibility. TLS mode works by establishing control and data channels which are multiplexed over a single TCP/UDP port. OpenVPN initiates a TLS session over the control channel and uses it to exchange cipher and HMAC keys to protect the data channel. TLS mode uses a robust reliability layer over the UDP connection for all control channel communication, while the data channel, over which encrypted tunnel data passes, is forwarded without any mediation. The result is the best of both worlds: a fast data channel that forwards over UDP with only the overhead of encrypt, decrypt, and HMAC functions, and a control channel that provides all of the security features of TLS, including certificate-based authentication and Diffie Hellman forward secrecy.
To use TLS mode, each peer that runs OpenVPN should have its own local
certificate/key pair (--cert
and --key
), signed by the root
certificate which is specified in --ca
.
When two OpenVPN peers connect, each presents its local certificate to
the other. Each peer will then check that its partner peer presented a
certificate which was signed by the master root certificate as specified
in --ca
.
If that check on both peers succeeds, then the TLS negotiation will succeed, both OpenVPN peers will exchange temporary session keys, and the tunnel will begin passing data.
The OpenVPN project provides a set of scripts for managing RSA certificates and keys: https://github.com/OpenVPN/easy-rsa
--askpass file | Get certificate password from console or Valid syntaxes: askpass askpass file For the extremely security conscious, it is possible to protect your
private key with a password. Of course this means that every time the
OpenVPN daemon is started you must be there to type the password. The
If |
--ca file | Certificate authority (CA) file in .pem format, also referred to as the root certificate. This file can have multiple certificates in .pem format, concatenated together. You can construct your own certificate authority certificate and private key by using a command such as: openssl req -nodes -new -x509 -keyout ca.key -out ca.crt Then edit your openssl.cnf file and edit the For testing purposes only, the OpenVPN distribution includes a sample CA certificate (ca.crt). Of course you should never use the test certificates and test keys distributed with OpenVPN in a production environment, since by virtue of the fact that they are distributed with OpenVPN, they are totally insecure. |
--capath dir | Directory containing trusted certificates (CAs and CRLs). Not available with mbed TLS. CAs in the capath directory are expected to be named <hash>.<n>. CRLs
are expected to be named <hash>.r<n>. See the Similar to the |
--cert file | Local peer's signed certificate in .pem format -- must be signed by a
certificate authority whose certificate is in openssl req -nodes -new -keyout mycert.key -out mycert.csr If your certificate authority private key lives on another machine, copy the certificate signing request (mycert.csr) to this other machine (this can be done over an insecure channel such as email). Now sign the certificate with a command such as: openssl ca -out mycert.crt -in mycert.csr Now copy the certificate (mycert.crt) back to the peer which initially
generated the .csr file (this can be over a public medium). Note that
the |
--crl-verify args | |
Check peer certificate against a Certificate Revocation List. Valid syntax: crl-verify file/directory flag Examples: crl-verify crl-file.pem crl-verify /etc/openvpn/crls dir A CRL (certificate revocation list) is used when a particular key is compromised but when the overall PKI is still intact. Suppose you had a PKI consisting of a CA, root certificate, and a number of client certificates. Suppose a laptop computer containing a client key and certificate was stolen. By adding the stolen certificate to the CRL file, you could reject any connection which attempts to use it, while preserving the overall integrity of the PKI. The only time when it would be necessary to rebuild the entire PKI from scratch would be if the root certificate key itself was compromised. The option is not mandatory - if the relevant CRL is missing, OpenVPN will log a warning in the logs - e.g. VERIFY WARNING: depth=0, unable to get certificate CRL but the connection will be allowed. If the optional
| |
--dh file | File containing Diffie Hellman parameters in .pem format (required for
Set Use |
--ecdh-curve name | |
Specify the curve to use for elliptic curve Diffie Hellman. Available
curves can be listed with This option is not supported in mbed TLS builds of OpenVPN. | |
--extra-certs file | |
Specify a This option is useful for "split" CAs, where the CA for server certs is
different than the CA for client certs. Putting certs in this file
allows them to be used to complete the local certificate chain without
trusting them to verify the peer-submitted certificate, as would be the
case if the certs were placed in the | |
--hand-window n | |
Handshake Window -- the TLS-based key exchange must finalize within
The | |
--key file | Local peer's private key in .pem format. Use the private key which was
generated when you built your peer's certificate (see --cert file
above). |
--pkcs12 file | Specify a PKCS #12 file containing local private key, local certificate,
and root CA certificate. This option can be used instead of --ca ,
--cert , and --key . Not available with mbed TLS. |
--remote-cert-eku oid | |
Require that peer certificate was signed with an explicit extended key usage. This is a useful security option for clients, to ensure that the host they connect to is a designated server. The extended key usage should be encoded in oid notation, or OpenSSL symbolic representation. | |
--remote-cert-ku key-usage | |
Require that peer certificate was signed with an explicit
If present in the certificate, the If The remote-cert-ku a0 | |
--remote-cert-tls type | |
Require that peer certificate was signed with an explicit key usage and extended key usage based on RFC3280 TLS rules. Valid syntaxes: remote-cert-tls server remote-cert-tls client This is a useful security option for clients, to ensure that the host they connect to is a designated server. Or the other way around; for a server to verify that only hosts with a client certificate can connect. The remote-cert-ku remote-cert-eku "TLS Web Client Authentication" The remote-cert-ku remote-cert-eku "TLS Web Server Authentication" This is an important security precaution to protect against a
man-in-the-middle attack where an authorized client attempts to connect
to another client by impersonating the server. The attack is easily
prevented by having clients verify the server certificate using any one
of | |
--tls-auth args | |
Add an additional layer of HMAC authentication on top of the TLS control channel to mitigate DoS attacks and attacks on the TLS stack. Valid syntaxes: tls-auth file tls-auth file 0 tls-auth file 1 In a nutshell,
Older versions (up to OpenVPN 2.3) supported a freeform passphrase file. This is no longer supported in newer versions (v2.4+). See the
The rationale for this feature is as follows. TLS requires a multi-packet exchange before it is able to authenticate a peer. During this time before authentication, OpenVPN is allocating resources (memory and CPU) to this potential peer. The potential peer is also exposing many parts of OpenVPN and the OpenSSL library to the packets it is sending. Most successful network attacks today seek to either exploit bugs in programs (such as buffer overflow attacks) or force a program to consume so many resources that it becomes unusable. Of course the first line of defense is always to produce clean, well-audited code. OpenVPN has been written with buffer overflow attack prevention as a top priority. But as history has shown, many of the most widely used network applications have, from time to time, fallen to buffer overflow attacks. So as a second line of defense, OpenVPN offers this special layer of authentication on top of the TLS control channel so that every packet on the control channel is authenticated by an HMAC signature and a unique ID for replay protection. This signature will also help protect against DoS (Denial of Service) attacks. An important rule of thumb in reducing vulnerability to DoS attacks is to minimize the amount of resources a potential, but as yet unauthenticated, client is able to consume.
It should be emphasized that this feature is optional and that the key
file used with Use | |
--tls-groups list | |
A list of allowable groups/curves in order of preference. Set the allowed elliptic curves/groups for the TLS session. These groups are allowed to be used in signatures and key exchange. mbedTLS currently allows all known curves per default. OpenSSL 1.1+ restricts the list per default to "X25519:secp256r1:X448:secp521r1:secp384r1". If you use certificates that use non-standard curves, you
might need to add them here. If you do not force the ecdh curve
by using OpenVPN maps the curve name secp256r1 to prime256v1 to allow specifying the same tls-groups option for mbedTLS and OpenSSL. Warning: this option not only affects elliptic curve certificates but also the key exchange in TLS 1.3 and using this option improperly will disable TLS 1.3. | |
--tls-cert-profile profile | |
Set the allowed cryptographic algorithms for certificates according to
The following profiles are supported:
This option is only fully supported for mbed TLS builds. OpenSSL builds use the following approximation:
OpenVPN will migrate to 'preferred' as default in the future. Please ensure that your keys already comply. |
- WARNING:
--tls-ciphers
,--tls-ciphersuites
andtls-groups
- These options are expert features, which - if used correctly - can improve the security of your VPN connection. But it is also easy to unwittingly use them to carefully align a gun with your foot, or just break your connection. Use with care!
--tls-cipher l | A list These setting can be used to ensure that certain cipher suites are used (or not used) for the TLS connection. OpenVPN uses TLS to secure the control channel, over which the keys that are used to protect the actual VPN traffic are exchanged. The supplied list of ciphers is (after potential OpenSSL/IANA name translation) simply supplied to the crypto library. Please see the OpenSSL and/or mbed TLS documentation for details on the cipher list interpretation. For OpenSSL, the Use The default for |
--tls-ciphersuites l | |
Same as The default for --tls-ciphersuites is to use the crypto library's default. | |
--tls-client | Enable TLS and assume client role during TLS handshake. |
--tls-crypt keyfile | |
Encrypt and authenticate all control channel packets with the key from
Encrypting (and authenticating) control channel packets:
In contrast to Security Considerations All peers use the same If IV collisions were to occur, this could result in the security of
For large setups or setups where clients are not trusted, consider using
| |
--tls-crypt-v2 keyfile | |
Valid syntax: tls-crypt-v2 keyfile tls-crypt-v2 keyfile force-cookie tls-crypt-v2 keyfile allow-noncookie Use client-specific tls-crypt keys. For clients, For servers, On servers, this option can be used together with the The optional parameters | |
--tls-crypt-v2-verify cmd | |
Run command OpenVPN supplies the following environment variables to the command:
The command can reject the connection by exiting with a non-zero exit code. | |
--tls-exit | Exit on TLS negotiation failure. |
--tls-export-cert directory | |
Store the certificates the clients use upon connection to this
directory. This will be done before --tls-verify is called. The
certificates will use a temporary name and will be deleted when the
tls-verify script returns. The file name used for the certificate is
available via the peer_cert environment variable. | |
--tls-server | Enable TLS and assume server role during TLS handshake. Note that OpenVPN is designed as a peer-to-peer application. The designation of client or server is only for the purpose of negotiating the TLS control channel. |
--tls-timeout n | |
Packet retransmit timeout on TLS control channel if no acknowledgment
from remote within n seconds (default 2 ). When OpenVPN sends
a control packet to its peer, it will expect to receive an
acknowledgement within n seconds or it will retransmit the packet,
subject to a TCP-like exponential backoff algorithm. This parameter only
applies to control channel packets. Data channel packets (which carry
encrypted tunnel data) are never acknowledged, sequenced, or
retransmitted by OpenVPN because the higher level network protocols
running on top of the tunnel such as TCP expect this role to be left to
them. | |
--tls-version-min args | |
Sets the minimum TLS version we will accept from the peer (default in 2.6.0 and later is "1.2"). Valid syntax: tls-version-min version ['or-highest'] Examples for version include | |
--tls-version-max version | |
Set the maximum TLS version we will use (default is the highest version
supported). Examples for version include 1.0 , 1.1 , or
1.2 . | |
--verify-hash args | |
DEPRECATED Specify SHA1 or SHA256 fingerprint for level-1 cert. Valid syntax: verify-hash hash [algo] The level-1 cert is the CA (or intermediate cert) that signs the leaf
certificate, and is one removed from the leaf certificate in the
direction of the root. When accepting a connection from a peer, the
level-1 cert fingerprint must match AD:B0:95:D8:09:C8:36:45:12:A9:89:C8:90:09:CB:13:72:A6:AD:16 The This option can also be inlined <verify-hash> 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 </verify-hash> |
If the option is inlined, algo
is always SHA256
.
--peer-fingerprint args | |
Specify a SHA256 fingerprint or list of SHA256 fingerprints to verify the peer certificate against. The peer certificate must match one of the fingerprint or certificate verification will fail. The option can also be inlined Valid syntax: peer-fingerprint AD:B0:95:D8:09:... or inline: <peer-fingerprint> 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff 11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00 </peer-fingerprint> When the | |
--verify-x509-name args | |
Accept connections only if a host's X.509 name is equal to name. The remote host must also pass all other tests of verification. Valid syntax: verify-x509 name type Which X.509 name is compared to C=KG, ST=NA, L=Bishkek, CN=Server-1 would be matched by: verify-x509-name 'C=KG, ST=NA, L=Bishkek, CN=Server-1' verify-x509-name Server-1 name verify-x509-name Server- name-prefix The last example is useful if you want a client to only accept
connections to
Using a name prefix is a useful alternative to managing a CRL (Certificate Revocation List) on the client, since it allows the client to refuse all certificates except for those associated with designated servers.
| |
--x509-track attribute | |
Save peer X509 attribute value in environment for use by plugins and
management interface. Prepend a + to attribute to save values
from full cert chain. Values will be encoded as
X509_<depth>_<attribute>=<value> . Multiple --x509-track
options can be defined to track multiple attributes. | |
--x509-username-field args | |
Fields in the X.509 certificate subject to be used as the username
(default Valid syntax: x509-username-field [ext:]fieldname [[ext:]fieldname...] Typically, this option is specified with fieldname arguments as either of the following: x509-username-field emailAddress x509-username-field ext:subjectAltName x509-username-field CN serialNumber The first example uses the value of the When this option is used, the Only the Please note: This option has a feature which will convert an
all-lowercase Non-compliant symbols are being replaced with the |