400 Cannot Find Key of Appropriate Type to Decrypt AP REP
Luke Hebert
- 3 minutes read - 541 wordsIf your application is throwing a 400 Cannot find key of appropriate type to decrypt AP REP error, the Kerberos ticket exchange is failing at the encryption layer. This typically means the client and the service disagree on which key or enctype to use, and the fix is almost always a configuration mismatch rather than a code defect.
Common Causes
Work through the following list in order. Each item is a frequent root cause in production environments:
- Service principal mismatch. The service principal name (SPN) in the security configuration does not exactly match the SPN registered in the keytab. Even a single character difference (case, domain suffix, or service name) will cause this error.
- Short hostname or invalid FQDN. The client is connecting to the service using a short hostname (e.g.,
myhost) instead of the fully qualified domain name (e.g.,myhost.example.com). Kerberos requires the FQDN to match the SPN. - Missing enctype in the ticket. Active Directory issued a ticket with an encryption type (enctype) for which no corresponding key exists on the service side.
- Keytab lacks the required enctype. The keytab was generated without a key for the enctype the client is requesting. This often overlaps with cause #2 when the FQDN mismatch causes the wrong SPN to be looked up.
- Kvno mismatch. The key version number (Kvno) in the ticket differs from the Kvno stored in the keytab. This happens after a password change on the service account if the keytab was not regenerated.
- Wrong or inaccessible keytab path. The application cannot read the keytab file because the path is incorrect or the file does not exist at the expected location.
- Permissions too open. The keytab file permissions are too permissive. Kerberos libraries (and many Java security managers) will reject a keytab that is world-readable. Set permissions to
600(owner read/write only) or640with the correct group. - Permitted encryption types. Review the Kerberos configuration on the client (
krb5.confor equivalent) and confirm the permitted encryption types include the enctype the service expects. - JCE policy files (Java clients). If the key size exceeds 128 bits, Java clients require the Unlimited Strength JCE policy files. These are bundled by default in JDK 8u151 and later. On older JDK builds, install the policy files manually into
$JAVA_HOME/jre/lib/security.
Quick Diagnostic Steps
- Run
klist -kt /path/to/keytabto inspect the SPN, Kvno, and enctypes present in the keytab. - Compare the SPN and Kvno against what Active Directory reports for the service account.
- Verify the client is resolving the service to the correct FQDN (
nslookupordig). - Check file permissions:
ls -l /path/to/keytab. - If using Java, confirm the JDK version and that the JCE policy is unlimited.
Kerberos Encryption Type Reference
| Enctype Number | Name |
|---|---|
| 1 | DES CBC MD5 |
| 3 | DES CBC MD4 |
| 17 | AES-128 CTS HMAC-SHA1 |
| 18 | AES-256 CTS HMAC-SHA1 |
| 16 | AES-128 CTS HMAC-SHA1 96 |
| 19 | AES-256 CTS HMAC-SHA1 96 |
Most modern Active Directory environments default to AES-256 (enctype 18). If your keytab was generated with only DES or RC4 keys, the AES ticket from AD will fail to decrypt, producing exactly this error.
After any password change on the service account, regenerate the keytab immediately. A stale keytab with an old Kvno is one of the most common causes of this error in production.