diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index 10b104e909..eb655878af 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -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.LokiP2PAPIDelegate; 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.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.FileInputStream; diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverDecryption.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverDecryption.kt index cb6320a717..2474d75ba5 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverDecryption.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverDecryption.kt @@ -1,66 +1,11 @@ package org.session.libsession.messaging.sending_receiving 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.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 { - /*internal fun decryptWithSignalProtocol(envelope: SignalServiceProtos.Envelope): Pair { - 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 { return MessagingConfiguration.shared.sessionProtocol.decrypt(ciphertext, x25519KeyPair) } - - /*internal fun decryptWithSharedSenderKeys(envelope: SignalServiceProtos.Envelope): Pair { - // 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) - }*/ } \ No newline at end of file