throw exception when unable to encrypt

This commit is contained in:
Daniel Gultsch 2021-03-03 08:22:21 +01:00
parent 8a6430ae29
commit e4b2bb4a42
2 changed files with 8 additions and 8 deletions

View file

@ -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(); final OmemoVerifiedIceUdpTransportInfo transportInfo = new OmemoVerifiedIceUdpTransportInfo();
transportInfo.setAttributes(element.getAttributes()); transportInfo.setAttributes(element.getAttributes());
for (final Element child : element.getChildren()) { for (final Element child : element.getChildren()) {
@ -1231,6 +1231,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
public OmemoVerifiedPayload<OmemoVerifiedRtpContentMap> encrypt(final RtpContentMap rtpContentMap, final Jid jid, final int deviceId) throws CryptoFailedException { public OmemoVerifiedPayload<OmemoVerifiedRtpContentMap> encrypt(final RtpContentMap rtpContentMap, final Jid jid, final int deviceId) throws CryptoFailedException {
final SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId); final SignalProtocolAddress address = new SignalProtocolAddress(jid.asBareJid().toString(), deviceId);
final XmppAxolotlSession session = sessions.get(address); final XmppAxolotlSession session = sessions.get(address);
if (session == null) {
throw new CryptoFailedException(String.format("No session found for %d", deviceId));
}
final ImmutableMap.Builder<String, RtpContentMap.DescriptionTransport> descriptionTransportBuilder = new ImmutableMap.Builder<>(); final ImmutableMap.Builder<String, RtpContentMap.DescriptionTransport> descriptionTransportBuilder = new ImmutableMap.Builder<>();
final OmemoVerification omemoVerification = new OmemoVerification(); final OmemoVerification omemoVerification = new OmemoVerification();
omemoVerification.setDeviceId(deviceId); omemoVerification.setDeviceId(deviceId);
@ -1267,7 +1270,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
); );
} }
public OmemoVerifiedPayload<IceUdpTransportInfo> decrypt(final OmemoVerifiedIceUdpTransportInfo verifiedIceUdpTransportInfo, final Jid from) throws CryptoFailedException { private OmemoVerifiedPayload<IceUdpTransportInfo> decrypt(final OmemoVerifiedIceUdpTransportInfo verifiedIceUdpTransportInfo, final Jid from) throws CryptoFailedException {
final IceUdpTransportInfo transportInfo = new IceUdpTransportInfo(); final IceUdpTransportInfo transportInfo = new IceUdpTransportInfo();
transportInfo.setAttributes(verifiedIceUdpTransportInfo.getAttributes()); transportInfo.setAttributes(verifiedIceUdpTransportInfo.getAttributes());
final OmemoVerification omemoVerification = new OmemoVerification(); final OmemoVerification omemoVerification = new OmemoVerification();

View file

@ -494,17 +494,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
this.responderRtpContentMap = rtpContentMap; this.responderRtpContentMap = rtpContentMap;
this.transitionOrThrow(State.SESSION_ACCEPTED); this.transitionOrThrow(State.SESSION_ACCEPTED);
final RtpContentMap outgoingContentMap; final RtpContentMap outgoingContentMap;
//TODO do on different thread
if (this.omemoVerification.hasDeviceId()) { if (this.omemoVerification.hasDeviceId()) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": encrypting session-accept"); final AxolotlService.OmemoVerifiedPayload<OmemoVerifiedRtpContentMap> verifiedPayload;
try { try {
final AxolotlService.OmemoVerifiedPayload<OmemoVerifiedRtpContentMap> verifiedPayload = id.account.getAxolotlService().encrypt(rtpContentMap, id.with, omemoVerification.getDeviceId()); verifiedPayload = id.account.getAxolotlService().encrypt(rtpContentMap, id.with, omemoVerification.getDeviceId());
outgoingContentMap = verifiedPayload.getPayload(); outgoingContentMap = verifiedPayload.getPayload();
this.omemoVerification.setOrEnsureEqual(verifiedPayload); this.omemoVerification.setOrEnsureEqual(verifiedPayload);
} catch (final Exception e) { } catch (final Exception e) {
//TODO fail application if something goes wrong here throw new SecurityException("Unable to verify DTLS Fingerprint with OMEMO", e);
Log.d(Config.LOGTAG, "unable to encrypt", e);
return;
} }
} else { } else {
outgoingContentMap = rtpContentMap; outgoingContentMap = rtpContentMap;