Replaced insecure Minecraft account authentication with server join technique

This commit is contained in:
CrushedPixel
2015-05-27 13:35:44 +02:00
parent f0f0f1aa86
commit 2744e7cf6c
6 changed files with 75 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
package eu.crushedpixel.replaymod.online.authentication;
import com.mojang.authlib.exceptions.AuthenticationException;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.api.ApiClient;
import eu.crushedpixel.replaymod.api.ApiException;
@@ -36,10 +37,10 @@ public class AuthenticationHandler {
private static Minecraft mc = Minecraft.getMinecraft();
public static void register(String usrname, String mail, String password) throws IOException, ApiException {
public static void register(String usrname, String mail, String password)
throws IOException, ApiException, AuthenticationException {
AuthKey auth = apiClient.register(usrname, mail, password,
mc.getSession().getProfile().getId().toString(),
Minecraft.getMinecraft().getSession().getToken());
mc.getSession().getProfile().getId().toString());
username = usrname;
authkey = auth.getAuthkey();
saveAuthkey(authkey);

View File

@@ -0,0 +1,44 @@
package eu.crushedpixel.replaymod.online.authentication;
import net.minecraft.client.Minecraft;
import java.util.Random;
public class AuthenticationHash {
private static final Random random = new Random();
public AuthenticationHash() {
username = Minecraft.getMinecraft().getSession().getUsername();
currentTime = System.currentTimeMillis();
randomLong = random.nextLong();
hash = getAuthenticationHash();
}
public final String username;
public final long currentTime;
public final long randomLong;
public final String hash;
private String getAuthenticationHash() {
StringBuilder builder = new StringBuilder();
builder.append(username);
builder.append(currentTime);
builder.append(randomLong);
String md5 = builder.toString();
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return sb.toString();
} catch (java.security.NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}