diff --git a/libsession-util/libsession-util b/libsession-util/libsession-util index 57f6bbd91b..462e2b6808 160000 --- a/libsession-util/libsession-util +++ b/libsession-util/libsession-util @@ -1 +1 @@ -Subproject commit 57f6bbd91bb4b1f2d115b75e8beb850153bb6767 +Subproject commit 462e2b6808122919141e8636822cbf00f9f587e9 diff --git a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt index 667e76425a..4294986628 100644 --- a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt +++ b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt @@ -1,6 +1,5 @@ package network.loki.messenger.libsession_util -import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import network.loki.messenger.libsession_util.util.KeyPair @@ -20,10 +19,11 @@ import org.session.libsignal.utilities.Hex class InstrumentedTests { private val keyPair: KeyPair - get() { - val seed = Hex.fromStringCondensed("0123456789abcdef0123456789abcdef00000000000000000000000000000000") - return Sodium.ed25519KeyPair(seed) - } + get() { + val seed = + Hex.fromStringCondensed("0123456789abcdef0123456789abcdef00000000000000000000000000000000") + return Sodium.ed25519KeyPair(seed) + } @Test fun useAppContext() { @@ -51,8 +51,8 @@ class InstrumentedTests { assertNull(userProfile.getName()) // Don't need to push yet so this is just for testing - val (toPush, seqNo) = userProfile.push() - assertEquals("d1:#i0e1:&de1:get_profile_pic(); if (pic == std::nullopt) return nullptr; // return nullptr if either parameter is null as per profile class - jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/UserPic"); + jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic"); jmethodID constructor = env->GetMethodID(returnObjectClass, "", "(Ljava/lang/String;[B)V"); jstring url = env->NewStringUTF(pic->url.data()); jbyteArray byteArray = bytes_from_ustring(env, pic->key); @@ -141,7 +141,7 @@ JNIEXPORT void JNICALL Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, jobject thiz, jobject user_pic) { auto profile = ptrToProfile(env, thiz); - jclass userPicClass = env->FindClass("network/loki/messenger/libsession_util/UserPic"); + jclass userPicClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic"); jfieldID picField = env->GetFieldID(userPicClass, "url", "Ljava/lang/String;"); jfieldID keyField = env->GetFieldID(userPicClass, "key", "[B"); auto pic = (jstring)env->GetObjectField(user_pic, picField); @@ -167,14 +167,28 @@ Java_network_loki_messenger_libsession_1util_util_Sodium_ed25519KeyPair(JNIEnv * std::array ed_pk; std::array ed_sk; auto seed_bytes = ustring_from_bytes(env, seed); - crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.c_str()); + crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.data()); jclass kp_class = env->FindClass("network/loki/messenger/libsession_util/util/KeyPair"); jmethodID kp_constructor = env->GetMethodID(kp_class, "", "([B[B)V"); - jbyteArray pk_jarray = bytes_from_ustring(env, ed_pk.data()); - jbyteArray sk_jarray = bytes_from_ustring(env, ed_sk.data()); + jbyteArray pk_jarray = bytes_from_ustring(env, session::ustring_view {ed_pk.data(), ed_pk.size()}); + jbyteArray sk_jarray = bytes_from_ustring(env, session::ustring_view {ed_sk.data(), ed_sk.size()}); jobject return_obj = env->NewObject(kp_class, kp_constructor, pk_jarray, sk_jarray); return return_obj; +} +extern "C" +JNIEXPORT jstring JNICALL +Java_network_loki_messenger_libsession_1util_ConfigBase_encryptionDomain(JNIEnv *env, + jobject thiz) { + auto conf = ptrToConfigBase(env, thiz); + return env->NewStringUTF(conf->encryption_domain()); +} +extern "C" +JNIEXPORT jbyteArray JNICALL +Java_network_loki_messenger_libsession_1util_ConfigBase_decrypt(JNIEnv *env, jobject thiz, + jbyteArray encrypted) { + auto profile = ptrToProfile(env, thiz); + auto encrypted_bytes = ustring_from_bytes(env, encrypted); } \ No newline at end of file diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt index 347c221130..0d44921cf7 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt @@ -15,6 +15,8 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) { external fun needsDump(): Boolean external fun push(): ConfigWithSeqNo external fun dump(): ByteArray + external fun encryptionDomain(): String + external fun decrypt(encrypted: ByteArray): ByteArray } class UserProfile(pointer: Long): ConfigBase(pointer) {