// "User authentication failed"
//
String errorMsg = pgStream.ReceiveString();
if (logger.logDebug())
logger.debug(" <=BE ErrorMessage(" + errorMsg + ")");
throw new PSQLException(GT.tr("Connection rejected: {0}.", errorMsg), PSQLState.CONNECTION_REJECTED);
case 'R':
// Authentication request.
// Get the type of request
int areq = pgStream.ReceiveInteger4();
// Process the request.
switch (areq)
{
case AUTH_REQ_CRYPT:
{
String salt = pgStream.ReceiveString(2);
if (logger.logDebug())
logger.debug(" <=BE AuthenticationReqCrypt(salt='" + salt + "')");
if (password == null)
throw new PSQLException(GT.tr("The server requested password-based authentication, but no password was provided."), PSQLState.CONNECTION_REJECTED);
String result = UnixCrypt.crypt(salt, password);
byte[] encodedResult = result.getBytes("US-ASCII");
if (logger.logDebug())
logger.debug(" FE=> Password(crypt='" + result + "')");
pgStream.SendInteger4(4 + encodedResult.length + 1);
pgStream.Send(encodedResult);
pgStream.SendChar(0);
pgStream.flush();
break;
}
case AUTH_REQ_MD5:
{
byte[] md5Salt = pgStream.Receive(4);
if (logger.logDebug())
logger.debug(" <=BE AuthenticationReqMD5(salt=" + Utils.toHexString(md5Salt) + ")");
if (password == null)
throw new PSQLException(GT.tr("The server requested password-based authentication, but no password was provided."), PSQLState.CONNECTION_REJECTED);
byte[] digest = MD5Digest.encode(user, password, md5Salt);
if (logger.logDebug())
logger.debug(" FE=> Password(md5digest=" + new String(digest, "US-ASCII") + ")");
pgStream.SendInteger4(4 + digest.length + 1);
pgStream.Send(digest);
pgStream.SendChar(0);
pgStream.flush();
break;
}
case AUTH_REQ_PASSWORD:
{
if (logger.logDebug())
logger.debug(" <=BE AuthenticationReqPassword");
if (password == null)
throw new PSQLException(GT.tr("The server requested password-based authentication, but no password was provided."), PSQLState.CONNECTION_REJECTED);
if (logger.logDebug())
logger.debug(" FE=> Password(password=<not shown>)");
byte[] encodedPassword = password.getBytes("US-ASCII");
pgStream.SendInteger4(4 + encodedPassword.length + 1);
pgStream.Send(encodedPassword);
pgStream.SendChar(0);
pgStream.flush();
break;
}
case AUTH_REQ_OK:
if (logger.logDebug())
logger.debug(" <=BE AuthenticationOk");
return ; // We're done.
default:
if (logger.logDebug())
logger.debug(" <=BE AuthenticationReq (unsupported type " + ((int)areq) + ")");
throw new PSQLException(GT.tr("The authentication type {0} is not supported. Check that you have configured the pg_hba.conf file to include the client''s IP address or subnet, and that it is using an authentication scheme supported by the driver.", new Integer(areq)), PSQLState.CONNECTION_REJECTED);
}
break;
default:
throw new PSQLException(GT.tr("Protocol error. Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
}
}