mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 10:09:38 +02:00
Work on Jingle Encrypted Transfers
This commit is contained in:
parent
1dbdafe28c
commit
c82b25ea09
11 changed files with 210 additions and 96 deletions
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
*
|
||||
* 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.jingle.callbacks;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
|
||||
/**
|
||||
* Callback used to signal success/failure of Jingle Security components.
|
||||
*/
|
||||
public interface JingleSecurityCallback {
|
||||
|
||||
void onSecurityReady(BytestreamSession bytestreamSession);
|
||||
|
||||
void onSecurityFailed(Exception e);
|
||||
}
|
|
@ -37,6 +37,7 @@ import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
|||
import org.jivesoftware.smackx.jingle.adapter.JingleDescriptionAdapter;
|
||||
import org.jivesoftware.smackx.jingle.adapter.JingleSecurityAdapter;
|
||||
import org.jivesoftware.smackx.jingle.adapter.JingleTransportAdapter;
|
||||
import org.jivesoftware.smackx.jingle.callbacks.JingleSecurityCallback;
|
||||
import org.jivesoftware.smackx.jingle.callbacks.JingleTransportCallback;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
|
@ -48,7 +49,7 @@ import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
|||
/**
|
||||
* Internal class that holds the state of a content in a modifiable form.
|
||||
*/
|
||||
public class JingleContent implements JingleTransportCallback {
|
||||
public class JingleContent implements JingleTransportCallback, JingleSecurityCallback {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleContent.class.getName());
|
||||
|
||||
|
@ -131,7 +132,7 @@ public class JingleContent implements JingleTransportCallback {
|
|||
return new JingleContent(description, transport, security, content.getName(), content.getDisposition(), content.getCreator(), content.getSenders());
|
||||
}
|
||||
|
||||
/* HANDLEXYZ */
|
||||
/* HANDLE_XYZ */
|
||||
|
||||
public IQ handleJingleRequest(JingleElement request, XMPPConnection connection) {
|
||||
switch (request.getAction()) {
|
||||
|
@ -334,7 +335,17 @@ public class JingleContent implements JingleTransportCallback {
|
|||
throw new AssertionError("bytestreamSession MUST NOT be null at this point.");
|
||||
}
|
||||
|
||||
description.onTransportReady(bytestreamSession);
|
||||
if (security != null) {
|
||||
if (isReceiving()) {
|
||||
LOGGER.log(Level.INFO, "Decrypt incoming Bytestream.");
|
||||
getSecurity().decryptIncomingBytestream(bytestreamSession, this);
|
||||
} else if (isSending()) {
|
||||
LOGGER.log(Level.INFO, "Encrypt outgoing Bytestream.");
|
||||
getSecurity().encryptIncomingBytestream(bytestreamSession, this);
|
||||
}
|
||||
} else {
|
||||
description.onBytestreamReady(bytestreamSession);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -352,6 +363,16 @@ public class JingleContent implements JingleTransportCallback {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSecurityReady(BytestreamSession bytestreamSession) {
|
||||
getDescription().onBytestreamReady(bytestreamSession);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSecurityFailed(Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Security failed: " + e, e);
|
||||
}
|
||||
|
||||
private void replaceTransport(Set<String> blacklist, XMPPConnection connection)
|
||||
throws SmackException.NotConnectedException, InterruptedException,
|
||||
XMPPException.XMPPErrorException, SmackException.NoResponseException {
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class JingleDescription<D extends JingleContentDescriptionElemen
|
|||
return parent;
|
||||
}
|
||||
|
||||
public abstract void onTransportReady(BytestreamSession bytestreamSession);
|
||||
public abstract void onBytestreamReady(BytestreamSession bytestreamSession);
|
||||
|
||||
public abstract String getNamespace();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle.components;
|
||||
|
||||
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;
|
||||
|
@ -40,4 +42,8 @@ public abstract class JingleSecurity<D extends JingleContentSecurityElement> {
|
|||
public JingleContent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public abstract void decryptIncomingBytestream(BytestreamSession bytestreamSession, JingleSecurityCallback callback);
|
||||
|
||||
public abstract void encryptIncomingBytestream(BytestreamSession bytestreamSession, JingleSecurityCallback callbacks);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue