Skip to content

Commit

Permalink
⬆️ Use the official signal java package instead of the archive impl (#41
Browse files Browse the repository at this point in the history
)
  • Loading branch information
guiyanakuang authored Nov 22, 2023
1 parent 58be2e5 commit 111c231
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
2 changes: 1 addition & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
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<PreKeyRecord> {
var newStart = start
val results: MutableList<PreKeyRecord> = 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,
override val preKeys: List<PreKeyRecord>,
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<PreKeyRecord>):
this(identityKeyPair,
registrationId,
preKeys,
generateSignedPreKey(identityKeyPair, 5))
}

fun readSignalProtocol(data: ByteArray): SignalProtocol {
Expand Down

This file was deleted.

0 comments on commit 111c231

Please sign in to comment.