Skip to content

Commit

Permalink
Update to v1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
simmac committed Feb 28, 2016
1 parent 84bd092 commit d28f0d0
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 142 deletions.
112 changes: 17 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <privateKey> <publicKey>
```

java -jar threema-msgapi-tool.jar -e <privateKey> <publicKey>
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 <privateKey> <publicKey> <nonce>
```

java -jar threema-msgapi-tool.jar -d <privateKey> <publicKey> <nonce>
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 <email>
```

java -jar threema-msgapi-tool.jar -h -e <email>
Hash an email address for identity lookup. Prints the hash in hex.

####Hash Phone Number

```shell
java -jar threema-msgapi-tool.jar -h -p <phoneNo>
```

java -jar threema-msgapi-tool.jar -h -p <phoneNo>
Hash a phone number for identity lookup. Prints the hash in hex.

####Generate Key Pair

```shell
java -jar threema-msgapi-tool.jar -g <privateKeyFile> <publicKeyPath>
```

java -jar threema-msgapi-tool.jar -g <privateKeyFile> <publicKeyPath>
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 <privateKey>
```

java -jar threema-msgapi-tool.jar -p <privateKey>
Derive the public key that corresponds with the given private key.

###Network operations
####Send Simple Message

```shell
java -jar threema-msgapi-tool.jar -s <to> <from> <secret>
```

java -jar threema-msgapi-tool.jar -s <to> <from> <secret>
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 <to> <from> <secret> <privateKey>
```

java -jar threema-msgapi-tool.jar -S <to> <from> <secret> <privateKey>
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 <to> <from> <secret> <privateKey> <imageFilePath>
```

java -jar threema-msgapi-tool.jar -S -i <to> <from> <secret> <privateKey> <imageFilePath>
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 <to> <from> <secret> <privateKey> <file> [thumbnail]
```

java -jar threema-msgapi-tool.jar -S -f <to> <from> <secret> <privateKey> <file> [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 <email> <from> <secret>
```

java -jar threema-msgapi-tool.jar -l -e <email> <from> <secret>
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 <phoneNo> <from> <secret>
```

java -jar threema-msgapi-tool.jar -l -p <phoneNo> <from> <secret>
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 <id> <from> <secret>
```

java -jar threema-msgapi-tool.jar -l -k <id> <from> <secret>
Lookup the public key for the given ID.

####Fetch Capability

```shell
java -jar threema-msgapi-tool.jar -c <id> <from> <secret>
```

java -jar threema-msgapi-tool.jar -c <id> <from> <secret>
Fetch the capability of a Threema ID

####Decrypt and download

```shell
java -jar threema-msgapi-tool.jar -D <id> <from> <secret> <privateKey> <messageId> <nonce> [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 <from> <secret>
```

Fetch remaining credits
java -jar threema-msgapi-tool.jar -D <id> <from> <secret> <privateKey> <messageId> <nonce> [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
63 changes: 20 additions & 43 deletions source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,16 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

<groupId>ch.threema.apitool</groupId>
<artifactId>msgapi-sdk-java</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>
<name>Threema MsgApi SDK</name>

<issueManagement>
<system>github issues</system>
<url>https://github.com/threema-ch/threema-msgapi-sdk-java/issues</url>
</issueManagement>

<properties>
<source.encoding>UTF-8</source.encoding>
<project.build.sourceEncoding>${source.encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${source.encoding}</project.reporting.outputEncoding>
</properties>

<scm>
<connection>scm:https://github.com/threema-ch/threema-msgapi-sdk-java.git</connection>
<developerConnection>scm:git:[email protected]:threema-ch/threema-msgapi-sdk-java.git</developerConnection>
<url>https://github.com/threema-ch/threema-msgapi-sdk-java</url>
</scm>

<organization>
<name>Threema GmbH, Staldenbachstrasse 11, 8808 Pfäffikon SZ, Schweiz</name>
<url>https://www.threema.ch</url>
Expand Down Expand Up @@ -78,54 +60,49 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>${source.encoding}</encoding>
</configuration>
</plugin>

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>${source.encoding}</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>ch.threema.apitool.ConsoleMain</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>ch.threema.apitool.Console</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- dependencies to jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<archive>
<manifest>
<mainClass>ch.threema.apitool.ConsoleMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
<goal>assembly</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
4 changes: 4 additions & 0 deletions source/src/main/java/ch/threema/apitool/APIConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ public byte[] lookupKey(String id) throws IOException {
Map<String, String> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/src/main/java/ch/threema/apitool/CryptTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d28f0d0

Please sign in to comment.