|
17 | 17 | import com.openrsc.interfaces.misc.*; |
18 | 18 | import com.openrsc.interfaces.misc.clan.Clan; |
19 | 19 | import com.openrsc.interfaces.misc.party.Party; |
| 20 | +import orsc.buffers.RSBuffer; |
20 | 21 | import orsc.buffers.RSBufferUtils; |
21 | 22 | import orsc.buffers.RSBuffer_Bits; |
22 | 23 | import orsc.enumerations.*; |
|
39 | 40 | import orsc.util.Utils; |
40 | 41 |
|
41 | 42 | import java.io.*; |
| 43 | +//import java.lang.management.ManagementFactory; //Commented out for Android |
| 44 | +import java.nio.charset.StandardCharsets; |
| 45 | +import java.nio.file.Paths; |
42 | 46 | import java.security.SecureRandom; |
43 | 47 | import java.time.LocalDateTime; |
44 | 48 | import java.time.format.DateTimeFormatter; |
@@ -72,6 +76,10 @@ public final class mudclient implements Runnable { |
72 | 76 | private static final ArrayList<String> skillNamesArray = new ArrayList<String>(); |
73 | 77 | private static String[] skillNameLong; |
74 | 78 | private static String[] skillNames; |
| 79 | + private static String[] programArgs; |
| 80 | + public void setProgramArgs(String[] progArgs) { |
| 81 | + this.programArgs = progArgs; |
| 82 | + } |
75 | 83 | public final int[] bankItemOnTab = new int[500]; |
76 | 84 | public final int[] equipIconXLocations = new int[]{98, 98, 98, 153, 43, 43, 98, 98, 43, 153, 153}; |
77 | 85 | public final int[] equipIconYLocations = new int[]{5, 85, 125, 85, 85, 165, 165, 45, 45, 45, 165}; |
@@ -14472,8 +14480,65 @@ private void login(int var1, String pass, String user, boolean reconnecting) { |
14472 | 14480 | } |
14473 | 14481 | this.packetHandler.getClientStream().bufferBits.putInt(CLIENT_VERSION); |
14474 | 14482 | this.packetHandler.getClientStream().bufferBits.putString(getUsername()); |
14475 | | - // TODO: This strips special chars to underscore. We may want to in the future allow special chars. |
14476 | | - this.packetHandler.getClientStream().bufferBits.putString(DataOperations.addCharacters(password, 20)); |
| 14483 | + //TODO: Add encryption version as server variable sent to client so we can read it here instead of hardcoding it so server operators can control the encryption version. |
| 14484 | + byte loginEncryptionVersion = 1; //0 = none, 1 = RSA, 2 = SSL/TLS --TODO: maybe "RSA enhanced" with a larger key size? |
| 14485 | + this.packetHandler.getClientStream().bufferBits.putByte(loginEncryptionVersion); |
| 14486 | + //TODO: This strips special chars to underscore. We may want to in the future allow special chars. |
| 14487 | + //this.packetHandler.getClientStream().bufferBits.putString(DataOperations.addCharacters(password, 20)); |
| 14488 | + |
| 14489 | + RSBuffer rsBuffer = new RSBuffer(500); |
| 14490 | + rsBuffer.putString(DataOperations.addCharacters(password, 20)); |
| 14491 | + rsBuffer.encodeWithRSA(MiscFunctions.RSA_EXPONENT, MiscFunctions.RSA_MODULUS); |
| 14492 | + this.packetHandler.getClientStream().bufferBits.writeBytes(rsBuffer.dataBuffer, rsBuffer.packetEnd); |
| 14493 | + |
| 14494 | + boolean runningFromJar = false; |
| 14495 | + String jarName = ""; |
| 14496 | + try { |
| 14497 | + String className = this.getClass().getName().replace('.', '/'); |
| 14498 | + String classJar = this.getClass().getResource("/" + className + ".class") != null ? this.getClass().getResource("/" + className + ".class").toString() : "unknown"; |
| 14499 | + if (classJar.startsWith("jar:")) { |
| 14500 | + runningFromJar = true; |
| 14501 | + String path = classJar.substring(4, classJar.indexOf("!")); |
| 14502 | + jarName = Paths.get(path).getFileName().toString(); |
| 14503 | + if (jarName.length() > 19) { |
| 14504 | + jarName = jarName.substring(0, 19); |
| 14505 | + } |
| 14506 | + } |
| 14507 | + } catch (Exception e) { |
| 14508 | + e.printStackTrace(); |
| 14509 | + } |
| 14510 | + |
| 14511 | + //List<String> jvmArgs = ManagementFactory.getRuntimeMXBean().getInputArguments(); |
| 14512 | + //String jvmArgsStr = String.join(" ", jvmArgs); |
| 14513 | + |
| 14514 | + String programArgsStr = programArgs != null && programArgs.length > 1 ? String.join(" ", programArgs) : ""; |
| 14515 | + |
| 14516 | + String workingDir = System.getProperty("user.dir"); |
| 14517 | + if (workingDir.length() > 38) { |
| 14518 | + String[] pathParts = workingDir.split(Pattern.quote(File.separator)); |
| 14519 | + if (pathParts.length > 2) { |
| 14520 | + String truncatedPath = String.join(File.separator, Arrays.copyOfRange(pathParts, pathParts.length - 3, pathParts.length)); |
| 14521 | + workingDir = truncatedPath; |
| 14522 | + if (workingDir.length() > 38) { |
| 14523 | + workingDir = truncatedPath.substring(truncatedPath.length() - 38); |
| 14524 | + } |
| 14525 | + } |
| 14526 | + } |
| 14527 | + if (jarName.isEmpty() && workingDir.length() < 2) { |
| 14528 | + workingDir = "Unknown"; |
| 14529 | + } |
| 14530 | + String osName = System.getProperty("os.name").toLowerCase(); |
| 14531 | + String javaVendor = System.getProperty("java.vendor").toLowerCase(); |
| 14532 | + boolean isAndroid = osName.contains("android") || javaVendor.contains("android"); |
| 14533 | + if (isAndroid) { |
| 14534 | + workingDir = "Android"; |
| 14535 | + } |
| 14536 | + //Ideally, we want this string to be less than 60 characters, and it must be less than 63 characters to be encrypted with RSA. |
| 14537 | + String loginDetails = String.format("%s/%s", workingDir, jarName); |
| 14538 | + RSBuffer rsDetailsBuffer = new RSBuffer(100); |
| 14539 | + rsDetailsBuffer.putString(loginDetails); |
| 14540 | + rsDetailsBuffer.encodeWithRSA(MiscFunctions.RSA_EXPONENT, MiscFunctions.RSA_MODULUS); |
| 14541 | + this.packetHandler.getClientStream().bufferBits.writeBytes(rsDetailsBuffer.dataBuffer, rsDetailsBuffer.packetEnd); |
14477 | 14542 |
|
14478 | 14543 | this.packetHandler.getClientStream().bufferBits.putLong(getUID()); |
14479 | 14544 |
|
|
0 commit comments