add password hashing and commands
This commit is contained in:
parent
1b61f085e3
commit
ec0a1aa5c3
9 changed files with 148 additions and 19 deletions
|
@ -39,7 +39,7 @@ public class CPacketForm implements Packet<IPlayer>
|
|||
obj = buf.readVarInt();
|
||||
break;
|
||||
default:
|
||||
obj = buf.readString(256);
|
||||
obj = buf.readString(1024);
|
||||
break;
|
||||
}
|
||||
this.data[z] = obj;
|
||||
|
|
|
@ -47,7 +47,7 @@ public class RPacketServerConfig implements Packet<IClientLoginHandler> {
|
|||
}
|
||||
|
||||
public boolean isAuthenticating() {
|
||||
return this.passwordAuth;
|
||||
return this.requiresAuth;
|
||||
}
|
||||
|
||||
public boolean canUsePassword() {
|
||||
|
|
|
@ -10,9 +10,11 @@ import java.security.MessageDigest;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.EncodedKeySpec;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Arrays;
|
||||
|
@ -24,7 +26,9 @@ import javax.crypto.IllegalBlockSizeException;
|
|||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import common.log.Log;
|
||||
|
@ -189,6 +193,7 @@ public class EncryptUtil {
|
|||
|
||||
private static final long CRC24_INIT = 0xB704CEL;
|
||||
private static final long CRC24_POLY = 0x1864CFBL;
|
||||
private static final byte[] CLIENT_SALT = "ItIsSaltySalt2765666 tftffs ##89n!.le98udMeowHAsh44m;+*3m9DI9Sqn".getBytes();
|
||||
|
||||
private static byte[] crc24(byte[] data) {
|
||||
long crc = CRC24_INIT;
|
||||
|
@ -203,4 +208,23 @@ public class EncryptUtil {
|
|||
int value = (int)(crc & 0xFFFFFFL);
|
||||
return new byte[] {(byte)((value >> 16) & 0xff), (byte)((value >> 8) & 0xff), (byte)(value & 0xff)};
|
||||
}
|
||||
|
||||
public static byte[] hashPassword(String password, byte[] salt) {
|
||||
try {
|
||||
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 256);
|
||||
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
|
||||
return factory.generateSecret(spec).getEncoded();
|
||||
}
|
||||
catch(NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||
Log.SYSTEM.error(e, "Konnte Passwort-Prüfwert nicht errechnen");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pair<byte[], byte[]> hashPassword(String password) {
|
||||
SecureRandom rand = new SecureRandom();
|
||||
byte[] salt = new byte[64];
|
||||
rand.nextBytes(salt);
|
||||
return new Pair<byte[], byte[]>(hashPassword(password, salt), salt);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue