From 585a1e28f9d3f7c095cc889cfc990f6dd82ba4e5 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 6 Oct 2024 00:50:09 +0200 Subject: [PATCH] Migrate from libsignal-protocol-java to libsignal --- smack-omemo-signal/build.gradle | 2 +- .../omemo/signal/SignalCachingOmemoStore.java | 18 ++-- .../signal/SignalFileBasedOmemoStore.java | 18 ++-- .../omemo/signal/SignalOmemoKeyUtil.java | 85 +++++++++++++------ .../omemo/signal/SignalOmemoRatchet.java | 53 +++++++----- .../omemo/signal/SignalOmemoService.java | 26 +++--- .../smackx/omemo/signal/SignalOmemoStore.java | 18 ++-- .../signal/SignalOmemoStoreConnector.java | 35 +++++--- .../omemo/LegacySignalOmemoKeyUtilTest.java | 6 +- .../smackx/omemo/SignalOmemoKeyUtilTest.java | 14 +-- .../smackx/omemo/SignalOmemoStoreTest.java | 18 ++-- 11 files changed, 172 insertions(+), 121 deletions(-) diff --git a/smack-omemo-signal/build.gradle b/smack-omemo-signal/build.gradle index aa0887f94a..dd5fd46029 100644 --- a/smack-omemo-signal/build.gradle +++ b/smack-omemo-signal/build.gradle @@ -11,7 +11,7 @@ dependencies { api project(":smack-im") api project(":smack-extensions") api project(":smack-omemo") - implementation 'org.whispersystems:signal-protocol-java:2.8.1' + implementation 'org.signal:libsignal-client:0.26.0' // TODO: Migrate Junit4 tests to Junit5. testImplementation "org.junit.vintage:junit-vintage-engine:$junitVersion" diff --git a/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalCachingOmemoStore.java b/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalCachingOmemoStore.java index 135bd96fb9..eafd0fb2db 100644 --- a/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalCachingOmemoStore.java +++ b/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalCachingOmemoStore.java @@ -23,15 +23,15 @@ import org.jivesoftware.smackx.omemo.CachingOmemoStore; import org.jivesoftware.smackx.omemo.OmemoStore; -import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.SessionCipher; -import org.whispersystems.libsignal.SignalProtocolAddress; -import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.state.PreKeyBundle; -import org.whispersystems.libsignal.state.PreKeyRecord; -import org.whispersystems.libsignal.state.SessionRecord; -import org.whispersystems.libsignal.state.SignedPreKeyRecord; +import org.signal.libsignal.protocol.IdentityKey; +import org.signal.libsignal.protocol.IdentityKeyPair; +import org.signal.libsignal.protocol.SessionCipher; +import org.signal.libsignal.protocol.SignalProtocolAddress; +import org.signal.libsignal.protocol.ecc.ECPublicKey; +import org.signal.libsignal.protocol.state.PreKeyBundle; +import org.signal.libsignal.protocol.state.PreKeyRecord; +import org.signal.libsignal.protocol.state.SessionRecord; +import org.signal.libsignal.protocol.state.SignedPreKeyRecord; /** * Implementation of the CachingOmemoStore for smack-omemo-signal. diff --git a/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalFileBasedOmemoStore.java b/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalFileBasedOmemoStore.java index f474b9b199..9cce37dfbb 100644 --- a/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalFileBasedOmemoStore.java +++ b/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalFileBasedOmemoStore.java @@ -25,15 +25,15 @@ import org.jivesoftware.smackx.omemo.FileBasedOmemoStore; import org.jivesoftware.smackx.omemo.util.OmemoKeyUtil; -import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.SessionCipher; -import org.whispersystems.libsignal.SignalProtocolAddress; -import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.state.PreKeyBundle; -import org.whispersystems.libsignal.state.PreKeyRecord; -import org.whispersystems.libsignal.state.SessionRecord; -import org.whispersystems.libsignal.state.SignedPreKeyRecord; +import org.signal.libsignal.protocol.IdentityKey; +import org.signal.libsignal.protocol.IdentityKeyPair; +import org.signal.libsignal.protocol.SessionCipher; +import org.signal.libsignal.protocol.SignalProtocolAddress; +import org.signal.libsignal.protocol.ecc.ECPublicKey; +import org.signal.libsignal.protocol.state.PreKeyBundle; +import org.signal.libsignal.protocol.state.PreKeyRecord; +import org.signal.libsignal.protocol.state.SessionRecord; +import org.signal.libsignal.protocol.state.SignedPreKeyRecord; /** * Implementation of a FileBasedOmemoStore for the smack-omemo-signal module. diff --git a/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalOmemoKeyUtil.java b/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalOmemoKeyUtil.java index c4e5a78d79..eb213d11ca 100644 --- a/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalOmemoKeyUtil.java +++ b/smack-omemo-signal/src/main/java/org/jivesoftware/smackx/omemo/signal/SignalOmemoKeyUtil.java @@ -20,26 +20,27 @@ */ package org.jivesoftware.smackx.omemo.signal; -import java.io.IOException; -import java.util.List; -import java.util.TreeMap; - import org.jivesoftware.smackx.omemo.element.OmemoBundleElement; import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException; import org.jivesoftware.smackx.omemo.internal.OmemoDevice; import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint; import org.jivesoftware.smackx.omemo.util.OmemoKeyUtil; +import org.signal.libsignal.protocol.IdentityKey; +import org.signal.libsignal.protocol.IdentityKeyPair; +import org.signal.libsignal.protocol.InvalidKeyException; +import org.signal.libsignal.protocol.InvalidMessageException; +import org.signal.libsignal.protocol.ecc.Curve; +import org.signal.libsignal.protocol.ecc.ECKeyPair; +import org.signal.libsignal.protocol.ecc.ECPublicKey; +import org.signal.libsignal.protocol.state.PreKeyBundle; +import org.signal.libsignal.protocol.state.PreKeyRecord; +import org.signal.libsignal.protocol.state.SessionRecord; +import org.signal.libsignal.protocol.state.SignedPreKeyRecord; +import org.signal.libsignal.protocol.util.Medium; -import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.InvalidKeyException; -import org.whispersystems.libsignal.ecc.Curve; -import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.state.PreKeyBundle; -import org.whispersystems.libsignal.state.PreKeyRecord; -import org.whispersystems.libsignal.state.SessionRecord; -import org.whispersystems.libsignal.state.SignedPreKeyRecord; -import org.whispersystems.libsignal.util.KeyHelper; +import java.io.IOException; +import java.util.List; +import java.util.TreeMap; /** * Concrete implementation of the KeyUtil for an implementation using the Signal library. @@ -51,13 +52,13 @@ public class SignalOmemoKeyUtil extends OmemoKeyUtil generateOmemoPreKeys(int currentPreKeyId, int count) { - List preKeyRecords = KeyHelper.generatePreKeys(currentPreKeyId, count); + List preKeyRecords = generatePreKeys(currentPreKeyId, count); TreeMap map = new TreeMap<>(); for (PreKeyRecord p : preKeyRecords) { map.put(p.getId(), p); @@ -65,20 +66,44 @@ public TreeMap generateOmemoPreKeys(int currentPreKeyId, return map; } + private static List generatePreKeys(int start, int count) { + List results = new ArrayList<>(count); + + start--; + + for (int i=0;i loadExistingSessions(List addresses) throws NoSessionException { + throw new RuntimeException("Not implemented."); + } + @Override public List getSubDeviceSessions(String s) { BareJid jid; diff --git a/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/LegacySignalOmemoKeyUtilTest.java b/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/LegacySignalOmemoKeyUtilTest.java index e7b91e0a8f..db89d04c11 100644 --- a/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/LegacySignalOmemoKeyUtilTest.java +++ b/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/LegacySignalOmemoKeyUtilTest.java @@ -32,9 +32,9 @@ import org.jivesoftware.smackx.omemo.signal.SignalOmemoKeyUtil; import org.junit.Test; -import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.state.SignedPreKeyRecord; +import org.signal.libsignal.protocol.IdentityKey; +import org.signal.libsignal.protocol.IdentityKeyPair; +import org.signal.libsignal.protocol.state.SignedPreKeyRecord; /** * Test SignalOmemoKeyUtil methods. diff --git a/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoKeyUtilTest.java b/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoKeyUtilTest.java index d14e08ef56..4dd3e7f447 100644 --- a/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoKeyUtilTest.java +++ b/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoKeyUtilTest.java @@ -28,13 +28,13 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.state.PreKeyBundle; -import org.whispersystems.libsignal.state.PreKeyRecord; -import org.whispersystems.libsignal.state.SessionRecord; -import org.whispersystems.libsignal.state.SignedPreKeyRecord; +import org.signal.libsignal.protocol.IdentityKey; +import org.signal.libsignal.protocol.IdentityKeyPair; +import org.signal.libsignal.protocol.ecc.ECPublicKey; +import org.signal.libsignal.protocol.state.PreKeyBundle; +import org.signal.libsignal.protocol.state.PreKeyRecord; +import org.signal.libsignal.protocol.state.SessionRecord; +import org.signal.libsignal.protocol.state.SignedPreKeyRecord; /** * smack-omemo-signal implementation of {@link OmemoKeyUtilTest}. diff --git a/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoStoreTest.java b/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoStoreTest.java index a4a9bedea1..ce39a26adb 100644 --- a/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoStoreTest.java +++ b/smack-omemo-signal/src/test/java/org/jivesoftware/smackx/omemo/SignalOmemoStoreTest.java @@ -35,15 +35,15 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.jxmpp.stringprep.XmppStringprepException; -import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.IdentityKeyPair; -import org.whispersystems.libsignal.SessionCipher; -import org.whispersystems.libsignal.SignalProtocolAddress; -import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.state.PreKeyBundle; -import org.whispersystems.libsignal.state.PreKeyRecord; -import org.whispersystems.libsignal.state.SessionRecord; -import org.whispersystems.libsignal.state.SignedPreKeyRecord; +import org.signal.libsignal.protocol.IdentityKey; +import org.signal.libsignal.protocol.IdentityKeyPair; +import org.signal.libsignal.protocol.SessionCipher; +import org.signal.libsignal.protocol.SignalProtocolAddress; +import org.signal.libsignal.protocol.ecc.ECPublicKey; +import org.signal.libsignal.protocol.state.PreKeyBundle; +import org.signal.libsignal.protocol.state.PreKeyRecord; +import org.signal.libsignal.protocol.state.SessionRecord; +import org.signal.libsignal.protocol.state.SignedPreKeyRecord; /** * smack-omemo-signal implementation of {@link OmemoStoreTest}.