Skip to content

Commit e8e6274

Browse files
Marat GainullinMarat Gainullin
authored andcommitted
SASL client nonce generation changed to random UUID
1 parent 6f5cf6a commit e8e6274

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

src/main/java/com/github/pgasync/PgProtocolStream.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,10 @@ private CompletableFuture<? super Message> consumeOnResponse() {
7575
return wasOnResponse;
7676
}
7777

78-
private static String saslNonce() {
79-
// Generate nonce
80-
SecureRandom rnd = new SecureRandom();
81-
byte[] nonce = new byte[24];
82-
rnd.nextBytes(nonce);
83-
// Sanitize it
84-
for (int i = 0; i < nonce.length; i++) {
85-
// Ascii space is also substituted with underscore
86-
if (nonce[i] < 33 || nonce[i] >= 127) {
87-
nonce[i] = '_';
88-
}
89-
}
90-
return new String(nonce, StandardCharsets.US_ASCII);
91-
}
92-
9378
@Override
9479
public CompletableFuture<Message> authenticate(String userName, String password, Authentication authRequired) {
9580
if (authRequired.isSaslScramSha256()) {
96-
String clientNonce = saslNonce();
81+
String clientNonce = UUID.randomUUID().toString();
9782
SASLInitialResponse saslInitialResponse = new SASLInitialResponse(Authentication.SUPPORTED_SASL, null, ""/*SaslPrep.asQueryString(userName) - Postgres requires an empty string here*/, clientNonce);
9883
return send(saslInitialResponse)
9984
.thenApply(message -> {

0 commit comments

Comments
 (0)