fix JET spec compliance
This commit is contained in:
parent
93b5a099b0
commit
2833fc833c
|
@ -209,8 +209,12 @@ public class JingleFileTransferConnection extends AbstractJingleConnection
|
||||||
this.transportSecurity =
|
this.transportSecurity =
|
||||||
new TransportSecurity(
|
new TransportSecurity(
|
||||||
xmppAxolotlMessage.getInnerKey(), xmppAxolotlMessage.getIV());
|
xmppAxolotlMessage.getInnerKey(), xmppAxolotlMessage.getIV());
|
||||||
jinglePacket.setSecurity(
|
final var contents = jinglePacket.getJingleContents();
|
||||||
Iterables.getOnlyElement(contentMap.contents.keySet()), xmppAxolotlMessage);
|
final var rawContent =
|
||||||
|
contents.get(Iterables.getOnlyElement(contentMap.contents.keySet()));
|
||||||
|
if (rawContent != null) {
|
||||||
|
rawContent.setSecurity(xmppAxolotlMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jinglePacket.setTo(id.with);
|
jinglePacket.setTo(id.with);
|
||||||
xmppConnectionService.sendIqPacket(
|
xmppConnectionService.sendIqPacket(
|
||||||
|
@ -327,8 +331,10 @@ public class JingleFileTransferConnection extends AbstractJingleConnection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
|
final XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
|
||||||
|
final var contents = jinglePacket.getJingleContents();
|
||||||
|
final var rawContent = contents.get(Iterables.getOnlyElement(contentMap.contents.keySet()));
|
||||||
final var security =
|
final var security =
|
||||||
jinglePacket.getSecurity(Iterables.getOnlyElement(contentMap.contents.keySet()));
|
rawContent == null ? null : rawContent.getSecurity(jinglePacket.getFrom());
|
||||||
if (security != null) {
|
if (security != null) {
|
||||||
Log.d(Config.LOGTAG, "found security element!");
|
Log.d(Config.LOGTAG, "found security element!");
|
||||||
keyTransportMessage =
|
keyTransportMessage =
|
||||||
|
@ -349,7 +355,6 @@ public class JingleFileTransferConnection extends AbstractJingleConnection
|
||||||
|
|
||||||
if (transition(State.SESSION_INITIALIZED, () -> setRemoteContentMap(contentMap))) {
|
if (transition(State.SESSION_INITIALIZED, () -> setRemoteContentMap(contentMap))) {
|
||||||
respondOk(jinglePacket);
|
respondOk(jinglePacket);
|
||||||
Log.d(Config.LOGTAG, jinglePacket.toString());
|
|
||||||
Log.d(
|
Log.d(
|
||||||
Config.LOGTAG,
|
Config.LOGTAG,
|
||||||
"got file offer " + file + " jet=" + Objects.nonNull(keyTransportMessage));
|
"got file offer " + file + " jet=" + Objects.nonNull(keyTransportMessage));
|
||||||
|
|
|
@ -9,8 +9,11 @@ import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
||||||
|
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xml.Namespace;
|
import eu.siacs.conversations.xml.Namespace;
|
||||||
|
import eu.siacs.conversations.xmpp.Jid;
|
||||||
import eu.siacs.conversations.xmpp.jingle.SessionDescription;
|
import eu.siacs.conversations.xmpp.jingle.SessionDescription;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -102,6 +105,37 @@ public class Content extends Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSecurity(final XmppAxolotlMessage xmppAxolotlMessage) {
|
||||||
|
final String contentName = this.getContentName();
|
||||||
|
final Element security = new Element("security", Namespace.JINGLE_ENCRYPTED_TRANSPORT);
|
||||||
|
security.setAttribute("name", contentName);
|
||||||
|
security.setAttribute("cipher", "urn:xmpp:ciphers:aes-128-gcm-nopadding");
|
||||||
|
security.setAttribute("type", AxolotlService.PEP_PREFIX);
|
||||||
|
security.addChild(xmppAxolotlMessage.toElement());
|
||||||
|
this.addChild(security);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XmppAxolotlMessage getSecurity(final Jid from) {
|
||||||
|
final String contentName = this.getContentName();
|
||||||
|
for (final Element child : this.children) {
|
||||||
|
if ("security".equals(child.getName())
|
||||||
|
&& Namespace.JINGLE_ENCRYPTED_TRANSPORT.equals(child.getNamespace())) {
|
||||||
|
final String name = child.getAttribute("name");
|
||||||
|
final String type = child.getAttribute("type");
|
||||||
|
final String cipher = child.getAttribute("cipher");
|
||||||
|
if (contentName.equals(name)
|
||||||
|
&& AxolotlService.PEP_PREFIX.equals(type)
|
||||||
|
&& "urn:xmpp:ciphers:aes-128-gcm-nopadding".equals(cipher)) {
|
||||||
|
final var encrypted = child.findChild("encrypted", AxolotlService.PEP_PREFIX);
|
||||||
|
if (encrypted != null) {
|
||||||
|
return XmppAxolotlMessage.fromElement(encrypted, from.asBareJid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTransport(GenericTransportInfo transportInfo) {
|
public void setTransport(GenericTransportInfo transportInfo) {
|
||||||
this.addChild(transportInfo);
|
this.addChild(transportInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.siacs.conversations.xmpp.jingle.stanzas;
|
package eu.siacs.conversations.xmpp.jingle.stanzas;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
|
@ -9,9 +7,6 @@ import com.google.common.base.Preconditions;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
|
||||||
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
|
||||||
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
|
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xml.Namespace;
|
import eu.siacs.conversations.xml.Namespace;
|
||||||
import eu.siacs.conversations.xmpp.Jid;
|
import eu.siacs.conversations.xmpp.Jid;
|
||||||
|
@ -121,39 +116,6 @@ public class JinglePacket extends IqPacket {
|
||||||
jingle.addChild(child);
|
jingle.addChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSecurity(final String name, final XmppAxolotlMessage xmppAxolotlMessage) {
|
|
||||||
final Element security = new Element("security", Namespace.JINGLE_ENCRYPTED_TRANSPORT);
|
|
||||||
security.setAttribute("name", name);
|
|
||||||
security.setAttribute("cipher", "urn:xmpp:ciphers:aes-128-gcm-nopadding");
|
|
||||||
security.setAttribute("type", AxolotlService.PEP_PREFIX);
|
|
||||||
security.addChild(xmppAxolotlMessage.toElement());
|
|
||||||
addJingleChild(security);
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmppAxolotlMessage getSecurity(final String nameNeedle) {
|
|
||||||
final Element jingle = findChild("jingle", Namespace.JINGLE);
|
|
||||||
if (jingle == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (final Element child : jingle.getChildren()) {
|
|
||||||
if ("security".equals(child.getName())
|
|
||||||
&& Namespace.JINGLE_ENCRYPTED_TRANSPORT.equals(child.getNamespace())) {
|
|
||||||
final String name = child.getAttribute("name");
|
|
||||||
final String type = child.getAttribute("type");
|
|
||||||
final String cipher = child.getAttribute("cipher");
|
|
||||||
if (nameNeedle.equals(name)
|
|
||||||
&& AxolotlService.PEP_PREFIX.equals(type)
|
|
||||||
&& "urn:xmpp:ciphers:aes-128-gcm-nopadding".equals(cipher)) {
|
|
||||||
final var encrypted = child.findChild("encrypted", AxolotlService.PEP_PREFIX);
|
|
||||||
if (encrypted != null) {
|
|
||||||
return XmppAxolotlMessage.fromElement(encrypted, getFrom().asBareJid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSessionId() {
|
public String getSessionId() {
|
||||||
return findChild("jingle", Namespace.JINGLE).getAttribute("sid");
|
return findChild("jingle", Namespace.JINGLE).getAttribute("sid");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue