mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 22:13:38 +00:00
clean
This commit is contained in:
parent
64352707d0
commit
c69a8bc15f
@ -108,12 +108,8 @@ import org.session.libsignal.service.loki.api.opengroups.PublicChatAPI;
|
|||||||
import org.session.libsignal.service.loki.api.shelved.p2p.LokiP2PAPI;
|
import org.session.libsignal.service.loki.api.shelved.p2p.LokiP2PAPI;
|
||||||
import org.session.libsignal.service.loki.api.shelved.p2p.LokiP2PAPIDelegate;
|
import org.session.libsignal.service.loki.api.shelved.p2p.LokiP2PAPIDelegate;
|
||||||
import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol;
|
import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol;
|
||||||
import org.session.libsignal.service.loki.protocol.closedgroups.SharedSenderKeysImplementation;
|
|
||||||
import org.session.libsignal.service.loki.protocol.closedgroups.SharedSenderKeysImplementationDelegate;
|
|
||||||
import org.session.libsignal.service.loki.protocol.mentions.MentionsManager;
|
import org.session.libsignal.service.loki.protocol.mentions.MentionsManager;
|
||||||
import org.session.libsignal.service.loki.protocol.meta.SessionMetaProtocol;
|
import org.session.libsignal.service.loki.protocol.meta.SessionMetaProtocol;
|
||||||
import org.session.libsignal.service.loki.protocol.sessionmanagement.SessionManagementProtocol;
|
|
||||||
import org.session.libsignal.service.loki.protocol.sessionmanagement.SessionManagementProtocolDelegate;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -1,66 +1,11 @@
|
|||||||
package org.session.libsession.messaging.sending_receiving
|
package org.session.libsession.messaging.sending_receiving
|
||||||
|
|
||||||
import org.session.libsession.messaging.MessagingConfiguration
|
import org.session.libsession.messaging.MessagingConfiguration
|
||||||
import org.session.libsession.messaging.sending_receiving.MessageReceiver.Error
|
|
||||||
import org.session.libsession.utilities.AESGCM
|
|
||||||
import org.session.libsession.utilities.GroupUtil
|
|
||||||
import org.session.libsignal.libsignal.ecc.ECKeyPair
|
import org.session.libsignal.libsignal.ecc.ECKeyPair
|
||||||
|
|
||||||
import org.whispersystems.curve25519.Curve25519
|
|
||||||
|
|
||||||
import org.session.libsignal.libsignal.loki.ClosedGroupCiphertextMessage
|
|
||||||
import org.session.libsignal.service.api.messages.SignalServiceEnvelope
|
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
|
||||||
import org.session.libsignal.service.loki.protocol.closedgroups.SharedSenderKeysImplementation
|
|
||||||
import org.session.libsignal.service.loki.utilities.toHexString
|
|
||||||
|
|
||||||
import javax.crypto.Mac
|
|
||||||
import javax.crypto.spec.SecretKeySpec
|
|
||||||
|
|
||||||
object MessageReceiverDecryption {
|
object MessageReceiverDecryption {
|
||||||
|
|
||||||
/*internal fun decryptWithSignalProtocol(envelope: SignalServiceProtos.Envelope): Pair<ByteArray, String> {
|
|
||||||
val storage = MessagingConfiguration.shared.signalStorage
|
|
||||||
val sskDatabase = MessagingConfiguration.shared.sskDatabase
|
|
||||||
val sessionResetImp = MessagingConfiguration.shared.sessionResetImp
|
|
||||||
val certificateValidator = MessagingConfiguration.shared.certificateValidator
|
|
||||||
val data = envelope.content
|
|
||||||
if (data.count() == 0) { throw Error.NoData }
|
|
||||||
val userPublicKey = MessagingConfiguration.shared.storage.getUserPublicKey() ?: throw Error.NoUserPublicKey
|
|
||||||
val localAddress = SignalServiceAddress(userPublicKey)
|
|
||||||
val cipher = SignalServiceCipher(localAddress, storage, sskDatabase, sessionResetImp, certificateValidator)
|
|
||||||
val result = cipher.decrypt(SignalServiceEnvelope(envelope))
|
|
||||||
return Pair(ByteArray(1), result.sender) // TODO: Return real plaintext
|
|
||||||
}*/
|
|
||||||
|
|
||||||
internal fun decryptWithSessionProtocol(ciphertext: ByteArray, x25519KeyPair: ECKeyPair): Pair<ByteArray, String> {
|
internal fun decryptWithSessionProtocol(ciphertext: ByteArray, x25519KeyPair: ECKeyPair): Pair<ByteArray, String> {
|
||||||
return MessagingConfiguration.shared.sessionProtocol.decrypt(ciphertext, x25519KeyPair)
|
return MessagingConfiguration.shared.sessionProtocol.decrypt(ciphertext, x25519KeyPair)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*internal fun decryptWithSharedSenderKeys(envelope: SignalServiceProtos.Envelope): Pair<ByteArray, String> {
|
|
||||||
// 1. ) Check preconditions
|
|
||||||
val groupPublicKey = envelope.source
|
|
||||||
if (!GroupUtil.isClosedGroup(groupPublicKey)) { throw Error.InvalidGroupPublicKey }
|
|
||||||
val data = envelope.content
|
|
||||||
if (data.count() == 0) { throw Error.NoData }
|
|
||||||
val groupPrivateKey = MessagingConfiguration.shared.sskDatabase.getClosedGroupPrivateKey(groupPublicKey) ?: throw Error.NoGroupPrivateKey
|
|
||||||
// 2. ) Parse the wrapper
|
|
||||||
val wrapper = SignalServiceProtos.ClosedGroupCiphertextMessageWrapper.parseFrom(data)
|
|
||||||
val ivAndCiphertext = wrapper.ciphertext.toByteArray()
|
|
||||||
val ephemeralPublicKey = wrapper.ephemeralPublicKey.toByteArray()
|
|
||||||
// 3. ) Decrypt the data inside
|
|
||||||
val ephemeralSharedSecret = Curve25519.getInstance(Curve25519.BEST).calculateAgreement(ephemeralPublicKey, groupPrivateKey.toByteArray())
|
|
||||||
val mac = Mac.getInstance("HmacSHA256")
|
|
||||||
mac.init(SecretKeySpec("LOKI".toByteArray(), "HmacSHA256"))
|
|
||||||
val symmetricKey = mac.doFinal(ephemeralSharedSecret)
|
|
||||||
val closedGroupCiphertextMessageAsData = AESGCM.decrypt(ivAndCiphertext, symmetricKey)
|
|
||||||
// 4. ) Parse the closed group ciphertext message
|
|
||||||
val closedGroupCiphertextMessage = ClosedGroupCiphertextMessage.from(closedGroupCiphertextMessageAsData) ?: throw Error.ParsingFailed
|
|
||||||
val senderPublicKey = closedGroupCiphertextMessage.senderPublicKey.toHexString()
|
|
||||||
if (senderPublicKey == MessagingConfiguration.shared.storage.getUserPublicKey()) { throw Error.SelfSend }
|
|
||||||
// 5. ) Use the info inside the closed group ciphertext message to decrypt the actual message content
|
|
||||||
val plaintext = SharedSenderKeysImplementation.shared.decrypt(closedGroupCiphertextMessage.ivAndCiphertext, groupPublicKey, senderPublicKey, closedGroupCiphertextMessage.keyIndex)
|
|
||||||
// 6. ) Return
|
|
||||||
return Pair(plaintext, senderPublicKey)
|
|
||||||
}*/
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user