Skip to content

Commit 468d8ce

Browse files
committed
Add detect SSL alert
1 parent f5a7ec4 commit 468d8ce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,8 @@ else if (MESSAGE_SERIALIZATION[0] == serMode) {
29602960
return (T)msg;
29612961
}
29622962

2963+
detectSslAlert(serMode, in);
2964+
29632965
throw new EOFException();
29642966
}
29652967
catch (Exception e) {
@@ -2976,5 +2978,24 @@ private void readNBytes(InputStream in, int nbytes) throws IOException {
29762978
if (in.readNBytes(buf.array(), 0, nbytes) < nbytes)
29772979
throw new EOFException();
29782980
}
2981+
2982+
/**
2983+
* Checks wheter input stream contains SSL alert.
2984+
* See handling {@code StreamCorruptedException} in {@link #readMessage(Socket, InputStream, long)}.
2985+
* Keeps logic similar to {@link java.io.ObjectInputStream#readStreamHeader}.
2986+
*/
2987+
private void detectSslAlert(byte firstByte, InputStream in) throws IOException {
2988+
byte[] hdr = new byte[4];
2989+
hdr[0] = firstByte;
2990+
int read = in.readNBytes(hdr, 1, 3);
2991+
2992+
if (read < 3)
2993+
throw new EOFException();
2994+
2995+
String hex = String.format("%02x%02x%02x%02x", hdr[0], hdr[1], hdr[2], hdr[3]);
2996+
2997+
if (hex.matches("15....00"))
2998+
throw new StreamCorruptedException("invalid stream header: " + hex);
2999+
}
29793000
}
29803001
}

0 commit comments

Comments
 (0)