From 3d87de4b56c848cf47a04c9509e93a4ef96f6042 Mon Sep 17 00:00:00 2001 From: Brice Date: Thu, 3 Dec 2020 14:29:50 +1100 Subject: [PATCH] SessionRequest implementation completed --- .../libsession/messaging/StorageProtocol.kt | 4 ++++ .../messages/control/unused/SessionRequest.kt | 24 ++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libsession/src/main/java/org/session/libsession/messaging/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/messaging/StorageProtocol.kt index a2ac740bbf..75702b6191 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/StorageProtocol.kt @@ -17,6 +17,10 @@ interface StorageProtocol { fun getUserProfileKey(): ByteArray? fun getUserProfilePictureURL(): String? + // Signal Protocol + + fun getOrGenerateRegistrationID(): Int //TODO needs impl + // Shared Sender Keys fun getClosedGroupPrivateKey(publicKey: String): ECPrivateKey? fun isClosedGroup(publicKey: String): Boolean diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt index b078ce5545..07bed84988 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/control/unused/SessionRequest.kt @@ -1,9 +1,10 @@ package org.session.libsession.messaging.messages.control.unused import com.google.protobuf.ByteString +import org.session.libsession.messaging.Configuration import org.session.libsession.messaging.messages.control.ControlMessage -import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate -import org.session.libsession.messaging.messages.control.TypingIndicator +import org.session.libsignal.libsignal.IdentityKey +import org.session.libsignal.libsignal.ecc.DjbECPublicKey import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.libsignal.state.PreKeyBundle import org.session.libsignal.service.internal.push.SignalServiceProtos @@ -19,8 +20,9 @@ class SessionRequest() : ControlMessage() { fun fromProto(proto: SignalServiceProtos.Content): SessionRequest? { if (proto.nullMessage == null) return null val preKeyBundleProto = proto.preKeyBundleMessage ?: return null - val registrationID: Int = 0 - //TODO looks like database stuff here + var registrationID: Int = 0 + registrationID = Configuration.shared.storage.getOrGenerateRegistrationID() //TODO no implementation for getOrGenerateRegistrationID yet + //TODO just confirm if the above code does the equivalent to swift below: /*iOS code: Configuration.shared.storage.with { transaction in registrationID = Configuration.shared.storage.getOrGenerateRegistrationID(using: transaction) }*/ @@ -28,11 +30,11 @@ class SessionRequest() : ControlMessage() { registrationID, 1, preKeyBundleProto.preKeyId, - null, //TODO preKeyBundleProto.preKey, - 0, //TODO preKeyBundleProto.signedKey, - null, //TODO preKeyBundleProto.signedKeyId, + DjbECPublicKey(preKeyBundleProto.preKey.toByteArray()), + preKeyBundleProto.signedKeyId, + DjbECPublicKey(preKeyBundleProto.signedKey.toByteArray()), preKeyBundleProto.signature.toByteArray(), - null, //TODO preKeyBundleProto.identityKey + IdentityKey(DjbECPublicKey(preKeyBundleProto.identityKey.toByteArray())) ) return SessionRequest(preKeyBundle) } @@ -61,12 +63,12 @@ class SessionRequest() : ControlMessage() { val padding = ByteArray(paddingSize) nullMessageProto.padding = ByteString.copyFrom(padding) val preKeyBundleProto = SignalServiceProtos.PreKeyBundleMessage.newBuilder() - //TODO preKeyBundleProto.identityKey = preKeyBundle.identityKey + preKeyBundleProto.identityKey = ByteString.copyFrom(preKeyBundle.identityKey.publicKey.serialize()) preKeyBundleProto.deviceId = preKeyBundle.deviceId preKeyBundleProto.preKeyId = preKeyBundle.preKeyId - //TODO preKeyBundleProto.preKey = preKeyBundle.preKeyPublic + preKeyBundleProto.preKey = ByteString.copyFrom(preKeyBundle.preKey.serialize()) preKeyBundleProto.signedKeyId = preKeyBundle.signedPreKeyId - //TODO preKeyBundleProto.signedKey = preKeyBundle.signedPreKeyPublic + preKeyBundleProto.signedKey = ByteString.copyFrom(preKeyBundle.signedPreKey.serialize()) preKeyBundleProto.signature = ByteString.copyFrom(preKeyBundle.signedPreKeySignature) val contentProto = SignalServiceProtos.Content.newBuilder() try {