forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change password hashing defaults according to OWASP recommendations (k…
…eycloak#16629) Changes according to the latest [OWASP cheat sheet for secure Password Storage](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2): - Changed default password hashing algorithm from pbkdf2-sha256 to pbkdf2-sha512 - Increased number of hash iterations for pbkdf2-sha1 from 20.000 to 1.300.000 - Increased number of hash iterations for pbkdf2-sha256 from 27.500 to 600.000 - Increased number of hash iterations for pbkdf2-sha512 from 30.000 to 210.000 - Adapt PasswordHashingTest to new defaults - The test testBenchmarkPasswordHashingConfigurations can be used to compare the different hashing configurations. - Document changes in changes document with note on performance and how to keep the old behaviour. - Log a warning at the first time when Pbkdf2PasswordHashProviderFactory is used directly Fixes keycloak#16629 Signed-off-by: Thomas Darimont <[email protected]>
- Loading branch information
1 parent
208e3a6
commit e736390
Showing
9 changed files
with
173 additions
and
18 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
docs/documentation/server_admin/topics/threat/password-db-compromised.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
=== Password database compromised | ||
|
||
{project_name} does not store passwords in raw text but as hashed text, using the PBKDF2 hashing algorithm. {project_name} performs 27,500 hashing iterations, the number of iterations recommended by the security community. This number of hashing iterations can adversely affect performance as PBKDF2 hashing uses a significant amount of CPU resources. | ||
{project_name} does not store passwords in raw text but as hashed text, using the `PBKDF2-HMAC-SHA512` message digest algorithm. {project_name} performs `210,000` hashing iterations, the number of iterations recommended by the security community. This number of hashing iterations can adversely affect performance as PBKDF2 hashing uses a significant amount of CPU resources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ | |
import java.security.spec.KeySpec; | ||
|
||
/** | ||
* Implementation PBKDF2 password hash algorithm. | ||
* | ||
* @author <a href="mailto:[email protected]">Kunal Kerkar</a> | ||
*/ | ||
public class Pbkdf2PasswordHashProvider implements PasswordHashProvider { | ||
|
@@ -137,4 +139,8 @@ private SecretKeyFactory getSecretKeyFactory() { | |
throw new RuntimeException("PBKDF2 algorithm not found", e); | ||
} | ||
} | ||
|
||
public String getPbkdf2Algorithm() { | ||
return pbkdf2Algorithm; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,21 +17,37 @@ | |
|
||
package org.keycloak.credential.hash; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.keycloak.models.KeycloakSession; | ||
|
||
/** | ||
* Provider factory for SHA1 variant of the PBKDF2 password hash algorithm. | ||
* | ||
* @author <a href="mailto:[email protected]">Kunal Kerkar</a> | ||
* @deprecated The PBKDF2 provider with SHA1 and the recommended number of 1.300.000 iterations is known to be very slow. We recommend to use the PBKDF2 variants with SHA256 or SHA512 instead. | ||
*/ | ||
@Deprecated | ||
public class Pbkdf2PasswordHashProviderFactory extends AbstractPbkdf2PasswordHashProviderFactory implements PasswordHashProviderFactory { | ||
|
||
private static final Logger LOG = Logger.getLogger(Pbkdf2PasswordHashProviderFactory.class); | ||
|
||
public static final String ID = "pbkdf2"; | ||
|
||
public static final String PBKDF2_ALGORITHM = "PBKDF2WithHmacSHA1"; | ||
|
||
public static final int DEFAULT_ITERATIONS = 20000; | ||
/** | ||
* Hash iterations for PBKDF2-HMAC-SHA1 according to the <a href="https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2">Password Storage Cheat Sheet</a>. | ||
*/ | ||
public static final int DEFAULT_ITERATIONS = 1_300_000; | ||
|
||
private static boolean usageWarningPrinted; | ||
|
||
@Override | ||
public PasswordHashProvider create(KeycloakSession session) { | ||
if (!usageWarningPrinted) { | ||
LOG.warnf("Detected usage of password hashing provider '%s'. The provider is no longer recommended, use 'pbkdf2-sha256' or 'pbkdf2-sha512' instead.", ID); | ||
usageWarningPrinted = true; | ||
} | ||
return new Pbkdf2PasswordHashProvider(ID, PBKDF2_ALGORITHM, DEFAULT_ITERATIONS, getMaxPaddingLength()); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters