diff options
author | Simon Rettberg | 2020-07-22 11:53:29 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-07-22 11:53:29 +0200 |
commit | e6bdf6fc9551ed455620b6eb6b6f13503350af07 (patch) | |
tree | f0aa2bf5b8ac40bc1349ea02c2cd3ad21907b29f /src | |
parent | Sanity checks, thread safety, remove unused grouplist in AvailableClient (diff) | |
download | bwlp-guacamole-ext-e6bdf6fc9551ed455620b6eb6b6f13503350af07.tar.gz bwlp-guacamole-ext-e6bdf6fc9551ed455620b6eb6b6f13503350af07.tar.xz bwlp-guacamole-ext-e6bdf6fc9551ed455620b6eb6b6f13503350af07.zip |
Add missing classes
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/de/bwlehrpool/bwlp_guac/Util.java | 30 | ||||
-rw-r--r-- | src/main/java/de/bwlehrpool/bwlp_guac/WeakCrypto.java | 44 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/Util.java b/src/main/java/de/bwlehrpool/bwlp_guac/Util.java new file mode 100644 index 0000000..2b07640 --- /dev/null +++ b/src/main/java/de/bwlehrpool/bwlp_guac/Util.java @@ -0,0 +1,30 @@ +package de.bwlehrpool.bwlp_guac; + +import org.apache.guacamole.net.auth.AuthenticatedUser; +import org.apache.guacamole.net.event.TunnelCloseEvent; +import org.apache.guacamole.net.event.TunnelConnectEvent; + +public class Util { + + public static String getUsername(TunnelConnectEvent event) { + return getUsername(event.getAuthenticatedUser()); + } + + public static String getUsername(TunnelCloseEvent event) { + return getUsername(event.getAuthenticatedUser()); + } + + public static String getUsername(AuthenticatedUser user) { + if (user == null) + return null; + String username = null; + if (user.getCredentials() != null) { + username = user.getCredentials().getUsername(); + } + if (username == null) { + username = user.getIdentifier(); + } + return username; + } + +} diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/WeakCrypto.java b/src/main/java/de/bwlehrpool/bwlp_guac/WeakCrypto.java new file mode 100644 index 0000000..b7d8a11 --- /dev/null +++ b/src/main/java/de/bwlehrpool/bwlp_guac/WeakCrypto.java @@ -0,0 +1,44 @@ +package de.bwlehrpool.bwlp_guac; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.SecretKeySpec; + +public class WeakCrypto { + + private static byte[] reverseBits(byte[] b) { + byte[] result = new byte[b.length]; + for (int i = 0; i < b.length; i++) { + result[i] = reverseBits(b[i]); + } + return result; + } + + private static byte reverseBits(byte input) { + byte result = 0x00; + for (int i = 0; i < 8; i++) { + result |= ((byte) ((input & (0x01 << i)) >>> i) << 7 - i); + } + return result; + } + + public static byte[] vncEncrypt(byte[] pw_bytes, byte[] challenge) { + Cipher des; + try { + des = Cipher.getInstance("DES/ECB/NoPadding"); + des.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(reverseBits(pw_bytes), 0, pw_bytes.length, "DES")); + return des.doFinal(challenge); + } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException + | BadPaddingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return new byte[16]; + } + +} |