SES-3053 Send only the first 32 bytes of admin key as promotion message (#860)

pull/1710/head
SessionHero01 5 months ago committed by GitHub
parent 0876f872c1
commit 8cc85337dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -501,7 +501,7 @@ class GroupManagerV2Impl @Inject constructor(
GroupUpdateMessage.newBuilder() GroupUpdateMessage.newBuilder()
.setPromoteMessage( .setPromoteMessage(
DataMessage.GroupUpdatePromoteMessage.newBuilder() DataMessage.GroupUpdatePromoteMessage.newBuilder()
.setGroupIdentitySeed(ByteString.copyFrom(adminKey)) .setGroupIdentitySeed(ByteString.copyFrom(adminKey).substring(0, 32))
.setName(groupName) .setName(groupName)
) )
.build() .build()
@ -693,7 +693,7 @@ class GroupManagerV2Impl @Inject constructor(
handleInvitation( handleInvitation(
groupId = groupId, groupId = groupId,
groupName = groupName, groupName = groupName,
authDataOrAdminKey = authData, authDataOrAdminSeed = authData,
fromPromotion = false, fromPromotion = false,
inviter = inviter, inviter = inviter,
inviterName = inviterName, inviterName = inviterName,
@ -721,7 +721,7 @@ class GroupManagerV2Impl @Inject constructor(
handleInvitation( handleInvitation(
groupId = groupId, groupId = groupId,
groupName = groupName, groupName = groupName,
authDataOrAdminKey = adminKey, authDataOrAdminSeed = adminKey,
fromPromotion = true, fromPromotion = true,
inviter = promoter, inviter = promoter,
inviterName = promoterName, inviterName = promoterName,
@ -759,7 +759,7 @@ class GroupManagerV2Impl @Inject constructor(
* *
* @param groupId the group ID * @param groupId the group ID
* @param groupName the group name * @param groupName the group name
* @param authDataOrAdminKey the auth data or admin key. If this is an invitation, this is the auth data, if this is a promotion, this is the admin key. * @param authDataOrAdminSeed the auth data or admin key. If this is an invitation, this is the auth data, if this is a promotion, this is the admin key.
* @param fromPromotion true if this is a promotion, false if this is an invitation * @param fromPromotion true if this is a promotion, false if this is an invitation
* @param inviter the invite message sender * @param inviter the invite message sender
* @return The newly created group info if the invitation is processed, null otherwise. * @return The newly created group info if the invitation is processed, null otherwise.
@ -767,7 +767,7 @@ class GroupManagerV2Impl @Inject constructor(
private suspend fun handleInvitation( private suspend fun handleInvitation(
groupId: AccountId, groupId: AccountId,
groupName: String, groupName: String,
authDataOrAdminKey: ByteArray, authDataOrAdminSeed: ByteArray,
fromPromotion: Boolean, fromPromotion: Boolean,
inviter: AccountId, inviter: AccountId,
inviterName: String?, inviterName: String?,
@ -781,8 +781,8 @@ class GroupManagerV2Impl @Inject constructor(
storage.getRecipientApproved(Address.fromSerialized(inviter.hexString)) storage.getRecipientApproved(Address.fromSerialized(inviter.hexString))
val closedGroupInfo = GroupInfo.ClosedGroupInfo( val closedGroupInfo = GroupInfo.ClosedGroupInfo(
groupAccountId = groupId, groupAccountId = groupId,
adminKey = authDataOrAdminKey.takeIf { fromPromotion }, adminKey = authDataOrAdminSeed.takeIf { fromPromotion }?.let { GroupInfo.ClosedGroupInfo.adminKeyFromSeed(it) },
authData = authDataOrAdminKey.takeIf { !fromPromotion }, authData = authDataOrAdminSeed.takeIf { !fromPromotion },
priority = PRIORITY_VISIBLE, priority = PRIORITY_VISIBLE,
invited = !shouldAutoApprove, invited = !shouldAutoApprove,
name = groupName, name = groupName,

@ -1,6 +1,8 @@
#include "user_groups.h" #include "user_groups.h"
#include "oxenc/hex.h" #include "oxenc/hex.h"
#include "session/ed25519.hpp"
extern "C" extern "C"
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_network_loki_messenger_libsession_1util_util_GroupInfo_00024LegacyGroupInfo_00024Companion_NAME_1MAX_1LENGTH( Java_network_loki_messenger_libsession_1util_util_GroupInfo_00024LegacyGroupInfo_00024Companion_NAME_1MAX_1LENGTH(
@ -324,3 +326,21 @@ Java_network_loki_messenger_libsession_1util_UserGroupsConfig_eraseClosedGroup(J
env->ReleaseStringUTFChars(session_id, session_id_bytes); env->ReleaseStringUTFChars(session_id, session_id_bytes);
return return_value; return return_value;
} }
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_util_GroupInfo_00024ClosedGroupInfo_adminKeyFromSeed(
JNIEnv *env, jclass clazz, jbyteArray seed) {
auto len = env->GetArrayLength(seed);
if (len != 32) {
env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "Seed must be 32 bytes");
return nullptr;
}
auto seed_bytes = env->GetByteArrayElements(seed, nullptr);
auto admin_key = session::ed25519::ed25519_key_pair(
session::ustring_view(reinterpret_cast<unsigned char *>(seed_bytes), 32)).second;
env->ReleaseByteArrayElements(seed, seed_bytes, 0);
return util::bytes_from_ustring(env, session::ustring_view(admin_key.data(), admin_key.size()));
}

@ -17,7 +17,6 @@ sealed class GroupInfo {
val destroyed: Boolean, val destroyed: Boolean,
val joinedAtSecs: Long val joinedAtSecs: Long
): GroupInfo() { ): GroupInfo() {
init { init {
require(adminKey == null || adminKey.isNotEmpty()) { require(adminKey == null || adminKey.isNotEmpty()) {
"Admin key must be non-empty if present" "Admin key must be non-empty if present"
@ -29,6 +28,17 @@ sealed class GroupInfo {
} }
fun hasAdminKey() = adminKey != null fun hasAdminKey() = adminKey != null
companion object {
/**
* Generate the group's admin key(64 bytes) from seed (32 bytes, normally used
* in group promotions).
*
* Use of JvmStatic makes the JNI signature less esoteric.
*/
@JvmStatic
external fun adminKeyFromSeed(seed: ByteArray): ByteArray
}
} }
data class LegacyGroupInfo( data class LegacyGroupInfo(

Loading…
Cancel
Save