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();
transportInfo.setAttributes(element.getAttributes());
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 {
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<String, RtpContentMap.DescriptionTransport> descriptionTransportBuilder = new ImmutableMap.Builder<>();
final OmemoVerification omemoVerification = new OmemoVerification();
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();
transportInfo.setAttributes(verifiedIceUdpTransportInfo.getAttributes());
final OmemoVerification omemoVerification = new OmemoVerification();

View file

@ -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<OmemoVerifiedRtpContentMap> verifiedPayload;
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();
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;