Nextcloud, Home Assistant, Outlook: “certificate not trusted” in the Android app

Your own Nextcloud, Home Assistant or internal Exchange works in the phone's browser, but the app reports an untrusted certificate. That is almost never the app's fault but comes down to three things: the chain, the root CA and whether the app trusts CAs you installed yourself at all.

Check your server’s chain nowShows for Android 7.0 to 17 whether apps trust your certificate chain and until when.

Why the browser works and the app doesn't

What the apps require

AppOwn CA possible?Note
Home Assistant Companionyes, via installed CATrusts user CAs but offers no option to ignore certificate errors. Message: “The Home Assistant certificate authority is not trusted”.
NextcloudyesAsks whether you want to trust an unknown certificate. That doesn't help permanently with chain errors.
Outlook with your own ExchangenoUses Java's standard root CAs. A certificate from an internal CA leads to “Insecure connection”. TLS 1.2 is also required.

For Outlook with Exchange you therefore need a publicly trusted certificate, see renewing the Exchange certificate.

Checklist

  1. Chain complete? The SSL check shows whether the server sends the intermediates. With Let's Encrypt the configuration needs fullchain.pem, not cert.pem.
  2. Right name? The name in the app must be a SAN in the certificate, even if you use an IP address internally, see Hostname not verified.
  3. Root CA installed instead of the server certificate? The phone needs your CA's certificate, installed as a “CA certificate”, not as a VPN or Wi-Fi certificate. Android requires a screen lock for this. Guide: installing a certificate on Android.
  4. Does the app trust user CAs? If not, only a publicly trusted certificate helps.
  5. Date and time correct on phone and server?
  6. Certificate renewed? Some apps remember a previously accepted certificate. After a change, clearing the app data and signing in again helps.

The permanent fix: a real certificate

The least trouble is a Let's Encrypt certificate, even for services that are only reachable at home. With the DNS challenge the server doesn't need to be reachable from the internet. All you need is your own domain and a DNS provider with an API. Internally the name points to the private IP address. The ACME helper generates the right commands. Every app then trusts the certificate without anything installed on the devices.

# Example: acme.sh with the DNS challenge via Cloudflare
export CF_Token="…"
acme.sh --issue --dns dns_cf -d ha.example.com

# Then check the chain from a client’s point of view
openssl s_client -connect ha.example.com:443 -servername ha.example.com -showcerts </dev/null 2>/dev/null | grep -E "s:|i:|Verify return"

If it has to be your own CA

With OpenSSL it looks like this:

# 1. Root CA, valid for 10 years
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout ca.key -out ca.pem \
  -subj "/CN=Home Root CA" -addext "basicConstraints=critical,CA:TRUE" -addext "keyUsage=critical,keyCertSign,cRLSign"

# 2. Server certificate with SAN for name and IP address
openssl req -newkey rsa:2048 -nodes -keyout ha.key -out ha.csr -subj "/CN=ha.home.example"
openssl x509 -req -in ha.csr -CA ca.pem -CAkey ca.key -CAcreateserial -days 397 -sha256 -out ha.pem \
  -extfile <(printf "subjectAltName=DNS:ha.home.example,IP:192.168.1.10\nbasicConstraints=CA:FALSE\nextendedKeyUsage=serverAuth")

# 3. CA for Android as a DER file
openssl x509 -in ca.pem -outform der -out ca.crt

FAQ

Is it enough to install the server certificate on the phone?

Usually not. Android expects a CA certificate. A self-signed server certificate without the CA flag often can't be installed as a CA.

Why does Home Assistant work in the browser but not in the app?

Usually an intermediate that Chrome fills in itself is missing from the chain, or the CA was installed as a Wi-Fi or VPN certificate instead of a CA certificate.

Can I use Outlook for Android with an internal CA?

No. Outlook uses Java's standard root CAs. For Exchange you need a publicly trusted certificate.

Sources and documentation