diff options
author | Vitaly Takmazov | 2017-10-09 15:27:48 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-10 09:37:31 +0300 |
commit | 448fc7e84732422011186a9a4633c345e9c6208e (patch) | |
tree | 7ec23a9f29939fecf6456956ead6cebd1338871d /juick-xmpp/src/main/java/com/juick/components/s2s | |
parent | 443daa747298de315840cdd6ee6992519707e61a (diff) |
xmpp:ConnectionOut -> StreamServerDialback
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java | 14 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java | 51 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java | 89 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionListener.java | 14 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/StreamServerDialback.java (renamed from juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java) | 130 | ||||
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/s2s/util/DialbackUtils.java | 5 |
6 files changed, 124 insertions, 179 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java b/juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java index 645b24f1..c8eeab53 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/CacheEntry.java @@ -17,20 +17,24 @@ package com.juick.components.s2s; +import rocks.xmpp.addr.Jid; + +import java.time.Instant; + /** * * @author ugnich */ public class CacheEntry { - public String hostname; - public long tsCreated; - public long tsUpdated; + public Jid hostname; + public Instant created; + public Instant updated; public String xml; - public CacheEntry(String hostname, String xml) { + public CacheEntry(Jid hostname, String xml) { this.hostname = hostname; - this.tsCreated = this.tsUpdated = System.currentTimeMillis(); + this.created = this.updated =Instant.now(); this.xml = xml; } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java index 7d3767a2..6a796307 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/Connection.java @@ -24,15 +24,11 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.io.*; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.net.Socket; import java.nio.charset.StandardCharsets; -import java.security.*; -import java.security.cert.CertificateException; import java.time.Instant; import java.util.UUID; @@ -50,7 +46,7 @@ public class Connection { public long bytesLocal = 0; public long packetsLocal = 0; XMPPServer xmpp; - Socket socket; + private Socket socket; public static final String NS_DB = "jabber:server:dialback"; public static final String NS_TLS = "urn:ietf:params:xml:ns:xmpp-tls"; public static final String NS_STREAM = "http://etherx.jabber.org/streams"; @@ -58,35 +54,12 @@ public class Connection { XmlPullParser parser = factory.newPullParser(); OutputStreamWriter writer; private boolean secured = false; - SSLContext sc; - private TrustManager[] trustAllCerts = new TrustManager[]{ - new X509TrustManager() { - public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { - } - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - } - }; - - - public Connection(XMPPServer xmpp) throws XmlPullParserException, KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, KeyManagementException { + + + + public Connection(XMPPServer xmpp) throws XmlPullParserException { this.xmpp = xmpp; created = updated = Instant.now(); - KeyStore ks = KeyStore.getInstance("JKS"); - try (InputStream ksIs = new FileInputStream(xmpp.keystore)) { - ks.load(ksIs, xmpp.keystorePassword.toCharArray()); - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory - .getDefaultAlgorithm()); - kmf.init(ks, xmpp.keystorePassword.toCharArray()); - sc = SSLContext.getInstance("TLSv1.2"); - sc.init(kmf.getKeyManagers(), trustAllCerts, new SecureRandom()); - } catch (Exception e) { - logger.warn("tls unavailable"); - } } public void logParser() { @@ -153,4 +126,12 @@ public class Connection { parser.setInput(new InputStreamReader(socket.getInputStream())); writer = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8); } + + public Socket getSocket() { + return socket; + } + + public void setSocket(Socket socket) { + this.socket = socket; + } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java index e6f404ef..16f207a7 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionIn.java @@ -24,52 +24,33 @@ import org.apache.commons.lang3.StringUtils; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import rocks.xmpp.addr.Jid; -import rocks.xmpp.core.stanza.model.Stanza; -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLSocket; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; import java.io.EOFException; import java.io.IOException; -import java.io.StringReader; import java.net.Socket; import java.net.SocketException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.util.ArrayList; +import java.time.Instant; import java.util.Arrays; import java.util.List; import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; /** * @author ugnich */ public class ConnectionIn extends Connection implements Runnable { - final public List<String> from = new ArrayList<>(); - public long tsRemoteData = 0; + final public List<Jid> from = new CopyOnWriteArrayList<>(); + public Instant received; public long packetsRemote = 0; + ConnectionListener listener; - public ConnectionIn(XMPPServer xmpp, Socket socket) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException { + public ConnectionIn(XMPPServer xmpp, Socket socket) throws XmlPullParserException, IOException { super(xmpp); - this.socket = socket; + this.setSocket(socket); restartParser(); } - protected Stanza parse(String xml) { - try { - Unmarshaller unmarshaller = xmpp.getSession().createUnmarshaller(); - return (Stanza)unmarshaller.unmarshal(new StringReader(xml)); - } catch (JAXBException e) { - logger.error("JAXB exception", e); - } - return null; - } - @Override public void run() { try { @@ -79,7 +60,7 @@ public class ConnectionIn extends Connection implements Runnable { || !parser.getNamespace("stream").equals(NS_STREAM)) { // || !parser.getAttributeValue(null, "version").equals("1.0") // || !parser.getAttributeValue(null, "to").equals(Main.HOSTNAME)) { - throw new Exception(String.format("stream from %s invalid", socket.getRemoteSocketAddress())); + throw new Exception(String.format("stream from %s invalid", getSocket().getRemoteSocketAddress())); } streamID = parser.getAttributeValue(null, "id"); if (streamID == null) { @@ -108,14 +89,15 @@ public class ConnectionIn extends Connection implements Runnable { String dfrom = parser.getAttributeValue(null, "from"); String to = parser.getAttributeValue(null, "to"); logger.info("stream from {} to {} {} asking for dialback", dfrom, to, streamID); - if (dfrom.endsWith(xmpp.HOSTNAME) && (dfrom.equals(xmpp.HOSTNAME) || dfrom.endsWith("." + xmpp.HOSTNAME))) { + if (dfrom.endsWith(xmpp.getJid().toEscapedString()) && (dfrom.equals(xmpp.getJid().toEscapedString()) + || dfrom.endsWith("." + xmpp.getJid()))) { logger.warn("stream from {} is invalid", dfrom); break; } - if (to != null && to.equals(xmpp.HOSTNAME)) { + if (to != null && to.equals(xmpp.getJid().toEscapedString())) { String dbKey = XmlUtils.getTagText(parser); updateTsRemoteData(); - xmpp.startDialback(dfrom, streamID, dbKey); + xmpp.startDialback(Jid.of(dfrom), streamID, dbKey); } else { logger.warn("stream from " + dfrom + " " + streamID + " invalid to " + to); break; @@ -128,7 +110,7 @@ public class ConnectionIn extends Connection implements Runnable { updateTsRemoteData(); final boolean[] valid = {false}; if (vfrom != null && vto != null && vid != null && vkey != null) { - xmpp.getConnectionOut(vfrom, false).ifPresent(c -> { + xmpp.getConnectionOut(Jid.of(vfrom), false).ifPresent(c -> { String dialbackKey = c.dbKey; valid[0] = vkey.equals(dialbackKey); }); @@ -143,12 +125,12 @@ public class ConnectionIn extends Connection implements Runnable { } else if (tag.equals("presence") && checkFromTo(parser)) { String xml = XmlUtils.parseToString(parser, false); logger.info("stream {} presence: {}", streamID, xml); - xmpp.onStanzaReceived(parse(xml)); + xmpp.onStanzaReceived(xml); } else if (tag.equals("message") && checkFromTo(parser)) { updateTsRemoteData(); String xml = XmlUtils.parseToString(parser, false); logger.info("stream {} message: {}", streamID, xml); - xmpp.onStanzaReceived(parse(xml)); + xmpp.onStanzaReceived(xml); } else if (tag.equals("iq") && checkFromTo(parser)) { updateTsRemoteData(); @@ -156,25 +138,10 @@ public class ConnectionIn extends Connection implements Runnable { String xml = XmlUtils.parseToString(parser, false); if (type == null || !type.equals("error")) { logger.info("stream {} iq: {}", streamID, xml); - xmpp.onStanzaReceived(parse(xml)); - } - } else if (sc != null && !isSecured() && tag.equals("starttls")) { - logger.info("stream {} securing", streamID); - sendStanza("<proceed xmlns=\"" + NS_TLS + "\" />"); - try { - socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(), - socket.getPort(), true); - ((SSLSocket) socket).setUseClientMode(false); - ((SSLSocket) socket).startHandshake(); - setSecured(true); - logger.info("stream {} secured", streamID); - restartParser(); - } catch (SSLException sex) { - logger.warn("stream {} ssl error {}", streamID, sex); - sendStanza("<failed xmlns\"" + NS_TLS + "\" />"); - xmpp.removeConnectionIn(this); - closeConnection(); + xmpp.onStanzaReceived(xml); } + } else if (!isSecured() && tag.equals("starttls")) { + listener.starttls(this); } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { sendOpenStream(null, true); } else if (tag.equals("error")) { @@ -202,16 +169,16 @@ public class ConnectionIn extends Connection implements Runnable { } void updateTsRemoteData() { - tsRemoteData = System.currentTimeMillis(); + received = Instant.now(); } void sendOpenStream(String from, boolean xmppversionnew) throws IOException { String openStream = "<?xml version='1.0'?><stream:stream xmlns='jabber:server' " + "xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" + - xmpp.HOSTNAME + "' id='" + streamID + "' version='1.0'>"; + xmpp.getJid().toEscapedString() + "' id='" + streamID + "' version='1.0'>"; if (xmppversionnew) { openStream += "<stream:features>"; - if (sc != null && !isSecured() && !Arrays.asList(xmpp.brokenSSLhosts).contains(from)) { + if (listener != null && !isSecured() && !Arrays.asList(xmpp.brokenSSLhosts).contains(from)) { openStream += "<starttls xmlns=\"" + NS_TLS + "\"><optional/></starttls>"; } openStream += "</stream:features>"; @@ -219,8 +186,8 @@ public class ConnectionIn extends Connection implements Runnable { sendStanza(openStream); } - public void sendDialbackResult(String sfrom, String type) { - sendStanza("<db:result from='" + xmpp.HOSTNAME + "' to='" + sfrom + "' type='" + type + "'/>"); + public void sendDialbackResult(Jid sfrom, String type) { + sendStanza("<db:result from='" + xmpp.getJid().toEscapedString() + "' to='" + sfrom + "' type='" + type + "'/>"); if (type.equals("valid")) { from.add(sfrom); logger.info("stream from {} {} ready", sfrom, streamID); @@ -232,11 +199,10 @@ public class ConnectionIn extends Connection implements Runnable { String cto = parser.getAttributeValue(null, "to"); if (StringUtils.isNotEmpty(cfrom) && StringUtils.isNotEmpty(cto)) { Jid jidto = Jid.of(cto); - if (jidto.getDomain().equals(xmpp.HOSTNAME)) { + if (jidto.getDomain().equals(xmpp.getJid().toEscapedString())) { Jid jidfrom = Jid.of(cfrom); - int size = from.size(); - for (int i = 0; i < size; i++) { - if (from.get(i).equals(jidfrom.getDomain())) { + for (Jid aFrom : from) { + if (aFrom.equals(Jid.of(jidfrom.getDomain()))) { return true; } } @@ -244,4 +210,7 @@ public class ConnectionIn extends Connection implements Runnable { } return false; } + public void setListener(ConnectionListener listener) { + this.listener = listener; + } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionListener.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionListener.java new file mode 100644 index 00000000..ef5a948b --- /dev/null +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionListener.java @@ -0,0 +1,14 @@ +package com.juick.components.s2s; + +import com.juick.xmpp.extensions.StreamError; + +public interface ConnectionListener { + void starttls(ConnectionIn connection); + void proceed(StreamServerDialback connection); + void verify(StreamServerDialback connection, String from, String type, String sid); + void dialbackError(StreamServerDialback connection, StreamError error); + void finished(StreamServerDialback connection, boolean dirty); + void exception(StreamServerDialback connection, Exception ex); + void ready(StreamServerDialback connection); + boolean securing(StreamServerDialback connection); +} diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java b/juick-xmpp/src/main/java/com/juick/components/s2s/StreamServerDialback.java index 589ed18a..48c4d72d 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionOut.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/StreamServerDialback.java @@ -17,77 +17,69 @@ package com.juick.components.s2s; -import com.juick.components.XMPPServer; import com.juick.components.s2s.util.DialbackUtils; +import com.juick.xmpp.Stream; import com.juick.xmpp.extensions.StreamError; import com.juick.xmpp.extensions.StreamFeatures; import com.juick.xmpp.utils.XmlUtils; import org.apache.commons.text.RandomStringGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; +import rocks.xmpp.addr.Jid; -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLSocket; import java.io.EOFException; import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; +import java.io.InputStream; +import java.io.OutputStream; import java.net.SocketException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.util.Arrays; import java.util.UUID; /** * @author ugnich */ -public class ConnectionOut extends Connection implements Runnable { +public class StreamServerDialback extends Stream { + protected static final Logger logger = LoggerFactory.getLogger(StreamServerDialback.class); + public static final String NS_TLS = "urn:ietf:params:xml:ns:xmpp-tls"; + public static final String NS_DB = "jabber:server:dialback"; + private boolean secured = false; public boolean streamReady = false; - public String to; String checkSID = null; String dbKey = null; + private String streamID; + ConnectionListener listener; RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('a', 'z').build(); - public ConnectionOut(XMPPServer xmpp, String hostname) throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, XmlPullParserException, KeyManagementException, KeyStoreException, IOException { - super(xmpp); - to = hostname; - dbKey = DialbackUtils.generateDialbackKey(generator.generate(15), to, xmpp.HOSTNAME, streamID); - } - - public ConnectionOut(XMPPServer xmpp, String hostname, String checkSID, String dbKey) throws Exception { - super(xmpp); - to = hostname; + public StreamServerDialback(Jid from, Jid to, InputStream is, OutputStream os, String checkSID, String dbKey) throws Exception { + super(from, to, is, os); + this.to = to; this.checkSID = checkSID; this.dbKey = dbKey; + if (dbKey == null) { + this.dbKey = DialbackUtils.generateDialbackKey(generator.generate(15), to, from, streamID); + } streamID = UUID.randomUUID().toString(); } - void sendOpenStream() throws IOException { - sendStanza("<?xml version='1.0'?><stream:stream xmlns='jabber:server' id='" + streamID + + public void sendOpenStream() throws IOException { + send("<?xml version='1.0'?><stream:stream xmlns='jabber:server' id='" + streamID + "' xmlns:stream='http://etherx.jabber.org/streams' xmlns:db='jabber:server:dialback' from='" + - xmpp.HOSTNAME + "' to='" + to + "' version='1.0'>"); + from.toEscapedString() + "' to='" + to.toEscapedString() + "' version='1.0'>"); } void processDialback() throws Exception { if (checkSID != null) { sendDialbackVerify(checkSID, dbKey); } - sendStanza("<db:result from='" + xmpp.HOSTNAME + "' to='" + to + "'>" + + send("<db:result from='" + from.toEscapedString() + "' to='" + to.toEscapedString() + "'>" + dbKey + "</db:result>"); } @Override - public void run() { - logger.info("stream to {} start", to); + public void handshake() { try { - socket = new Socket(); - InetSocketAddress address = DNSQueries.getServerAddress(to); - socket.connect(address); - restartParser(); + restartStream(); sendOpenStream(); @@ -107,21 +99,13 @@ public class ConnectionOut extends Connection implements Runnable { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } - logParser(); String tag = parser.getName(); if (tag.equals("result") && parser.getNamespace().equals(NS_DB)) { String type = parser.getAttributeValue(null, "type"); if (type != null && type.equals("valid")) { streamReady = true; - logger.info("stream to {} {} ready", to, streamID); - - String cache = xmpp.getFromCache(to); - if (cache != null) { - logger.info("stream to {} {} sending cache", to, streamID); - sendStanza(cache); - } - + listener.ready(this); } else { logger.info("stream to {} {} dialback fail", to, streamID); } @@ -130,62 +114,54 @@ public class ConnectionOut extends Connection implements Runnable { String from = parser.getAttributeValue(null, "from"); String type = parser.getAttributeValue(null, "type"); String sid = parser.getAttributeValue(null, "id"); - if (from != null && from.equals(to) && sid != null && !sid.isEmpty() && type != null) { - xmpp.getConnectionIn(sid).ifPresent(c -> c.sendDialbackResult(from, type)); - } + listener.verify(this, from, type, sid); XmlUtils.skip(parser); } else if (tag.equals("features") && parser.getNamespace().equals(NS_STREAM)) { StreamFeatures features = StreamFeatures.parse(parser); - if (sc != null && !isSecured() && features.STARTTLS >= 0 && !Arrays.asList(xmpp.brokenSSLhosts).contains(to)) { - logger.info("stream to {} {} securing", to, streamID); - sendStanza("<starttls xmlns=\"" + NS_TLS + "\" />"); + if (listener != null && !secured && features.STARTTLS >= 0 + && listener.securing(this)) { + logger.info("stream to {} {} securing", to.toEscapedString(), streamID); + send("<starttls xmlns=\"" + NS_TLS + "\" />"); } else { processDialback(); } } else if (tag.equals("proceed") && parser.getNamespace().equals(NS_TLS)) { - try { - socket = sc.getSocketFactory().createSocket(socket, socket.getInetAddress().getHostAddress(), - socket.getPort(), true); - ((SSLSocket) socket).startHandshake(); - setSecured(true); - logger.info("stream {} secured", streamID); - restartParser(); - sendOpenStream(); - } catch (SSLException sex) { - logger.error("s2s ssl error: {} {}, error {}", to, streamID, sex); - sendStanza("<failed xmlns\"" + NS_TLS + "\" />"); - xmpp.removeConnectionOut(this); - closeConnection(); - } - } else if (isSecured() && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { + listener.proceed(this); + } else if (secured && tag.equals("stream") && parser.getNamespace().equals(NS_STREAM)) { streamID = parser.getAttributeValue(null, "id"); } else if (tag.equals("error")) { StreamError streamError = StreamError.parse(parser); - logger.warn("Stream error from {}: {}", streamID, streamError.getCondition()); - xmpp.removeConnectionOut(this); - closeConnection(); + listener.dialbackError(this, streamError); } else { String unhandledStanza = XmlUtils.parseToString(parser, true); logger.warn("Unhandled stanza from {} {} : {}", to, streamID, unhandledStanza); } } - - logger.warn("stream to {} {} finished", to, streamID); - xmpp.removeConnectionOut(ConnectionOut.this); - closeConnection(); + listener.finished(this, false); } catch (EOFException | SocketException eofex) { - logger.info("stream {} {} closed (dirty)", to, streamID); - xmpp.removeConnectionOut(ConnectionOut.this); - closeConnection(); + listener.finished(this, true); } catch (Exception e) { - logger.error("s2s out exception: {} {}, exception {}", to, streamID, e); - xmpp.removeConnectionOut(ConnectionOut.this); - closeConnection(); + listener.exception(this, e); } } public void sendDialbackVerify(String sid, String key) { - sendStanza("<db:verify from='" + xmpp.HOSTNAME + "' to='" + to + "' id='" + sid + "'>" + + send("<db:verify from='" + from.toEscapedString() + "' to='" + to + "' id='" + sid + "'>" + key + "</db:verify>"); } + public void setListener(ConnectionListener listener) { + this.listener = listener; + } + + public String getStreamID() { + return streamID; + } + + public boolean isSecured() { + return secured; + } + + public void setSecured(boolean secured) { + this.secured = secured; + } } diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/util/DialbackUtils.java b/juick-xmpp/src/main/java/com/juick/components/s2s/util/DialbackUtils.java index 88626606..fc08c5d6 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/util/DialbackUtils.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/util/DialbackUtils.java @@ -19,6 +19,7 @@ package com.juick.components.s2s.util; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.HmacUtils; +import rocks.xmpp.addr.Jid; /** * Created by vitalyster on 05.12.2016. @@ -28,8 +29,8 @@ public class DialbackUtils { throw new IllegalStateException(); } - public static String generateDialbackKey(String secret, String to, String from, String id) { + public static String generateDialbackKey(String secret, Jid to, Jid from, String id) { return HmacUtils.hmacSha256Hex(DigestUtils.sha256(secret), - (to + " " + from + " " + id).getBytes()); + (to.toEscapedString() + " " + from.toEscapedString() + " " + id).getBytes()); } } |