mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 19:47:58 +01:00
JET is close to working
This commit is contained in:
parent
177ed6ea0d
commit
d2f979ed15
17 changed files with 242 additions and 208 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<XMPPConnection, JetManager> INSTANCES = new WeakHashMap<>();
|
||||
private static final Map<String, JingleEncryptionMethod> encryptionMethods = new HashMap<>();
|
||||
private static final HashMap<String, JingleEncryptionMethod> encryptionMethods = new HashMap<>();
|
||||
private static final HashMap<String, ExtensionElementProvider<?>> 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;
|
||||
|
|
|
@ -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<String, ExtensionElementProvider<ExtensionElement>> securityKeyTransportProviders = new HashMap<>();
|
||||
|
||||
private JingleEncryptionMethodManager() {
|
||||
// $(man true)
|
||||
}
|
||||
|
||||
public static void registerSecurityKeyTransportProvider(String namespace, ExtensionElementProvider<ExtensionElement> provider) {
|
||||
securityKeyTransportProviders.put(namespace, provider);
|
||||
}
|
||||
|
||||
public static ExtensionElementProvider<ExtensionElement> getSecurityKeyTransportProvider(String namespace) {
|
||||
return securityKeyTransportProviders.get(namespace);
|
||||
}
|
||||
}
|
|
@ -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<JetSecurityElement> {
|
||||
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<JetSecurityElement> {
|
|||
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<JetSecurityElement> {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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<JetSecurityElement> {
|
||||
public class JetSecurityProvider extends JingleContentSecurityProvider<JetSecurityElement> {
|
||||
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<ExtensionElement> 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<JetSecurityEle
|
|||
|
||||
return new JetSecurityElement(name, child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JetSecurity.NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
|
@ -45,7 +47,6 @@ import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
|||
import org.jivesoftware.smackx.jingle.components.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.util.Role;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
@ -54,6 +55,7 @@ import org.jxmpp.jid.FullJid;
|
|||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public final class JingleFileTransferManager extends Manager implements JingleDescriptionManager {
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManager.class.getName());
|
||||
|
||||
private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<D extends JingleContentSecurityElement> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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<String, JingleContentDescriptionProvider<?>> jingleContentDescriptionProviders = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<String, JingleContentTransportProvider<?>> 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);
|
||||
}
|
||||
}
|
|
@ -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<JingleElement> {
|
|||
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<JingleElement> {
|
|||
}
|
||||
|
||||
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<JingleElement> {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
Loading…
Reference in a new issue