Skip to content

Commit

Permalink
JDBC-635 Fixed: Some usernames cannot authenticate using SRP
Browse files Browse the repository at this point in the history
Usernames that produce a SHA-1 hash with leading zeroes could not authenticate
  • Loading branch information
mrotteveel committed Dec 4, 2020
1 parent bcadf68 commit e72e27d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/documentation/release_notes.md
Expand Up @@ -256,6 +256,7 @@ The following has been changed or fixed since Jaybird 3.0.9:
- Fixed: Use of `isc_dpb_no_db_triggers` no longer logs a warning ([JDBC-628](http://tracker.firebirdsql.org/browse/JDBC-628))
- Fixed: First letter of JDBC escape was case-sensitive ([JDBC-632](http://tracker.firebirdsql.org/browse/JDBC-632)) \
This was a regression compared to 2.2.x.
- Fixed: Some usernames cannot authenticate using SRP ([JDBC-635](http://tracker.firebirdsql.org/browse/JDBC-635))

### Known issues in Jaybird 3.0.10

Expand Down
7 changes: 5 additions & 2 deletions src/main/org/firebirdsql/gds/ng/wire/auth/SrpClient.java
Expand Up @@ -81,7 +81,10 @@ private static BigInteger fromBigByteArray(byte[] b) {
}

private static byte[] toBigByteArray(BigInteger n) {
byte[] b = n.toByteArray();
return stripLeadingZeroes(n.toByteArray());
}

private static byte[] stripLeadingZeroes(byte[] b) {
if (b[0] != 0) {
return b;
}
Expand Down Expand Up @@ -200,7 +203,7 @@ byte[] clientProof(String user, String password, byte[] salt, BigInteger serverP
final BigInteger n2 = fromBigByteArray(sha1(toBigByteArray(g)));
final byte[] M = clientProofHash(
toBigByteArray(n1.modPow(n2, N)),
sha1(user.getBytes(StandardCharsets.UTF_8)),
stripLeadingZeroes(sha1(user.getBytes(StandardCharsets.UTF_8))),
salt,
toBigByteArray(publicKey),
toBigByteArray(serverPublicKey),
Expand Down
22 changes: 22 additions & 0 deletions src/test/org/firebirdsql/jdbc/TestFBDriver.java
Expand Up @@ -437,5 +437,27 @@ public void testNormalizeProperties_dpbLongAliasAndAlias_throwsException() throw
FBDriver.normalizeProperties(url, props);
}

/**
* Test Srp authentication with an account (DAVIDS) that produces a hash with leading zero.
* <p>
* See <a href="http://tracker.firebirdsql.org/browse/JDBC-635">JDBC-635</a>.
* </p>
*/
@Test
public void testProblematicUserAccount_DAVIDS() throws Exception {
String username = "DAVIDS";
String password = "aaa123";
databaseUserRule.createUser(username, password, "Srp");

Properties connectionProperties = getDefaultPropertiesForConnection();
connectionProperties.setProperty("user", username);
connectionProperties.setProperty("password", password);
connectionProperties.setProperty("authPlugins", "Srp256");

try (Connection connection = DriverManager.getConnection(getUrl(), connectionProperties)) {
assertTrue(connection.isValid(1000));
}
}

}

0 comments on commit e72e27d

Please sign in to comment.