Search in sources :

Example 1 with OmemoVerifiedIceUdpTransportInfo

use of eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo in project Conversations by siacs.

the class AxolotlService method encrypt.

private ListenableFuture<OmemoVerifiedPayload<OmemoVerifiedRtpContentMap>> encrypt(final RtpContentMap rtpContentMap, final XmppAxolotlSession session) {
    if (Config.REQUIRE_RTP_VERIFICATION) {
        requireVerification(session);
    }
    final ImmutableMap.Builder<String, RtpContentMap.DescriptionTransport> descriptionTransportBuilder = new ImmutableMap.Builder<>();
    final OmemoVerification omemoVerification = new OmemoVerification();
    omemoVerification.setDeviceId(session.getRemoteAddress().getDeviceId());
    omemoVerification.setSessionFingerprint(session.getFingerprint());
    for (final Map.Entry<String, RtpContentMap.DescriptionTransport> content : rtpContentMap.contents.entrySet()) {
        final RtpContentMap.DescriptionTransport descriptionTransport = content.getValue();
        final OmemoVerifiedIceUdpTransportInfo encryptedTransportInfo;
        try {
            encryptedTransportInfo = encrypt(descriptionTransport.transport, session);
        } catch (final CryptoFailedException e) {
            return Futures.immediateFailedFuture(e);
        }
        descriptionTransportBuilder.put(content.getKey(), new RtpContentMap.DescriptionTransport(descriptionTransport.description, encryptedTransportInfo));
    }
    return Futures.immediateFuture(new OmemoVerifiedPayload<>(omemoVerification, new OmemoVerifiedRtpContentMap(rtpContentMap.group, descriptionTransportBuilder.build())));
}
Also used : OmemoVerification(eu.siacs.conversations.xmpp.jingle.OmemoVerification) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) OmemoVerifiedIceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo) OmemoVerifiedRtpContentMap(eu.siacs.conversations.xmpp.jingle.OmemoVerifiedRtpContentMap) RtpContentMap(eu.siacs.conversations.xmpp.jingle.RtpContentMap) ImmutableMap(com.google.common.collect.ImmutableMap) OmemoVerifiedRtpContentMap(eu.siacs.conversations.xmpp.jingle.OmemoVerifiedRtpContentMap) OmemoVerifiedRtpContentMap(eu.siacs.conversations.xmpp.jingle.OmemoVerifiedRtpContentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RtpContentMap(eu.siacs.conversations.xmpp.jingle.RtpContentMap)

Example 2 with OmemoVerifiedIceUdpTransportInfo

use of eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo in project Conversations by siacs.

the class AxolotlService method decrypt.

private OmemoVerifiedPayload<IceUdpTransportInfo> decrypt(final OmemoVerifiedIceUdpTransportInfo verifiedIceUdpTransportInfo, final Jid from, ImmutableList.Builder<ListenableFuture<XmppAxolotlSession>> pepVerificationFutures) throws CryptoFailedException {
    final IceUdpTransportInfo transportInfo = new IceUdpTransportInfo();
    transportInfo.setAttributes(verifiedIceUdpTransportInfo.getAttributes());
    final OmemoVerification omemoVerification = new OmemoVerification();
    for (final Element child : verifiedIceUdpTransportInfo.getChildren()) {
        if ("fingerprint".equals(child.getName()) && Namespace.OMEMO_DTLS_SRTP_VERIFICATION.equals(child.getNamespace())) {
            final Element fingerprint = new Element("fingerprint", Namespace.JINGLE_APPS_DTLS);
            fingerprint.setAttribute("setup", child.getAttribute("setup"));
            fingerprint.setAttribute("hash", child.getAttribute("hash"));
            final Element encrypted = child.findChildEnsureSingle(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
            final XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, from.asBareJid());
            final XmppAxolotlSession session = getReceivingSession(xmppAxolotlMessage);
            final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintext = xmppAxolotlMessage.decrypt(session, getOwnDeviceId());
            final Integer preKeyId = session.getPreKeyIdAndReset();
            if (preKeyId != null) {
                postponedSessions.add(session);
            }
            if (session.isFresh()) {
                pepVerificationFutures.add(putFreshSession(session));
            } else if (Config.REQUIRE_RTP_VERIFICATION) {
                pepVerificationFutures.add(Futures.immediateFuture(session));
            }
            fingerprint.setContent(plaintext.getPlaintext());
            omemoVerification.setDeviceId(session.getRemoteAddress().getDeviceId());
            omemoVerification.setSessionFingerprint(plaintext.getFingerprint());
            transportInfo.addChild(fingerprint);
        } else {
            transportInfo.addChild(child);
        }
    }
    return new OmemoVerifiedPayload<>(omemoVerification, transportInfo);
}
Also used : OmemoVerification(eu.siacs.conversations.xmpp.jingle.OmemoVerification) IceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.IceUdpTransportInfo) OmemoVerifiedIceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo) Element(eu.siacs.conversations.xml.Element)

Example 3 with OmemoVerifiedIceUdpTransportInfo

use of eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo in project Conversations by siacs.

the class AxolotlService method encrypt.

private OmemoVerifiedIceUdpTransportInfo encrypt(final IceUdpTransportInfo element, final XmppAxolotlSession session) throws CryptoFailedException {
    final OmemoVerifiedIceUdpTransportInfo transportInfo = new OmemoVerifiedIceUdpTransportInfo();
    transportInfo.setAttributes(element.getAttributes());
    for (final Element child : element.getChildren()) {
        if ("fingerprint".equals(child.getName()) && Namespace.JINGLE_APPS_DTLS.equals(child.getNamespace())) {
            final Element fingerprint = new Element("fingerprint", Namespace.OMEMO_DTLS_SRTP_VERIFICATION);
            fingerprint.setAttribute("setup", child.getAttribute("setup"));
            fingerprint.setAttribute("hash", child.getAttribute("hash"));
            final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId());
            final String content = child.getContent();
            axolotlMessage.encrypt(content);
            axolotlMessage.addDevice(session, true);
            fingerprint.addChild(axolotlMessage.toElement());
            transportInfo.addChild(fingerprint);
        } else {
            transportInfo.addChild(child);
        }
    }
    return transportInfo;
}
Also used : Element(eu.siacs.conversations.xml.Element) OmemoVerifiedIceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo)

Example 4 with OmemoVerifiedIceUdpTransportInfo

use of eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo in project Conversations by siacs.

the class AxolotlService method decrypt.

public ListenableFuture<OmemoVerifiedPayload<RtpContentMap>> decrypt(OmemoVerifiedRtpContentMap omemoVerifiedRtpContentMap, final Jid from) {
    final ImmutableMap.Builder<String, RtpContentMap.DescriptionTransport> descriptionTransportBuilder = new ImmutableMap.Builder<>();
    final OmemoVerification omemoVerification = new OmemoVerification();
    final ImmutableList.Builder<ListenableFuture<XmppAxolotlSession>> pepVerificationFutures = new ImmutableList.Builder<>();
    for (final Map.Entry<String, RtpContentMap.DescriptionTransport> content : omemoVerifiedRtpContentMap.contents.entrySet()) {
        final RtpContentMap.DescriptionTransport descriptionTransport = content.getValue();
        final OmemoVerifiedPayload<IceUdpTransportInfo> decryptedTransport;
        try {
            decryptedTransport = decrypt((OmemoVerifiedIceUdpTransportInfo) descriptionTransport.transport, from, pepVerificationFutures);
        } catch (CryptoFailedException e) {
            return Futures.immediateFailedFuture(e);
        }
        omemoVerification.setOrEnsureEqual(decryptedTransport);
        descriptionTransportBuilder.put(content.getKey(), new RtpContentMap.DescriptionTransport(descriptionTransport.description, decryptedTransport.payload));
    }
    processPostponed();
    final ImmutableList<ListenableFuture<XmppAxolotlSession>> sessionFutures = pepVerificationFutures.build();
    return Futures.transform(Futures.allAsList(sessionFutures), sessions -> {
        if (Config.REQUIRE_RTP_VERIFICATION) {
            for (XmppAxolotlSession session : sessions) {
                requireVerification(session);
            }
        }
        return new OmemoVerifiedPayload<>(omemoVerification, new RtpContentMap(omemoVerifiedRtpContentMap.group, descriptionTransportBuilder.build()));
    }, MoreExecutors.directExecutor());
}
Also used : OmemoVerification(eu.siacs.conversations.xmpp.jingle.OmemoVerification) IceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.IceUdpTransportInfo) OmemoVerifiedIceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo) ImmutableList(com.google.common.collect.ImmutableList) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) OmemoVerifiedIceUdpTransportInfo(eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo) OmemoVerifiedRtpContentMap(eu.siacs.conversations.xmpp.jingle.OmemoVerifiedRtpContentMap) RtpContentMap(eu.siacs.conversations.xmpp.jingle.RtpContentMap) ImmutableMap(com.google.common.collect.ImmutableMap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) OmemoVerifiedRtpContentMap(eu.siacs.conversations.xmpp.jingle.OmemoVerifiedRtpContentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RtpContentMap(eu.siacs.conversations.xmpp.jingle.RtpContentMap)

Aggregations

OmemoVerifiedIceUdpTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.OmemoVerifiedIceUdpTransportInfo)4 OmemoVerification (eu.siacs.conversations.xmpp.jingle.OmemoVerification)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Element (eu.siacs.conversations.xml.Element)2 OmemoVerifiedRtpContentMap (eu.siacs.conversations.xmpp.jingle.OmemoVerifiedRtpContentMap)2 RtpContentMap (eu.siacs.conversations.xmpp.jingle.RtpContentMap)2 IceUdpTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.IceUdpTransportInfo)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1