Initial commit

This commit is contained in:
vanitasvitae 2017-04-22 21:17:23 +02:00
parent dcc92e8053
commit 5501976211
7 changed files with 713 additions and 0 deletions

32
.gitignore vendored Normal file
View file

@ -0,0 +1,32 @@
# IntelliJ
.idea
.idea/*
*.iml
.idea/workspace.xml
# Mac OS X
.DS_Store
.classpath
.project
.settings
.gradle
gradle.properties
build/
core/build/
debug/build/
experimental/build/
extensions/build/
store/
bin/
core/bin
debug/bin
experimental/bin
extensions/bin
target/
.metadata

38
build.gradle Normal file
View file

@ -0,0 +1,38 @@
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
compile "xpp3:xpp3:1.1.4c"
compile "org.jxmpp:jxmpp-core:0.5.0-alpha7"
compile "org.jxmpp:jxmpp-jid:0.5.0-alpha7"
compile "org.jxmpp:jxmpp-util-cache:0.5.0-alpha7"
compile "org.jxmpp:jxmpp-stringprep-libidn:0.5.0-alpha7"
compile "org.bouncycastle:bcprov-jdk15on:1.56"
compile "org.whispersystems:signal-protocol-java:2.3.0"
compile "org.igniterealtime.smack:smack-core:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-experimental:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-extensions:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-im:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-java7:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-omemo:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-omemo-signal:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-resolver-dnsjava:4.2.1-SNAPSHOT"
compile "org.igniterealtime.smack:smack-tcp:4.2.1-SNAPSHOT"
}
jar {
from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude "META-INF/*.SF"
exclude "META-INF/LICENSE"
}
manifest {
attributes(
'Main-Class': 'main.java.Main'
)
}
}

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,6 @@
#Sat Apr 22 20:58:42 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip

164
gradlew vendored Executable file
View file

@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored Normal file
View file

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

383
src/main/java/Main.java Normal file
View file

@ -0,0 +1,383 @@
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smack.roster.RosterEntry;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smackx.carbons.CarbonManager;
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.OmemoManager;
import org.jivesoftware.smackx.omemo.exceptions.*;
import org.jivesoftware.smackx.omemo.internal.*;
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.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
import org.whispersystems.libsignal.IdentityKey;
import java.io.File;
import java.security.Security;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
/**
* Test
* Created by vanitas on 28.11.16.
*/
public class Main {
private AbstractXMPPConnection connection;
private OmemoManager omemoManager;
private Main() throws XmppStringprepException {
/*
SmackConfiguration.DEBUG = true;
/*/
SmackConfiguration.DEBUG = false;
//*/
OmemoManager.setAddOmemoHintBody(false);
new OmemoInitializer().initialize();
}
public void start() throws Exception {
Scanner scanner = new Scanner(System.in);
String jidname = null, password = null;
while(jidname == null) {
System.out.println("Enter username:");
jidname = scanner.nextLine();
}
while (password == null) {
System.out.println("Enter password:");
password = scanner.nextLine();
}
connection = new XMPPTCPConnection(jidname, password);
Security.addProvider(new BouncyCastleProvider());
connection.setPacketReplyTimeout(50000);
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();
if (sender != null && decrypted != null) {
System.out.println("\033[34m" + sender + ": " + decrypted + "\033[0m "+(omemoMessageInformation != null ? omemoMessageInformation : ""));
}
};
OmemoMucMessageListener mucMessageListener = (multiUserChat, bareJid, s, message, message1, omemoMessageInformation) -> {
if(multiUserChat != null && bareJid != null && s != null) {
System.out.println("\033[36m"+multiUserChat.getRoom()+": "+bareJid+": "+s+"\033[0m "+(omemoMessageInformation != null ? omemoMessageInformation : ""));
}
};
SignalOmemoService omemoService = new SignalOmemoService(omemoManager, store);
omemoManager.initialize();
CarbonManager.getInstanceFor(connection).enableCarbons();
omemoManager.addOmemoMessageListener(messageListener);
omemoManager.addOmemoMucMessageListener(mucMessageListener);
Roster roster = Roster.getInstanceFor(connection);
roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
ChatManager cm = ChatManager.getInstanceFor(connection);
cm.addChatListener((chat, b) -> chat.addMessageListener((chat1, message) -> {
if(message.getBody() != null && chat1 != null) {
System.out.println("Message received: " + chat1.getParticipant().toString() + ": " + message.getBody());
}
}));
MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection);
mucm.setAutoJoinOnReconnect(true);
mucm.addInvitationListener((xmppConnection, multiUserChat, entityFullJid, s, s1, message, invite) -> {
try {
multiUserChat.join(Resourcepart.from("OMEMO"));
multiUserChat.addMessageListener(message1 -> {
System.out.println("MUC: "+message1.getFrom()+": "+message1.getBody());
});
System.out.println("Joined Room "+multiUserChat.getRoom().asBareJid().toString());
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | MultiUserChatException.NotAMucServiceException | SmackException.NotConnectedException | XmppStringprepException e) {
e.printStackTrace();
}
});
System.out.println("OMEMO setup complete. You can now start chatting.");
String line;
Chat current = null;
boolean omemo = false;
while ((line = scanner.nextLine()) != null) {
String [] split = line.split(" ");
if(line.startsWith("/chat ")) {
String l = line.substring("/chat ".length());
if(l.length() == 0) {
System.out.println(current != null ? current.getParticipant() : "null");
} else {
String id = split[1];
BareJid jid = getJid(id);
if(jid != null) {
current = cm.createChat(jid.asEntityJidIfPossible());
current.sendMessage(l.substring(id.length() + 1));
}
}
} else if (line.startsWith("/quit")) {
scanner.close();
connection.disconnect(new Presence(Presence.Type.unavailable, "Smack is still alive :D", 100, Presence.Mode.away));
break;
} else if (line.startsWith("/add")) {
String jid = split.length == 4 ? split[1] : null;
if(jid != null) {
BareJid b = JidCreate.bareFrom(jid);
roster.createEntry(b, split[2], new String[]{split[3]});
} else {
System.out.println("Usage: /add jid@server nick group");
}
} else if(line.startsWith("/remove")) {
if(split.length == 2) {
BareJid b = getJid(split[1]);
roster.removeEntry(roster.getEntry(b));
System.out.println("Removed contact from roster");
}
} else if(line.startsWith("/list")){
if(split.length == 1) {
for (RosterEntry r : roster.getEntries()) {
System.out.println(r.getName() + " (" + r.getJid() + ") Can I see? " + r.canSeeHisPresence() + ". Can they see? " + r.canSeeMyPresence() + ". Online? " + roster.getPresence(r.getJid()).isAvailable());
}
for (EntityBareJid r : mucm.getJoinedRooms()) {
System.out.println(r.asBareJid().toString());
}
} else {
BareJid jid = getJid(split[1]);
try {
List<Presence> presences = roster.getAllPresences(jid);
for(Presence p : presences) {
System.out.println(p.getFrom()+" "+omemoManager.resourceSupportsOmemo(p.getFrom().asDomainFullJidIfPossible()));
}
} catch (Exception e) {}
CachedDeviceList list = store.loadCachedDeviceList(jid);
if(list == null) {
list = new CachedDeviceList();
}
ArrayList<String> fps = new ArrayList<>();
for(int id : list.getActiveDevices()) {
OmemoDevice d = new OmemoDevice(jid, id);
IdentityKey idk = store.loadOmemoIdentityKey(d);
if(idk == null) {
try {
omemoManager.buildSessionWith(d);
idk = store.loadOmemoIdentityKey(d);
} catch (CannotEstablishOmemoSessionException | CorruptedOmemoKeyException e) {
System.out.println("Error: "+e.getMessage());
}
}
if(idk != null) {
fps.add(KeyUtil.prettyFingerprint(store.keyUtil().getFingerprint(idk)));
}
}
for(int i=0; i<fps.size(); i++) {
System.out.println(i+": "+fps.get(i));
}
}
} else if(line.startsWith("/trust")) {
if(split.length == 2) {
System.out.println("Usage: \n0: Untrusted, 1: Trusted, otherwise: Undecided");
BareJid jid = getJid(split[1]);
if(jid != null) {
CachedDeviceList l = store.loadCachedDeviceList(jid);
int ourId = store.loadOmemoDeviceId();
l.getActiveDevices().stream().filter(i -> i != ourId).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);
s = (SignalOmemoSession) store.getOmemoSessionOf(d);
System.out.println("Session built.");
} catch (CannotEstablishOmemoSessionException | CorruptedOmemoKeyException e) {
e.printStackTrace();
}
}
if (store.isDecidedOmemoIdentity(d, s.getIdentityKey())) {
if (store.isTrustedOmemoIdentity(d, s.getIdentityKey())) {
System.out.println("Status: Trusted");
} else {
System.out.println("Status: Untrusted");
}
} else {
System.out.println("Status: Undecided");
}
System.out.println(KeyUtil.prettyFingerprint(s.getFingerprint()));
String decision = scanner.nextLine();
if (decision.equals("0")) {
store.distrustOmemoIdentity(d, s.getIdentityKey());
System.out.println("Identity has been untrusted.");
} else if (decision.equals("1")) {
store.trustOmemoIdentity(d, s.getIdentityKey());
System.out.println("Identity has been trusted.");
}
});
}
}
} else if(line.startsWith("/purge")) {
omemoManager.purgeDevices();
System.out.println("Purge successful.");
} else if(line.startsWith("/regenerate")) {
omemoManager.regenerate();
System.out.println("Regeneration successful.");
} else if(line.startsWith("/omemo")) {
if(split.length == 1) {
} else {
BareJid recipient = getJid(split[1]);
if (recipient != null) {
String message = "";
for (int i = 2; i < split.length; i++) {
message += split[i] + " ";
}
Message m = new Message();
m.setBody(message.trim());
m.setTo(recipient);
try {
Message e = omemoManager.encrypt(recipient, m);
current = cm.createChat(recipient.asEntityJidIfPossible());
current.sendMessage(e);
} catch (UndecidedOmemoIdentityException e) {
System.out.println("There are undecided identities:");
for(OmemoDevice d : e.getUntrustedDevices()) {
System.out.println(d.toString());
}
}
}
}
omemo = true;
}
else if(line.startsWith("/mucomemo")) {
if(split.length >= 3) {
BareJid mucJid = getJid(split[1]);
if (mucJid != null) {
String message = "";
for (int i = 2; i < split.length; i++) {
message += split[i] + " ";
}
Message m = new Message();
m.setBody(message.trim());
MultiUserChat muc = mucm.getMultiUserChat(mucJid.asEntityBareJidIfPossible());
List<EntityFullJid> occupants = muc.getOccupants();
ArrayList<BareJid> recipients = occupants.stream().map(e ->
muc.getOccupant(e.asEntityFullJidIfPossible()).getJid().asBareJid())
.collect(Collectors.toCollection(ArrayList::new));
Message encrypted = omemoManager.encrypt(recipients, m);
muc.sendMessage(encrypted);
}
}
} else if(line.startsWith("/fingerprint")) {
String fingerprint = omemoManager.getOurFingerprint();
System.out.println(KeyUtil.prettyFingerprint(fingerprint));
} else if(line.startsWith("/help")) {
if(split.length == 1) {
System.out.println("Available options: \n" +
"/chat <Nickname/Jid> <Message>: Send a normal unencrypted chat message to a user. \n" +
"/omemo <Nickname/Jid> <Message>: Send an OMEMO encrypted message to a user. \n" +
"/mucomemo <MUC-Jid> <Message>: Send an OMEMO encrypted message to a group chat. \n" +
"/list: List your roster. \n" +
"/list <Nickname/Jid>: List all devices of a user. \n" +
"/fingerprint: Show your OMEMO fingerprint. \n" +
"/purge: Remove all other devices from your list of active devices. \n" +
"/regenerate: Create a new OMEMO identity. \n" +
"/add <jid> <Nickname> <group>: Add a new contact to your roster. \n" +
"/remove <jid>: Remove a contact from your roster. \n" +
"/quit: Quit the application.");
}
} else if(line.startsWith("/mam")) {
MamManager mamManager = MamManager.getInstanceFor(connection);
MamManager.MamQueryResult result = mamManager.queryArchive(new Date(System.currentTimeMillis()-1000*60*60*24), new Date(System.currentTimeMillis()));
for(ClearTextMessage d : omemoManager.decryptMamQueryResult(result)) {
messageListener.onOmemoMessageReceived(d.getBody(), d.getOriginalMessage(), null, d.getMessageInformation());
}
System.out.println("Query finished");
}
else {
if(current != null) {
if(!omemo) {
current.sendMessage(line);
} else {
Message m = new Message();
m.setBody(line.trim());
try {
Message e = omemoManager.encrypt(current.getParticipant().asEntityBareJid(), m);
current.sendMessage(e);
} catch (UndecidedOmemoIdentityException e) {
System.out.println("There are undecided identities:");
for(OmemoDevice d : e.getUntrustedDevices()) {
System.out.println(d.toString());
}
}
}
}
else
System.out.println("please open a chat");
}
}
}
public static void main(String[] args) {
try {
Main main = new Main();
main.start();
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
public BareJid getJid(String user) {
Roster roster = Roster.getInstanceFor(connection);
RosterEntry r = null;
for(RosterEntry s : roster.getEntries()) {
if(s.getName() != null && s.getName().equals(user)) {
r = s;
break;
}
}
if(r != null) {
return r.getJid();
} else {
try {
return JidCreate.bareFrom(user);
} catch (XmppStringprepException e) {
e.printStackTrace();
return null;
}
}
}
}