From b5bc7d8d9f1a03498d380493c0d4ed51923007e2 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 9 Apr 2018 08:18:13 +0200 Subject: [PATCH 1/6] Use XMPP service name when creating the TLS socket instead of the hostname. This should make SNI also to use the XMPP service name instead of the hostname. Fixes SMACK-813. --- .../main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 33bf2845e..ffa79c341 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -795,7 +795,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { Socket plain = socket; // Secure the plain connection socket = context.getSocketFactory().createSocket(plain, - host, plain.getPort(), true); + config.getXMPPServiceDomain().toString(), plain.getPort(), true); final SSLSocket sslSocket = (SSLSocket) socket; // Immediately set the enabled SSL protocols and ciphers. See SMACK-712 why this is From 2614c0d5c1827097c0ad322916af01b4326fbf21 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 9 Apr 2018 20:59:39 +0200 Subject: [PATCH 2/6] Add support for XEP-0319: Last User Interaction (SMACK-636) --- documentation/extensions/index.md | 1 + .../last_interaction/element/IdleElement.java | 101 ++++++++++++++++++ .../element/package-info.java | 21 ++++ .../smackx/last_interaction/package-info.java | 21 ++++ .../provider/IdleProvider.java | 40 +++++++ .../provider/package-info.java | 21 ++++ .../extensions.providers | 9 +- .../smackx/last_interaction/IdleTest.java | 57 ++++++++++ 8 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/package-info.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/package-info.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/IdleProvider.java create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/package-info.java create mode 100644 smack-extensions/src/test/java/org/jivesoftware/smackx/last_interaction/IdleTest.java diff --git a/documentation/extensions/index.md b/documentation/extensions/index.md index b333e2024..4c8aad88d 100644 --- a/documentation/extensions/index.md +++ b/documentation/extensions/index.md @@ -70,6 +70,7 @@ Smack Extensions and currently supported XEPs of smack-extensions | Bits of Binary | [XEP-0231](https://xmpp.org/extensions/xep-0231.html) | n/a | Including or referring to small bits of binary data in an XML stanza. | | Best Practices for Resource Locking | [XEP-0296](https://xmpp.org/extensions/xep-0296.html) | n/a | Specifies best practices to be followed by Jabber/XMPP clients about when to lock into, and unlock away from, resources. | | Last Message Correction | [XEP-0308](https://xmpp.org/extensions/xep-0308.html) | n/a | Provides a method for indicating that a message is a correction of the last sent message. | +| Last User Interaction in Presence | [XEP-0319](https://xmpp.org/extensions/xep-0319.html) | n/a | Communicate time of last user interaction via XMPP presence notifications. | | [Group Chat Invitations](invitation.md) | n/a | n/a | Send invitations to other users to join a group chat room. | | [Jive Properties](properties.md) | n/a | n/a | TODO | diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java new file mode 100644 index 000000000..85c383b2c --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/IdleElement.java @@ -0,0 +1,101 @@ +/** + * + * Copyright © 2018 Paul Schaub + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.last_interaction.element; + +import java.util.Date; + +import org.jivesoftware.smack.packet.ExtensionElement; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.util.Objects; +import org.jivesoftware.smack.util.XmlStringBuilder; + +public class IdleElement implements ExtensionElement { + + public static final String NAMESPACE = "urn:xmpp:idle:1"; + public static final String ELEMENT = "idle"; + public static final String ATTR_SINCE = "since"; + + private final Date since; + + /** + * Create a new IdleElement with the current date as date of last user interaction. + */ + public IdleElement() { + this(new Date()); + } + + /** + * Create a new IdleElement. + * @param since date of last user interaction + */ + public IdleElement(Date since) { + this.since = Objects.requireNonNull(since); + } + + /** + * Return the value of last user interaction. + * @return date of last interaction + */ + public Date getSince() { + return since; + } + + /** + * Add an Idle element with current date to the presence. + * @param presence presence + */ + public static void addToPresence(Presence presence) { + presence.addExtension(new IdleElement()); + } + + /** + * Return the IdleElement from a presence. + * Returns null, if no IdleElement found. + * + * @param presence presence + * @return idleElement from presence or null + */ + public static IdleElement fromPresence(Presence presence) { + return presence.getExtension(ELEMENT, NAMESPACE); + } + + /** + * {@inheritDoc} + */ + @Override + public String getNamespace() { + return NAMESPACE; + } + + /** + * {@inheritDoc} + */ + @Override + public String getElementName() { + return ELEMENT; + } + + /** + * {@inheritDoc} + */ + @Override + public XmlStringBuilder toXML() { + return new XmlStringBuilder(this) + .attribute(ATTR_SINCE, since) + .closeEmptyElement(); + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/package-info.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/package-info.java new file mode 100644 index 000000000..28fb57a4a --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/element/package-info.java @@ -0,0 +1,21 @@ +/** + * + * Copyright © 2018 Paul Schaub + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Element classes for XEP-0319: Last User Interaction in Presence. + */ +package org.jivesoftware.smackx.last_interaction.element; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/package-info.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/package-info.java new file mode 100644 index 000000000..8a314022b --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/package-info.java @@ -0,0 +1,21 @@ +/** + * + * Copyright © 2018 Paul Schaub + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Smack's API for XEP-0319: Last User Interaction in Presence. + */ +package org.jivesoftware.smackx.last_interaction; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/IdleProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/IdleProvider.java new file mode 100644 index 000000000..102edc7df --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/IdleProvider.java @@ -0,0 +1,40 @@ +/** + * + * Copyright © 2018 Paul Schaub + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.last_interaction.provider; + +import java.util.Date; + +import org.jivesoftware.smack.provider.ExtensionElementProvider; +import org.jivesoftware.smackx.last_interaction.element.IdleElement; + +import org.jxmpp.util.XmppDateTime; +import org.xmlpull.v1.XmlPullParser; + +public class IdleProvider extends ExtensionElementProvider { + + public static final IdleProvider TEST_INSTANCE = new IdleProvider(); + + /** + * {@inheritDoc} + */ + @Override + public IdleElement parse(XmlPullParser parser, int initialDepth) throws Exception { + String dateString = parser.getAttributeValue(null, IdleElement.ATTR_SINCE); + Date since = XmppDateTime.parseXEP0082Date(dateString); + return new IdleElement(since); + } +} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/package-info.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/package-info.java new file mode 100644 index 000000000..99d31d50a --- /dev/null +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/last_interaction/provider/package-info.java @@ -0,0 +1,21 @@ +/** + * + * Copyright © 2018 Paul Schaub + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Provider classes for XEP-0319: Last User Interaction in Presence. + */ +package org.jivesoftware.smackx.last_interaction.provider; diff --git a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers index 41705f0ca..70e2c94e0 100644 --- a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers +++ b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers @@ -514,7 +514,14 @@ urn:xmpp:message-correct:0 org.jivesoftware.smackx.message_correct.provider.MessageCorrectProvider - + + + + idle + urn:xmpp:idle:1 + org.jivesoftware.smackx.last_interaction.provider.IdleProvider + + blocklist diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/last_interaction/IdleTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/last_interaction/IdleTest.java new file mode 100644 index 000000000..59bee0cf0 --- /dev/null +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/last_interaction/IdleTest.java @@ -0,0 +1,57 @@ +/** + * + * Copyright © 2018 Paul Schaub + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smackx.last_interaction; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; + +import java.util.Date; + +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.test.util.SmackTestSuite; +import org.jivesoftware.smack.test.util.TestUtils; +import org.jivesoftware.smackx.last_interaction.element.IdleElement; +import org.jivesoftware.smackx.last_interaction.provider.IdleProvider; + +import org.junit.Test; +import org.jxmpp.util.XmppDateTime; +import org.xmlpull.v1.XmlPullParser; + +public class IdleTest extends SmackTestSuite { + + @Test + public void providerTest() throws Exception { + String xml = ""; + XmlPullParser parser = TestUtils.getParser(xml); + assertNotNull(parser); + IdleElement parsed = IdleProvider.TEST_INSTANCE.parse(parser); + Date date = XmppDateTime.parseXEP0082Date("1969-07-21T02:56:15Z"); + assertEquals(date, parsed.getSince()); + + IdleElement element = new IdleElement(date); + assertXMLEqual("", element.toXML().toString()); + } + + @Test + public void helperTest() { + Presence presence = new Presence(Presence.Type.available); + IdleElement.addToPresence(presence); + IdleElement element = IdleElement.fromPresence(presence); + assertNotNull(element); + } +} From 5f58529c3a6e97619407552502bdb822acfd02e8 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 11 Apr 2018 09:55:56 +0200 Subject: [PATCH 3/6] Switch argument of VCard.setJabberId() to CharSequence instead of String. --- .../java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java index 4ef50b2c6..d264be306 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java @@ -249,8 +249,8 @@ public class VCard extends IQ { return otherSimpleFields.get("JABBERID"); } - public void setJabberId(String jabberId) { - otherSimpleFields.put("JABBERID", jabberId); + public void setJabberId(CharSequence jabberId) { + otherSimpleFields.put("JABBERID", jabberId.toString()); } public String getOrganization() { From 7baf276ba0c3c2be93e03429127cebbb6c158c80 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 13 Apr 2018 10:15:28 +0200 Subject: [PATCH 4/6] Bump jxmpp to 0.6.2 --- version.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.gradle b/version.gradle index 82aae01ad..a86094932 100644 --- a/version.gradle +++ b/version.gradle @@ -2,7 +2,7 @@ allprojects { ext { shortVersion = '4.2.4' isSnapshot = true - jxmppVersion = '0.6.0' + jxmppVersion = '0.6.2' smackMinAndroidSdk = 8 } } From e200f2ddf84d11713415f0e72dbd599a1678401c Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 15 Apr 2018 13:39:27 +0200 Subject: [PATCH 5/6] Add OMEMO to EME --- .../smackx/eme/element/ExplicitMessageEncryptionElement.java | 2 ++ .../java/org/jivesoftware/smackx/omemo/OmemoManager.java | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java index 04e0df9c6..452d988a5 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/eme/element/ExplicitMessageEncryptionElement.java @@ -42,6 +42,8 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement { otrV0("urn:xmpp:otr:0", "Off-the-Record Messaging (XEP-0364)"), + omemoVAxolotl("eu.siacs.conversations.axolotl", "OMEMO Multi End Message and Object Encryption (XEP-0384)"), + legacyOpenPGP("jabber:x:encrypted", "Legacy OpenPGP for XMPP [DANGEROUS, DO NOT USE!]"), ; diff --git a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java index 61f3f7010..be584d3d9 100644 --- a/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java +++ b/smack-omemo/src/main/java/org/jivesoftware/smackx/omemo/OmemoManager.java @@ -17,7 +17,6 @@ package org.jivesoftware.smackx.omemo; import static org.jivesoftware.smackx.omemo.util.OmemoConstants.BODY_OMEMO_HINT; -import static org.jivesoftware.smackx.omemo.util.OmemoConstants.OMEMO; import static org.jivesoftware.smackx.omemo.util.OmemoConstants.OMEMO_NAMESPACE_V_AXOLOTL; import static org.jivesoftware.smackx.omemo.util.OmemoConstants.PEP_NODE_DEVICE_LIST_NOTIFY; @@ -42,7 +41,6 @@ import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.Async; - import org.jivesoftware.smackx.carbons.CarbonManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement; @@ -474,7 +472,8 @@ public final class OmemoManager extends Manager { } if (OmemoConfiguration.getAddEmeEncryptionHint()) { - chatMessage.addExtension(new ExplicitMessageEncryptionElement(OMEMO_NAMESPACE_V_AXOLOTL, OMEMO)); + chatMessage.addExtension(new ExplicitMessageEncryptionElement( + ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl)); } return chatMessage; From b548da07072dce849a7d56a6a1cd4dfd6001ed76 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 15 Apr 2018 14:01:49 +0200 Subject: [PATCH 6/6] Smack 4.2.4 --- resources/releasedocs/changelog.html | 34 ++++++++++++++++++++++++++++ version.gradle | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/resources/releasedocs/changelog.html b/resources/releasedocs/changelog.html index 91fecaa6d..5d87462d0 100644 --- a/resources/releasedocs/changelog.html +++ b/resources/releasedocs/changelog.html @@ -142,6 +142,40 @@ hr {
+

4.2.4 -- 2018-04-15

+ +

Bug +

+
    +
  • [SMACK-804] - ServiceAdministrationManager does not use correct form actions +
  • +
  • [SMACK-805] - ServiceDiscoveryManager.findService() only considers the first service by feature +
  • +
  • [SMACK-813] - Smack uses hostname instead of XMPP service name for SNI +
  • +
+ +

New Feature +

+
    +
  • [SMACK-794] - Add support for XEP-0394: Message Markup +
  • +
  • [SMACK-795] - Add support for XEP-0382: Spoiler messages +
  • +
  • [SMACK-799] - Add support for XEP-0372: References +
  • +
  • [SMACK-800] - Add support for XEP-0392: Consistent Color Generation +
  • +
+ +

Improvement +

+
    +
  • [SMACK-802] - Rename and deprecate: addPacketSendingListener(), removePacketSendingListener(), addPacketInterceptor() and removePacketInterceptor() +
  • +
  • [SMACK-809] - Make Roster's non-roster presence map second-level map bounded +
  • +

4.2.3 -- 2018-02-07

diff --git a/version.gradle b/version.gradle index a86094932..7d485e8c9 100644 --- a/version.gradle +++ b/version.gradle @@ -1,7 +1,7 @@ allprojects { ext { shortVersion = '4.2.4' - isSnapshot = true + isSnapshot = false jxmppVersion = '0.6.2' smackMinAndroidSdk = 8 }