diff --git a/source/src/main/java/ch/threema/apitool/APIConnector.java b/source/src/main/java/ch/threema/apitool/APIConnector.java index a310191..8e075ce 100644 --- a/source/src/main/java/ch/threema/apitool/APIConnector.java +++ b/source/src/main/java/ch/threema/apitool/APIConnector.java @@ -249,6 +249,7 @@ public UploadResult uploadFile(EncryptResult fileEncryptionResult) throws IOExc request.write(fileEncryptionResult.getResult()); request.writeBytes(crlf); request.writeBytes(twoHyphens + boundary + twoHyphens + crlf); + request.close(); String response = null; int responseCode = connection.getResponseCode(); diff --git a/source/src/main/java/ch/threema/apitool/ConsoleMain.java b/source/src/main/java/ch/threema/apitool/ConsoleMain.java index 469e815..b5c0887 100644 --- a/source/src/main/java/ch/threema/apitool/ConsoleMain.java +++ b/source/src/main/java/ch/threema/apitool/ConsoleMain.java @@ -110,7 +110,7 @@ static class ArgumentCommand { public void run(String[] givenArguments) throws Exception { if(givenArguments.length < this.arguments.length) { - throw new Exception("invalid arguments"); + throw new IllegalArgumentException("invalid arguments"); } this.command.run((String[]) ArrayUtils.subarray(givenArguments, this.arguments.length, givenArguments.length)); diff --git a/source/src/main/java/ch/threema/apitool/console/commands/Command.java b/source/src/main/java/ch/threema/apitool/console/commands/Command.java index f8e136f..594581c 100644 --- a/source/src/main/java/ch/threema/apitool/console/commands/Command.java +++ b/source/src/main/java/ch/threema/apitool/console/commands/Command.java @@ -32,7 +32,7 @@ import java.util.LinkedList; import java.util.List; -abstract public class Command { +public abstract class Command { private final List fields = new LinkedList<>(); private final String subject; private final String description; diff --git a/source/src/main/java/ch/threema/apitool/console/commands/CreditsCommand.java b/source/src/main/java/ch/threema/apitool/console/commands/CreditsCommand.java index c4b2171..23075ad 100644 --- a/source/src/main/java/ch/threema/apitool/console/commands/CreditsCommand.java +++ b/source/src/main/java/ch/threema/apitool/console/commands/CreditsCommand.java @@ -52,7 +52,7 @@ protected void execute() throws Exception { System.out.println("Remaining credits: " + credits); } else { - System.out.println("Error fetching credits");; + System.out.println("Error fetching credits"); } } } diff --git a/source/src/main/java/ch/threema/apitool/messages/FileMessage.java b/source/src/main/java/ch/threema/apitool/messages/FileMessage.java index b0eb3d2..bb4c48b 100644 --- a/source/src/main/java/ch/threema/apitool/messages/FileMessage.java +++ b/source/src/main/java/ch/threema/apitool/messages/FileMessage.java @@ -35,13 +35,13 @@ * A file message that can be sent/received with end-to-end encryption via Threema. */ public class FileMessage extends ThreemaMessage { - private final static String KEY_BLOB_ID = "b"; - private final static String KEY_THUMBNAIL_BLOB_ID = "t"; - private final static String KEY_ENCRYPTION_KEY = "k"; - private final static String KEY_MIME_TYPE = "m"; - private final static String KEY_FILE_NAME = "n"; - private final static String KEY_FILE_SIZE = "s"; - private final static String KEY_TYPE = "i"; + private static final String KEY_BLOB_ID = "b"; + private static final String KEY_THUMBNAIL_BLOB_ID = "t"; + private static final String KEY_ENCRYPTION_KEY = "k"; + private static final String KEY_MIME_TYPE = "m"; + private static final String KEY_FILE_NAME = "n"; + private static final String KEY_FILE_SIZE = "s"; + private static final String KEY_TYPE = "i"; public static final int TYPE_CODE = 0x17; diff --git a/source/src/test/java/ch/threema/apitool/Common.java b/source/src/test/java/ch/threema/apitool/Common.java index c3af9a0..2ff03cc 100644 --- a/source/src/test/java/ch/threema/apitool/Common.java +++ b/source/src/test/java/ch/threema/apitool/Common.java @@ -29,17 +29,17 @@ */ public abstract class Common { - public static final String myPrivateKey = "private:94af3260fa2a19adc8e82e82be598be15bc6ad6f47c8ee303cb185ef860e16d2"; - public static final String myPrivateKeyExtract = "94af3260fa2a19adc8e82e82be598be15bc6ad6f47c8ee303cb185ef860e16d2"; + public static final String MY_PRIVATE_KEY = "private:94af3260fa2a19adc8e82e82be598be15bc6ad6f47c8ee303cb185ef860e16d2"; + public static final String MY_PRIVATE_KEY_EXTRACT = "94af3260fa2a19adc8e82e82be598be15bc6ad6f47c8ee303cb185ef860e16d2"; - public static final String myPublicKey = "public:3851ad59c96146a05b32e41c0ccd0fd639dc8cd66bf6e1cbd3c8d67e4e8f5531"; - public static final String myPublicKeyExtract = "3851ad59c96146a05b32e41c0ccd0fd639dc8cd66bf6e1cbd3c8d67e4e8f5531"; + public static final String MY_PUBLIC_KEY = "public:3851ad59c96146a05b32e41c0ccd0fd639dc8cd66bf6e1cbd3c8d67e4e8f5531"; + public static final String MY_PUBLIC_KEY_EXTRACT = "3851ad59c96146a05b32e41c0ccd0fd639dc8cd66bf6e1cbd3c8d67e4e8f5531"; - public static final String otherPrivateKey = "private:8318e05220acd38e97ba41a9a6318688214219916075ca060f9339a6d1f7fc29"; - public static final String otherPublicKey = "public:10ac7fd937eafb806f9a05bf9afa340a99387b0063cc9cb0d1ea5505d39cc076"; + public static final String OTHER_PRIVATE_KEY = "private:8318e05220acd38e97ba41a9a6318688214219916075ca060f9339a6d1f7fc29"; + public static final String OTHER_PUBLIC_KEY = "public:10ac7fd937eafb806f9a05bf9afa340a99387b0063cc9cb0d1ea5505d39cc076"; - public static final String echochoPublicKey = "public:4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; - public static final String randomNonce = "516f4f1562dda0704a7bae8997cf0b354c6980181152ac32"; + public static final String ECHOCHO_PUBLIC_KEY = "public:4a6a1b34dcef15d43cb74de2fd36091be99fbbaf126d099d47d83d919712c72b"; + public static final String RANDOM_NONCE = "516f4f1562dda0704a7bae8997cf0b354c6980181152ac32"; public static boolean isEmpty(byte[] byteArray) { if(byteArray == null) { diff --git a/source/src/test/java/ch/threema/apitool/CryptToolTest.java b/source/src/test/java/ch/threema/apitool/CryptToolTest.java index ddb563b..3dcb742 100644 --- a/source/src/test/java/ch/threema/apitool/CryptToolTest.java +++ b/source/src/test/java/ch/threema/apitool/CryptToolTest.java @@ -59,8 +59,8 @@ public void testDecrypt() throws Exception { String nonce = "0a1ec5b67b4d61a1ef91f55e8ce0471fee96ea5d8596dfd0"; String box = "45181c7aed95a1c100b1b559116c61b43ce15d04014a805288b7d14bf3a993393264fe554794ce7d6007233e8ef5a0f1ccdd704f34e7c7b77c72c239182caf1d061d6fff6ffbbfe8d3b8f3475c2fe352e563aa60290c666b2e627761e32155e62f048b52ef2f39c13ac229f393c67811749467396ecd09f42d32a4eb419117d0451056ac18fac957c52b0cca67568e2d97e5a3fd829a77f914a1ad403c5909fd510a313033422ea5db71eaf43d483238612a54cb1ecfe55259b1de5579e67c6505df7d674d34a737edf721ea69d15b567bc2195ec67e172f3cb8d6842ca88c29138cc33e9351dbc1e4973a82e1cf428c1c763bb8f3eb57770f914a"; - Key privateKey = Key.decodeKey(Common.otherPrivateKey); - Key publicKey = Key.decodeKey(Common.myPublicKey); + Key privateKey = Key.decodeKey(Common.OTHER_PRIVATE_KEY); + Key publicKey = Key.decodeKey(Common.MY_PUBLIC_KEY); ThreemaMessage message = CryptTool.decryptMessage( DataUtils.hexStringToByteArray(box), @@ -79,8 +79,8 @@ public void testEncrypt() throws Exception { String text = "Dies ist eine Testnachricht. äöü"; String nonce = "0a1ec5b67b4d61a1ef91f55e8ce0471fee96ea5d8596dfd0"; - Key privateKey = Key.decodeKey(Common.myPrivateKey); - Key publicKey = Key.decodeKey(Common.otherPublicKey); + Key privateKey = Key.decodeKey(Common.MY_PRIVATE_KEY); + Key publicKey = Key.decodeKey(Common.OTHER_PUBLIC_KEY); EncryptResult res = CryptTool.encryptTextMessage(text, privateKey.key, publicKey.key); Assert.assertNotNull(res); @@ -92,8 +92,8 @@ public void testEncrypt() throws Exception { @Test public void testDerivePublicKey() throws Exception{ - Key privateKey = Key.decodeKey(Common.myPrivateKey); - Key publicKey = Key.decodeKey(Common.myPublicKey); + Key privateKey = Key.decodeKey(Common.MY_PRIVATE_KEY); + Key publicKey = Key.decodeKey(Common.MY_PUBLIC_KEY); byte[] derivedPublicKey = CryptTool.derivePublicKey(privateKey.key); Assert.assertNotNull("derived public key", derivedPublicKey); Assert.assertEquals(derivedPublicKey, publicKey.key); diff --git a/source/src/test/java/ch/threema/apitool/KeyTest.java b/source/src/test/java/ch/threema/apitool/KeyTest.java index 104188b..a2d3ec6 100644 --- a/source/src/test/java/ch/threema/apitool/KeyTest.java +++ b/source/src/test/java/ch/threema/apitool/KeyTest.java @@ -58,7 +58,7 @@ public void testDecodeKeyPublic() throws Exception { @Test public void testEncodePrivate() throws Exception { - byte[] keyAsByte = DataUtils.hexStringToByteArray(Common.myPrivateKeyExtract); + byte[] keyAsByte = DataUtils.hexStringToByteArray(Common.MY_PRIVATE_KEY_EXTRACT); Key key = new Key(Key.KeyType.PRIVATE, keyAsByte); Assert.assertNotNull("key instance", key); @@ -66,6 +66,6 @@ public void testEncodePrivate() throws Exception { Assert.assertEquals(Key.KeyType.PRIVATE, key.type); Assert.assertEquals(key.key, keyAsByte); - Assert.assertEquals(key.encode(), Common.myPrivateKey); + Assert.assertEquals(key.encode(), Common.MY_PRIVATE_KEY); } } \ No newline at end of file