2626
2727import io .questdb .BuildInformation ;
2828import io .questdb .cairo .CairoException ;
29- import io .questdb .cairo .SecurityContext ;
3029import io .questdb .cairo .sql .NetworkSqlExecutionCircuitBreaker ;
3130import io .questdb .cutlass .auth .AuthenticatorException ;
3231import io .questdb .cutlass .auth .SocketAuthenticator ;
@@ -79,6 +78,7 @@ public class CleartextPasswordPgWireAuthenticatorModern implements SocketAuthent
7978 private final CircuitBreakerRegistry registry ;
8079 private final String serverVersion ;
8180 private final ResponseSink sink ;
81+ private byte authType = AUTH_TYPE_NONE ;
8282 private UsernamePasswordMatcher matcher ;
8383 private long recvBufEnd ;
8484 private long recvBufReadPos ;
@@ -119,6 +119,7 @@ public CleartextPasswordPgWireAuthenticatorModern(
119119
120120 @ Override
121121 public void clear () {
122+ authType = AUTH_TYPE_NONE ;
122123 circuitBreaker .setSecret (-1 );
123124 circuitBreaker .resetMaxTimeToDefault ();
124125 circuitBreaker .unsetTimer ();
@@ -143,7 +144,7 @@ public int denyAccess(CharSequence message) throws AuthenticatorException {
143144
144145 @ Override
145146 public byte getAuthType () {
146- return SecurityContext . AUTH_TYPE_CREDENTIALS ;
147+ return authType ;
147148 }
148149
149150 public CharSequence getPrincipal () {
@@ -292,6 +293,8 @@ private void compactSendBuf() {
292293 private void prepareBackendKeyData (ResponseSink responseSink ) {
293294 responseSink .put ('K' );
294295 responseSink .putInt (Integer .BYTES * 3 ); // length of this message
296+
297+ // the below 8 bytes will not match when dumping PG traffic!
295298 responseSink .putInt (circuitBreakerId );
296299 responseSink .putInt (circuitBreaker .getSecret ());
297300 }
@@ -426,7 +429,8 @@ private int processPasswordMessage() throws BadProtocolException {
426429 recvBufReadPos += 1 + Integer .BYTES ; // first move beyond the msgType and msgLen
427430
428431 long hi = PGConnectionContextModern .getUtf8StrSize (recvBufReadPos , msgLimit , "bad password length" , null );
429- if (matcher .verifyPassword (username , recvBufReadPos , (int ) (hi - recvBufReadPos )) != AUTH_TYPE_NONE ) {
432+ authType = verifyPassword (username , recvBufReadPos , (int ) (hi - recvBufReadPos ));
433+ if (authType != AUTH_TYPE_NONE ) {
430434 recvBufReadPos = msgLimit ;
431435 state = State .AUTH_SUCCESS ;
432436 } else {
@@ -515,6 +519,10 @@ private int writeToSocketAndAdvance(State nextState) {
515519 return SocketAuthenticator .NEEDS_WRITE ;
516520 }
517521
522+ // kept protected for enterprise
523+ protected byte verifyPassword (CharSequence username , long passwordPtr , int passwordLen ) {
524+ return matcher .verifyPassword (username , passwordPtr , passwordLen );
525+ }
518526
519527 private enum State {
520528 EXPECT_INIT_MESSAGE ,
0 commit comments