diff --git a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt index 5a828784e2..49853b33e2 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/utilities/DotNetAPI.kt @@ -12,7 +12,7 @@ import org.session.libsession.snode.SnodeAPI import org.session.libsession.messaging.fileserver.FileServerAPI import org.session.libsignal.utilities.logging.Log -import org.session.libsignal.libsignal.loki.DiffieHellman +import org.session.libsignal.utilities.DiffieHellman import org.session.libsignal.service.api.crypto.ProfileCipherOutputStream import org.session.libsignal.service.api.messages.SignalServiceAttachment import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException diff --git a/libsignal/src/main/java/org/session/libsignal/libsignal/SessionCipher.java b/libsignal/src/main/java/org/session/libsignal/libsignal/SessionCipher.java index 8f1066a2ea..dffa2b9355 100644 --- a/libsignal/src/main/java/org/session/libsignal/libsignal/SessionCipher.java +++ b/libsignal/src/main/java/org/session/libsignal/libsignal/SessionCipher.java @@ -8,7 +8,6 @@ package org.session.libsignal.libsignal; import org.session.libsignal.libsignal.ecc.Curve; import org.session.libsignal.libsignal.ecc.ECKeyPair; import org.session.libsignal.libsignal.ecc.ECPublicKey; -import org.session.libsignal.libsignal.loki.FallbackSessionCipher; import org.session.libsignal.libsignal.protocol.CiphertextMessage; import org.session.libsignal.libsignal.protocol.PreKeySignalMessage; import org.session.libsignal.libsignal.protocol.SignalMessage; @@ -332,7 +331,7 @@ public class SessionCipher { synchronized (SESSION_LOCK) { if (!sessionStore.containsSession(remoteAddress)) { // Loki - If we have no session then we must be using the FallbackSessionCipher - return FallbackSessionCipher.getSessionVersion(); + return 3; } SessionRecord record = sessionStore.loadSession(remoteAddress); diff --git a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/ClosedGroupCiphertextMessage.kt b/libsignal/src/main/java/org/session/libsignal/libsignal/loki/ClosedGroupCiphertextMessage.kt deleted file mode 100644 index 00f3446b22..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/ClosedGroupCiphertextMessage.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.session.libsignal.libsignal.loki - -import com.google.protobuf.ByteString -import org.session.libsignal.utilities.logging.Log -import org.session.libsignal.libsignal.protocol.CiphertextMessage -import org.session.libsignal.libsignal.protocol.SignalProtos - -class ClosedGroupCiphertextMessage(val ivAndCiphertext: ByteArray, val senderPublicKey: ByteArray, val keyIndex: Int) : CiphertextMessage { - private val serialized: ByteArray - - companion object { - - fun from(serialized: ByteArray): ClosedGroupCiphertextMessage? { - try { - val proto = SignalProtos.ClosedGroupCiphertextMessage.parseFrom(serialized) - return ClosedGroupCiphertextMessage(proto.ciphertext.toByteArray(), proto.senderPublicKey.toByteArray(), proto.keyIndex) - } catch (exception: Exception) { - Log.d("Loki", "Couldn't parse proto due to error: $exception.") - return null - } - } - } - - init { - val builder = SignalProtos.ClosedGroupCiphertextMessage.newBuilder() - builder.ciphertext = ByteString.copyFrom(ivAndCiphertext) - builder.senderPublicKey = ByteString.copyFrom(senderPublicKey) - builder.keyIndex = keyIndex - serialized = builder.build().toByteArray() - } - - override fun getType(): Int { - return CiphertextMessage.CLOSED_GROUP_CIPHERTEXT - } - - override fun serialize(): ByteArray { - return serialized - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/FallbackMessage.kt b/libsignal/src/main/java/org/session/libsignal/libsignal/loki/FallbackMessage.kt deleted file mode 100644 index 1066ae315a..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/FallbackMessage.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.session.libsignal.libsignal.loki - -import org.session.libsignal.libsignal.protocol.CiphertextMessage - -class FallbackMessage(private val paddedMessageBody: ByteArray) : CiphertextMessage { - - override fun serialize(): ByteArray { - return paddedMessageBody - } - - override fun getType(): Int { - return CiphertextMessage.FALLBACK_MESSAGE_TYPE - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/FallbackSessionCipher.kt b/libsignal/src/main/java/org/session/libsignal/libsignal/loki/FallbackSessionCipher.kt deleted file mode 100644 index 02c4012e74..0000000000 --- a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/FallbackSessionCipher.kt +++ /dev/null @@ -1,51 +0,0 @@ -package org.session.libsignal.libsignal.loki - -import org.whispersystems.curve25519.Curve25519 -import org.session.libsignal.utilities.Hex -import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded - -/** - * A session cipher that uses the current user's private key along with a contact's public key to encrypt data. - */ -class FallbackSessionCipher(private val userPrivateKey: ByteArray, private val hexEncodedContactPublicKey: String) { - - private val contactPublicKey by lazy { - val hexEncodedContactPublicKey = hexEncodedContactPublicKey.removing05PrefixIfNeeded() - Hex.fromStringCondensed(hexEncodedContactPublicKey) - } - - private val symmetricKey: ByteArray? - get() { - try { - val curve = Curve25519.getInstance(Curve25519.BEST) - return curve.calculateAgreement(contactPublicKey, userPrivateKey) - } catch (e: Exception) { - e.printStackTrace() - return null - } - } - - companion object { - @JvmStatic val sessionVersion = 3 - } - - fun encrypt(paddedMessageBody: ByteArray): ByteArray? { - val symmetricKey = symmetricKey ?: return null - try { - return DiffieHellman.encrypt(paddedMessageBody, symmetricKey) - } catch (e: Exception) { - e.printStackTrace() - return null - } - } - - fun decrypt(bytes: ByteArray): ByteArray? { - val symmetricKey = symmetricKey ?: return null - try { - return DiffieHellman.decrypt(bytes, symmetricKey) - } catch (e: Exception) { - e.printStackTrace() - return null - } - } -} diff --git a/libsignal/src/main/java/org/session/libsignal/metadata/SealedSessionCipher.java b/libsignal/src/main/java/org/session/libsignal/metadata/SealedSessionCipher.java index 6db3b81019..53ed84db6b 100644 --- a/libsignal/src/main/java/org/session/libsignal/metadata/SealedSessionCipher.java +++ b/libsignal/src/main/java/org/session/libsignal/metadata/SealedSessionCipher.java @@ -23,7 +23,6 @@ import org.session.libsignal.libsignal.ecc.ECKeyPair; import org.session.libsignal.libsignal.ecc.ECPrivateKey; import org.session.libsignal.libsignal.ecc.ECPublicKey; import org.session.libsignal.libsignal.kdf.HKDFv3; -import org.session.libsignal.libsignal.loki.FallbackSessionCipher; import org.session.libsignal.libsignal.protocol.CiphertextMessage; import org.session.libsignal.libsignal.protocol.PreKeySignalMessage; import org.session.libsignal.libsignal.protocol.SignalMessage; @@ -197,14 +196,6 @@ public class SealedSessionCipher { switch (message.getType()) { case CiphertextMessage.WHISPER_TYPE: return new SessionCipher(signalProtocolStore, sender).decrypt(new SignalMessage(message.getContent())); case CiphertextMessage.PREKEY_TYPE: return new SessionCipher(signalProtocolStore, sender).decrypt(new PreKeySignalMessage(message.getContent())); - case CiphertextMessage.FALLBACK_MESSAGE_TYPE: { - try { - byte[] privateKey = signalProtocolStore.getIdentityKeyPair().getPrivateKey().serialize(); - return new FallbackSessionCipher(privateKey, sender.getName()).decrypt(message.getContent()); - } catch (Exception e) { - throw new InvalidMessageException("Failed to decrypt fallback message."); - } - } default: throw new InvalidMessageException("Unknown type: " + message.getType()); } } diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt index fa1326686a..044afa6301 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/api/DotNetAPI.kt @@ -9,7 +9,7 @@ import okhttp3.MultipartBody import okhttp3.Request import okhttp3.RequestBody import org.session.libsignal.utilities.logging.Log -import org.session.libsignal.libsignal.loki.DiffieHellman +import org.session.libsignal.utilities.DiffieHellman import org.session.libsignal.service.api.crypto.ProfileCipherOutputStream import org.session.libsignal.service.api.push.exceptions.NonSuccessfulResponseCodeException import org.session.libsignal.service.api.push.exceptions.PushNetworkException diff --git a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/DiffieHellman.kt b/libsignal/src/main/java/org/session/libsignal/utilities/DiffieHellman.kt similarity index 97% rename from libsignal/src/main/java/org/session/libsignal/libsignal/loki/DiffieHellman.kt rename to libsignal/src/main/java/org/session/libsignal/utilities/DiffieHellman.kt index 3db0eac9df..a3b3f53527 100644 --- a/libsignal/src/main/java/org/session/libsignal/libsignal/loki/DiffieHellman.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/DiffieHellman.kt @@ -1,4 +1,4 @@ -package org.session.libsignal.libsignal.loki +package org.session.libsignal.utilities import org.whispersystems.curve25519.Curve25519 import org.session.libsignal.service.internal.util.Util