Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from wireapp/update-cryptobox-c
Browse files Browse the repository at this point in the history
Update Cryptobox C
  • Loading branch information
marcoconti83 authored Jul 5, 2019
2 parents 031c8c1 + 90d8ed6 commit a6b7522
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ JNI bindings for the [cryptobox](https://github.com/wireapp/cryptobox) with supp

## Building

### Host Architecture
### Host Architecture

Besides common OS-specific development tooling, the following prerequisites
are needed to build for the host architecture:

* A Rust compiler (1.12.1 or newer).
* A Rust compiler (1.16.0).
* A Java compiler (1.6 or later).

With that in place
Expand All @@ -28,7 +28,7 @@ will leave a tarball in the `dist` directory containing all the binaries for
your host architecture in the form of shared libraries, as well as a `.jar`
file and the corresponding `javadoc` output.

### Android
### Android

Besides common OS-specific development tooling, the following prerequisites
are needed to build for Android:
Expand All @@ -44,7 +44,7 @@ are needed to build for Android:

* A Java compiler (1.6 or later).

* A Rust compiler (1.12.1 or newer) that can cross-compile to the following
* A Rust compiler (1.16.0) that can cross-compile to the following
targets corresponding to the aforementioned NDK standalone toolchains:
* `armv7-linux-androideabi`
* `aarch64-linux-android`
Expand Down Expand Up @@ -88,6 +88,17 @@ With the prerequisites in place, the Android build can be run with:
The distribution artifacts will be in the `android/dist` directory, which includes
an [Android Library Archive](http://tools.android.com/tech-docs/new-build-system/aar-format) (`.aar`).

If [Maven](https://maven.apache.org) is installed (availble on [homebrew](https://formulae.brew.sh/formula/maven)), you can publish the aar to a your local Maven repository with the command:

```
mvn install:install-file \
-Dfile="<path to aar>" \
-DgroupId=com.wire \
-DartifactId=cryptobox-android \
-Dpackaging=aar \
-Dversion=<version number>
```

### Windows

You need:
Expand Down
7 changes: 6 additions & 1 deletion android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ include ../mk/version.mk
# cf. https://github.com/alexcrichton/pkg-config-rs/blob/master/src/lib.rs#L12
export PKG_CONFIG_ALLOW_CROSS=1

# Hint for sodiumoxide to find the precompiled libsodium library
# See the README at https://github.com/sodiumoxide/sodiumoxide
export SODIUM_LIB_DIR="./libs"

.PHONY: all
all: compile

.PHONY: clean
clean:
$(ANDROID_NDK_HOME)/ndk-build clean || true
rm -rf libs

.PHONY: compile
compile: cryptobox
Expand Down Expand Up @@ -69,7 +74,7 @@ dist/cryptobox-android-$(VERSION).aar: dist-libs dist-jar
dist-aar: dist/cryptobox-android-$(VERSION).aar

.PHONY: dist
dist: dist-tar dist-aar
dist: compile dist-tar dist-aar

#############################################################################
# cryptobox
Expand Down
2 changes: 1 addition & 1 deletion mk/cryptobox-src.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CRYPTOBOX_VERSION := develop
CRYPTOBOX_VERSION := v1.1.1
CRYPTOBOX_NAME := cryptobox-$(CRYPTOBOX_VERSION)
CRYPTOBOX_GIT_URL := https://github.com/wireapp/cryptobox-c.git

Expand Down
2 changes: 1 addition & 1 deletion mk/libsodium-src.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LIBSODIUM_VERSION := 1.0.11
LIBSODIUM_VERSION := 1.0.16
LIBSODIUM_NAME := libsodium-$(LIBSODIUM_VERSION)
LIBSODIUM_URL := http://download.libsodium.org/libsodium/releases/$(LIBSODIUM_NAME).tar.gz

Expand Down
2 changes: 1 addition & 1 deletion mk/version.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION := 1.0.0
VERSION := 1.1.0
41 changes: 30 additions & 11 deletions src/cryptobox-jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ cboxjni_close(JNIEnv * j_env, jclass j_class, jlong j_ptr) {
cbox_close(cbox);
}

JNIEXPORT jbyteArray JNICALL
cboxjni_get_fingerprint_from_prekey(JNIEnv * j_env, jclass j_class, jbyteArray j_prekey) {
size_t prekey_len = (*j_env)->GetArrayLength(j_env, j_prekey);
jbyte * prekey = (*j_env)->GetByteArrayElements(j_env, j_prekey, NULL);

CBoxVec * fp = NULL;
CBoxResult rc = cbox_fingerprint_prekey((uint8_t *) prekey, prekey_len, &fp);

(*j_env)->ReleaseByteArrayElements(j_env, j_prekey, prekey, JNI_ABORT);

if (rc != CBOX_SUCCESS) {
cboxjni_throw(j_env, rc);
return NULL;
}

return cboxjni_vec2arr(j_env, fp);
}

JNIEXPORT jobject JNICALL
cboxjni_new_last_prekey(JNIEnv * j_env, jclass j_class, jlong j_ptr) {
#ifdef CBOXJNI_ANDROID_DEBUG
Expand Down Expand Up @@ -487,17 +505,18 @@ cboxjni_remote_fingerprint(JNIEnv * j_env, jclass j_class, jlong j_ptr) {
// Bookkeeping //////////////////////////////////////////////////////////////

static JNINativeMethod cboxjni_box_methods[] = {
{ "jniOpen" , "(Ljava/lang/String;)Lcom/wire/cryptobox/CryptoBox;" , (void *) cboxjni_open },
{ "jniOpenWith" , "(Ljava/lang/String;[BI)Lcom/wire/cryptobox/CryptoBox;" , (void *) cboxjni_open_with },
{ "jniClose" , "(J)V" , (void *) cboxjni_close },
{ "jniNewPreKeys" , "(JII)[Lcom/wire/cryptobox/PreKey;" , (void *) cboxjni_new_prekeys },
{ "jniNewLastPreKey" , "(J)Lcom/wire/cryptobox/PreKey;" , (void *) cboxjni_new_last_prekey },
{ "jniGetLocalFingerprint" , "(J)[B" , (void *) cboxjni_local_fingerprint },
{ "jniCopyIdentity" , "(J)[B" , (void *) cboxjni_copy_identity },
{ "jniInitSessionFromPreKey" , "(JLjava/lang/String;[B)Lcom/wire/cryptobox/CryptoSession;" , (void *) cboxjni_init_from_prekey },
{ "jniInitSessionFromMessage", "(JLjava/lang/String;[B)Lcom/wire/cryptobox/SessionMessage;" , (void *) cboxjni_init_from_message },
{ "jniLoadSession" , "(JLjava/lang/String;)Lcom/wire/cryptobox/CryptoSession;" , (void *) cboxjni_session_load },
{ "jniDeleteSession" , "(JLjava/lang/String;)V" , (void *) cboxjni_session_delete }
{ "jniOpen" , "(Ljava/lang/String;)Lcom/wire/cryptobox/CryptoBox;" , (void *) cboxjni_open },
{ "jniOpenWith" , "(Ljava/lang/String;[BI)Lcom/wire/cryptobox/CryptoBox;" , (void *) cboxjni_open_with },
{ "jniClose" , "(J)V" , (void *) cboxjni_close },
{ "jniGetFingerprintFromPrekey", "([B)[B" , (void *) cboxjni_get_fingerprint_from_prekey },
{ "jniNewPreKeys" , "(JII)[Lcom/wire/cryptobox/PreKey;" , (void *) cboxjni_new_prekeys },
{ "jniNewLastPreKey" , "(J)Lcom/wire/cryptobox/PreKey;" , (void *) cboxjni_new_last_prekey },
{ "jniGetLocalFingerprint" , "(J)[B" , (void *) cboxjni_local_fingerprint },
{ "jniCopyIdentity" , "(J)[B" , (void *) cboxjni_copy_identity },
{ "jniInitSessionFromPreKey" , "(JLjava/lang/String;[B)Lcom/wire/cryptobox/CryptoSession;" , (void *) cboxjni_init_from_prekey },
{ "jniInitSessionFromMessage" , "(JLjava/lang/String;[B)Lcom/wire/cryptobox/SessionMessage;" , (void *) cboxjni_init_from_message },
{ "jniLoadSession" , "(JLjava/lang/String;)Lcom/wire/cryptobox/CryptoSession;" , (void *) cboxjni_session_load },
{ "jniDeleteSession" , "(JLjava/lang/String;)V" , (void *) cboxjni_session_delete }
};

static JNINativeMethod cboxjni_sess_methods[] = {
Expand Down
10 changes: 10 additions & 0 deletions src/java/com/wire/cryptobox/CryptoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ public static CryptoBox openWith(String dir, byte[] id, IdentityMode mode) throw
}
}

/**
* Get the public key fingerprint from a prekey.
*
* @return The HEX encoded fingerprint.
*/
public static byte[] getFingerprintFromPrekey(PreKey preKey) throws CryptoException {
return jniGetFingerprintFromPrekey(preKey.data);
}

/**
* Copy the long-term identity from this <tt>CryptoBox</tt>.
*
Expand Down Expand Up @@ -344,6 +353,7 @@ private void errorIfClosed() {

private native static CryptoBox jniOpen(String dir) throws CryptoException;
private native static CryptoBox jniOpenWith(String dir, byte[] id, int mode) throws CryptoException;
private native static byte[] jniGetFingerprintFromPrekey(byte[] prekey) throws CryptoException;
private native static PreKey jniNewLastPreKey(long ptr) throws CryptoException;
private native static PreKey[] jniNewPreKeys(long ptr, int start, int num) throws CryptoException;
private native static byte[] jniGetLocalFingerprint(long ptr) throws CryptoException;
Expand Down

0 comments on commit a6b7522

Please sign in to comment.