From e4b2bb4a4209d7a227eb222bcdab1526c69bfad5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 3 Mar 2021 08:22:21 +0100 Subject: [PATCH] throw exception when unable to encrypt --- .../conversations/crypto/axolotl/AxolotlService.java | 7 +++++-- .../conversations/xmpp/jingle/JingleRtpConnection.java | 9 +++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 57b0a0d43..ce8c3a381 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -1206,7 +1206,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { }); } - public OmemoVerifiedIceUdpTransportInfo encrypt(final IceUdpTransportInfo element, final XmppAxolotlSession session) throws CryptoFailedException { + 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()) { @@ -1231,6 +1231,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { public OmemoVerifiedPayload encrypt(final RtpContentMap rtpContentMap, final Jid jid, final int deviceId) throws CryptoFailedException { final SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId); final XmppAxolotlSession session = sessions.get(address); + if (session == null) { + throw new CryptoFailedException(String.format("No session found for %d", deviceId)); + } final ImmutableMap.Builder descriptionTransportBuilder = new ImmutableMap.Builder<>(); final OmemoVerification omemoVerification = new OmemoVerification(); omemoVerification.setDeviceId(deviceId); @@ -1267,7 +1270,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded { ); } - public OmemoVerifiedPayload decrypt(final OmemoVerifiedIceUdpTransportInfo verifiedIceUdpTransportInfo, final Jid from) throws CryptoFailedException { + private OmemoVerifiedPayload decrypt(final OmemoVerifiedIceUdpTransportInfo verifiedIceUdpTransportInfo, final Jid from) throws CryptoFailedException { final IceUdpTransportInfo transportInfo = new IceUdpTransportInfo(); transportInfo.setAttributes(verifiedIceUdpTransportInfo.getAttributes()); final OmemoVerification omemoVerification = new OmemoVerification(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 5d00f0c00..68e03f403 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -494,17 +494,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web this.responderRtpContentMap = rtpContentMap; this.transitionOrThrow(State.SESSION_ACCEPTED); final RtpContentMap outgoingContentMap; - //TODO do on different thread if (this.omemoVerification.hasDeviceId()) { - Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": encrypting session-accept"); + final AxolotlService.OmemoVerifiedPayload verifiedPayload; try { - final AxolotlService.OmemoVerifiedPayload verifiedPayload = id.account.getAxolotlService().encrypt(rtpContentMap, id.with, omemoVerification.getDeviceId()); + verifiedPayload = id.account.getAxolotlService().encrypt(rtpContentMap, id.with, omemoVerification.getDeviceId()); outgoingContentMap = verifiedPayload.getPayload(); this.omemoVerification.setOrEnsureEqual(verifiedPayload); } catch (final Exception e) { - //TODO fail application if something goes wrong here - Log.d(Config.LOGTAG, "unable to encrypt", e); - return; + throw new SecurityException("Unable to verify DTLS Fingerprint with OMEMO", e); } } else { outgoingContentMap = rtpContentMap;