mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-309 added code to better reject third party connections which turn out not to be chronicle.
This commit is contained in:
@@ -36,6 +36,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.nio.BufferUnderflowException;
|
||||
@@ -512,11 +513,44 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check that the version number is valid text,
|
||||
*
|
||||
* @param versionNumber the version number to check
|
||||
* @return true, if the version number looks correct
|
||||
*/
|
||||
boolean isValidVersionNumber(String versionNumber) {
|
||||
|
||||
if (versionNumber.length()<=2)
|
||||
return false;
|
||||
|
||||
for (char c : versionNumber.toCharArray()) {
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
continue;
|
||||
|
||||
if (c == '.' || c == '-' || c == '_')
|
||||
continue;
|
||||
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
continue;
|
||||
|
||||
if (c >= 'a' && c <= 'z')
|
||||
continue;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkVersions(final Attached<K, V> attached) {
|
||||
|
||||
final String localVersion = BuildVersion.version();
|
||||
final String remoteVersion = attached.serverVersion;
|
||||
|
||||
|
||||
if (!remoteVersion.equals(localVersion)) {
|
||||
byte remoteIdentifier = attached.remoteIdentifier;
|
||||
LOG.warn("DIFFERENT CHRONICLE-MAP VERSIONS : " +
|
||||
@@ -613,10 +647,21 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
|
||||
}
|
||||
|
||||
if (attached.serverVersion == null) {
|
||||
attached.serverVersion = reader.readRemoteServerVersion();
|
||||
try {
|
||||
attached.serverVersion = reader.readRemoteServerVersion();
|
||||
} catch (IllegalStateException e1) {
|
||||
socketChannel.close();
|
||||
}
|
||||
|
||||
if (attached.serverVersion == null)
|
||||
return;
|
||||
|
||||
if (!isValidVersionNumber(attached.serverVersion)) {
|
||||
LOG.warn("Please check that you don't have a third party system incorrectly connecting to ChronicleMap, " +
|
||||
"Closing the remote connection as Chronicle can not make sense of the remote version number received from the external connection, version="+attached.serverVersion+", Chronicle is expecting the version number to only contain '.',A-Z,a-z,0-9");
|
||||
socketChannel.close();
|
||||
}
|
||||
|
||||
checkVersions(attached);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,8 @@ public class TCPSocketReplicationTest {
|
||||
|
||||
assertEquals(map1, map2);
|
||||
assertTrue(!map1.isEmpty());
|
||||
|
||||
Thread.sleep(9999999);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user