From d2f979ed156bfff870330b1e28684236dc7217b2 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Mon, 31 Jul 2017 12:08:18 +0200 Subject: [PATCH] JET is close to working --- .../smackx/ciphers/Aes256GcmNoPadding.java | 2 +- .../smackx/ciphers/AesGcmNoPadding.java | 10 +- .../jivesoftware/smackx/jet/JetManager.java | 22 ++- .../jet/JingleEncryptionMethodManager.java | 42 ------ .../smackx/jet/internal/JetSecurity.java | 32 +++++ .../jet/provider/JetSecurityProvider.java | 18 ++- .../smackx/jft/JingleFileTransferManager.java | 9 +- .../smackx/jingle/JingleManager.java | 60 +++++---- .../jingle/components/JingleContent.java | 3 + .../jingle/components/JingleSecurity.java | 7 + .../JingleContentProviderManager.java | 53 -------- .../jingle/provider/JingleProvider.java | 127 ++++++++++-------- .../jingle_ibb/JingleIBBTransportManager.java | 3 +- .../jingle_s5b/JingleS5BTransportManager.java | 3 +- .../JingleContentProviderManagerTest.java | 19 ++- .../org/jivesoftware/smackx/jet/JetTest.java | 19 +++ .../jivesoftware/smackx/jet/package-info.java | 21 +++ 17 files changed, 242 insertions(+), 208 deletions(-) delete mode 100644 smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JingleEncryptionMethodManager.java delete mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleContentProviderManager.java create mode 100644 smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/package-info.java diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/Aes256GcmNoPadding.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/Aes256GcmNoPadding.java index 545006c34..17b223795 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/Aes256GcmNoPadding.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/Aes256GcmNoPadding.java @@ -33,7 +33,7 @@ public class Aes256GcmNoPadding extends AesGcmNoPadding { public Aes256GcmNoPadding(byte[] keyAndIv) throws NoSuchProviderException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException { super(AesGcmNoPadding.copyOfRange(keyAndIv, 0, keyAndIv.length / 2), //Key - AesGcmNoPadding.copyOfRange(keyAndIv, keyAndIv.length / 2, keyAndIv.length / 2)); //IV + AesGcmNoPadding.copyOfRange(keyAndIv, keyAndIv.length / 2, keyAndIv.length)); //IV } @Override diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java index 6f64e3bf0..22681c5ed 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java @@ -62,15 +62,13 @@ public abstract class AesGcmNoPadding { public AesGcmNoPadding(byte[] key, byte[] iv) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, InvalidKeyException { - this.length = key.length; + this.length = key.length * 8; this.key = key; this.iv = iv; - int bytes = length / 8; - - keyAndIv = new byte[2 * bytes]; - System.arraycopy(key, 0, keyAndIv, 0, bytes); - System.arraycopy(iv, 0, keyAndIv, bytes, bytes); + keyAndIv = new byte[key.length + iv.length]; + System.arraycopy(key, 0, keyAndIv, 0, key.length); + System.arraycopy(iv, 0, keyAndIv, key.length, iv.length); cipher = Cipher.getInstance(cipherMode, "BC"); SecretKeySpec keySpec = new SecretKeySpec(key, keyType); diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java index abb5724e1..74a27a4f6 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JetManager.java @@ -18,13 +18,15 @@ package org.jivesoftware.smackx.jet; import java.io.File; import java.util.HashMap; -import java.util.Map; import java.util.WeakHashMap; +import java.util.logging.Logger; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.jet.internal.JetSecurity; +import org.jivesoftware.smackx.jet.provider.JetSecurityProvider; import org.jivesoftware.smackx.jft.JingleFileTransferManager; import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController; import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer; @@ -43,13 +45,17 @@ import org.jxmpp.jid.FullJid; */ public final class JetManager extends Manager implements JingleDescriptionManager { + private static final Logger LOGGER = Logger.getLogger(JetManager.class.getName()); + private static final WeakHashMap INSTANCES = new WeakHashMap<>(); - private static final Map encryptionMethods = new HashMap<>(); + private static final HashMap encryptionMethods = new HashMap<>(); + private static final HashMap> encryptionMethodProviders = new HashMap<>(); private final JingleManager jingleManager; static { JingleManager.addJingleSecurityAdapter(new JetSecurityAdapter()); + JingleManager.addJingleSecurityProvider(new JetSecurityProvider()); } private JetManager(XMPPConnection connection) { @@ -105,6 +111,18 @@ public final class JetManager extends Manager implements JingleDescriptionManage return encryptionMethods.get(namespace); } + public static void registerEncryptionMethodProvider(String namespace, ExtensionElementProvider provider) { + encryptionMethodProviders.put(namespace, provider); + } + + public static void removeEncryptionMethodProvider(String namespace) { + encryptionMethodProviders.remove(namespace); + } + + public static ExtensionElementProvider getEncryptionMethodProvider(String namespace) { + return encryptionMethodProviders.get(namespace); + } + @Override public String getNamespace() { return JetSecurity.NAMESPACE; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JingleEncryptionMethodManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JingleEncryptionMethodManager.java deleted file mode 100644 index ae669b2d4..000000000 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/JingleEncryptionMethodManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * - * Copyright 2017 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.jet; - -import java.util.HashMap; - -import org.jivesoftware.smack.packet.ExtensionElement; -import org.jivesoftware.smack.provider.ExtensionElementProvider; - -/** - * Manager where JingleEncryptionMethods can register their SecurityKeyTransportProviders. - */ -public final class JingleEncryptionMethodManager { - - public static HashMap> securityKeyTransportProviders = new HashMap<>(); - - private JingleEncryptionMethodManager() { - // $(man true) - } - - public static void registerSecurityKeyTransportProvider(String namespace, ExtensionElementProvider provider) { - securityKeyTransportProviders.put(namespace, provider); - } - - public static ExtensionElementProvider getSecurityKeyTransportProvider(String namespace) { - return securityKeyTransportProviders.get(namespace); - } -} diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/internal/JetSecurity.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/internal/JetSecurity.java index 1bad7ef5a..01a2487cd 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/internal/JetSecurity.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/internal/JetSecurity.java @@ -20,14 +20,18 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.crypto.NoSuchPaddingException; import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.ciphers.Aes256GcmNoPadding; import org.jivesoftware.smackx.ciphers.AesGcmNoPadding; +import org.jivesoftware.smackx.jet.JetManager; import org.jivesoftware.smackx.jet.JingleEncryptionMethod; import org.jivesoftware.smackx.jet.element.JetSecurityElement; import org.jivesoftware.smackx.jingle.callbacks.JingleSecurityCallback; @@ -41,6 +45,7 @@ import org.jxmpp.jid.FullJid; * Created by vanitas on 22.07.17. */ public class JetSecurity extends JingleSecurity { + private static final Logger LOGGER = Logger.getLogger(JetSecurity.class.getName()); public static final String NAMESPACE_V0 = "urn:xmpp:jingle:jet:0"; public static final String NAMESPACE = NAMESPACE_V0; @@ -75,6 +80,7 @@ public class JetSecurity extends JingleSecurity { SmackException.NotConnectedException, SmackException.NoResponseException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException, InvalidKeyException, NoSuchPaddingException { byte[] keyAndIv = method.decryptJingleTransfer(sender, child); + LOGGER.log(Level.INFO, "Transported JET Key has length: " + keyAndIv.length); aesKey = new Aes256GcmNoPadding(keyAndIv); } @@ -103,6 +109,32 @@ public class JetSecurity extends JingleSecurity { callback.onSecurityReady(securityBytestreamSession); } + @Override + public String getNamespace() { + return NAMESPACE; + } + + @Override + public void prepare(XMPPConnection connection, FullJid sender) { + if (getParent().getParent().isInitiator()) { + return; + } + + if (aesKey != null) { + return; + } + + JingleEncryptionMethod method = JetManager.getInstanceFor(connection).getEncryptionMethod(getMethodNamespace()); + if (method == null) { + throw new AssertionError("No JingleEncryptionMethodManager found for " + getMethodNamespace()); + } + try { + decryptEncryptionKey(method, sender); + } catch (InterruptedException | NoSuchPaddingException | InvalidKeyException | NoSuchProviderException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException | JingleEncryptionMethod.JingleEncryptionException e) { + LOGGER.log(Level.SEVERE, "Could not decrypt security key: " + e, e); + } + } + public String getMethodNamespace() { return methodNamespace; } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/provider/JetSecurityProvider.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/provider/JetSecurityProvider.java index 7e817cb8b..1ac2232e3 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/provider/JetSecurityProvider.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jet/provider/JetSecurityProvider.java @@ -22,28 +22,29 @@ import java.util.logging.Logger; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smack.util.Objects; -import org.jivesoftware.smackx.jet.JingleEncryptionMethodManager; +import org.jivesoftware.smackx.jet.JetManager; import org.jivesoftware.smackx.jet.element.JetSecurityElement; import org.jivesoftware.smackx.jet.internal.JetSecurity; +import org.jivesoftware.smackx.jingle.provider.JingleContentSecurityProvider; import org.xmlpull.v1.XmlPullParser; /** * Provider for the Jingle security element for XEP-XXXX (Jingle Encrypted Transfers). */ -public class JetSecurityProvider extends ExtensionElementProvider { +public class JetSecurityProvider extends JingleContentSecurityProvider { private static final Logger LOGGER = Logger.getLogger(JetSecurityProvider.class.getName()); @Override public JetSecurityElement parse(XmlPullParser parser, int initialDepth) throws Exception { - String name = parser.getAttributeValue(JetSecurity.NAMESPACE, JetSecurityElement.ATTR_NAME); - String type = parser.getAttributeValue(JetSecurity.NAMESPACE, JetSecurityElement.ATTR_TYPE); + String name = parser.getAttributeValue("", JetSecurityElement.ATTR_NAME); + String type = parser.getAttributeValue("", JetSecurityElement.ATTR_TYPE); ExtensionElement child; Objects.requireNonNull(type); - ExtensionElementProvider encryptionElementProvider = - JingleEncryptionMethodManager.getSecurityKeyTransportProvider(type); + ExtensionElementProvider encryptionElementProvider = + JetManager.getEncryptionMethodProvider(type); if (encryptionElementProvider != null) { child = encryptionElementProvider.parse(parser); @@ -54,4 +55,9 @@ public class JetSecurityProvider extends ExtensionElementProvider INSTANCES = new WeakHashMap<>(); private final JingleManager jingleManager; @@ -65,6 +67,7 @@ public final class JingleFileTransferManager extends Manager implements JingleDe static { JingleManager.addJingleDescriptionAdapter(new JingleFileTransferAdapter()); + JingleManager.addJingleDescriptionProvider(new JingleFileTransferProvider()); } private JingleFileTransferManager(XMPPConnection connection) { @@ -72,7 +75,6 @@ public final class JingleFileTransferManager extends Manager implements JingleDe ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace()); jingleManager = JingleManager.getInstanceFor(connection); jingleManager.addJingleDescriptionManager(this); - JingleContentProviderManager.addJingleContentDescriptionProvider(getNamespace(), new JingleFileTransferProvider()); } public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) { @@ -127,6 +129,9 @@ public final class JingleFileTransferManager extends Manager implements JingleDe } public void notifyIncomingFileOfferListeners(JingleIncomingFileOffer offer) { + LOGGER.log(Level.INFO, "Incoming File transfer: [" + offer.getNamespace() + ", " + + offer.getParent().getTransport().getNamespace() + ", " + + offer.getParent().getSecurity().getNamespace()); for (IncomingFileOfferListener l : offerListeners) { l.onIncomingFileOffer(offer); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java index acb354e17..d84ca8cb9 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleManager.java @@ -130,30 +130,6 @@ public final class JingleManager extends Manager { return manager; } - public static void registerDescriptionProvider(JingleContentDescriptionProvider provider) { - descriptionProviders.put(provider.getNamespace(), provider); - } - - public static JingleContentDescriptionProvider getDescriptionProvider(String namespace) { - return descriptionProviders.get(namespace); - } - - public static void registerTransportProvider(JingleContentTransportProvider provider) { - transportProviders.put(provider.getNamespace(), provider); - } - - public static JingleContentTransportProvider getTransportProvider(String namespace) { - return transportProviders.get(namespace); - } - - public static void registerSecurityProvider(JingleContentSecurityProvider provider) { - securityProviders.put(provider.getNamespace(), provider); - } - - public static JingleContentSecurityProvider getSecurityProvider(String namespace) { - return securityProviders.get(namespace); - } - public static void addJingleDescriptionAdapter(JingleDescriptionAdapter adapter) { descriptionAdapters.put(adapter.getNamespace(), adapter); } @@ -178,6 +154,42 @@ public final class JingleManager extends Manager { return securityAdapters.get(namespace); } + public static void addJingleDescriptionProvider(JingleContentDescriptionProvider provider) { + descriptionProviders.put(provider.getNamespace(), provider); + } + + public static void removeJingleDescriptionProvider(String namespace) { + descriptionProviders.remove(namespace); + } + + public static JingleContentDescriptionProvider getJingleDescriptionProvider(String namespace) { + return descriptionProviders.get(namespace); + } + + public static void addJingleTransportProvider(JingleContentTransportProvider provider) { + transportProviders.put(provider.getNamespace(), provider); + } + + public static void removeJingleTransportProvider(String namespace) { + transportProviders.remove(namespace); + } + + public static JingleContentTransportProvider getJingleTransportProvider(String namespace) { + return transportProviders.get(namespace); + } + + public static void addJingleSecurityProvider(JingleContentSecurityProvider provider) { + securityProviders.put(provider.getNamespace(), provider); + } + + public static void removeJingleSecurityProvider(String namespace) { + securityProviders.remove(namespace); + } + + public static JingleContentSecurityProvider getJingleSecurityProvider(String namespace) { + return securityProviders.get(namespace); + } + public void addJingleDescriptionManager(JingleDescriptionManager manager) { descriptionManagers.put(manager.getNamespace(), manager); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleContent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleContent.java index 3635be548..f05bed425 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleContent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleContent.java @@ -306,6 +306,9 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal } public void onAccept(final XMPPConnection connection) { + if (security != null) { + security.prepare(connection, getParent().getPeer()); + } //Establish transport Async.go(new Runnable() { @Override diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleSecurity.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleSecurity.java index 5662a4b82..153cda5b2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleSecurity.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleSecurity.java @@ -16,12 +16,15 @@ */ package org.jivesoftware.smackx.jingle.components; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.jingle.callbacks.JingleSecurityCallback; import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement; import org.jivesoftware.smackx.jingle.element.JingleContentSecurityInfoElement; import org.jivesoftware.smackx.jingle.element.JingleElement; +import org.jxmpp.jid.FullJid; + /** * Class that represents a contents security component. */ @@ -46,4 +49,8 @@ public abstract class JingleSecurity { public abstract void decryptIncomingBytestream(BytestreamSession bytestreamSession, JingleSecurityCallback callback); public abstract void encryptOutgoingBytestream(BytestreamSession bytestreamSession, JingleSecurityCallback callbacks); + + public abstract String getNamespace(); + + public abstract void prepare(XMPPConnection connection, FullJid sender); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleContentProviderManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleContentProviderManager.java deleted file mode 100644 index 3c0939950..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleContentProviderManager.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright 2017 Florian Schmaus - * - * 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.jingle.provider; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public class JingleContentProviderManager { - - private static final Map> jingleContentDescriptionProviders = new ConcurrentHashMap<>(); - - private static final Map> jingleContentTransportProviders = new ConcurrentHashMap<>(); - - public static void removeJingleContentTransportProvider(String namespace) { - jingleContentTransportProviders.remove(namespace); - } - - public static void removeJingleContentDescriptionProvider(String namespace) { - jingleContentDescriptionProviders.remove(namespace); - } - - public static JingleContentDescriptionProvider addJingleContentDescriptionProvider(String namespace, - JingleContentDescriptionProvider provider) { - return jingleContentDescriptionProviders.put(namespace, provider); - } - - public static JingleContentDescriptionProvider getJingleContentDescriptionProvider(String namespace) { - return jingleContentDescriptionProviders.get(namespace); - } - - public static JingleContentTransportProvider addJingleContentTransportProvider(String namespace, - JingleContentTransportProvider provider) { - return jingleContentTransportProviders.put(namespace, provider); - } - - public static JingleContentTransportProvider getJingleContentTransportProvider(String namespace) { - return jingleContentTransportProviders.get(namespace); - } -} diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleProvider.java index 3e6daae1d..fbc537313 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/provider/JingleProvider.java @@ -20,9 +20,11 @@ import java.util.logging.Logger; import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.util.ParserUtils; +import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement; import org.jivesoftware.smackx.jingle.element.JingleContentElement; +import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement; import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement; import org.jivesoftware.smackx.jingle.element.JingleElement; import org.jivesoftware.smackx.jingle.element.JingleReasonElement; @@ -57,35 +59,35 @@ public class JingleProvider extends IQProvider { outerloop: while (true) { int eventType = parser.next(); switch (eventType) { - case XmlPullParser.START_TAG: - String tagName = parser.getName(); - switch (tagName) { - case JingleContentElement.ELEMENT: - JingleContentElement content = parseJingleContent(parser, parser.getDepth()); - builder.addJingleContent(content); - break; - case JingleReasonElement.ELEMENT: - parser.next(); - String reasonString = parser.getName(); - JingleReasonElement reason; - if (reasonString.equals("alternative-session")) { - parser.next(); - String sid = parser.nextText(); - reason = new JingleReasonElement.AlternativeSession(sid); - } else { - reason = new JingleReasonElement(JingleReasonElement.Reason.fromString(reasonString)); + case XmlPullParser.START_TAG: + String tagName = parser.getName(); + switch (tagName) { + case JingleContentElement.ELEMENT: + JingleContentElement content = parseJingleContent(parser, parser.getDepth()); + builder.addJingleContent(content); + break; + case JingleReasonElement.ELEMENT: + parser.next(); + String reasonString = parser.getName(); + JingleReasonElement reason; + if (reasonString.equals("alternative-session")) { + parser.next(); + String sid = parser.nextText(); + reason = new JingleReasonElement.AlternativeSession(sid); + } else { + reason = new JingleReasonElement(JingleReasonElement.Reason.fromString(reasonString)); + } + builder.setReason(reason); + break; + default: + LOGGER.severe("Unknown Jingle element: " + tagName); + break; } - builder.setReason(reason); break; - default: - LOGGER.severe("Unknown Jingle element: " + tagName); - break; - } - break; - case XmlPullParser.END_TAG: - if (parser.getDepth() == initialDepth) { - break outerloop; - } + case XmlPullParser.END_TAG: + if (parser.getDepth() == initialDepth) { + break outerloop; + } } } @@ -93,7 +95,7 @@ public class JingleProvider extends IQProvider { } public static JingleContentElement parseJingleContent(XmlPullParser parser, final int initialDepth) - throws Exception { + throws Exception { JingleContentElement.Builder builder = JingleContentElement.getBuilder(); String creatorString = parser.getAttributeValue("", JingleContentElement.CREATOR_ATTRIBUTE_NAME); @@ -115,39 +117,48 @@ public class JingleProvider extends IQProvider { outerloop: while (true) { int eventType = parser.next(); switch (eventType) { - case XmlPullParser.START_TAG: - String tagName = parser.getName(); - String namespace = parser.getNamespace(); - switch (tagName) { - case JingleContentDescriptionElement.ELEMENT: { - JingleContentDescriptionProvider provider = JingleContentProviderManager.getJingleContentDescriptionProvider(namespace); - if (provider == null) { - // TODO handle this case (DefaultExtensionElement wrapped in something?) - break; + case XmlPullParser.START_TAG: + String tagName = parser.getName(); + String namespace = parser.getNamespace(); + switch (tagName) { + case JingleContentDescriptionElement.ELEMENT: { + JingleContentDescriptionProvider provider = JingleManager.getJingleDescriptionProvider(namespace); + if (provider == null) { + // TODO handle this case (DefaultExtensionElement wrapped in something?) + break; + } + JingleContentDescriptionElement description = provider.parse(parser); + builder.setDescription(description); + break; + } + case JingleContentTransportElement.ELEMENT: { + JingleContentTransportProvider provider = JingleManager.getJingleTransportProvider(namespace); + if (provider == null) { + // TODO handle this case (DefaultExtensionElement wrapped in something?) + break; + } + JingleContentTransportElement transport = provider.parse(parser); + builder.setTransport(transport); + break; + } + case JingleContentSecurityElement.ELEMENT: { + JingleContentSecurityProvider provider = JingleManager.getJingleSecurityProvider(namespace); + if (provider == null) { + //TODO: handle this case (see above) + } + JingleContentSecurityElement security = provider.parse(parser); + builder.setSecurity(security); + break; + } + default: + LOGGER.severe("Unknown Jingle content element: " + tagName); + break; } - JingleContentDescriptionElement description = provider.parse(parser); - builder.setDescription(description); break; - } - case JingleContentTransportElement.ELEMENT: { - JingleContentTransportProvider provider = JingleContentProviderManager.getJingleContentTransportProvider(namespace); - if (provider == null) { - // TODO handle this case (DefaultExtensionElement wrapped in something?) - break; + case XmlPullParser.END_TAG: + if (parser.getDepth() == initialDepth) { + break outerloop; } - JingleContentTransportElement transport = provider.parse(parser); - builder.setTransport(transport); - break; - } - default: - LOGGER.severe("Unknown Jingle content element: " + tagName); - break; - } - break; - case XmlPullParser.END_TAG: - if (parser.getDepth() == initialDepth) { - break outerloop; - } } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java index 1d9efba66..1fb9f0e5a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_ibb/JingleIBBTransportManager.java @@ -25,7 +25,6 @@ import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.JingleTransportManager; import org.jivesoftware.smackx.jingle.components.JingleContent; import org.jivesoftware.smackx.jingle.components.JingleTransport; -import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager; import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider; /** @@ -39,6 +38,7 @@ public final class JingleIBBTransportManager extends Manager implements JingleTr static { JingleManager.addJingleTransportAdapter(new JingleIBBTransportAdapter()); + JingleManager.addJingleTransportProvider(new JingleIBBTransportProvider()); } private JingleIBBTransportManager(XMPPConnection connection) { @@ -46,7 +46,6 @@ public final class JingleIBBTransportManager extends Manager implements JingleTr ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace()); JingleManager jingleManager = JingleManager.getInstanceFor(connection); jingleManager.addJingleTransportManager(this); - JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleIBBTransportProvider()); } public static JingleIBBTransportManager getInstanceFor(XMPPConnection connection) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportManager.java index 64d7d0234..8c829c8dd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransportManager.java @@ -44,7 +44,6 @@ import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate; import org.jivesoftware.smackx.jingle.element.JingleAction; import org.jivesoftware.smackx.jingle.element.JingleContentElement; import org.jivesoftware.smackx.jingle.element.JingleElement; -import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportInfoElement; @@ -70,6 +69,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr static { JingleManager.addJingleTransportAdapter(new JingleS5BTransportAdapter()); + JingleManager.addJingleTransportProvider(new JingleS5BTransportProvider()); } private JingleS5BTransportManager(XMPPConnection connection) { @@ -77,7 +77,6 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace()); JingleManager jingleManager = JingleManager.getInstanceFor(connection); jingleManager.addJingleTransportManager(this); - JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleS5BTransportProvider()); connection.addConnectionListener(connectionListener); } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java index 698a2cc85..92bf2acf8 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/jingle/JingleContentProviderManagerTest.java @@ -20,7 +20,6 @@ import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertNull; import org.jivesoftware.smack.test.util.SmackTestSuite; -import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager; import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport; import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider; import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransport; @@ -35,19 +34,19 @@ public class JingleContentProviderManagerTest extends SmackTestSuite { @Test public void transportProviderTest() { - JingleContentProviderManager.removeJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1); - JingleContentProviderManager.removeJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1); + JingleManager.removeJingleTransportProvider(JingleIBBTransport.NAMESPACE_V1); + JingleManager.removeJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1); - assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1)); - assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1)); + assertNull(JingleManager.getJingleTransportProvider(JingleIBBTransport.NAMESPACE_V1)); + assertNull(JingleManager.getJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1)); JingleIBBTransportProvider ibbProvider = new JingleIBBTransportProvider(); - JingleContentProviderManager.addJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1, ibbProvider); - assertEquals(ibbProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleIBBTransport.NAMESPACE_V1)); + JingleManager.addJingleTransportProvider(ibbProvider); + assertEquals(ibbProvider, JingleManager.getJingleTransportProvider(JingleIBBTransport.NAMESPACE_V1)); - assertNull(JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1)); + assertNull(JingleManager.getJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1)); JingleS5BTransportProvider s5bProvider = new JingleS5BTransportProvider(); - JingleContentProviderManager.addJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1, s5bProvider); - assertEquals(s5bProvider, JingleContentProviderManager.getJingleContentTransportProvider(JingleS5BTransport.NAMESPACE_V1)); + JingleManager.addJingleTransportProvider(s5bProvider); + assertEquals(s5bProvider, JingleManager.getJingleTransportProvider(JingleS5BTransport.NAMESPACE_V1)); } } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/JetTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/JetTest.java index 964fd9afc..37e718008 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/JetTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/JetTest.java @@ -1,3 +1,19 @@ +/** + * + * Copyright 2017 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.jet; import static org.jivesoftware.smackx.jft.JingleFileTransferTest.prepareNewTestFile; @@ -22,6 +38,8 @@ import org.jivesoftware.smackx.omemo.AbstractOmemoIntegrationTest; import org.jivesoftware.smackx.omemo.OmemoManager; import org.jivesoftware.smackx.omemo.OmemoService; import org.jivesoftware.smackx.omemo.OmemoStore; +import org.jivesoftware.smackx.omemo.provider.OmemoVAxolotlProvider; +import org.jivesoftware.smackx.omemo.util.OmemoConstants; import org.igniterealtime.smack.inttest.SmackIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; @@ -62,6 +80,7 @@ public class JetTest extends AbstractOmemoIntegrationTest { jb = JetManager.getInstanceFor(conTwo); ia = JingleIBBTransportManager.getInstanceFor(conOne); ib = JingleIBBTransportManager.getInstanceFor(conTwo); + JetManager.registerEncryptionMethodProvider(OmemoConstants.OMEMO_NAMESPACE_V_AXOLOTL, new OmemoVAxolotlProvider()); } @SmackIntegrationTest diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/package-info.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/package-info.java new file mode 100644 index 000000000..804d14a10 --- /dev/null +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/jet/package-info.java @@ -0,0 +1,21 @@ +/** + * + * Copyright 2017 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. + */ + +/** + * Tests for XEP-XXXX - Jingle Encrypted Transfers. + */ +package org.jivesoftware.smackx.jet;