Update API (hacky)

This commit is contained in:
vanitasvitae 2017-05-08 15:28:01 +02:00
parent 04eb0f1d78
commit bc4d5feb4d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 79 additions and 55 deletions

3
.gitignore vendored
View file

@ -31,3 +31,6 @@ extensions/bin
target/
.metadata
clocc.ipr
clocc.iws

View file

@ -1,5 +1,6 @@
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
repositories {
mavenLocal()

View file

@ -15,16 +15,27 @@ import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.smackx.muc.MultiUserChatException;
import org.jivesoftware.smackx.muc.MultiUserChatManager;
import org.jivesoftware.smackx.omemo.OmemoInitializer;
import org.jivesoftware.smackx.omemo.OmemoConfiguration;
import org.jivesoftware.smackx.omemo.OmemoManager;
import org.jivesoftware.smackx.omemo.exceptions.*;
import org.jivesoftware.smackx.omemo.internal.*;
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.internal.CachedDeviceList;
import org.jivesoftware.smackx.omemo.internal.ClearTextMessage;
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
import org.jivesoftware.smackx.omemo.listener.OmemoMessageListener;
import org.jivesoftware.smackx.omemo.listener.OmemoMucMessageListener;
import org.jivesoftware.smackx.omemo.signal.SignalFileBasedOmemoStore;
import org.jivesoftware.smackx.omemo.signal.SignalOmemoService;
import org.jivesoftware.smackx.omemo.signal.SignalOmemoSession;
import org.jivesoftware.smackx.omemo.util.KeyUtil;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jline.reader.EndOfFileException;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.UserInterruptException;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
@ -33,13 +44,6 @@ import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
import org.whispersystems.libsignal.IdentityKey;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.UserInterruptException;
import org.jline.reader.EndOfFileException;
import java.io.File;
import java.security.Security;
import java.util.ArrayList;
@ -57,14 +61,15 @@ public class Main {
private AbstractXMPPConnection connection;
private OmemoManager omemoManager;
private int deviceId = 20305655;
private Main() throws XmppStringprepException {
/*
//*
SmackConfiguration.DEBUG = true;
/*/
SmackConfiguration.DEBUG = false;
//*/
OmemoManager.setAddOmemoHintBody(false);
new OmemoInitializer().initialize();
OmemoConfiguration.getInstance().setAddOmemoHintBody(false);
}
public void start() throws Exception {
@ -87,12 +92,17 @@ public class Main {
connection = new XMPPTCPConnection(jidname, password);
Security.addProvider(new BouncyCastleProvider());
connection.setPacketReplyTimeout(50000);
omemoManager = OmemoManager.getInstanceFor(connection, deviceId);
SignalFileBasedOmemoStore store = new SignalFileBasedOmemoStore(omemoManager, new File("store"));
SignalOmemoService signalOmemoService = SignalOmemoService.getInstance();
signalOmemoService.registerDevice(omemoManager, store);
connection.setPacketReplyTimeout(10000);
connection = connection.connect();
connection.login();
System.out.println("Logged in. Begin setting up OMEMO...");
omemoManager = OmemoManager.getInstanceFor(connection);
SignalFileBasedOmemoStore store = new SignalFileBasedOmemoStore(omemoManager, new File("store"));
OmemoMessageListener messageListener = (decrypted, message, wrapping, omemoMessageInformation) -> {
BareJid sender = message.getFrom().asBareJid();
@ -114,8 +124,6 @@ public class Main {
}
};
SignalOmemoService omemoService = new SignalOmemoService(omemoManager, store);
omemoManager.initialize();
CarbonManager.getInstanceFor(connection).enableCarbons();
omemoManager.addOmemoMessageListener(messageListener);
@ -234,19 +242,24 @@ public class Main {
if(split.length == 2) {
System.out.println("Usage: \n0: Untrusted, 1: Trusted, otherwise: Undecided");
BareJid jid = getJid(split[1]);
if(jid != null) {
if(jid == null) {
continue;
}
omemoManager.requestDeviceListUpdateFor(jid);
CachedDeviceList l = store.loadCachedDeviceList(jid);
int ourId = store.loadOmemoDeviceId();
l.getActiveDevices().stream().filter(i -> i != ourId).forEach(i -> {
l.getActiveDevices().stream().filter(i -> i != omemoManager.getDeviceId()).forEach(i -> {
OmemoDevice d = new OmemoDevice(jid, i);
SignalOmemoSession s = (SignalOmemoSession) store.getOmemoSessionOf(d);
if(s.getIdentityKey() == null) {
try {
System.out.println("Build session...");
omemoService.buildSessionFromOmemoBundle(d);
omemoManager.getFingerprint(d);
s = (SignalOmemoSession) store.getOmemoSessionOf(d);
System.out.println("Session built.");
} catch (CannotEstablishOmemoSessionException | CorruptedOmemoKeyException e) {
} catch (CannotEstablishOmemoSessionException e) {
e.printStackTrace();
}
}
@ -270,7 +283,6 @@ public class Main {
}
});
}
}
} else if(line.startsWith("/purge")) {
omemoManager.purgeDevices();
@ -351,6 +363,14 @@ public class Main {
}
System.out.println("Query finished");
}
else if (line.startsWith("/test")) {
PubSubManager pm = PubSubManager.getInstance(connection, connection.getUser().asBareJid());
try {
pm.getLeafNode("blablasda");
} catch (Exception e) {
System.out.println(e.getClass().getName()+": "+e.getMessage());
}
}
else {
if(current != null) {