Skip to content

TNS-12638 Credential Retrieval Failed - Authentication and Security Error Fix

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”
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
├── Oracle Wallet (.p12 files)
├── System Keystore
├── LDAP Directory
├── Kerberos Ticket Cache
└── External Authentication Services
  • Wallet not found or inaccessible
  • Wallet password incorrect or expired
  • Wallet corrupted or invalid format
  • Incorrect wallet location configuration
  • Certificate expiration in wallet
Terminal window
# Common SSL issues
- Certificate chain incomplete
- CA certificate not trusted
- SSL handshake failures
- Protocol version mismatches
- Cipher suite incompatibilities
  • Ticket cache expired or invalid
  • KDC (Key Distribution Center) unreachable
  • Service principal name (SPN) misconfigured
  • Time synchronization issues
  • Kerberos configuration file errors
  • LDAP server unreachable
  • Incorrect LDAP DN (Distinguished Name)
  • LDAP password policy violations
  • Directory structure changes
  • SSL certificate issues with LDAPS
Terminal window
# Check wallet location
echo $ORACLE_HOME/network/admin
ls -la $ORACLE_HOME/network/admin/
# Look for wallet files
ls -la $ORACLE_HOME/network/admin/cwallet.sso
ls -la $ORACLE_HOME/network/admin/ewallet.p12
# Check sqlnet.ora for wallet configuration
cat $ORACLE_HOME/network/admin/sqlnet.ora | grep -i wallet
Terminal window
# Check SSL configuration in sqlnet.ora
grep -i ssl $ORACLE_HOME/network/admin/sqlnet.ora
# Test SSL connectivity
openssl s_client -connect database_server:2484 -verify_return_error
# Check certificate validity
openssl x509 -in certificate.pem -text -noout
Terminal window
# Check Kerberos configuration
cat /etc/krb5.conf
# List current Kerberos tickets
klist
# Test Kerberos authentication
# Check service tickets
klist -s
Terminal window
# Test LDAP connectivity
ldapsearch -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.ora
cat $ORACLE_HOME/network/admin/ldap.ora
Terminal window
# Create new wallet
mkdir -p $ORACLE_HOME/network/admin
cd $ORACLE_HOME/network/admin
# Create wallet with orapki
orapki wallet create -wallet . -pwd wallet_password -auto_login
# Add trusted certificate
orapki wallet add -wallet . -trusted_cert -cert ca_cert.crt -pwd wallet_password
# Create credential entry
mkstore -wrl . -createCredential database_alias username password
Terminal window
# Add wallet configuration to sqlnet.ora
cat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Wallet Configuration
WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = $ORACLE_HOME/network/admin)))
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 0
EOF
Terminal window
# Test connection using wallet
sqlplus /@database_alias
# Or with specific credentials
sqlplus username/@database_alias
Terminal window
# Download and install CA certificate
wget https://ca-server.com/ca-cert.crt
# Add to Oracle wallet
orapki wallet add -wallet $ORACLE_HOME/network/admin -trusted_cert -cert ca-cert.crt -pwd wallet_password
# Verify certificate installation
orapki wallet display -wallet $ORACLE_HOME/network/admin -pwd wallet_password
Terminal window
# Configure SSL in sqlnet.ora
cat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# SSL Configuration
SSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA)
SSL_VERSION = 1.2
SSL_CLIENT_AUTHENTICATION = FALSE
EOF
# Configure SSL listener
cat >> $ORACLE_HOME/network/admin/listener.ora << EOF
SSL_CLIENT_AUTHENTICATION = FALSE
WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = $ORACLE_HOME/network/admin)))
EOF
Terminal window
# Edit krb5.conf
sudo 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
Terminal window
# Configure sqlnet.ora for Kerberos
cat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Kerberos Configuration
SQLNET.AUTHENTICATION_SERVICES = (BEQ, KERBEROS5)
SQLNET.KERBEROS5_KEYTAB = /etc/krb5.keytab
SQLNET.KERBEROS5_REALMS = /etc/krb5.conf
SQLNET.KERBEROS5_CC_NAME = /tmp/krb5cc_oracle
EOF
# Test Kerberos authentication
sqlplus /@database_service
Terminal window
# Create ldap.ora
cat > $ORACLE_HOME/network/admin/ldap.ora << EOF
# LDAP Configuration
DIRECTORY_SERVERS = (ldap.company.com:389)
DEFAULT_ADMIN_CONTEXT = "dc=company,dc=com"
DIRECTORY_SERVER_TYPE = OID
EOF
# Configure sqlnet.ora for LDAP
cat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# LDAP Authentication
NAMES.DIRECTORY_PATH = (LDAP, TNSNAMES, EZCONNECT)
NAMES.LDAP_CONTEXT = "dc=company,dc=com"
EOF
Terminal window
# Test LDAP connectivity
ldapbind -h ldap.company.com -p 389 -D "cn=oracle,dc=company,dc=com"
# Test Oracle LDAP authentication
sqlplus username@ldap_service_name
Terminal window
# Enable detailed authentication tracing
cat >> $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Authentication Tracing
TRACE_LEVEL_CLIENT = 16
TRACE_DIRECTORY_CLIENT = /tmp/trace
TRACE_FILE_CLIENT = auth_trace
TRACE_UNIQUE_CLIENT = ON
# Specific authentication tracing
SQLNET.KERBEROS5_CC_NAME = FILE:/tmp/krb5cc_oracle
SQLNET.AUTHENTICATION_GSSAPI_SERVICE = oracle
EOF
# Reproduce the error and check trace files
ls -la /tmp/trace/
grep -i "credential\|auth\|error" /tmp/trace/auth_trace*.trc
Terminal window
# Check wallet status
orapki wallet display -wallet $ORACLE_HOME/network/admin
# Verify wallet auto-login
ls -la $ORACLE_HOME/network/admin/cwallet.sso
# Test wallet without auto-login
orapki wallet display -wallet $ORACLE_HOME/network/admin -pwd wallet_password
# Recreate auto-login wallet
orapki wallet create -wallet $ORACLE_HOME/network/admin -pwd wallet_password -auto_login
Terminal window
# Verify certificate chain
openssl verify -CAfile ca-cert.pem server-cert.pem
# Check certificate details
openssl x509 -in server-cert.pem -text -noout | grep -A2 "Validity"
# Test SSL handshake
openssl s_client -connect database_server:2484 -CAfile ca-cert.pem
// Java application using Oracle Wallet
import 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);
}
}
# Python with Kerberos authentication
import cx_Oracle
import 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 advanced authentication
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:oracle:thin:@database_server:1521/service");
// Wallet configuration
config.addDataSourceProperty("oracle.net.wallet_location",
"(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=/path/to/wallet)))");
config.addDataSourceProperty("oracle.net.ssl_server_dn_match", "false");
// Connection validation
config.setConnectionTestQuery("SELECT 1 FROM DUAL");
config.setValidationTimeout(5000);
// Pool settings
config.setMaximumPoolSize(20);
config.setConnectionTimeout(30000);
HikariDataSource dataSource = new HikariDataSource(config);
-- Monitor authentication events
CREATE 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 trigger
CREATE OR REPLACE TRIGGER trg_auth_monitor
AFTER LOGON ON DATABASE
DECLARE
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;
/
#!/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" | \
mail -s "Oracle Certificate Alert" [email protected]
fi
}
# Check all certificates in wallet directory
for cert in $WALLET_DIR/*.pem $WALLET_DIR/*.crt; do
if [ -f "$cert" ]; then
check_certificate_expiration "$cert"
fi
done
#!/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" | \
mail -s "Oracle Kerberos Alert" [email protected]
fi
fi
}
monitor_kerberos_tickets
Terminal window
# Secure wallet permissions
chmod 600 $ORACLE_HOME/network/admin/ewallet.p12
chmod 644 $ORACLE_HOME/network/admin/cwallet.sso
chown oracle:oinstall $ORACLE_HOME/network/admin/*wallet*
# Regular wallet backup
cp $ORACLE_HOME/network/admin/ewallet.p12 /backup/wallet/ewallet_$(date +%Y%m%d).p12
cp $ORACLE_HOME/network/admin/cwallet.sso /backup/wallet/cwallet_$(date +%Y%m%d).sso
-- Implement strong authentication policies
CREATE 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 users
ALTER USER app_user PROFILE secure_profile;
#!/bin/bash
# Emergency credential recovery
echo "Starting credential recovery procedure..."
# Backup current configuration
cp $ORACLE_HOME/network/admin/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora.backup
# Disable advanced authentication temporarily
cat > $ORACLE_HOME/network/admin/sqlnet.ora << EOF
# Temporary basic authentication
SQLNET.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"
#!/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 wallet
mkdir -p "$BACKUP_DIR"
cp $WALLET_DIR/*wallet* "$BACKUP_DIR/" 2>/dev/null || true
# Remove corrupted wallet
rm -f $WALLET_DIR/cwallet.sso $WALLET_DIR/ewallet.p12
# Create new wallet
orapki 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"
  • TNS-12537: TNS connection closed
  • TNS-12560: TNS protocol adapter error
  • ORA-01017: Invalid username/password
  • ORA-28040: No matching authentication protocol
  1. Regular certificate and credential rotation
  2. Implement proper wallet security and backups
  3. Monitor authentication events and failures
  4. Use principle of least privilege
  5. Regular security audits and compliance checks
  6. Proper time synchronization for Kerberos
  • 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