-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add argon2 implementation - Extract argon2 library check to method on Argon 2 - Add link to Wiki page on errors - Check within Argon2Test if the test cases should be run, not in the abstract parent
- Loading branch information
Showing
10 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package fr.xephi.authme.security.crypts; | ||
|
||
import de.mkammerer.argon2.Argon2Constants; | ||
import de.mkammerer.argon2.Argon2Factory; | ||
import fr.xephi.authme.ConsoleLogger; | ||
import fr.xephi.authme.security.crypts.description.HasSalt; | ||
import fr.xephi.authme.security.crypts.description.Recommendation; | ||
import fr.xephi.authme.security.crypts.description.SaltType; | ||
import fr.xephi.authme.security.crypts.description.Usage; | ||
|
||
@Recommendation(Usage.RECOMMENDED) | ||
@HasSalt(value = SaltType.TEXT, length = Argon2Constants.DEFAULT_SALT_LENGTH) | ||
// Note: Argon2 is actually a salted algorithm but salt generation is handled internally | ||
// and isn't exposed to the outside, so we treat it as an unsalted implementation | ||
public class Argon2 extends UnsaltedMethod { | ||
|
||
private de.mkammerer.argon2.Argon2 argon2; | ||
|
||
public Argon2() { | ||
argon2 = Argon2Factory.create(); | ||
} | ||
|
||
/** | ||
* Checks if the argon2 library is available in java.library.path. | ||
* | ||
* @return true if the library is present, false otherwise | ||
*/ | ||
public static boolean isLibraryLoaded() { | ||
try { | ||
System.loadLibrary("argon2"); | ||
return true; | ||
} catch (UnsatisfiedLinkError e) { | ||
ConsoleLogger.logException( | ||
"Cannot find argon2 library: https://github.com/AuthMe/AuthMeReloaded/wiki/Argon2-as-Password-Hash", e); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String computeHash(String password) { | ||
return argon2.hash(2, 65536, 1, password); | ||
} | ||
|
||
@Override | ||
public boolean comparePassword(String password, HashedPassword hashedPassword, String name) { | ||
return argon2.verify(hashedPassword.getHash(), password); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/test/java/fr/xephi/authme/security/crypts/Argon2Test.java
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package fr.xephi.authme.security.crypts; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assume.assumeThat; | ||
|
||
/** | ||
* Test for {@link Argon2}. | ||
*/ | ||
public class Argon2Test extends AbstractEncryptionMethodTest { | ||
|
||
private static final boolean IS_LIBRARY_LOADED = Argon2.isLibraryLoaded(); | ||
|
||
public Argon2Test() { | ||
super(new Argon2(), | ||
"$argon2i$v=19$m=65536,t=2,p=1$dOP8NiXsPTcMgzI4Z8Rbew$ShdowtoTEWTL5UTFz1UgQOigb9JOlm4ZxWPA6WbIeUw", // password | ||
"$argon2i$v=19$m=65536,t=2,p=1$amZHbPfgc5peKd/4w1AI1g$Q2PUiOVw47TACijP57U0xf7QfiZ00HV4eFzMDA6yKRE", // PassWord1 | ||
"$argon2i$v=19$m=65536,t=2,p=1$58v7dWNn9/bpD00QLzSebw$7cMC7p0qceE3Mgf2yQp4X7c+UkO9oyJwQ7S6XTBubNs", // &^%te$t?Pw@_ | ||
"$argon2i$v=19$m=65536,t=2,p=1$93OSU71DgBOzpmhti7+6rQ$sSSI6QQQdoG9DlGwLjYz576kTek89nwr9CyNpy6bsL0"); // âË_3(íù* | ||
|
||
assumeThat("Argon2 library is not loaded - skipping test", | ||
IS_LIBRARY_LOADED, equalTo(true)); | ||
} | ||
|
||
@Override | ||
protected boolean testHashEqualityForSameSalt() { | ||
// Argon2 has a salt but it is handled internally | ||
return false; | ||
} | ||
} |