# Admit Trustaige devices on FreeRADIUS

> Configure FreeRADIUS 3 to admit Trustaige device certificates over EAP-TLS for one network, refuse revoked or held devices, and keep trust through rollovers.

Source: https://docs.trustaige.com/manage/own-radius-freeradius

Replace these placeholders with your organization's own values:

- `<your-ssid>`: Network name (SSID), for example `Acme-Secure`. The Wi-Fi name the network broadcasts, as entered in the hub.
- `<your-network-ca-id>`: Network authority ID, for example `3b8f6a1e-5c2d-4e7f-9a10-6d4c2b8e1f35`. The ID in the authority’s CRL address, under Your RADIUS server on the network’s page.
- `<your-network-issuer>`: Network authority subject, for example `/C=NG/O=Trustaige/OU=MDM/CN=Acme MDM CA`. What the openssl command in the FreeRADIUS guide prints for your trust bundle.

This guide adds one network to a FreeRADIUS server you already run. Devices
that join it present their Trustaige certificate over EAP-TLS; FreeRADIUS
checks that your organization's authority issued it, that its subject is a
Trustaige network certificate, and that it isn't on your authority's
revocation list. Your other networks keep the EAP settings they have today,
because this network gets its own instance of the `eap` module.

Start from [Your own RADIUS server](/manage/own-radius-server): the network
must exist in the hub with **Your RADIUS server** as its server, and you need
the files and addresses from its **Your RADIUS server** page.

1. FreeRADIUS → Trustaige: every 15 minutes: fetch each authority’s CRL
2. Device → Access point: joins the SSID
3. Access point → FreeRADIUS: Access-Request, Called-Station-Id ends in the SSID
4. FreeRADIUS → Device: EAP-TLS: your server certificate
5. Device → FreeRADIUS: the device certificate: chain, CRL and subject checked
6. FreeRADIUS → Access point: Access-Accept or Access-Reject

Paths and the `freerad` user below are Debian and Ubuntu's
(`/etc/freeradius/3.0`). On Red Hat family systems the same files are under
`/etc/raddb`, the user is `radiusd`, and the command is `radiusd`.

## Revocation: the CRL, not OCSP

FreeRADIUS's OCSP client sends its requests over plain HTTP, and Trustaige's
responder answers only over HTTPS, so leave the `ocsp` section off. Use your
authority's CRL instead: it lists the same revoked and held certificates the
responder would report, and a small job keeps a fresh copy on disk.

Each CRL is republished within 10 seconds of a change and hourly, and is valid
for 90 minutes. Fetch every 15 minutes. If fetching stops for longer than the
CRL is valid, FreeRADIUS refuses every device until a fresh one arrives, which
is the safe way round.

## Put the files in place

1. **Make a directory** for Trustaige's files, readable by the user
   FreeRADIUS runs as:

   ```sh
   sudo install -d -o freerad -g freerad -m 0750 /etc/freeradius/3.0/certs/trustaige/crl
   ```

2. **Copy the trust bundle** (**Download** under **Trust bundle** on the
   network's **Your RADIUS server** page, or **Download trust bundle** on
   **Certificates**) to
   `/etc/freeradius/3.0/certs/trustaige/trustaige-network-trust.pem`.

3. **Add the CRL job.** List each authority's ID: the one in its CRL address,
   `https://id.trustaige.com/pki/crl/<your-network-ca-id>.crl`. During a
   rollover there are two; list both.

   ```sh title="/usr/local/sbin/trustaige-crl"
   #!/bin/sh
   set -eu
   dir=/etc/freeradius/3.0/certs/trustaige/crl
   work=$(mktemp -d)
   trap 'rm -rf "$work"' EXIT
   for id in <your-network-ca-id>; do
     curl -fsS --max-time 30 -o "$work/$id.der" "https://id.trustaige.com/pki/crl/$id.crl"
     openssl crl -inform DER -in "$work/$id.der" -outform PEM -out "$work/$id.crl.pem"
     install -m 0640 -o freerad -g freerad "$work/$id.crl.pem" "$dir/.$id.next"
     mv -f "$dir/.$id.next" "$dir/$id.crl.pem"
   done
   openssl rehash "$dir"
   ```

   ```txt title="/etc/cron.d/trustaige-crl"
   */15 * * * * root /usr/local/sbin/trustaige-crl
   ```

   Make it executable and run it once now, so a CRL is on disk before
   FreeRADIUS needs it:

   ```sh
   sudo chmod 0755 /usr/local/sbin/trustaige-crl
   sudo /usr/local/sbin/trustaige-crl
   ```

## Configure FreeRADIUS

1. **Add the network's `eap` instance.** It trusts only your Trustaige
   authorities. `certificate_file` is your server's certificate followed by its
   intermediates (the chain devices check against the CA you gave the hub), and
   `auto_chain = no` keeps your server's own CA out of the client trust list.

   ```txt title="/etc/freeradius/3.0/mods-available/eap_trustaige" {9-13,24}
   eap eap_trustaige {
   	default_eap_type = tls
   	timer_expire = 60
   	max_sessions = ${max_requests}

   	tls-config tls-trustaige {
   		private_key_file = ${certdir}/server.key
   		certificate_file = ${certdir}/server-chain.pem
   		auto_chain = no
   		ca_file = ${certdir}/trustaige/trustaige-network-trust.pem
   		ca_path = ${certdir}/trustaige/crl
   		ca_path_reload_interval = 900
   		check_crl = yes
   		tls_min_version = "1.2"
   		tls_max_version = "1.2"

   		ocsp {
   			enable = no
   		}
   	}

   	tls {
   		tls = tls-trustaige
   		virtual_server = check-trustaige
   	}
   }
   ```

   ```sh
   sudo ln -s ../mods-available/eap_trustaige /etc/freeradius/3.0/mods-enabled/eap_trustaige
   ```

   `tls_max_version = "1.2"` follows FreeRADIUS's own recommendation for EAP.
   Under TLS 1.2 the device's certificate crosses the air unencrypted; it names
   the device's ID and your authority, nothing about the person.

2. **Admit only Trustaige network certificates.** Your authorities also sign
   device-management identities (`eid:…`) and RadSec controller certificates
   (`nas-…`); this virtual server lets in only `tq-` subjects.

   ```txt title="/etc/freeradius/3.0/sites-available/check-trustaige"
   server check-trustaige {
   	authorize {
   		if (&TLS-Client-Cert-Common-Name =~ /^tq-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/) {
   			update config {
   				&Auth-Type := Accept
   			}
   		}
   		else {
   			update config {
   				&Auth-Type := Reject
   			}
   		}
   	}
   }
   ```

   ```sh
   sudo ln -s ../sites-available/check-trustaige /etc/freeradius/3.0/sites-enabled/check-trustaige
   ```

3. **Send the network's requests to it.** In `sites-available/default`, add
   this to `authorize` above the existing `eap` line, and the `Auth-Type`
   block to `authenticate`:

   ```txt title="/etc/freeradius/3.0/sites-available/default"
   authorize {
   	if (&Called-Station-Id =~ /:<your-ssid>$/) {
   		eap_trustaige {
   			ok = return
   		}
   	}
   	# … the existing authorize section, including eap …
   }

   authenticate {
   	Auth-Type eap_trustaige {
   		eap_trustaige
   	}
   	# … the existing Auth-Type blocks …
   }
   ```

   The SSID is a regular expression here: put `\` before any `.`, `(`, `)`,
   `[`, `+`, `*`, `?` or `$` in it.

4. **Check and restart.** `freeradius -XC` reads the configuration and stops.
   Then restart the service, or run `freeradius -X` in the foreground to watch
   the first join.

Leave `check_cert_cn` unset. It compares the certificate's subject with the
`User-Name` the device sends, and what each platform sends there hasn't been
recorded in Trustaige's lab yet; the virtual server above checks the subject
on its own.

## If your FreeRADIUS needs the root

FreeRADIUS sets OpenSSL's partial-chain flag (`X509_V_FLAG_PARTIAL_CHAIN`),
so it can anchor on your authorities without the root. Trustaige's lab hasn't
confirmed it on every build yet. If joins fail with `unable to get issuer
certificate`, use the bundle with the root and pin the issuer, so the root
completes the chain and the pin keeps it to your organization:

1. Copy **Download with root** from **Certificates**
   (`trustaige-network-trust-with-root.pem`: the bundle with the root after it)
   next to the bundle, and print your authority's subject in the form FreeRADIUS
   compares:

   ```sh
   openssl x509 -in trustaige-network-trust.pem -noout -subject -nameopt compat
   ```

   Every generation has the same subject, so one value covers a rollover.

2. In `tls-config tls-trustaige`, point `ca_file` at that file and add the pin.
   Where your FreeRADIUS has `reject_unknown_intermediate_ca`, turn it on too,
   so a chain through any authority that isn't in the file is refused:

   ```txt title="/etc/freeradius/3.0/mods-available/eap_trustaige"
   		ca_file = ${certdir}/trustaige/trustaige-network-trust-with-root.pem
   		check_cert_issuer = "<your-network-issuer>"
   		reject_unknown_intermediate_ca = yes
   ```

Some FreeRADIUS 3.2 releases are reported to refuse chains through authorities
that are in the file when `reject_unknown_intermediate_ca` is on. If yours
does, leave that line out; the issuer pin still keeps the root to your
organization's authority.

## Rollover

When the hub shows a generation that **Takes over on** a date, download the
trust bundle again over the old file, add the new authority's ID to the CRL
job, and run the job once. FreeRADIUS reads the CRL directory again within
`ca_path_reload_interval`; restart it to pick up the new bundle. Remove the
retiring authority's ID only after its **certificates in use** reaches zero.

## Troubleshooting

**`(TLS) OpenSSL says error 20 : unable to get local issuer certificate`**

FreeRADIUS doesn't trust the authority that issued the device's certificate.
Download the trust bundle again: after a rollover it holds the new
generation. Check that `ca_file` points at it and restart FreeRADIUS.

**`(TLS) unable to get issuer certificate for issuer=…`**

Your build can't anchor on an authority below a root. Follow [If your
FreeRADIUS needs the root](#if-your-freeradius-needs-the-root).

**`(TLS) OpenSSL says error 3 : unable to get certificate CRL`**

There's no CRL on disk for the authority that issued the device's certificate.
Run `/usr/local/sbin/trustaige-crl` by hand and read its error. During a
rollover, check that both IDs are in it.

**`(TLS) OpenSSL says error 12 : CRL has expired`**

The CRL job hasn't run successfully for over 90 minutes, so every device is
refused. Run it by hand: it needs outbound HTTPS to `id.trustaige.com`.

**`(TLS) OpenSSL says error 23 : certificate revoked`**

The device's certificate is revoked or on hold. Open the device in the hub: a
hold lifts when the device is unblocked, leaves Lost Mode, becomes compliant,
or its owner is an active member again, and the next CRL drops it.

**`Certificate issuer (…) does not match specified value (…)!`**

The value of `check_cert_issuer` isn't exactly your authority's subject.
Print it again with the `openssl` command above and paste it unchanged.

**`There are untrusted certificates in the certificate chain.  Rejecting.`**

`reject_unknown_intermediate_ca = yes` refused a chain through an authority
that isn't in `ca_file`. Download the bundle with the root again, so it holds
every generation in use.

**The join reaches FreeRADIUS but `check-trustaige` rejects it**

The certificate's subject isn't a Trustaige network certificate, such as a
device-management identity. In `freeradius -X`, look at
`TLS-Client-Cert-Common-Name`: a network certificate's starts with `tq-`. A
device without one hasn't received its network certificate yet; the network's
page in the hub lists each device and why it can't join yet.

## FreeRADIUS's documentation

- [`mods-available/eap` in FreeRADIUS 3.2](https://github.com/FreeRADIUS/freeradius-server/blob/v3.2.x/raddb/mods-available/eap): every `tls-config` option used here
- [`sites-available/check-eap-tls` in FreeRADIUS 3.2](https://github.com/FreeRADIUS/freeradius-server/blob/v3.2.x/raddb/sites-available/check-eap-tls): the certificate-checking virtual server
- [`mods-available/eap` in FreeRADIUS 3.0](https://github.com/FreeRADIUS/freeradius-server/blob/v3.0.x/raddb/mods-available/eap)
