SessionRequest implementation completed

This commit is contained in:
Brice 2020-12-03 14:29:50 +11:00
parent 69ba55138f
commit 3d87de4b56
2 changed files with 17 additions and 11 deletions

View file

@ -17,6 +17,10 @@ interface StorageProtocol {
fun getUserProfileKey(): ByteArray? fun getUserProfileKey(): ByteArray?
fun getUserProfilePictureURL(): String? fun getUserProfilePictureURL(): String?
// Signal Protocol
fun getOrGenerateRegistrationID(): Int //TODO needs impl
// Shared Sender Keys // Shared Sender Keys
fun getClosedGroupPrivateKey(publicKey: String): ECPrivateKey? fun getClosedGroupPrivateKey(publicKey: String): ECPrivateKey?
fun isClosedGroup(publicKey: String): Boolean fun isClosedGroup(publicKey: String): Boolean

View file

@ -1,9 +1,10 @@
package org.session.libsession.messaging.messages.control.unused package org.session.libsession.messaging.messages.control.unused
import com.google.protobuf.ByteString 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.ControlMessage
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate import org.session.libsignal.libsignal.IdentityKey
import org.session.libsession.messaging.messages.control.TypingIndicator import org.session.libsignal.libsignal.ecc.DjbECPublicKey
import org.session.libsignal.libsignal.logging.Log import org.session.libsignal.libsignal.logging.Log
import org.session.libsignal.libsignal.state.PreKeyBundle import org.session.libsignal.libsignal.state.PreKeyBundle
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
@ -19,8 +20,9 @@ class SessionRequest() : ControlMessage() {
fun fromProto(proto: SignalServiceProtos.Content): SessionRequest? { fun fromProto(proto: SignalServiceProtos.Content): SessionRequest? {
if (proto.nullMessage == null) return null if (proto.nullMessage == null) return null
val preKeyBundleProto = proto.preKeyBundleMessage ?: return null val preKeyBundleProto = proto.preKeyBundleMessage ?: return null
val registrationID: Int = 0 var registrationID: Int = 0
//TODO looks like database stuff here 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 /*iOS code: Configuration.shared.storage.with { transaction in
registrationID = Configuration.shared.storage.getOrGenerateRegistrationID(using: transaction) registrationID = Configuration.shared.storage.getOrGenerateRegistrationID(using: transaction)
}*/ }*/
@ -28,11 +30,11 @@ class SessionRequest() : ControlMessage() {
registrationID, registrationID,
1, 1,
preKeyBundleProto.preKeyId, preKeyBundleProto.preKeyId,
null, //TODO preKeyBundleProto.preKey, DjbECPublicKey(preKeyBundleProto.preKey.toByteArray()),
0, //TODO preKeyBundleProto.signedKey, preKeyBundleProto.signedKeyId,
null, //TODO preKeyBundleProto.signedKeyId, DjbECPublicKey(preKeyBundleProto.signedKey.toByteArray()),
preKeyBundleProto.signature.toByteArray(), preKeyBundleProto.signature.toByteArray(),
null, //TODO preKeyBundleProto.identityKey IdentityKey(DjbECPublicKey(preKeyBundleProto.identityKey.toByteArray()))
) )
return SessionRequest(preKeyBundle) return SessionRequest(preKeyBundle)
} }
@ -61,12 +63,12 @@ class SessionRequest() : ControlMessage() {
val padding = ByteArray(paddingSize) val padding = ByteArray(paddingSize)
nullMessageProto.padding = ByteString.copyFrom(padding) nullMessageProto.padding = ByteString.copyFrom(padding)
val preKeyBundleProto = SignalServiceProtos.PreKeyBundleMessage.newBuilder() val preKeyBundleProto = SignalServiceProtos.PreKeyBundleMessage.newBuilder()
//TODO preKeyBundleProto.identityKey = preKeyBundle.identityKey preKeyBundleProto.identityKey = ByteString.copyFrom(preKeyBundle.identityKey.publicKey.serialize())
preKeyBundleProto.deviceId = preKeyBundle.deviceId preKeyBundleProto.deviceId = preKeyBundle.deviceId
preKeyBundleProto.preKeyId = preKeyBundle.preKeyId preKeyBundleProto.preKeyId = preKeyBundle.preKeyId
//TODO preKeyBundleProto.preKey = preKeyBundle.preKeyPublic preKeyBundleProto.preKey = ByteString.copyFrom(preKeyBundle.preKey.serialize())
preKeyBundleProto.signedKeyId = preKeyBundle.signedPreKeyId preKeyBundleProto.signedKeyId = preKeyBundle.signedPreKeyId
//TODO preKeyBundleProto.signedKey = preKeyBundle.signedPreKeyPublic preKeyBundleProto.signedKey = ByteString.copyFrom(preKeyBundle.signedPreKey.serialize())
preKeyBundleProto.signature = ByteString.copyFrom(preKeyBundle.signedPreKeySignature) preKeyBundleProto.signature = ByteString.copyFrom(preKeyBundle.signedPreKeySignature)
val contentProto = SignalServiceProtos.Content.newBuilder() val contentProto = SignalServiceProtos.Content.newBuilder()
try { try {