Skip to content

Commit 73f365b

Browse files
ipkpjersiHubcapp
authored andcommitted
Added RSA to login for custom protocol
1 parent c77de0b commit 73f365b

13 files changed

Lines changed: 121 additions & 17 deletions

File tree

Client_Base/src/orsc/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Config {
1818
public static String WELCOME_TEXT = "You need a members account to use this server";
1919
public static String SERVER_IP = null; // Modify this to override "Cache/ip.txt"
2020
public static int SERVER_PORT; // Modify SERVER_IP above to override "Cache/port.txt" with this value
21-
public static final int CLIENT_VERSION = 10009;
21+
public static final int CLIENT_VERSION = 10010;
2222
private static final int CACHE_VERSION = 4;
2323
public static boolean MEMBER_WORLD = false;
2424
public static boolean DISPLAY_LOGO_SPRITE = false;

Client_Base/src/orsc/MiscFunctions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import orsc.util.GenUtil;
66

77
public final class MiscFunctions {
8-
public static final BigInteger RSA_MODULUS = new BigInteger(
9-
"120553535534604110920450760502772983886474996352454951528826209241321739073070541065736996931396402671853619219844292625227994972012232687659966972603887946951318606732409243729781965910432692806353709960600356722700558734565129892087142295493761639344537209286019991702122529293841694419415125046632027858457");
10-
public static final BigInteger RSA_EXPONENT = new BigInteger("65537");
8+
public static BigInteger RSA_MODULUS;
9+
public static BigInteger RSA_EXPONENT;
1110
private static byte[][] s_j = new byte[1000][];
1211
public static int cachingFile_s_g = 0;
1312
public static int frustumNearZ;

Client_Base/src/orsc/PacketHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.ByteArrayInputStream;
2121
import java.io.IOException;
22+
import java.math.BigInteger;
2223
import java.net.InetAddress;
2324
import java.net.Socket;
2425
import java.util.HashMap;
@@ -1036,6 +1037,8 @@ private void setServerConfiguration() {
10361037
disableMinimapRotation = this.getClientStream().getUnsignedByte(); // 84
10371038
allowBeardedLadies = this.getClientStream().getUnsignedByte(); // 85
10381039
prideMonth = this.getClientStream().getUnsignedByte(); // 86
1040+
MiscFunctions.RSA_EXPONENT = new BigInteger(this.getClientStream().readString()); // 87
1041+
MiscFunctions.RSA_MODULUS = new BigInteger(this.getClientStream().readString()); // 88
10391042
} else {
10401043
serverName = packetsIncoming.readString(); // 1
10411044
serverNameWelcome = packetsIncoming.readString(); // 2
@@ -1123,6 +1126,8 @@ private void setServerConfiguration() {
11231126
disableMinimapRotation = packetsIncoming.getUnsignedByte(); // 84
11241127
allowBeardedLadies = packetsIncoming.getUnsignedByte(); // 85
11251128
prideMonth = packetsIncoming.getUnsignedByte(); // 86
1129+
MiscFunctions.RSA_EXPONENT = new BigInteger(packetsIncoming.readString()); // 87
1130+
MiscFunctions.RSA_MODULUS = new BigInteger(packetsIncoming.readString()); // 88
11261131
}
11271132

11281133
if (Config.DEBUG) {
@@ -1212,7 +1217,9 @@ private void setServerConfiguration() {
12121217
"\nS_SHOW_UNDERGROUND_FLICKER_TOGGLE " + showUndergroundFlickerToggle + // 83
12131218
"\nS_DISABLE_MINIMAP_ROTATION " + disableMinimapRotation + // 84
12141219
"\nS_ALLOW_BEARDED_LADIES " + allowBeardedLadies + // 85
1215-
"\nS_PRIDE_MONTH " + prideMonth // 86
1220+
"\nS_PRIDE_MONTH " + prideMonth + // 86
1221+
"\nRSA_EXPONENT " + MiscFunctions.RSA_EXPONENT + // 87
1222+
"\nRSA_MODULUS " + MiscFunctions.RSA_MODULUS // 88
12161223
);
12171224
}
12181225

Client_Base/src/orsc/buffers/RSBuffer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public final boolean isCRCValid() {
7272
}
7373
}
7474

75-
private void readBytes(int count, byte[] out) {
75+
public void readBytes(int count, byte[] out) {
7676
try {
7777
for (int i = 0; i < count; ++i) {
7878
out[i] = this.dataBuffer[this.packetEnd++];
@@ -84,7 +84,7 @@ private void readBytes(int count, byte[] out) {
8484
}
8585
}
8686

87-
private void writeBytes(byte[] src, int count) {
87+
public void writeBytes(byte[] src, int count) {
8888
try {
8989
for (int i = 0; i < count; ++i) {
9090
this.dataBuffer[this.packetEnd++] = src[i];
@@ -322,7 +322,7 @@ public final void encodeWithRSA(BigInteger var1, BigInteger var3) {
322322

323323
this.readBytes(pointerPosition, encodedBuffer);
324324
BigInteger var7 = new BigInteger(encodedBuffer);
325-
BigInteger var8 = var7.modPow(var3, var1);
325+
BigInteger var8 = var7.modPow(var1, var3);
326326
byte[] var9 = var8.toByteArray();
327327
this.packetEnd = 0;
328328
this.putShort(var9.length);

Client_Base/src/orsc/mudclient.java

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.openrsc.interfaces.misc.*;
1818
import com.openrsc.interfaces.misc.clan.Clan;
1919
import com.openrsc.interfaces.misc.party.Party;
20+
import orsc.buffers.RSBuffer;
2021
import orsc.buffers.RSBufferUtils;
2122
import orsc.buffers.RSBuffer_Bits;
2223
import orsc.enumerations.*;
@@ -39,6 +40,9 @@
3940
import orsc.util.Utils;
4041

4142
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;
4246
import java.security.SecureRandom;
4347
import java.time.LocalDateTime;
4448
import java.time.format.DateTimeFormatter;
@@ -72,6 +76,10 @@ public final class mudclient implements Runnable {
7276
private static final ArrayList<String> skillNamesArray = new ArrayList<String>();
7377
private static String[] skillNameLong;
7478
private static String[] skillNames;
79+
private static String[] programArgs;
80+
public void setProgramArgs(String[] progArgs) {
81+
this.programArgs = progArgs;
82+
}
7583
public final int[] bankItemOnTab = new int[500];
7684
public final int[] equipIconXLocations = new int[]{98, 98, 98, 153, 43, 43, 98, 98, 43, 153, 153};
7785
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) {
1447214480
}
1447314481
this.packetHandler.getClientStream().bufferBits.putInt(CLIENT_VERSION);
1447414482
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);
1447714542

1447814543
this.packetHandler.getClientStream().bufferBits.putLong(getUID());
1447914544

server/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ world:
1616
want_custom_walking_speed: false # Do we want to enable custom walking speed?
1717
idle_timer: 300000 # 5 minute player idle alert, 0 disables
1818
auto_save: 30000 # 30 second autosave interval
19-
client_version: 10009
19+
client_version: 10010
2020
enforce_custom_client_version: true
2121
server_port: 43594 # 43593 2001scape / 43594 preservation / 43595 cabbage / 43596 openrsc / 43597 openpk / 43598 wk / 43599 dev
2222
ws_server_port: 43494 # 43493 2001scape / 43494 preservation / 43495 cabbage / 43496 openrsc / 43497 openpk / 43498 wk / 43499 dev

server/openpk.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ world:
1717
want_custom_walking_speed: false # Do we want to enable custom walking speed?
1818
idle_timer: 300000 # 5 minute player idle alert, 0 disables
1919
auto_save: 30000 # 30 second autosave interval
20-
client_version: 10009
20+
client_version: 10010
2121
enforce_custom_client_version: false
2222
server_port: 43597 # 43594 preservation / 43595 cabbage / 43596 openrsc / 43597 openpk / 43598 wk / 43599 dev
2323
ws_server_port: 43497 # MODIFIED

server/preservation.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ world:
1818
want_custom_walking_speed: false # Do we want to enable custom walking speed?
1919
idle_timer: 300000 # 5 minute player idle alert, 0 disables
2020
auto_save: 120000 # 120 second autosave interval
21-
client_version: 10009
21+
client_version: 10010
2222
enforce_custom_client_version: false
2323
server_port: 43596 # MODIFIED
2424
ws_server_port: 43496 # MODIFIED

server/rsccabbage.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ world:
1515
want_custom_walking_speed: false # Do we want to enable custom walking speed?
1616
idle_timer: 600000 # MODIFIED 10 minute player idle alert, 0 disables
1717
auto_save: 30000 # 30 second autosave interval
18-
client_version: 10009
18+
client_version: 10010
1919
enforce_custom_client_version: false
2020
server_port: 43595 # MODIFIED
2121
ws_server_port: 43495 # MODIFIED

server/rsccoleslaw.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ world:
1616
want_custom_walking_speed: false # Do we want to enable custom walking speed?
1717
idle_timer: 600000 # MODIFIED 10 minute player idle alert, 0 disables
1818
auto_save: 30000 # 30 second autosave interval
19-
client_version: 10009
19+
client_version: 10010
2020
enforce_custom_client_version: false
2121
server_port: 43599 # MODIFIED
2222
ws_server_port: 43499 # MODIFIED

0 commit comments

Comments
 (0)