diff --git a/pom.xml b/pom.xml deleted file mode 100644 index f4850bf..0000000 --- a/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - 4.0.0 - - eu.siacs.conversations - ImageDownloader - 0.1 - - - - org.bouncycastle - bcprov-jdk15on - 1.54 - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.4.3 - - - package - - shade - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - eu.siacs.conversations.Downloader - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 7 - 7 - - - - - diff --git a/src/main/java/eu/siacs/conversations/Downloader.java b/src/main/java/eu/siacs/conversations/Downloader.java deleted file mode 100644 index d81cc42..0000000 --- a/src/main/java/eu/siacs/conversations/Downloader.java +++ /dev/null @@ -1,62 +0,0 @@ -package eu.siacs.conversations; - -import org.bouncycastle.crypto.engines.AESEngine; -import org.bouncycastle.crypto.io.CipherOutputStream; -import org.bouncycastle.crypto.modes.AEADBlockCipher; -import org.bouncycastle.crypto.modes.GCMBlockCipher; -import org.bouncycastle.crypto.params.AEADParameters; -import org.bouncycastle.crypto.params.KeyParameter; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.HttpURLConnection; -import java.net.URL; - -public class Downloader { - - public static void main(String[] args) { - if (args.length != 1) { - System.err.println("Usage: java -jar ImageDownloader.jar https://url.tld/filename#C0FFEBABE"); - } else { - try { - final URL url = new URL(args[0]); - OutputStream os = setupOutputStream(new PrintStream(System.out), url.getRef()); - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - InputStream inputStream = connection.getInputStream(); - connection.connect(); - byte[] buffer = new byte[4096]; - int count; - while ((count = inputStream.read(buffer)) != -1) { - os.write(buffer, 0, count); - } - } catch (Exception e) { - System.err.println("could not connect to host "+e.getMessage()); - } - } - } - - private static OutputStream setupOutputStream(OutputStream os, String reference) { - if (reference != null && reference.length() == 96) { - byte[] keyAndIv = hexToBytes(reference); - byte[] key = new byte[32]; - byte[] iv = new byte[16]; - System.arraycopy(keyAndIv, 0, iv, 0, 16); - System.arraycopy(keyAndIv, 16, key, 0, 32); - AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine()); - cipher.init(false, new AEADParameters(new KeyParameter(key), 128, iv)); - return new CipherOutputStream(os, cipher); - } else { - return os; - } - } - - private static byte[] hexToBytes(String hex) { - int len = hex.length(); - byte[] array = new byte[len / 2]; - for (int i = 0; i < len; i += 2) { - array[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); - } - return array; - } -}