mirror of
https://github.com/vanitasvitae/OmemoQRCodeGenerator.git
synced 2024-11-23 12:52:09 +01:00
Initial crappy commit
This commit is contained in:
commit
f131259fb9
14 changed files with 699 additions and 0 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
.gradle/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*/out
|
||||||
|
*/build/
|
||||||
|
|
||||||
|
out/
|
55
build.gradle
Normal file
55
build.gradle
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
group 'de.vanitasvitae'
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Material Design
|
||||||
|
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'javafx-gradle-plugin'
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url "https://igniterealtime.org/repo/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
smackVersion="4.4.0-alpha2-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileClasspath 'de.dynamicfiles.projects.gradle.plugins:javafx-gradle-plugin:8.8.2'
|
||||||
|
implementation 'com.jfoenix:jfoenix:8.0.7'
|
||||||
|
implementation 'com.google.zxing:core:3.3.3'
|
||||||
|
|
||||||
|
implementation "org.igniterealtime.smack:smack-java7:$smackVersion"
|
||||||
|
implementation "org.igniterealtime.smack:smack-resolver-dnsjava:$smackVersion"
|
||||||
|
implementation "org.igniterealtime.smack:smack-tcp:$smackVersion"
|
||||||
|
implementation "org.igniterealtime.smack:smack-extensions:$smackVersion"
|
||||||
|
|
||||||
|
implementation "org.igniterealtime.smack:smack-omemo-signal:$smackVersion"
|
||||||
|
implementation "org.igniterealtime.smack:smack-omemo:$smackVersion"
|
||||||
|
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
}
|
||||||
|
|
||||||
|
jfx {
|
||||||
|
mainClass = 'de.vanitasvitae.omemoqrgenerator.Main'
|
||||||
|
|
||||||
|
vendor = 'vanitasvitae'
|
||||||
|
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#Wed Oct 24 01:10:40 CEST 2018
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
|
172
gradlew
vendored
Executable file
172
gradlew
vendored
Executable file
|
@ -0,0 +1,172 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## 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
|
||||||
|
|
||||||
|
# Escape application args
|
||||||
|
save () {
|
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
|
echo " "
|
||||||
|
}
|
||||||
|
APP_ARGS=$(save "$@")
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
|
|
||||||
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||||
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
@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
|
||||||
|
|
||||||
|
: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=%*
|
||||||
|
|
||||||
|
: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
|
2
settings.gradle
Normal file
2
settings.gradle
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
rootProject.name = 'omemoqrgenerator'
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
|
public interface LoginCallback {
|
||||||
|
|
||||||
|
void login(String username, String password);
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import com.jfoenix.controls.JFXPasswordField;
|
||||||
|
import com.jfoenix.controls.JFXTextField;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
|
||||||
|
public class LoginController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXButton button_login;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXTextField text_username;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXPasswordField text_password;
|
||||||
|
|
||||||
|
public void setLoginCallback(LoginCallback callback) {
|
||||||
|
button_login.setOnAction(actionEvent -> {
|
||||||
|
String username = text_username.getText();
|
||||||
|
String password = text_password.getText();
|
||||||
|
callback.login(username, password);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
115
src/main/java/de/vanitasvitae/omemoqrgenerator/Main.java
Normal file
115
src/main/java/de/vanitasvitae/omemoqrgenerator/Main.java
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||||
|
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||||
|
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
|
public class Main extends Application implements LoginCallback {
|
||||||
|
|
||||||
|
private Stage stage;
|
||||||
|
|
||||||
|
|
||||||
|
static {
|
||||||
|
SmackConfiguration.DEBUG = true;
|
||||||
|
SmackConfiguration.addDisabledSmackClasses("org.jivesoftware.smack.ReconnectionManager",
|
||||||
|
"org.jivesoftware.smack.sasl.javax",
|
||||||
|
"org.jivesoftware.smack.legacy",
|
||||||
|
"org.jivesoftware.smackx.gcm",
|
||||||
|
"org.jivesoftware.smackx.httpfileupload",
|
||||||
|
"org.jivesoftware.smackx.hoxt",
|
||||||
|
"org.jivesoftware.smackx.iot",
|
||||||
|
"org.jivesoftware.smackx.json",
|
||||||
|
"org.jivesoftware.smackx.muc",
|
||||||
|
"org.jivesoftware.smackx.xdata",
|
||||||
|
"org.jivesoftware.smackx.xdatalayout",
|
||||||
|
"org.jivesoftware.smackx.xdatavalidation",
|
||||||
|
"org.jivesoftware.smackx.admin",
|
||||||
|
"org.jivesoftware.smackx.amp",
|
||||||
|
"org.jivesoftware.smackx.attention",
|
||||||
|
"org.jivesoftware.smackx.blocking",
|
||||||
|
"org.jivesoftware.smackx.bob",
|
||||||
|
"org.jivesoftware.smackx.bookmark",
|
||||||
|
"org.jivesoftware.smackx.bytestreams",
|
||||||
|
"org.jivesoftware.smackx.chatstates",
|
||||||
|
"org.jivesoftware.smackx.commands",
|
||||||
|
"org.jivesoftware.smackx.filetransfer",
|
||||||
|
"org.jivesoftware.smackx.forward",
|
||||||
|
"org.jivesoftware.smackx.sid",
|
||||||
|
"org.jivesoftware.smackx.eme",
|
||||||
|
"org.jivesoftware.smackx.vcardtemp",
|
||||||
|
"org.jivesoftware.smackx.xhtmlim",
|
||||||
|
"org.jivesoftware.smackx.time",
|
||||||
|
"org.jivesoftware.smackx.privacy",
|
||||||
|
"org.jivesoftware.smackx.ping",
|
||||||
|
"org.jivesoftware.smackx.iqlast",
|
||||||
|
"org.jivesoftware.smackx.receipts",
|
||||||
|
"org.jivesoftware.smackx.iqversion"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws Exception {
|
||||||
|
this.stage = stage;
|
||||||
|
FXMLLoader loader = new FXMLLoader();
|
||||||
|
loader.setLocation(getClass().getResource("/fxml/login.fxml"));
|
||||||
|
Parent root = loader.load();
|
||||||
|
stage.setMinHeight(600);
|
||||||
|
stage.setMinWidth(400);
|
||||||
|
LoginController loginController = loader.getController();
|
||||||
|
loginController.setLoginCallback(this);
|
||||||
|
|
||||||
|
Scene scene = new Scene(root, 400, 600);
|
||||||
|
stage.setTitle("OMEMO QR-Code Generator - Login");
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void login(String username, String password) {
|
||||||
|
try {
|
||||||
|
XMPPTCPConnection connection = new XMPPTCPConnection(username, password);
|
||||||
|
connection.connect().login();
|
||||||
|
|
||||||
|
BareJid jid = connection.getUser().asBareJid();
|
||||||
|
Map<OmemoDevice, OmemoFingerprint> fingerprints = Util.getFingerprints(connection);
|
||||||
|
|
||||||
|
connection.disconnect(new Presence(Presence.Type.unavailable));
|
||||||
|
|
||||||
|
FXMLLoader loader = new FXMLLoader();
|
||||||
|
loader.setLocation(getClass().getResource("/fxml/qrdisplay.fxml"));
|
||||||
|
Parent root = loader.load();
|
||||||
|
QrDisplayController controller = loader.getController();
|
||||||
|
controller.setFingerprints(jid, fingerprints);
|
||||||
|
|
||||||
|
Scene scene = new Scene(root, 400, 600);
|
||||||
|
stage.setTitle("OMEMO QR-Code Generator");
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||||
|
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||||
|
|
||||||
|
import com.google.zxing.BarcodeFormat;
|
||||||
|
import com.google.zxing.WriterException;
|
||||||
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
|
import com.jfoenix.controls.JFXTextArea;
|
||||||
|
import javafx.embed.swing.SwingFXUtils;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
|
public class QrDisplayController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ImageView qr_view;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXTextArea content_text;
|
||||||
|
|
||||||
|
private BareJid jid;
|
||||||
|
private Map<OmemoDevice, OmemoFingerprint> fingerprintMap;
|
||||||
|
|
||||||
|
public void setFingerprints(BareJid jid, Map<OmemoDevice, OmemoFingerprint> fingerprints) {
|
||||||
|
this.jid = jid;
|
||||||
|
this.fingerprintMap = fingerprints;
|
||||||
|
drawQRCode(jid, fingerprints);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawQRCode(BareJid jid, Map<OmemoDevice, OmemoFingerprint> fingerprints) {
|
||||||
|
int width = 300, height = 300;
|
||||||
|
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||||
|
|
||||||
|
String content = "xmpp:" + jid.toString();
|
||||||
|
|
||||||
|
Iterator<OmemoDevice> iterator = fingerprints.keySet().iterator();
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
OmemoDevice first = iterator.next();
|
||||||
|
content += "?omemo-sid-" + first.getDeviceId() + "=" + fingerprints.get(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
OmemoDevice next = iterator.next();
|
||||||
|
content += ";omemo-sid-" + next.getDeviceId() + "=" + fingerprints.get(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
content_text.setText(content);
|
||||||
|
|
||||||
|
BufferedImage image;
|
||||||
|
|
||||||
|
try {
|
||||||
|
BitMatrix byteMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height);
|
||||||
|
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
|
image.createGraphics();
|
||||||
|
|
||||||
|
Graphics2D graphics = (Graphics2D) image.getGraphics();
|
||||||
|
graphics.setColor(Color.WHITE);
|
||||||
|
graphics.fillRect(0, 0, width, height);
|
||||||
|
graphics.setColor(Color.BLACK);
|
||||||
|
|
||||||
|
for (int i = 0; i < height; i++) {
|
||||||
|
for (int j = 0; j < width; j++) {
|
||||||
|
if (byteMatrix.get(i, j)) {
|
||||||
|
graphics.fillRect(i, j, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Success...");
|
||||||
|
|
||||||
|
} catch (WriterException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qr_view.setImage(SwingFXUtils.toFXImage(image, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
97
src/main/java/de/vanitasvitae/omemoqrgenerator/Util.java
Normal file
97
src/main/java/de/vanitasvitae/omemoqrgenerator/Util.java
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
|
import org.jivesoftware.smackx.omemo.element.OmemoBundleElement;
|
||||||
|
import org.jivesoftware.smackx.omemo.element.OmemoDeviceListElement;
|
||||||
|
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||||
|
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||||
|
import org.jivesoftware.smackx.omemo.signal.SignalOmemoKeyUtil;
|
||||||
|
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||||
|
import org.jivesoftware.smackx.omemo.util.OmemoConstants;
|
||||||
|
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||||
|
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
||||||
|
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||||
|
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
private static final SignalOmemoKeyUtil KEYUTIL = new SignalOmemoKeyUtil();
|
||||||
|
|
||||||
|
public static Map<OmemoDevice, OmemoFingerprint> getFingerprints(XMPPTCPConnection connection)
|
||||||
|
throws InterruptedException, PubSubException.NotALeafNodeException,
|
||||||
|
SmackException.NoResponseException, SmackException.NotConnectedException,
|
||||||
|
XMPPException.XMPPErrorException, PubSubException.NotAPubSubNodeException,
|
||||||
|
CorruptedOmemoKeyException {
|
||||||
|
BareJid jid = connection.getUser().asBareJid();
|
||||||
|
Map<OmemoDevice, OmemoFingerprint> fingerprintMap = new HashMap<>();
|
||||||
|
|
||||||
|
OmemoDeviceListElement deviceList = fetchDeviceList(connection, jid);
|
||||||
|
if (deviceList == null) {
|
||||||
|
return fingerprintMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int id : deviceList.getDeviceIds()) {
|
||||||
|
OmemoDevice device = new OmemoDevice(jid, id);
|
||||||
|
OmemoBundleElement bundle = fetchBundle(connection, device);
|
||||||
|
if (bundle == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
OmemoFingerprint fingerprint = KEYUTIL.getFingerprintOfIdentityKey(KEYUTIL.BUNDLE.identityKey(bundle));
|
||||||
|
fingerprintMap.put(device, fingerprint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fingerprintMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OmemoBundleElement fetchBundle(XMPPConnection connection,
|
||||||
|
OmemoDevice contactsDevice)
|
||||||
|
throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException,
|
||||||
|
XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException,
|
||||||
|
PubSubException.NotAPubSubNodeException {
|
||||||
|
|
||||||
|
PubSubManager pm = PubSubManager.getInstance(connection, contactsDevice.getJid());
|
||||||
|
LeafNode node = pm.getLeafNode(contactsDevice.getBundleNodeName());
|
||||||
|
|
||||||
|
if (node == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PayloadItem<OmemoBundleElement>> bundleItems = node.getItems();
|
||||||
|
if (bundleItems.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bundleItems.get(bundleItems.size() - 1).getPayload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OmemoDeviceListElement fetchDeviceList(XMPPConnection connection, BareJid contact)
|
||||||
|
throws InterruptedException, PubSubException.NotALeafNodeException, SmackException.NoResponseException,
|
||||||
|
SmackException.NotConnectedException, XMPPException.XMPPErrorException,
|
||||||
|
PubSubException.NotAPubSubNodeException {
|
||||||
|
|
||||||
|
PubSubManager pm = PubSubManager.getInstance(connection, contact);
|
||||||
|
String nodeName = OmemoConstants.PEP_NODE_DEVICE_LIST;
|
||||||
|
LeafNode node = pm.getLeafNode(nodeName);
|
||||||
|
|
||||||
|
if (node == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PayloadItem<OmemoDeviceListElement>> items = node.getItems();
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return items.get(items.size() - 1).getPayload();
|
||||||
|
}
|
||||||
|
}
|
25
src/main/resources/fxml/login.fxml
Normal file
25
src/main/resources/fxml/login.fxml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXButton?>
|
||||||
|
<?import com.jfoenix.controls.JFXPasswordField?>
|
||||||
|
<?import com.jfoenix.controls.JFXTextField?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
<VBox alignment="CENTER" minHeight="400.0" minWidth="600.0" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.vanitasvitae.omemoqrgenerator.LoginController">
|
||||||
|
<children>
|
||||||
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
|
<VBox alignment="CENTER" maxHeight="150.0" maxWidth="300.0" minHeight="150.0" minWidth="300.0" prefHeight="150.0" prefWidth="300.0" spacing="8.0">
|
||||||
|
<children>
|
||||||
|
<JFXTextField fx:id="text_username" promptText="Username" />
|
||||||
|
<JFXPasswordField fx:id="text_password" promptText="Password" />
|
||||||
|
<JFXButton fx:id="button_login" mnemonicParsing="false" text="Login" />
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="16.0" left="16.0" right="16.0" top="16.0" />
|
||||||
|
</padding>
|
||||||
|
</VBox>
|
||||||
|
</HBox>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
15
src/main/resources/fxml/qrdisplay.fxml
Normal file
15
src/main/resources/fxml/qrdisplay.fxml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
<?import com.jfoenix.controls.JFXTextArea?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<VBox alignment="TOP_CENTER" minHeight="400.0" minWidth="600.0" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.vanitasvitae.omemoqrgenerator.QrDisplayController">
|
||||||
|
<children>
|
||||||
|
<ImageView fx:id="qr_view"/>
|
||||||
|
<HBox>
|
||||||
|
<JFXTextArea fx:id="content_text" />
|
||||||
|
</HBox>
|
||||||
|
|
||||||
|
</children>
|
||||||
|
</VBox>
|
Loading…
Reference in a new issue