make session completion work with untrusted devices as well

This commit is contained in:
Daniel Gultsch 2018-05-09 09:24:31 +02:00
parent ffe610f961
commit 18a8a6e5ac
3 changed files with 11 additions and 7 deletions

View file

@ -1437,7 +1437,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
private void completeSession(XmppAxolotlSession session) { private void completeSession(XmppAxolotlSession session) {
final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId()); final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId());
axolotlMessage.addDevice(session); axolotlMessage.addDevice(session, true);
try { try {
Jid jid = Jid.of(session.getRemoteAddress().getName()); Jid jid = Jid.of(session.getRemoteAddress().getName());
MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateKeyTransportMessage(jid, axolotlMessage); MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateKeyTransportMessage(jid, axolotlMessage);

View file

@ -218,16 +218,20 @@ public class XmppAxolotlMessage {
return this.from; return this.from;
} }
public int getSenderDeviceId() { int getSenderDeviceId() {
return sourceDeviceId; return sourceDeviceId;
} }
public void addDevice(XmppAxolotlSession session) { void addDevice(XmppAxolotlSession session) {
addDevice(session, false);
}
void addDevice(XmppAxolotlSession session, boolean ignoreSessionTrust) {
XmppAxolotlSession.AxolotlKey key; XmppAxolotlSession.AxolotlKey key;
if (authtagPlusInnerKey != null) { if (authtagPlusInnerKey != null) {
key = session.processSending(authtagPlusInnerKey); key = session.processSending(authtagPlusInnerKey, ignoreSessionTrust);
} else { } else {
key = session.processSending(innerKey); key = session.processSending(innerKey, ignoreSessionTrust);
} }
if (key != null) { if (key != null) {
keys.put(session.getRemoteAddress().getDeviceId(), key); keys.put(session.getRemoteAddress().getDeviceId(), key);

View file

@ -118,9 +118,9 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
} }
@Nullable @Nullable
public AxolotlKey processSending(@NonNull byte[] outgoingMessage) { public AxolotlKey processSending(@NonNull byte[] outgoingMessage, boolean ignoreSessionTrust) {
FingerprintStatus status = getTrust(); FingerprintStatus status = getTrust();
if (status.isTrustedAndActive()) { if (ignoreSessionTrust || status.isTrustedAndActive()) {
try { try {
CiphertextMessage ciphertextMessage = cipher.encrypt(outgoingMessage); CiphertextMessage ciphertextMessage = cipher.encrypt(outgoingMessage);
return new AxolotlKey(ciphertextMessage.serialize(),ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE); return new AxolotlKey(ciphertextMessage.serialize(),ciphertextMessage.getType() == CiphertextMessage.PREKEY_TYPE);