TNS-12638 Credential Retrieval Failed - Authentication and Security Error Fix
TNS-12638: Credential Retrieval Failed
Section titled “TNS-12638: Credential Retrieval Failed”Error Overview
Section titled “Error Overview”Error Text: TNS-12638: Credential retrieval failed
This error occurs when Oracle cannot retrieve or validate authentication credentials during the connection process. It’s typically related to Oracle Wallet configuration, SSL/TLS certificate issues, Kerberos authentication problems, or other advanced security mechanisms that Oracle uses for credential management.
Understanding Oracle Authentication Methods
Section titled “Understanding Oracle Authentication Methods”Authentication Types
Section titled “Authentication Types”Oracle Authentication Methods├── Database Authentication (username/password)├── OS Authentication (identified externally)├── Oracle Wallet (PKI certificates)├── Kerberos Authentication (Active Directory)├── LDAP Authentication (directory services)├── RADIUS Authentication (network access servers)└── SSL/TLS Certificate Authentication
Credential Storage Mechanisms
Section titled “Credential Storage Mechanisms”Credential Storage├── Oracle Wallet (.p12 files)├── System Keystore├── LDAP Directory├── Kerberos Ticket Cache└── External Authentication Services
Common Causes
Section titled “Common Causes”Oracle Wallet Issues
Section titled “Oracle Wallet Issues”- Wallet not found or inaccessible
- Wallet password incorrect or expired
- Wallet corrupted or invalid format
- Incorrect wallet location configuration
- Certificate expiration in wallet
SSL/TLS Configuration Problems
Section titled “SSL/TLS Configuration Problems”# Common SSL issues- Certificate chain incomplete- CA certificate not trusted- SSL handshake failures- Protocol version mismatches- Cipher suite incompatibilities
Kerberos Authentication Issues
Section titled “Kerberos Authentication Issues”- Ticket cache expired or invalid
- KDC (Key Distribution Center) unreachable
- Service principal name (SPN) misconfigured
- Time synchronization issues
- Kerberos configuration file errors
LDAP Authentication Problems
Section titled “LDAP Authentication Problems”- LDAP server unreachable
- Incorrect LDAP DN (Distinguished Name)
- LDAP password policy violations
- Directory structure changes
- SSL certificate issues with LDAPS
Diagnostic Steps
Section titled “Diagnostic Steps”Check Oracle Wallet Configuration
Section titled “Check Oracle Wallet Configuration”# Check wallet locationecho $ORACLE_HOME/network/adminls -la $ORACLE_HOME/network/admin/
# Look for wallet filesls -la $ORACLE_HOME/network/admin/cwallet.ssols -la $ORACLE_HOME/network/admin/ewallet.p12
# Check sqlnet.ora for wallet configurationcat $ORACLE_HOME/network/admin/sqlnet.ora | grep -i wallet
Verify SSL/TLS Configuration
Section titled “Verify SSL/TLS Configuration”# Check SSL configuration in sqlnet.oragrep -i ssl $ORACLE_HOME/network/admin/sqlnet.ora
# Test SSL connectivityopenssl s_client -connect database_server:2484 -verify_return_error
# Check certificate validityopenssl x509 -in certificate.pem -text -noout
Kerberos Diagnostics
Section titled “Kerberos Diagnostics”# Check Kerberos configurationcat /etc/krb5.conf
# List current Kerberos ticketsklist
# Test Kerberos authentication
# Check service ticketsklist -s
LDAP Authentication Testing
Section titled “LDAP Authentication Testing”# Test LDAP connectivityldapsearch -H ldap://ldap_server:389 -D "cn=testuser,dc=company,dc=com" -W
# Test LDAPS (secure LDAP)ldapsearch -H ldaps://ldap_server:636 -D "cn=testuser,dc=company,dc=com" -W
# Check LDAP configuration in ldap.oracat $ORACLE_HOME/network/admin/ldap.ora
Resolution Steps
Section titled “Resolution Steps”Oracle Wallet Management
Section titled “Oracle Wallet Management”1. Create or Recreate Oracle Wallet
Section titled “1. Create or Recreate Oracle Wallet”# Create new walletmkdir -p $ORACLE_HOME/network/admincd $ORACLE_HOME/network/admin
# Create wallet with orapkiorapki wallet create -wallet . -pwd wallet_password -auto_login
# Add trusted certificateorapki wallet add -wallet . -trusted_cert -cert ca_cert.crt -pwd wallet_password
# Create credential entrymkstore -wrl . -createCredential database_alias username password
2. Configure Wallet in sqlnet.ora
Section titled “2. Configure Wallet in sqlnet.ora”# Add wallet configuration to sqlnet.oracat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Wallet ConfigurationWALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = $ORACLE_HOME/network/admin)))SQLNET.WALLET_OVERRIDE = TRUESSL_CLIENT_AUTHENTICATION = FALSESSL_VERSION = 0
EOF
3. Test Wallet Connectivity
Section titled “3. Test Wallet Connectivity”# Test connection using walletsqlplus /@database_alias
# Or with specific credentialssqlplus username/@database_alias
SSL/TLS Certificate Management
Section titled “SSL/TLS Certificate Management”1. Certificate Installation
Section titled “1. Certificate Installation”# Download and install CA certificatewget https://ca-server.com/ca-cert.crt
# Add to Oracle walletorapki wallet add -wallet $ORACLE_HOME/network/admin -trusted_cert -cert ca-cert.crt -pwd wallet_password
# Verify certificate installationorapki wallet display -wallet $ORACLE_HOME/network/admin -pwd wallet_password
2. SSL Configuration
Section titled “2. SSL Configuration”# Configure SSL in sqlnet.oracat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# SSL ConfigurationSSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA)SSL_VERSION = 1.2SSL_CLIENT_AUTHENTICATION = FALSE
EOF
# Configure SSL listenercat >> $ORACLE_HOME/network/admin/listener.ora << EOF
SSL_CLIENT_AUTHENTICATION = FALSEWALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = $ORACLE_HOME/network/admin)))
EOF
Kerberos Authentication Setup
Section titled “Kerberos Authentication Setup”1. Configure Kerberos
Section titled “1. Configure Kerberos”# Edit krb5.confsudo vi /etc/krb5.conf
# Sample configuration[libdefaults] default_realm = COMPANY.COM ticket_lifetime = 24h renewable = true forwardable = true
[realms] COMPANY.COM = { kdc = kdc.company.com:88 admin_server = kdc.company.com:749 default_domain = company.com }
[domain_realm] .company.com = COMPANY.COM company.com = COMPANY.COM
2. Oracle Kerberos Configuration
Section titled “2. Oracle Kerberos Configuration”# Configure sqlnet.ora for Kerberoscat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Kerberos ConfigurationSQLNET.AUTHENTICATION_SERVICES = (BEQ, KERBEROS5)SQLNET.KERBEROS5_KEYTAB = /etc/krb5.keytabSQLNET.KERBEROS5_REALMS = /etc/krb5.confSQLNET.KERBEROS5_CC_NAME = /tmp/krb5cc_oracle
EOF
# Test Kerberos authenticationsqlplus /@database_service
LDAP Authentication Configuration
Section titled “LDAP Authentication Configuration”1. Configure LDAP Parameters
Section titled “1. Configure LDAP Parameters”# Create ldap.oracat > $ORACLE_HOME/network/admin/ldap.ora << EOF
# LDAP ConfigurationDIRECTORY_SERVERS = (ldap.company.com:389)DEFAULT_ADMIN_CONTEXT = "dc=company,dc=com"DIRECTORY_SERVER_TYPE = OID
EOF
# Configure sqlnet.ora for LDAPcat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# LDAP AuthenticationNAMES.DIRECTORY_PATH = (LDAP, TNSNAMES, EZCONNECT)NAMES.LDAP_CONTEXT = "dc=company,dc=com"
EOF
2. Test LDAP Authentication
Section titled “2. Test LDAP Authentication”# Test LDAP connectivityldapbind -h ldap.company.com -p 389 -D "cn=oracle,dc=company,dc=com"
# Test Oracle LDAP authenticationsqlplus username@ldap_service_name
Advanced Troubleshooting
Section titled “Advanced Troubleshooting”Enable Authentication Tracing
Section titled “Enable Authentication Tracing”# Enable detailed authentication tracingcat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Authentication TracingTRACE_LEVEL_CLIENT = 16TRACE_DIRECTORY_CLIENT = /tmp/traceTRACE_FILE_CLIENT = auth_traceTRACE_UNIQUE_CLIENT = ON
# Specific authentication tracingSQLNET.KERBEROS5_CC_NAME = FILE:/tmp/krb5cc_oracleSQLNET.AUTHENTICATION_GSSAPI_SERVICE = oracle
EOF
# Reproduce the error and check trace filesls -la /tmp/trace/grep -i "credential\|auth\|error" /tmp/trace/auth_trace*.trc
Wallet Troubleshooting
Section titled “Wallet Troubleshooting”# Check wallet statusorapki wallet display -wallet $ORACLE_HOME/network/admin
# Verify wallet auto-loginls -la $ORACLE_HOME/network/admin/cwallet.sso
# Test wallet without auto-loginorapki wallet display -wallet $ORACLE_HOME/network/admin -pwd wallet_password
# Recreate auto-login walletorapki wallet create -wallet $ORACLE_HOME/network/admin -pwd wallet_password -auto_login
Certificate Chain Validation
Section titled “Certificate Chain Validation”# Verify certificate chainopenssl verify -CAfile ca-cert.pem server-cert.pem
# Check certificate detailsopenssl x509 -in server-cert.pem -text -noout | grep -A2 "Validity"
# Test SSL handshakeopenssl s_client -connect database_server:2484 -CAfile ca-cert.pem
Application Integration
Section titled “Application Integration”Wallet-Based Connection (Java)
Section titled “Wallet-Based Connection (Java)”// Java application using Oracle Walletimport oracle.jdbc.OracleConnection;import java.util.Properties;
public class WalletConnection { public static Connection getWalletConnection() throws SQLException { String url = "jdbc:oracle:thin:/@database_alias";
Properties props = new Properties(); // Wallet configuration props.setProperty("oracle.net.wallet_location", "(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=/path/to/wallet)))"); props.setProperty("oracle.net.ssl_server_dn_match", "false");
return DriverManager.getConnection(url, props); }}
Kerberos Authentication (Python)
Section titled “Kerberos Authentication (Python)”# Python with Kerberos authenticationimport cx_Oracleimport os
def kerberos_connection(): # Set Kerberos environment os.environ['KRB5CCNAME'] = '/tmp/krb5cc_oracle'
# Connect using external authentication dsn = cx_Oracle.makedsn("database_server", 1521, service_name="service")
connection = cx_Oracle.connect( dsn=dsn, mode=cx_Oracle.SYSDBA, # if needed # Use external authentication externalauth=True )
return connection
Connection Pool with Authentication
Section titled “Connection Pool with Authentication”// Connection pool with advanced authenticationHikariConfig config = new HikariConfig();config.setJdbcUrl("jdbc:oracle:thin:@database_server:1521/service");
// Wallet configurationconfig.addDataSourceProperty("oracle.net.wallet_location", "(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=/path/to/wallet)))");config.addDataSourceProperty("oracle.net.ssl_server_dn_match", "false");
// Connection validationconfig.setConnectionTestQuery("SELECT 1 FROM DUAL");config.setValidationTimeout(5000);
// Pool settingsconfig.setMaximumPoolSize(20);config.setConnectionTimeout(30000);
HikariDataSource dataSource = new HikariDataSource(config);
Monitoring and Maintenance
Section titled “Monitoring and Maintenance”Authentication Monitoring
Section titled “Authentication Monitoring”-- Monitor authentication eventsCREATE TABLE auth_event_log ( log_time TIMESTAMP, username VARCHAR2(128), authentication_type VARCHAR2(50), client_info VARCHAR2(200), status VARCHAR2(20), error_message VARCHAR2(4000));
-- Create monitoring triggerCREATE OR REPLACE TRIGGER trg_auth_monitor AFTER LOGON ON DATABASEDECLARE v_auth_type VARCHAR2(50);BEGIN -- Determine authentication type SELECT DECODE( SYS_CONTEXT('USERENV', 'AUTHENTICATION_METHOD'), 'PASSWORD', 'DATABASE', 'OS', 'EXTERNAL', 'SSL', 'CERTIFICATE', 'KERBEROS', 'KERBEROS', 'UNKNOWN' ) INTO v_auth_type FROM dual;
INSERT INTO auth_event_log VALUES ( SYSTIMESTAMP, USER, v_auth_type, SYS_CONTEXT('USERENV', 'HOST') || ':' || SYS_CONTEXT('USERENV', 'IP_ADDRESS'), 'SUCCESS', NULL ); COMMIT;EXCEPTION WHEN OTHERS THEN INSERT INTO auth_event_log VALUES ( SYSTIMESTAMP, USER, 'UNKNOWN', SYS_CONTEXT('USERENV', 'HOST'), 'FAILED', SQLERRM ); COMMIT;END;/
Certificate Expiration Monitoring
Section titled “Certificate Expiration Monitoring”#!/bin/bash# Certificate expiration monitor
WALLET_DIR="$ORACLE_HOME/network/admin"ALERT_DAYS=30
check_certificate_expiration() { local cert_file="$1" local expiry_date=$(openssl x509 -in "$cert_file" -noout -enddate | cut -d= -f2) local expiry_epoch=$(date -d "$expiry_date" +%s) local current_epoch=$(date +%s) local days_until_expiry=$(( (expiry_epoch - current_epoch) / 86400 ))
if [ $days_until_expiry -le $ALERT_DAYS ]; then echo "WARNING: Certificate $cert_file expires in $days_until_expiry days" echo "Certificate expiration warning for $cert_file" | \ fi}
# Check all certificates in wallet directoryfor cert in $WALLET_DIR/*.pem $WALLET_DIR/*.crt; do if [ -f "$cert" ]; then check_certificate_expiration "$cert" fidone
Kerberos Ticket Monitoring
Section titled “Kerberos Ticket Monitoring”#!/bin/bash# Kerberos ticket monitoring
ORACLE_USER="oracle"TICKET_CACHE="/tmp/krb5cc_oracle"
monitor_kerberos_tickets() { # Check if ticket cache exists if [ ! -f "$TICKET_CACHE" ]; then echo "ERROR: Kerberos ticket cache not found: $TICKET_CACHE" return 1 fi
# Check ticket expiration export KRB5CCNAME="FILE:$TICKET_CACHE"
if ! klist -s 2>/dev/null; then echo "WARNING: No valid Kerberos tickets found"
# Attempt ticket renewal if kinit -R 2>/dev/null; then echo "Kerberos tickets renewed successfully" else echo "ERROR: Failed to renew Kerberos tickets" echo "Kerberos ticket renewal failed" | \ fi fi}
monitor_kerberos_tickets
Security Best Practices
Section titled “Security Best Practices”Wallet Security
Section titled “Wallet Security”# Secure wallet permissionschmod 600 $ORACLE_HOME/network/admin/ewallet.p12chmod 644 $ORACLE_HOME/network/admin/cwallet.ssochown oracle:oinstall $ORACLE_HOME/network/admin/*wallet*
# Regular wallet backupcp $ORACLE_HOME/network/admin/ewallet.p12 /backup/wallet/ewallet_$(date +%Y%m%d).p12cp $ORACLE_HOME/network/admin/cwallet.sso /backup/wallet/cwallet_$(date +%Y%m%d).sso
Password Policy Compliance
Section titled “Password Policy Compliance”-- Implement strong authentication policiesCREATE PROFILE secure_profile LIMIT FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 30 PASSWORD_LIFE_TIME 90 PASSWORD_GRACE_TIME 7 PASSWORD_REUSE_TIME 365 PASSWORD_REUSE_MAX 12;
-- Apply to usersALTER USER app_user PROFILE secure_profile;
Emergency Procedures
Section titled “Emergency Procedures”Credential Recovery
Section titled “Credential Recovery”#!/bin/bash# Emergency credential recovery
echo "Starting credential recovery procedure..."
# Backup current configurationcp $ORACLE_HOME/network/admin/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora.backup
# Disable advanced authentication temporarilycat > $ORACLE_HOME/network/admin/sqlnet.ora << EOF# Temporary basic authenticationSQLNET.AUTHENTICATION_SERVICES = (NONE)NAMES.DIRECTORY_PATH = (TNSNAMES, EZCONNECT)EOF
echo "Advanced authentication disabled - use basic username/password"echo "Remember to restore original configuration after resolving issues"
Wallet Reset Procedure
Section titled “Wallet Reset Procedure”#!/bin/bash# Emergency wallet reset
WALLET_DIR="$ORACLE_HOME/network/admin"BACKUP_DIR="/tmp/wallet_backup_$(date +%Y%m%d_%H%M%S)"
# Backup existing walletmkdir -p "$BACKUP_DIR"cp $WALLET_DIR/*wallet* "$BACKUP_DIR/" 2>/dev/null || true
# Remove corrupted walletrm -f $WALLET_DIR/cwallet.sso $WALLET_DIR/ewallet.p12
# Create new walletorapki wallet create -wallet "$WALLET_DIR" -pwd "temp_password" -auto_login
echo "Wallet reset completed. Add certificates and credentials as needed."echo "Backup saved to: $BACKUP_DIR"
Related Errors
Section titled “Related Errors”- TNS-12537: TNS connection closed
- TNS-12560: TNS protocol adapter error
- ORA-01017: Invalid username/password
- ORA-28040: No matching authentication protocol
Best Practices
Section titled “Best Practices”- Regular certificate and credential rotation
- Implement proper wallet security and backups
- Monitor authentication events and failures
- Use principle of least privilege
- Regular security audits and compliance checks
- Proper time synchronization for Kerberos
Troubleshooting Checklist
Section titled “Troubleshooting Checklist”- Verify Oracle Wallet location and accessibility
- Check certificate validity and expiration
- Test SSL/TLS connectivity
- Validate Kerberos configuration and tickets
- Verify LDAP server connectivity
- Check authentication service configuration
- Review security policies and restrictions
- Test with simplified authentication method