mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
MessaageSender: use of session protocol for closed groups
This commit is contained in:
parent
6f22c3d6e3
commit
3357672516
4 changed files with 17 additions and 5 deletions
|
@ -272,6 +272,10 @@ class Storage(val context: Context): StorageProtocol {
|
|||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getLatestClosedGroupEncryptionKeyPair(groupPublicKey: String): ECKeyPair {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun setProfileSharing(address: Address, value: Boolean) {
|
||||
val recipient = Recipient.from(context, address, false)
|
||||
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(recipient, value)
|
||||
|
|
|
@ -104,6 +104,7 @@ interface StorageProtocol {
|
|||
members: Collection<String>, admins: Collection<String>, threadID: Long)
|
||||
fun isClosedGroup(publicKey: String): Boolean //TODO
|
||||
fun getClosedGroupEncryptionKeyPairs(groupPublicKey: String): MutableList<ECKeyPair> //TODO
|
||||
fun getLatestClosedGroupEncryptionKeyPair(groupPublicKey: String): ECKeyPair //TODO
|
||||
|
||||
// Settings
|
||||
fun setProfileSharing(address: Address, value: Boolean)
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.session.libsignal.service.api.messages.SignalServiceAttachment
|
|||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||
import org.session.libsignal.service.internal.util.Base64
|
||||
import org.session.libsignal.service.loki.api.crypto.ProofOfWork
|
||||
import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey
|
||||
|
||||
|
||||
object MessageSender {
|
||||
|
@ -32,7 +33,10 @@ object MessageSender {
|
|||
object InvalidMessage : Error("Invalid message.")
|
||||
object ProtoConversionFailed : Error("Couldn't convert message to proto.")
|
||||
object ProofOfWorkCalculationFailed : Error("Proof of work calculation failed.")
|
||||
object NoUserPublicKey : Error("Couldn't find user key pair.")
|
||||
object NoUserX25519KeyPair : Error("Couldn't find user X25519 key pair.")
|
||||
object NoUserED25519KeyPair : Error("Couldn't find user ED25519 key pair.")
|
||||
object SigningFailed : Error("Couldn't sign message.")
|
||||
object EncryptionFailed : Error("Couldn't encrypt message.")
|
||||
|
||||
// Closed groups
|
||||
object NoThread : Error("Couldn't find a thread associated with the given group public key.")
|
||||
|
@ -71,7 +75,7 @@ object MessageSender {
|
|||
var snodeMessage: SnodeMessage? = null
|
||||
// Set the timestamp, sender and recipient
|
||||
message.sentTimestamp ?: run { message.sentTimestamp = System.currentTimeMillis() } /* Visible messages will already have their sent timestamp set */
|
||||
message.sender = storage.getUserPublicKey()
|
||||
message.sender = userPublicKey
|
||||
try {
|
||||
when (destination) {
|
||||
is Destination.Contact -> message.recipient = destination.publicKey
|
||||
|
@ -117,7 +121,10 @@ object MessageSender {
|
|||
val ciphertext: ByteArray
|
||||
when (destination) {
|
||||
is Destination.Contact -> ciphertext = MessageSenderEncryption.encryptWithSessionProtocol(plaintext, destination.publicKey)
|
||||
is Destination.ClosedGroup -> ciphertext = MessageSenderEncryption.encryptWithSharedSenderKeys(plaintext, destination.groupPublicKey)
|
||||
is Destination.ClosedGroup -> {
|
||||
val encryptionKeyPair = MessagingConfiguration.shared.storage.getLatestClosedGroupEncryptionKeyPair(destination.groupPublicKey)
|
||||
ciphertext = MessageSenderEncryption.encryptWithSessionProtocol(plaintext, encryptionKeyPair.hexEncodedPublicKey)
|
||||
}
|
||||
is Destination.OpenGroup -> throw preconditionFailure
|
||||
}
|
||||
// Wrap the result
|
||||
|
|
|
@ -38,7 +38,7 @@ object MessageSenderEncryption {
|
|||
return MessagingConfiguration.shared.sessionProtocol.encrypt(plaintext, recipientPublicKey)
|
||||
}
|
||||
|
||||
internal fun encryptWithSharedSenderKeys(plaintext: ByteArray, groupPublicKey: String): ByteArray {
|
||||
/*internal fun encryptWithSharedSenderKeys(plaintext: ByteArray, groupPublicKey: String): ByteArray {
|
||||
// 1. ) Encrypt the data with the user's sender key
|
||||
val userPublicKey = MessagingConfiguration.shared.storage.getUserPublicKey() ?: throw Error.NoUserPublicKey
|
||||
val ciphertextAndKeyIndex = SharedSenderKeysImplementation.shared.encrypt(plaintext, groupPublicKey, userPublicKey)
|
||||
|
@ -52,5 +52,5 @@ object MessageSenderEncryption {
|
|||
.setCiphertext(ByteString.copyFrom(intermediate.ciphertext))
|
||||
.setEphemeralPublicKey(ByteString.copyFrom(intermediate.ephemeralPublicKey))
|
||||
.build().toByteArray()
|
||||
}
|
||||
}*/
|
||||
}
|
Loading…
Reference in a new issue