VpnHood!

Use a domain name and a trusted certificate

Out of the box, the server presents a self-signed certificate with a made-up name. Give it a domain name you own, with a certificate from a certificate authority, and a connection to it looks like a visit to an ordinary website.

What it changes

Apps check the certificate the way a browser does, by the authority that signed it and the name it carries, so keys made after the change keep working when the certificate is renewed.

A domain does not hide the server, though: it points at the server's IP address, and the keys still carry that address. To keep your users connected when the address is blocked, put the server behind a reverse proxy, which needs this certificate first.

Before you start

  • A domain or a subdomain you control, such as server1.example.com. Use a single name, not a wildcard, and one that does not say VPN: apps send it in clear at the start of every connection, where the network can read it.
  • A DNS record that points it straight at the server's connection IP: an A record, and an AAAA record if the server has an IPv6 address. To put Cloudflare in front of the server, finish this page first, then turn its proxy on.

On a standalone server

A standalone server cannot get a certificate by itself. Get one for the domain from a certificate authority, as a PFX file with its private key, and put it in place of /opt/VpnHoodServer/storage/access/certificates/default.pfx, under the same name.

Then put the file's password in SslCertificatesPassword and set IsValidHostName to true, both under FileAccessManager in /opt/VpnHoodServer/storage/appsettings.json. A new install has no such file: create it, and from then on the server uses it in place of the settings it was installed with.

The whole file, with your certificate's password in place of the example

{
  "FileAccessManager": {
    "SslCertificatesPassword": "your-pfx-password",
    "IsValidHostName": true
  },
  "ServerConfig": {
    "LogAnonymizer": true,
    "AddListenerIpsToNetwork": "*"
  },
  "LogLevel": "Information"
}

The server takes the domain from the certificate itself, so there is no setting for it.

Restart the server with sudo systemctl restart VpnHoodServer, or with sudo docker restart VpnHoodServer in Docker. With a wrong password it does not start, and its log says The server could not start.

Keys made before the change stop working, as they expect the old certificate. Print each of them again and give your users the new key: its options and its usage stay the same. A key's ID is the name of its file in /opt/VpnHoodServer/storage/access, without .token2.

List the keys, then print one again by its ID

sudo ls /opt/VpnHoodServer/storage/access | sed -n "s/\.token2$//p"
sudo /opt/VpnHoodServer/vhserver print 2b9d4a6e-1c3f-4e8a-9b7d-5f0e8c2a1d34

In Docker, run the same through sudo docker exec VpnHoodServer /app/vhsupervisor, as for vhserver gen.

The new keys carry the domain and no longer depend on the certificate itself, so they keep working when you renew it: put the new file in place and restart the server.

Use a name of your choice, without a domain

Without a domain, a standalone server can still replace its made-up name. A self-signed certificate can carry any name, even one you do not own, as apps accept it by the fingerprint in their key and never look the name up. It hides less than a trusted certificate, though, and a real site's name can do more harm than good: Which certificate should your server use? explains why.

On the server, make a certificate, with your name in place of api.example.com in both places, and put it in place of /opt/VpnHoodServer/storage/access/certificates/default.pfx. It has no password, so leave SslCertificatesPassword out of your settings, and keep IsValidHostName at false, its default.

Valid for ten years: a new certificate has a new fingerprint, so it needs new keys

openssl req -x509 -newkey rsa:2048 -nodes -days 3650 -subj "/CN=api.example.com" -addext "subjectAltName=DNS:api.example.com" -keyout server.key -out server.crt
openssl pkcs12 -export -inkey server.key -in server.crt -out default.pfx -passout pass:
sudo cp default.pfx /opt/VpnHoodServer/storage/access/certificates/default.pfx
rm server.key server.crt default.pfx

Restart the server with sudo systemctl restart VpnHoodServer, or with sudo docker restart VpnHoodServer in Docker. Keys made before the change stop working, as they carry the old certificate's fingerprint: print each of them again and give your users the new key.

List the keys, then print one again by its ID

sudo ls /opt/VpnHoodServer/storage/access | sed -n "s/\.token2$//p"
sudo /opt/VpnHoodServer/vhserver print 2b9d4a6e-1c3f-4e8a-9b7d-5f0e8c2a1d34

In Docker, run the same through sudo docker exec VpnHoodServer /app/vhsupervisor, as for vhserver gen.

Next steps