Fix #391 Wordpress algorithm fails sometimes

This commit is contained in:
ljacqu 2016-01-18 14:19:04 +01:00
parent 3b33dc774d
commit 07e7a8815b

View File

@ -1,5 +1,7 @@
package fr.xephi.authme.security.crypts; package fr.xephi.authme.security.crypts;
import fr.xephi.authme.security.HashUtils;
import fr.xephi.authme.security.MessageDigestAlgorithm;
import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.HasSalt;
import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.Recommendation;
import fr.xephi.authme.security.crypts.description.SaltType; import fr.xephi.authme.security.crypts.description.SaltType;
@ -7,12 +9,10 @@ import fr.xephi.authme.security.crypts.description.Usage;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Arrays; import java.util.Arrays;
// TODO #391: Wordpress algorithm fails sometimes. Fix it and change the Recommendation to "ACCEPTABLE" if appropriate @Recommendation(Usage.ACCEPTABLE)
@Recommendation(Usage.DO_NOT_USE)
@HasSalt(value = SaltType.TEXT, length = 9) @HasSalt(value = SaltType.TEXT, length = 9)
// Note ljacqu 20151228: Wordpress is actually a salted algorithm but salt generation is handled internally // Note ljacqu 20151228: Wordpress 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 // and isn't exposed to the outside, so we treat it as an unsalted implementation
@ -30,6 +30,7 @@ public class WORDPRESS extends UnsaltedMethod {
byte[] t = new byte[count]; byte[] t = new byte[count];
System.arraycopy(src, 0, t, 0, src.length); System.arraycopy(src, 0, t, 0, src.length);
Arrays.fill(t, src.length, count - 1, (byte) 0); Arrays.fill(t, src.length, count - 1, (byte) 0);
src = t;
} }
do { do {
@ -73,13 +74,7 @@ public class WORDPRESS extends UnsaltedMethod {
if (salt.length() != 8) { if (salt.length() != 8) {
return output; return output;
} }
MessageDigest md; MessageDigest md = HashUtils.getDigest(MessageDigestAlgorithm.MD5);
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return output;
}
byte[] pass = stringToUtf8(password); byte[] pass = stringToUtf8(password);
byte[] hash = md.digest(stringToUtf8(salt + password)); byte[] hash = md.digest(stringToUtf8(salt + password));
do { do {