diff --git a/README.md b/README.md index 6f6b902..c74b863 100644 --- a/README.md +++ b/README.md @@ -1,143 +1,65 @@ -**Dear visitor** - -**This repository is no longer maintained.** - -**To download the latest version of the Threema Getway SDK please go to:** - -https://gateway.threema.ch/en/developer/sdk-java - - # msgapi-sdk-java -Version: 1.1.2 +Version: 1.1.3 ## Console client usage ###Local operations (no network communication) ####Encrypt - -```shell -java -jar threema-msgapi-tool.jar -e -``` - + java -jar threema-msgapi-tool.jar -e Encrypt standard input using the given sender private key and recipient public key. Prints two lines to standard output: first the nonce (hex), and then the box (hex). ####Decrypt - -```shell -java -jar threema-msgapi-tool.jar -d -``` - + java -jar threema-msgapi-tool.jar -d Decrypt standard input using the given recipient private key and sender public key. The nonce must be given on the command line, and the box (hex) on standard input. Prints the decrypted message to standard output. ####Hash Email Address - -```shell -java -jar threema-msgapi-tool.jar -h -e -``` - + java -jar threema-msgapi-tool.jar -h -e Hash an email address for identity lookup. Prints the hash in hex. ####Hash Phone Number - -```shell -java -jar threema-msgapi-tool.jar -h -p -``` - + java -jar threema-msgapi-tool.jar -h -p Hash a phone number for identity lookup. Prints the hash in hex. ####Generate Key Pair - -```shell -java -jar threema-msgapi-tool.jar -g -``` - + java -jar threema-msgapi-tool.jar -g Generate a new key pair and write the private and public keys to the respective files (in hex). ####Derive Public Key - -```shell -java -jar threema-msgapi-tool.jar -p -``` - + java -jar threema-msgapi-tool.jar -p Derive the public key that corresponds with the given private key. ###Network operations ####Send Simple Message - -```shell -java -jar threema-msgapi-tool.jar -s -``` - + java -jar threema-msgapi-tool.jar -s Send a message from standard input with server-side encryption to the given ID. 'from' is the API identity and 'secret' is the API secret. Returns the message ID on success. ####Send End-to-End Encrypted Text Message - -```shell -java -jar threema-msgapi-tool.jar -S -``` - + java -jar threema-msgapi-tool.jar -S Encrypt standard input and send the message to the given ID. 'from' is the API identity and 'secret' is the API secret. Prints the message ID on success. ####Send End-to-End Encrypted Image Message - -```shell -java -jar threema-msgapi-tool.jar -S -i -``` - + java -jar threema-msgapi-tool.jar -S -i Encrypt standard input and send the message to the given ID. 'from' is the API identity and 'secret' is the API secret. Prints the message ID on success. ####Send End-to-End Encrypted File Message - -```shell -java -jar threema-msgapi-tool.jar -S -f [thumbnail] -``` - + java -jar threema-msgapi-tool.jar -S -f [thumbnail] Encrypt the file (and thumbnail) and send a file message to the given ID. 'from' is the API identity and 'secret' is the API secret. Prints the message ID on success. ####ID Lookup By Email Address - -```shell -java -jar threema-msgapi-tool.jar -l -e -``` - + java -jar threema-msgapi-tool.jar -l -e Lookup the ID linked to the given email address (will be hashed locally). ####ID Lookup By Phone Number - -```shell -java -jar threema-msgapi-tool.jar -l -p -``` - + java -jar threema-msgapi-tool.jar -l -p Lookup the ID linked to the given phone number (will be hashed locally). ####Fetch Public Key - -```shell -java -jar threema-msgapi-tool.jar -l -k -``` - + java -jar threema-msgapi-tool.jar -l -k Lookup the public key for the given ID. ####Fetch Capability - -```shell -java -jar threema-msgapi-tool.jar -c -``` - + java -jar threema-msgapi-tool.jar -c Fetch the capability of a Threema ID ####Decrypt and download - -```shell -java -jar threema-msgapi-tool.jar -D [outputFolder] -``` - -Decrypt a box (box from the stdin) message and download (if the message is a image or file message) the file(s) to the defined directory - - -#### Remaining credits - -```shell -java -jar threema-msgapi-tool.jar -C -``` - -Fetch remaining credits + java -jar threema-msgapi-tool.jar -D [outputFolder] +Decrypt a box (box from the stdin) message and download (if the message is a image or file message) the file(s) to the defined directory \ No newline at end of file diff --git a/source/pom.xml b/source/pom.xml index e3917f8..d1d30c9 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -4,34 +4,16 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.sonatype.oss - oss-parent - 7 - - ch.threema.apitool msgapi-sdk-java - 1.1.2 + 1.1.3 Threema MsgApi SDK - - - github issues - https://github.com/threema-ch/threema-msgapi-sdk-java/issues - - UTF-8 ${source.encoding} ${source.encoding} - - scm:https://github.com/threema-ch/threema-msgapi-sdk-java.git - scm:git:git@github.com:threema-ch/threema-msgapi-sdk-java.git - https://github.com/threema-ch/threema-msgapi-sdk-java - - Threema GmbH, Staldenbachstrasse 11, 8808 Pfäffikon SZ, Schweiz https://www.threema.ch @@ -78,18 +60,10 @@ org.apache.maven.plugins maven-compiler-plugin 3.3 - - 8 - 8 - ${source.encoding} - - - - - maven-resources-plugin - 2.5 ${source.encoding} + 1.8 + 1.8 @@ -97,35 +71,38 @@ org.apache.maven.plugins maven-jar-plugin - 2.3.1 + 2.6 true lib/ - ch.threema.apitool.ConsoleMain - true + ch.threema.apitool.Console + - org.apache.maven.plugins - maven-dependency-plugin - 2.1 + maven-assembly-plugin + 2.5.4 + + + + ch.threema.apitool.ConsoleMain + + + + jar-with-dependencies + + - copy-dependencies + make-assembly package - copy-dependencies + assembly - - ${project.build.directory}/lib - false - false - true - diff --git a/source/src/main/java/ch/threema/apitool/APIConnector.java b/source/src/main/java/ch/threema/apitool/APIConnector.java index 8fa524b..a310191 100644 --- a/source/src/main/java/ch/threema/apitool/APIConnector.java +++ b/source/src/main/java/ch/threema/apitool/APIConnector.java @@ -170,6 +170,10 @@ public byte[] lookupKey(String id) throws IOException { Map getParams = makeRequestParams(); String pubkeyHex = doGet(new URL(this.apiUrl + "pubkeys/" + id), getParams); key = DataUtils.hexStringToByteArray(pubkeyHex); + + if(key != null) { + this.publicKeyStore.save(id, key); + } } catch (FileNotFoundException e) { return null; } diff --git a/source/src/main/java/ch/threema/apitool/CryptTool.java b/source/src/main/java/ch/threema/apitool/CryptTool.java index 2263c89..688a798 100644 --- a/source/src/main/java/ch/threema/apitool/CryptTool.java +++ b/source/src/main/java/ch/threema/apitool/CryptTool.java @@ -243,7 +243,7 @@ public static ThreemaMessage decryptMessage(byte[] box, byte[] recipientPrivate System.arraycopy(data, 1, blobId, 0, ThreemaMessage.BLOB_ID_LEN); int size = EndianUtils.readSwappedInteger(data, 1 + ThreemaMessage.BLOB_ID_LEN); byte[] fileNonce = new byte[NaCl.NONCEBYTES]; - System.arraycopy(data, 1 + 4 + ThreemaMessage.BLOB_ID_LEN, nonce, 0, nonce.length); + System.arraycopy(data, 1 + 4 + ThreemaMessage.BLOB_ID_LEN, fileNonce, 0, nonce.length); return new ImageMessage(blobId, size, fileNonce); diff --git a/source/src/main/java/ch/threema/apitool/PublicKeyStore.java b/source/src/main/java/ch/threema/apitool/PublicKeyStore.java index 54f5cb7..741a0a0 100644 --- a/source/src/main/java/ch/threema/apitool/PublicKeyStore.java +++ b/source/src/main/java/ch/threema/apitool/PublicKeyStore.java @@ -47,7 +47,7 @@ public final byte[] getPublicKey(String threemaId) { if (pk == null) { pk = this.fetchPublicKey(threemaId); - this.setPublicKey(threemaId, pk); + this.cache.put(threemaId, pk); } return pk; } diff --git a/source/src/main/java/ch/threema/apitool/console/commands/fields/PublicKeyField.java b/source/src/main/java/ch/threema/apitool/console/commands/fields/PublicKeyField.java index 7a97dac..42b8c5a 100644 --- a/source/src/main/java/ch/threema/apitool/console/commands/fields/PublicKeyField.java +++ b/source/src/main/java/ch/threema/apitool/console/commands/fields/PublicKeyField.java @@ -35,7 +35,7 @@ public byte[] getValue() throws InvalidKeyException { try { return this.readKey(this.value, Key.KeyType.PUBLIC); } catch (Exception e) { - throw new InvalidKeyException("invalid private key"); + throw new InvalidKeyException("invalid public key"); } } } diff --git a/source/src/main/java/ch/threema/apitool/helpers/E2EHelper.java b/source/src/main/java/ch/threema/apitool/helpers/E2EHelper.java index 9f955b4..cd298a9 100644 --- a/source/src/main/java/ch/threema/apitool/helpers/E2EHelper.java +++ b/source/src/main/java/ch/threema/apitool/helpers/E2EHelper.java @@ -267,7 +267,7 @@ public ReceiveMessageResult receiveMessage(String threemaId, String messageId, b throw new MessageParseException(); } - byte[] decryptedFileContent = CryptTool.decrypt(fileData, privateKey, publicKey, nonce); + byte[] decryptedFileContent = CryptTool.decrypt(fileData, privateKey, publicKey, imageMessage.getNonce()); File imageFile = new File(outputFolder.toString() + "/" + messageId + ".jpg"); FileOutputStream fos = new FileOutputStream(imageFile); fos.write(decryptedFileContent);