From 3882ea669d19a7fd8a6ad62bc80615368043b1d3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 7 Feb 2024 10:55:33 +0100 Subject: [PATCH] check server from on stream open --- .../siacs/conversations/xmpp/XmppConnection.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 9097a1256..69fad55e8 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -526,8 +526,7 @@ public class XmppConnection implements Runnable { tagReader.setInputStream(socket.getInputStream()); tagWriter.beginDocument(); final boolean quickStart; - if (socket instanceof SSLSocket) { - final SSLSocket sslSocket = (SSLSocket) socket; + if (socket instanceof SSLSocket sslSocket) { SSLSockets.log(account, sslSocket); quickStart = establishStream(SSLSockets.version(sslSocket)); } else { @@ -537,7 +536,16 @@ public class XmppConnection implements Runnable { if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } - final boolean success = tag != null && tag.isStart("stream", Namespace.STREAMS); + if (tag == null) { + return false; + } + final boolean success = tag.isStart("stream", Namespace.STREAMS); + if (success) { + final var from = tag.getAttribute("from"); + if (from == null || !from.equals(account.getServer())) { + throw new StateChangingException(Account.State.HOST_UNKNOWN); + } + } if (success && quickStart) { this.quickStartInProgress = true; }