Skip to content

Commit

Permalink
(probably) fix EOFException is thrown on proxy-side
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Apr 15, 2022
1 parent d7e4b0f commit c9b44b7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
import java.io.IOException;

public class ProxyboundEncryptionPacket implements ProxyMessageHandler<EncryptionMessage> {
@Override
public @NotNull EncryptionMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) {
public @NotNull EncryptionMessage read(@NotNull ServerConnection server, @NotNull DataInputStream in) throws IOException {
try {
return EncryptionMessage.read(in);
} catch (Exception e) {
if (e instanceof IOException) {
throw (IOException) e;
}
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import org.jetbrains.annotations.NotNull;

import java.io.DataInputStream;
import java.io.IOException;

public class ServerboundEncryptionPacket implements ServerMessageHandler<EncryptionMessage> {
@Override
public @NotNull EncryptionMessage read(@NotNull DataInputStream in) {
public @NotNull EncryptionMessage read(@NotNull DataInputStream in) throws IOException {
try {
return EncryptionMessage.read(in);
} catch (Exception e) {
if (e instanceof IOException) {
throw (IOException) e;
}
throw new RuntimeException(e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "net.azisaba.azipluginmessaging"
version = "2.0.2"
version = "2.0.3"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public static PacketSender getAnyPacketSender() {

@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
// do inside the separate thread to avoid blocking main thread
new Thread(() -> {
Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> {
KeyPair keyPair;
try {
// generate keypair
Expand All @@ -76,6 +75,6 @@ public void onPlayerJoin(PlayerJoinEvent e) {

// send our public key
Protocol.P_ENCRYPTION.sendPacket(player, new EncryptionMessage(player.challenge, keyPair.getPublic()));
}, "AziPluginMessaging-" + e.getPlayer().getName()).start();
}, 20L);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void setKeyPair(@NotNull KeyPair keyPair) {
@Override
public void setEncrypted(boolean encrypted) {
this.encrypted = encrypted;

// clear challenge, so any new encryption requests will be denied.
this.challenge = null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ public void setRemotePublicKey(@NotNull PublicKey publicKey) {
this.publicKey = publicKey;
}

@NotNull
@Override
public String toString() {
return "ServerConnectionImpl{handle=" + handle + '}';
return "ServerConnectionImpl{" +
"handle=" + handle +
", encrypted=" + encrypted +
'}';
}
}

0 comments on commit c9b44b7

Please sign in to comment.