moodle/moodle · error · WebAuthnException

CERTIFICATE_NOT_TRUSTED

CERTIFICATE_NOT_TRUSTED

Error message

error on validating root certificate: 

What it means

WebAuthnException::CERTIFICATE_NOT_TRUSTED thrown by AndroidKey's root certificate validation when openssl_x509_checkpurpose() returns -1, meaning the attestation certificate chain could not be verified against the configured root CAs (Google Hardware Attestation Root and any additional CA files). It means the attestation does not chain to a trusted root.

Solutions

  1. Provide the current Google Hardware Attestation Root certificate and correct rootCaFile / additional CA file paths to the Attestation verifier
  2. Confirm openssl_x509_checkpurpose can read each CA file (permissions, PEM format)
  3. Inspect the x5c chain: check validity dates and that all intermediates are included; test the chain with `openssl verify -CAfile root.pem -untrusted chain.pem leaf.pem`
  4. Decide policy: reject the registration, or accept with reduced attestation trust depending on your security requirements

Example fix

// before
$rootCas = [$pathToMissingRoot];
// after
$rootCas = ['/etc/webauthn/google-hardware-attestation-root.pem']; // valid, current root CA file
Defensive patterns

Strategy: try-catch

Validate before calling

// verify trust anchors before processing attestations
foreach ($rootCaFiles as $f) {
    if (!is_readable($f)) throw new RuntimeException("CA file unreadable: $f");
}
openssl_x509_checkpurpose($leafPem, -1, $rootCas); // pre-check chain locally

Try / catch

try {
    $format->validateAttestation($clientDataHash);
} catch (WebAuthnException $e) {
    if ($e->getCode() === WebAuthnException::CERTIFICATE_NOT_TRUSTED) {
        // treat registration as untrusted attestation; apply your policy
    }
}

Prevention

When it happens

Trigger: Calling validateAttestation() (which invokes root certificate validation) on an android-key attestation whose x5c chain fails purpose checking: missing/incorrect CA file paths, untrusted or expired chain, or an intermediate CA not supplied.

Common situations: Server has no or outdated Google attestation root CA file configured; OpenSSL cannot build the chain because intermediates are absent; expired or revoked attestation certs; emulators/rooted devices producing non-Google-signed chains.

Understand the failure class

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/fe793e1c556e07d7. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/webauthn/src/Attestation/Format/AndroidKey.php:91

        // check certificate
        return \openssl_verify($dataToVerify, $this->_signature, $publicKey, $coseAlgorithm->openssl) === 1;
    }

    /**
     * validates the certificate against root certificates
     * @param array $rootCas
     * @return boolean
     * @throws WebAuthnException
     */
    public function validateRootCertificate($rootCas) {
        $chainC = $this->_createX5cChainFile();
        if ($chainC) {
            $rootCas[] = $chainC;
        }

        $v = \openssl_x509_checkpurpose($this->getCertificatePem(), -1, $rootCas);
        if ($v === -1) {
            throw new WebAuthnException('error on validating root certificate: ' . \openssl_error_string(), WebAuthnException::CERTIFICATE_NOT_TRUSTED);
        }
        return $v;
    }
}

View on GitHub (pinned to 48ea8c3322)