diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index 5c791657e..f762e8269 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -21,7 +21,7 @@ kotlin { implementation("com.google.zxing:javase:3.5.2") implementation("ch.qos.logback:logback-classic:1.4.11") implementation("io.javalin:javalin:5.6.3") - implementation("org.whispersystems:signal-protocol-java:2.8.1") + implementation("org.signal:libsignal-client:0.35.0") } commonMain.dependencies { implementation(compose.runtime) diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/encrypt/SignalProtocol.kt b/composeApp/src/commonMain/kotlin/com/clipevery/encrypt/SignalProtocol.kt index a0bdbac8b..f5e851f86 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/encrypt/SignalProtocol.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/encrypt/SignalProtocol.kt @@ -1,16 +1,16 @@ package com.clipevery.encrypt -import org.whispersystems.libsignal.IdentityKeyPair -import org.whispersystems.libsignal.state.IdentityKeyStore -import org.whispersystems.libsignal.state.PreKeyRecord -import org.whispersystems.libsignal.state.PreKeyStore -import org.whispersystems.libsignal.state.SessionStore -import org.whispersystems.libsignal.state.SignedPreKeyRecord -import org.whispersystems.libsignal.state.SignedPreKeyStore -import org.whispersystems.libsignal.state.impl.InMemoryIdentityKeyStore -import org.whispersystems.libsignal.state.impl.InMemoryPreKeyStore -import org.whispersystems.libsignal.state.impl.InMemorySessionStore -import org.whispersystems.libsignal.state.impl.InMemorySignedPreKeyStore +import org.signal.libsignal.protocol.IdentityKeyPair +import org.signal.libsignal.protocol.state.IdentityKeyStore +import org.signal.libsignal.protocol.state.PreKeyRecord +import org.signal.libsignal.protocol.state.PreKeyStore +import org.signal.libsignal.protocol.state.SessionStore +import org.signal.libsignal.protocol.state.SignedPreKeyRecord +import org.signal.libsignal.protocol.state.SignedPreKeyStore +import org.signal.libsignal.protocol.state.impl.InMemoryIdentityKeyStore +import org.signal.libsignal.protocol.state.impl.InMemoryPreKeyStore +import org.signal.libsignal.protocol.state.impl.InMemorySessionStore +import org.signal.libsignal.protocol.state.impl.InMemorySignedPreKeyStore interface SignalProtocol { val identityKeyPair: IdentityKeyPair diff --git a/composeApp/src/commonMain/kotlin/com/clipevery/model/AppRequestBindInfo.kt b/composeApp/src/commonMain/kotlin/com/clipevery/model/AppRequestBindInfo.kt index 6a16988da..ecbe7b26e 100644 --- a/composeApp/src/commonMain/kotlin/com/clipevery/model/AppRequestBindInfo.kt +++ b/composeApp/src/commonMain/kotlin/com/clipevery/model/AppRequestBindInfo.kt @@ -1,7 +1,7 @@ package com.clipevery.model import com.clipevery.encrypt.base64Encode -import org.whispersystems.libsignal.IdentityKey +import org.signal.libsignal.protocol.IdentityKey import java.io.ByteArrayOutputStream import java.io.DataOutputStream diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/DesktopSignalProtocol.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/DesktopSignalProtocol.kt index b5df2aee8..b74c9b034 100644 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/DesktopSignalProtocol.kt +++ b/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/DesktopSignalProtocol.kt @@ -1,12 +1,39 @@ package com.clipevery.encrypt -import org.whispersystems.libsignal.IdentityKeyPair -import org.whispersystems.libsignal.state.PreKeyRecord -import org.whispersystems.libsignal.state.SignedPreKeyRecord -import org.whispersystems.libsignal.util.KeyHelper +import org.signal.libsignal.protocol.IdentityKeyPair +import org.signal.libsignal.protocol.InvalidKeyException +import org.signal.libsignal.protocol.ecc.Curve +import org.signal.libsignal.protocol.ecc.ECKeyPair +import org.signal.libsignal.protocol.state.PreKeyRecord +import org.signal.libsignal.protocol.state.SignedPreKeyRecord +import org.signal.libsignal.protocol.util.KeyHelper +import org.signal.libsignal.protocol.util.Medium import java.io.ByteArrayOutputStream import java.io.DataInputStream import java.io.DataOutputStream +import java.util.LinkedList + + +fun generatePreKeys(start: Int, count: Int): List { + var newStart = start + val results: MutableList = LinkedList() + newStart-- + for (i in 0 until count) { + results.add(PreKeyRecord((newStart + i) % (Medium.MAX_VALUE - 1) + 1, Curve.generateKeyPair())) + } + return results +} + +@Throws(InvalidKeyException::class) +fun generateSignedPreKey( + identityKeyPair: IdentityKeyPair, + signedPreKeyId: Int +): SignedPreKeyRecord { + val keyPair: ECKeyPair = Curve.generateKeyPair() + val signature = + Curve.calculateSignature(identityKeyPair.privateKey, keyPair.getPublicKey().serialize()) + return SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature) +} class DesktopSignalProtocol(override val identityKeyPair: IdentityKeyPair, override val registrationId: Int, @@ -14,10 +41,16 @@ class DesktopSignalProtocol(override val identityKeyPair: IdentityKeyPair, override val signedPreKey: SignedPreKeyRecord ): SignalProtocol { - constructor(): this(KeyHelper.generateIdentityKeyPair(), + constructor(): this( + IdentityKeyPair.generate(), KeyHelper.generateRegistrationId(false), - KeyHelper.generatePreKeys(0, 5), - KeyHelper.generateSignedPreKey(KeyHelper.generateIdentityKeyPair(), 5)) + generatePreKeys(0, 5)) + + constructor(identityKeyPair: IdentityKeyPair, registrationId: Int, preKeys: List): + this(identityKeyPair, + registrationId, + preKeys, + generateSignedPreKey(identityKeyPair, 5)) } fun readSignalProtocol(data: ByteArray): SignalProtocol { diff --git a/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/SessionStore.kt b/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/SessionStore.kt deleted file mode 100644 index 48bbe73b8..000000000 --- a/composeApp/src/desktopMain/kotlin/com/clipevery/encrypt/SessionStore.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.clipevery.encrypt - -import org.whispersystems.libsignal.SignalProtocolAddress -import org.whispersystems.libsignal.state.SessionRecord -import org.whispersystems.libsignal.state.SessionStore - -class MacSessionStore: SessionStore { - override fun loadSession(address: SignalProtocolAddress?): SessionRecord { - TODO("Not yet implemented") - } - - override fun getSubDeviceSessions(name: String?): MutableList { - TODO("Not yet implemented") - } - - override fun storeSession(address: SignalProtocolAddress?, record: SessionRecord?) { - TODO("Not yet implemented") - } - - override fun containsSession(address: SignalProtocolAddress?): Boolean { - TODO("Not yet implemented") - } - - override fun deleteSession(address: SignalProtocolAddress?) { - TODO("Not yet implemented") - } - - override fun deleteAllSessions(name: String?) { - TODO("Not yet implemented") - } -} \ No newline at end of file