Update latest smack-omemo
This commit is contained in:
parent
3e283093c0
commit
b8a78dffe0
2 changed files with 48 additions and 43 deletions
|
@ -9,7 +9,7 @@ To build it, you must first clone smack-omemo and install it in your local maven
|
||||||
```
|
```
|
||||||
git clone git@github.com:vanitasvitae/smack-omemo.git
|
git clone git@github.com:vanitasvitae/smack-omemo.git
|
||||||
cd smack-omemo
|
cd smack-omemo
|
||||||
git checkout 4.2
|
git checkout eec7cfcf0d5fdbba1b9f66b8cc013daab5642284
|
||||||
gradle install
|
gradle install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ import org.jivesoftware.smackx.muc.MultiUserChatException;
|
||||||
import org.jivesoftware.smackx.muc.MultiUserChatManager;
|
import org.jivesoftware.smackx.muc.MultiUserChatManager;
|
||||||
import org.jivesoftware.smackx.omemo.OmemoConfiguration;
|
import org.jivesoftware.smackx.omemo.OmemoConfiguration;
|
||||||
import org.jivesoftware.smackx.omemo.OmemoManager;
|
import org.jivesoftware.smackx.omemo.OmemoManager;
|
||||||
|
import org.jivesoftware.smackx.omemo.OmemoService;
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException;
|
import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException;
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
|
||||||
import org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException;
|
import org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException;
|
||||||
import org.jivesoftware.smackx.omemo.internal.CachedDeviceList;
|
import org.jivesoftware.smackx.omemo.internal.CachedDeviceList;
|
||||||
import org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag;
|
import org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag;
|
||||||
|
@ -29,8 +29,7 @@ import org.jivesoftware.smackx.omemo.listener.OmemoMucMessageListener;
|
||||||
import org.jivesoftware.smackx.omemo.signal.SignalFileBasedOmemoStore;
|
import org.jivesoftware.smackx.omemo.signal.SignalFileBasedOmemoStore;
|
||||||
import org.jivesoftware.smackx.omemo.signal.SignalOmemoService;
|
import org.jivesoftware.smackx.omemo.signal.SignalOmemoService;
|
||||||
import org.jivesoftware.smackx.omemo.signal.SignalOmemoSession;
|
import org.jivesoftware.smackx.omemo.signal.SignalOmemoSession;
|
||||||
import org.jivesoftware.smackx.omemo.util.KeyUtil;
|
import org.jivesoftware.smackx.omemo.util.OmemoKeyUtil;
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
|
||||||
import org.jline.reader.EndOfFileException;
|
import org.jline.reader.EndOfFileException;
|
||||||
import org.jline.reader.LineReader;
|
import org.jline.reader.LineReader;
|
||||||
import org.jline.reader.LineReaderBuilder;
|
import org.jline.reader.LineReaderBuilder;
|
||||||
|
@ -39,7 +38,6 @@ import org.jline.terminal.Terminal;
|
||||||
import org.jline.terminal.TerminalBuilder;
|
import org.jline.terminal.TerminalBuilder;
|
||||||
import org.jxmpp.jid.BareJid;
|
import org.jxmpp.jid.BareJid;
|
||||||
import org.jxmpp.jid.EntityBareJid;
|
import org.jxmpp.jid.EntityBareJid;
|
||||||
import org.jxmpp.jid.EntityFullJid;
|
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
import org.jxmpp.jid.impl.JidCreate;
|
||||||
import org.jxmpp.jid.parts.Resourcepart;
|
import org.jxmpp.jid.parts.Resourcepart;
|
||||||
import org.jxmpp.stringprep.XmppStringprepException;
|
import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
|
@ -50,7 +48,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,12 +59,12 @@ public class Main {
|
||||||
private OmemoManager omemoManager;
|
private OmemoManager omemoManager;
|
||||||
|
|
||||||
private Main() throws XmppStringprepException {
|
private Main() throws XmppStringprepException {
|
||||||
/*
|
//*
|
||||||
SmackConfiguration.DEBUG = true;
|
SmackConfiguration.DEBUG = true;
|
||||||
/*/
|
/*/
|
||||||
SmackConfiguration.DEBUG = false;
|
SmackConfiguration.DEBUG = false;
|
||||||
//*/
|
//*/
|
||||||
OmemoConfiguration.getInstance().setAddOmemoHintBody(false);
|
OmemoConfiguration.setAddOmemoHintBody(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
@ -90,9 +87,9 @@ public class Main {
|
||||||
connection = new XMPPTCPConnection(jidname, password);
|
connection = new XMPPTCPConnection(jidname, password);
|
||||||
|
|
||||||
SignalOmemoService.setup();
|
SignalOmemoService.setup();
|
||||||
OmemoConfiguration.getInstance().setFileBasedOmemoStoreDefaultPath(new File("store"));
|
OmemoConfiguration.setFileBasedOmemoStoreDefaultPath(new File("store"));
|
||||||
omemoManager = OmemoManager.getInstanceFor(connection);
|
omemoManager = OmemoManager.getInstanceFor(connection);
|
||||||
SignalFileBasedOmemoStore omemoStore = (SignalFileBasedOmemoStore) omemoManager.getOmemoService().getOmemoStoreBackend();
|
SignalFileBasedOmemoStore omemoStore = (SignalFileBasedOmemoStore) OmemoService.getInstance().getOmemoStoreBackend();
|
||||||
connection.setPacketReplyTimeout(10000);
|
connection.setPacketReplyTimeout(10000);
|
||||||
connection = connection.connect();
|
connection = connection.connect();
|
||||||
connection.login();
|
connection.login();
|
||||||
|
@ -233,6 +230,7 @@ public class Main {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
omemoManager.requestDeviceListUpdateFor(jid);
|
omemoManager.requestDeviceListUpdateFor(jid);
|
||||||
|
omemoManager.buildSessionsWith(jid);
|
||||||
CachedDeviceList list = omemoStore.loadCachedDeviceList(omemoManager, jid);
|
CachedDeviceList list = omemoStore.loadCachedDeviceList(omemoManager, jid);
|
||||||
if(list == null) {
|
if(list == null) {
|
||||||
list = new CachedDeviceList();
|
list = new CachedDeviceList();
|
||||||
|
@ -242,15 +240,9 @@ public class Main {
|
||||||
OmemoDevice d = new OmemoDevice(jid, id);
|
OmemoDevice d = new OmemoDevice(jid, id);
|
||||||
IdentityKey idk = omemoStore.loadOmemoIdentityKey(omemoManager, d);
|
IdentityKey idk = omemoStore.loadOmemoIdentityKey(omemoManager, d);
|
||||||
if(idk == null) {
|
if(idk == null) {
|
||||||
try {
|
System.out.println("No identityKey for "+d);
|
||||||
omemoManager.buildSessionWith(d);
|
} else {
|
||||||
idk = omemoStore.loadOmemoIdentityKey(omemoManager, d);
|
fps.add(OmemoKeyUtil.prettyFingerprint(omemoStore.keyUtil().getFingerprint(idk)));
|
||||||
} catch (CannotEstablishOmemoSessionException | CorruptedOmemoKeyException e) {
|
|
||||||
System.out.println("Error: "+e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(idk != null) {
|
|
||||||
fps.add(KeyUtil.prettyFingerprint(omemoStore.keyUtil().getFingerprint(idk)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i=0; i<fps.size(); i++) {
|
for(int i=0; i<fps.size(); i++) {
|
||||||
|
@ -269,9 +261,7 @@ public class Main {
|
||||||
omemoManager.requestDeviceListUpdateFor(jid);
|
omemoManager.requestDeviceListUpdateFor(jid);
|
||||||
CachedDeviceList l = omemoStore.loadCachedDeviceList(omemoManager, jid);
|
CachedDeviceList l = omemoStore.loadCachedDeviceList(omemoManager, jid);
|
||||||
|
|
||||||
l.getActiveDevices().stream().filter(i -> {
|
l.getActiveDevices().stream().filter(i -> (!jid.equals(connection.getUser().asBareJid()) || i != omemoManager.getDeviceId())).forEach(i -> {
|
||||||
return (!jid.equals(connection.getUser().asBareJid()) || i != omemoManager.getDeviceId());
|
|
||||||
}).forEach(i -> {
|
|
||||||
OmemoDevice d = new OmemoDevice(jid, i);
|
OmemoDevice d = new OmemoDevice(jid, i);
|
||||||
SignalOmemoSession s = (SignalOmemoSession) omemoStore.getOmemoSessionOf(omemoManager, d);
|
SignalOmemoSession s = (SignalOmemoSession) omemoStore.getOmemoSessionOf(omemoManager, d);
|
||||||
if(s.getIdentityKey() == null) {
|
if(s.getIdentityKey() == null) {
|
||||||
|
@ -282,6 +272,7 @@ public class Main {
|
||||||
System.out.println("Session built.");
|
System.out.println("Session built.");
|
||||||
} catch (CannotEstablishOmemoSessionException e) {
|
} catch (CannotEstablishOmemoSessionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (omemoStore.isDecidedOmemoIdentity(omemoManager, d, s.getIdentityKey())) {
|
if (omemoStore.isDecidedOmemoIdentity(omemoManager, d, s.getIdentityKey())) {
|
||||||
|
@ -293,7 +284,7 @@ public class Main {
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Status: Undecided");
|
System.out.println("Status: Undecided");
|
||||||
}
|
}
|
||||||
System.out.println(KeyUtil.prettyFingerprint(s.getFingerprint()));
|
System.out.println(OmemoKeyUtil.prettyFingerprint(s.getFingerprint()));
|
||||||
String decision = scanner.nextLine();
|
String decision = scanner.nextLine();
|
||||||
if (decision.equals("0")) {
|
if (decision.equals("0")) {
|
||||||
omemoStore.distrustOmemoIdentity(omemoManager, d, s.getIdentityKey());
|
omemoStore.distrustOmemoIdentity(omemoManager, d, s.getIdentityKey());
|
||||||
|
@ -320,21 +311,21 @@ public class Main {
|
||||||
for (int i = 2; i < split.length; i++) {
|
for (int i = 2; i < split.length; i++) {
|
||||||
message += split[i] + " ";
|
message += split[i] + " ";
|
||||||
}
|
}
|
||||||
Message m = new Message();
|
Message encrypted = null;
|
||||||
m.setBody(message.trim());
|
|
||||||
m.setTo(recipient);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Message e = omemoManager.encrypt(recipient, m);
|
encrypted = omemoManager.encrypt(recipient, message.trim());
|
||||||
current = cm.createChat(recipient.asEntityJidIfPossible());
|
|
||||||
current.sendMessage(e);
|
|
||||||
} catch (UndecidedOmemoIdentityException e) {
|
} catch (UndecidedOmemoIdentityException e) {
|
||||||
System.out.println("There are undecided identities:");
|
System.out.println("There are undecided identities:");
|
||||||
for(OmemoDevice d : e.getUntrustedDevices()) {
|
for(OmemoDevice d : e.getUntrustedDevices()) {
|
||||||
System.out.println(d.toString());
|
System.out.println(d.toString());
|
||||||
}
|
}
|
||||||
|
} catch (CannotEstablishOmemoSessionException e) {
|
||||||
|
encrypted = omemoManager.encryptForExistingSessions(e, message);
|
||||||
|
}
|
||||||
|
if(encrypted != null) {
|
||||||
|
current = cm.createChat(recipient.asEntityJidIfPossible());
|
||||||
|
current.sendMessage(encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
omemo = true;
|
omemo = true;
|
||||||
|
@ -347,20 +338,27 @@ public class Main {
|
||||||
for (int i = 2; i < split.length; i++) {
|
for (int i = 2; i < split.length; i++) {
|
||||||
message += split[i] + " ";
|
message += split[i] + " ";
|
||||||
}
|
}
|
||||||
Message m = new Message();
|
|
||||||
m.setBody(message.trim());
|
|
||||||
MultiUserChat muc = mucm.getMultiUserChat(mucJid.asEntityBareJidIfPossible());
|
MultiUserChat muc = mucm.getMultiUserChat(mucJid.asEntityBareJidIfPossible());
|
||||||
List<EntityFullJid> occupants = muc.getOccupants();
|
Message encrypted = null;
|
||||||
ArrayList<BareJid> recipients = occupants.stream().map(e ->
|
try {
|
||||||
muc.getOccupant(e.asEntityFullJidIfPossible()).getJid().asBareJid())
|
encrypted = omemoManager.encrypt(muc, message.trim());
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
} catch (UndecidedOmemoIdentityException e) {
|
||||||
Message encrypted = omemoManager.encrypt(recipients, m);
|
System.out.println("There are undecided identities:");
|
||||||
muc.sendMessage(encrypted);
|
for(OmemoDevice d : e.getUntrustedDevices()) {
|
||||||
|
System.out.println(d.toString());
|
||||||
|
}
|
||||||
|
} catch (CannotEstablishOmemoSessionException e) {
|
||||||
|
encrypted = omemoManager.encryptForExistingSessions(e, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(encrypted != null) {
|
||||||
|
muc.sendMessage(encrypted);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(line.startsWith("/fingerprint")) {
|
} else if(line.startsWith("/fingerprint")) {
|
||||||
String fingerprint = omemoManager.getOurFingerprint();
|
String fingerprint = omemoManager.getOurFingerprint();
|
||||||
System.out.println(KeyUtil.prettyFingerprint(fingerprint));
|
System.out.println(OmemoKeyUtil.prettyFingerprint(fingerprint));
|
||||||
} else if(line.startsWith("/help")) {
|
} else if(line.startsWith("/help")) {
|
||||||
if(split.length == 1) {
|
if(split.length == 1) {
|
||||||
System.out.println("Available options: \n" +
|
System.out.println("Available options: \n" +
|
||||||
|
@ -383,16 +381,23 @@ public class Main {
|
||||||
messageListener.onOmemoMessageReceived(d.getBody(), d.getOriginalMessage(), null, d.getMessageInformation());
|
messageListener.onOmemoMessageReceived(d.getBody(), d.getOriginalMessage(), null, d.getMessageInformation());
|
||||||
}
|
}
|
||||||
System.out.println("Query finished");
|
System.out.println("Query finished");
|
||||||
|
} else if(line.startsWith("/ratchetUpdate")) {
|
||||||
|
if(split.length == 2) {
|
||||||
|
BareJid jid = getJid(split[1]);
|
||||||
|
CachedDeviceList cachedDeviceList = omemoStore.loadCachedDeviceList(omemoManager, jid);
|
||||||
|
for(int id : cachedDeviceList.getActiveDevices()) {
|
||||||
|
OmemoDevice d = new OmemoDevice(jid, id);
|
||||||
|
omemoManager.sendRatchetUpdateMessage(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(current != null) {
|
if(current != null) {
|
||||||
if(!omemo) {
|
if(!omemo) {
|
||||||
current.sendMessage(line);
|
current.sendMessage(line);
|
||||||
} else {
|
} else {
|
||||||
Message m = new Message();
|
|
||||||
m.setBody(line.trim());
|
|
||||||
try {
|
try {
|
||||||
Message e = omemoManager.encrypt(current.getParticipant().asEntityBareJid(), m);
|
Message e = omemoManager.encrypt(current.getParticipant().asEntityBareJid(), line.trim());
|
||||||
current.sendMessage(e);
|
current.sendMessage(e);
|
||||||
} catch (UndecidedOmemoIdentityException e) {
|
} catch (UndecidedOmemoIdentityException e) {
|
||||||
System.out.println("There are undecided identities:");
|
System.out.println("There are undecided identities:");
|
||||||
|
|
Loading…
Reference in a new issue