Introduction
Theimpacket.krb5 module provides a comprehensive implementation of the Kerberos v5 network authentication protocol (RFC 4120) with Microsoft extensions from [MS-KILE] and [MS-PAC]. This module enables Python applications to:
- Request and manage Kerberos tickets (TGT/TGS)
- Perform Kerberos authentication operations
- Manipulate credential caches and keytabs
- Handle ASN.1 structures for Kerberos messages
- Encrypt/decrypt Kerberos messages with various cipher suites
- Process Privilege Attribute Certificates (PAC)
Module Structure
The Kerberos implementation is organized into several specialized modules:Core Components
Authentication Flow
The typical Kerberos authentication workflow:Principal Names
Principal objects represent Kerberos identities:Tickets
Ticket objects encapsulate Kerberos tickets:Encryption Types
Supported encryption algorithms:| Encryption Type | Value | Description |
|---|---|---|
| DES-CBC-CRC | 1 | DES with CRC-32 (deprecated) |
| DES-CBC-MD5 | 3 | DES with MD5 (deprecated) |
| DES3-CBC-SHA1 | 16 | Triple DES with SHA-1 |
| AES128-CTS-HMAC-SHA1-96 | 17 | AES-128 encryption |
| AES256-CTS-HMAC-SHA1-96 | 18 | AES-256 encryption (recommended) |
| RC4-HMAC | 23 | RC4 with HMAC-MD5 |
Principal Name Types
Common principal name types:Ticket Flags
Kerberos ticket flags control ticket properties:Error Handling
Kerberos operations raiseKerberosError exceptions:
Common Error Codes
| Code | Name | Description |
|---|---|---|
| 6 | KDC_ERR_C_PRINCIPAL_UNKNOWN | Client not found |
| 7 | KDC_ERR_S_PRINCIPAL_UNKNOWN | Service not found |
| 14 | KDC_ERR_ETYPE_NOSUPP | Encryption type not supported |
| 18 | KDC_ERR_CLIENT_REVOKED | Client credentials revoked |
| 23 | KDC_ERR_KEY_EXPIRED | Password has expired |
| 24 | KDC_ERR_PREAUTH_FAILED | Pre-auth failed (wrong password) |
| 25 | KDC_ERR_PREAUTH_REQUIRED | Pre-auth required |
| 32 | KRB_AP_ERR_TKT_EXPIRED | Ticket expired |
| 37 | KRB_AP_ERR_SKEW | Clock skew too great |
Time Handling
Kerberos timestamps use theKerberosTime class:
Credential Management
Using Credential Caches
Using Keytabs
Authentication Methods
Password Authentication
Hash Authentication (Pass-the-Hash)
AES Key Authentication
GSS-API Integration
The module supports GSS-API for application-level authentication:Best Practices
Security Considerations
- Use AES encryption: Prefer AES-256 over RC4 or DES
- Handle clock skew: Ensure system time is synchronized
- Secure credential storage: Protect keytabs and caches
- Request PAC when needed: Include authorization data
Performance Tips
- Cache tickets: Reuse TGT for multiple TGS requests
- Specify KDC host: Avoid DNS lookups
- Use appropriate cipher: Balance security and performance
Advanced Features
Ticket Renewal
S4U Extensions
Service-for-User extensions for constrained delegation:Module Reference
Core Modules
- ASN.1 Structures - Kerberos message formats
- Credential Cache - Ticket cache operations
- Cryptography - Encryption and key derivation
- Protocol Functions - TGT/TGS operations
Supporting Modules
constants- Enumerations and error codestypes- Type definitions (Principal, Ticket, etc.)keytab- Keytab file handlingpac- Privilege Attribute Certificategssapi- GSS-API integration
Examples
Complete Authentication Example
See Also
- ASN.1 Reference - Message structure details
- Crypto Reference - Encryption operations
- CCache Reference - Credential cache format
- Kerberos RFC 4120
- MS-KILE Specification