upassword: réintégrer password wom

This commit is contained in:
Jephté Clain 2021-11-22 15:59:02 +04:00
parent 7030b8783c
commit 5cdd93d3d8
1 changed files with 86 additions and 4 deletions

View File

@ -19,6 +19,7 @@ import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern;
import javax.crypto.Cipher;
@ -138,6 +139,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class Base64 {
public final static int NO_OPTIONS = 0;
@ -966,6 +968,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class DES {
private int[] encryptKeys = new int[32];
@ -1870,6 +1873,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class MD4 extends MessageDigest implements Cloneable {
private static final int BLOCK_LENGTH = 64;
@ -2026,6 +2030,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class jcrypt {
private jcrypt() {
}
@ -3655,6 +3660,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class Salt {
public static final String getCryptSalt(String pw) {
if (pw == null) return null;
@ -3752,6 +3758,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class Password {
public static final String CLEARTEXT = "", CRYPT = "CRYPT", MD5 = "MD5", SMD5 = "SMD5",
SHA = "SHA", XSHA = "XSHA", SSHA = "SSHA";
@ -4186,6 +4193,7 @@ public class upassword {
}
// ------------------------------------------------------------------------
public static class PasswordChecker {
public PasswordChecker(int minLen, int minUpper, int minLower, int minAlpha, int minNumber,
int minSymbol, int minSpecial, boolean allowMultibytes) {
@ -4559,7 +4567,7 @@ public class upassword {
/**
* Génère une chaine de caractère aléatoire d'une taille définie adapté aux mot de passe
*
* @param size Nombre de bloque de 4 caractères à générer
* @param size Nombre de blocs de 4 caractères à générer
* @param punctuationsNumber Nombre de ponctuations à insérer
* @return Chaine de caractères aléatoires générée
*/
@ -4583,9 +4591,9 @@ public class upassword {
// calcule aléatoirement le caractère à sélectionner
for (int index = 0; index < size * 4; index++) {
// espace
if (index != 0 && index % 4 == 0) {
builder.append(" ");
}
//if (index != 0 && index % 4 == 0) {
// builder.append(" ");
//}
// lettre
seed = index % 2 == 0 ? CONSONANTS : VOWELS;
builder.append(
@ -4672,12 +4680,14 @@ public class upassword {
public String generate(int maxLen) {
return generate(minLen, maxLen, sections, minCounts, rand);
}
public String generateJk() {
return generateJk(3, 1, rand);
}
}
// ------------------------------------------------------------------------
public static class AESEnc {
private static final String AES = "AES";
@ -4769,6 +4779,76 @@ public class upassword {
// ------------------------------------------------------------------------
public static class WOJavaMonitorPassword {
public static long myrand() {
long nextLong = ThreadLocalRandom.current().nextLong();
while (nextLong == Long.MIN_VALUE) {
nextLong = ThreadLocalRandom.current().nextLong();
}
return Math.abs(nextLong);
}
public static String encryptStringWithKey(String to_be_encrypted, String aKey) {
String encrypted_value = "";
char xdigit[] = { '0' , '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
MessageDigest messageDigest;
try {
messageDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException exc) {
throw new AssertionError("MD5 n'est pas disponible: " + getSummary(exc));
}
if (to_be_encrypted != null) {
byte digest[];
byte fudge_constant[];
try {
fudge_constant = ("X#@!").getBytes("UTF8");
} catch (UnsupportedEncodingException uee) {
fudge_constant = ("X#@!").getBytes();
}
byte fudgetoo_part[] = {
(byte)xdigit[(int)(myrand() % 16)] ,
(byte)xdigit[(int)(myrand() % 16)] ,
(byte)xdigit[(int)(myrand() % 16)] ,
(byte)xdigit[(int)(myrand() % 16)]
};
int i = 0;
if (aKey != null) {
try {
fudgetoo_part = aKey.getBytes("UTF8");
} catch (UnsupportedEncodingException uee) {
fudgetoo_part = aKey.getBytes();
}
}
messageDigest.update(fudge_constant);
try {
messageDigest.update(to_be_encrypted.getBytes("UTF8"));
} catch (UnsupportedEncodingException uee) {
messageDigest.update(to_be_encrypted.getBytes());
}
messageDigest.update(fudgetoo_part);
digest = messageDigest.digest();
encrypted_value = new String(fudgetoo_part);
for (i = 0; i < digest.length; i++) {
int mashed;
char temp[] = new char[2];
if (digest[i] < 0) {
mashed = 127 + ( -1 * digest[i]);
} else {
mashed = digest[i];
}
temp[0] = xdigit[mashed / 16];
temp[1] = xdigit[mashed % 16];
encrypted_value = encrypted_value + (new String(temp));
}
}
return encrypted_value;
}
}
// ------------------------------------------------------------------------
private Password getPasswordAnySalt(String clear, String scheme, final String anySalt) {
return new Password(clear, scheme) {
@Override
@ -5164,6 +5244,7 @@ public class upassword {
String md5 = getPasswordAnySalt(clear, Password.MD5, null).getNormalized();
String smd5 = getPasswordBinarySalt(clear, Password.SMD5, newBinarySalt)
.getNormalized();
String wojmp = WOJavaMonitorPassword.encryptStringWithKey(clear, null);
String aes = null;
if (aeskey != null) {
try {
@ -5182,6 +5263,7 @@ public class upassword {
printvar("ssha", ssha, shell);
printvar("md5", md5, shell);
printvar("smd5", smd5, shell);
printvar("wojmp", wojmp, shell);
if (aes != null) printvar("aes", aes, shell);
} else if (hashAction == EHashAction.CHECK_MATCH) {
// Afficher uniquement les versions cryptées des mots de passe avec