Skip to content

Commit

Permalink
androidim-265: Add support for OMEMO
Browse files Browse the repository at this point in the history
bugfixes
add: list of other own devices fingerprints
  • Loading branch information
bmalkow committed Oct 3, 2019
1 parent d76a382 commit 028cb4e
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@
import org.tigase.messenger.phone.pro.settings.AppCompatPreferenceActivity;
import org.tigase.messenger.phone.pro.settings.FingerprintPreference;
import org.tigase.messenger.phone.pro.utils.AccountHelper;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.SignalProtocolAddress;
import tigase.jaxmpp.android.Jaxmpp;
import tigase.jaxmpp.core.client.JID;
import tigase.jaxmpp.core.client.XMPPException;
import tigase.jaxmpp.core.client.exceptions.JaxmppException;
import tigase.jaxmpp.core.client.xmpp.modules.mam.MessageArchiveManagementModule;
import tigase.jaxmpp.core.client.xmpp.modules.omemo.JaXMPPSignalProtocolStore;
import tigase.jaxmpp.core.client.xmpp.modules.omemo.OmemoModule;
import tigase.jaxmpp.core.client.xmpp.stanzas.Stanza;

Expand Down Expand Up @@ -268,51 +270,6 @@ public static class AccountPropertiesFragment
private ListPreference mamSynchronizationTime;
private boolean modified = false;

public void checkMAM() {
FingerprintPreference omemoFingerprint = (FingerprintPreference) findPreference("omemo_fingerprint");

SignalProtocolStore omemoStore = OmemoModule.getSignalProtocolStore(
((AccountProperties) getActivity()).getJaxmpp().getSessionObject());
omemoFingerprint.setFingerprint(omemoStore.getIdentityKeyPair().getPublicKey().serialize(), 1);

try {
Jaxmpp jaxmpp = ((AccountProperties) getActivity()).getJaxmpp();
MessageArchiveManagementModule mam = jaxmpp.getModule(MessageArchiveManagementModule.class);
mam.retrieveSettings(new MessageArchiveManagementModule.SettingsCallback() {
@Override
public void onError(Stanza responseStanza, XMPPException.ErrorCondition error)
throws JaxmppException {
try {
setMamSwitch(false, MessageArchiveManagementModule.DefaultValue.never);
} catch (Exception e) {
Log.w(TAG, "Cannot update switch", e);
}
}

@Override
public void onSuccess(MessageArchiveManagementModule.DefaultValue defValue, List<JID> always,
List<JID> never) throws JaxmppException {
try {
setMamSwitch(true, defValue);
} catch (Exception e) {
Log.w(TAG, "Cannot update switch", e);
}
}

@Override
public void onTimeout() throws JaxmppException {
try {
setMamSwitch(false, MessageArchiveManagementModule.DefaultValue.never);
} catch (Exception e) {
Log.w(TAG, "Cannot update switch", e);
}
}
});
} catch (Exception e) {
Log.e(TAG, "Cannot check MAM status", e);
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
String tmp;
Expand All @@ -336,8 +293,7 @@ public void onCreate(Bundle savedInstanceState) {
getActivity().startActivity(i);
getActivity().finish();
} catch (Exception e) {
e.printStackTrace();
Log.e("X", "CHuj!", e);
Log.e("X", "WHY????", e);
}
return true;
});
Expand Down Expand Up @@ -461,6 +417,80 @@ public void onPause() {
super.onPause();
}

void checkMAM() {
showOMEMODetails();
try {
Jaxmpp jaxmpp = ((AccountProperties) getActivity()).getJaxmpp();
MessageArchiveManagementModule mam = jaxmpp.getModule(MessageArchiveManagementModule.class);
mam.retrieveSettings(new MessageArchiveManagementModule.SettingsCallback() {
@Override
public void onError(Stanza responseStanza, XMPPException.ErrorCondition error)
throws JaxmppException {
try {
setMamSwitch(false, MessageArchiveManagementModule.DefaultValue.never);
} catch (Exception e) {
Log.w(TAG, "Cannot update switch", e);
}
}

@Override
public void onSuccess(MessageArchiveManagementModule.DefaultValue defValue, List<JID> always,
List<JID> never) throws JaxmppException {
try {
setMamSwitch(true, defValue);
} catch (Exception e) {
Log.w(TAG, "Cannot update switch", e);
}
}

@Override
public void onTimeout() throws JaxmppException {
try {
setMamSwitch(false, MessageArchiveManagementModule.DefaultValue.never);
} catch (Exception e) {
Log.w(TAG, "Cannot update switch", e);
}
}
});
} catch (Exception e) {
Log.e(TAG, "Cannot check MAM status", e);
}
}

private void showOMEMODetails() {
final Jaxmpp jaxmpp = ((AccountProperties) getActivity()).getJaxmpp();
final JaXMPPSignalProtocolStore omemoStore = OmemoModule.getSignalProtocolStore(jaxmpp.getSessionObject());
final String jid = jaxmpp.getSessionObject().getUserBareJid().toString();
final int localId = omemoStore.getLocalRegistrationId();

FingerprintPreference omemoFingerprint = (FingerprintPreference) findPreference("omemo_fingerprint");
omemoFingerprint.setFingerprint(omemoStore.getIdentityKeyPair().getPublicKey().serialize(), 1);

PreferenceCategory otherDevices = (PreferenceCategory) findPreference("omemo_other");

List<Integer> ids = omemoStore.getSubDevice(jid);
boolean added = false;
for (Integer id : ids) {
if (id == localId) {
continue;
}
FingerprintPreference checkBoxPref = new FingerprintPreference(getContext());

checkBoxPref.setTitle("title");
checkBoxPref.setSummary("summary");
IdentityKey identity = omemoStore.getIdentity(new SignalProtocolAddress(jid, id));
checkBoxPref.setFingerprint(identity.getPublicKey().serialize(), 1);

otherDevices.addPreference(checkBoxPref);
added = true;
}

if (!added) {
getPreferenceScreen().removePreference(otherDevices);
}

}

private void sendBroadcast(boolean forceDisconnect) {
Intent i = new Intent();
i.setAction(LoginActivity.ACCOUNT_MODIFIED_MSG);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fingerprint_switch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:textStyle="bold"
android:includeFontPadding="true"
android:textSize="16sp"
style="@android:"
android:layout_toLeftOf="@id/switcher"
android:typeface="monospace"/>

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/layout/preference_fingerprint_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
>
android:background="?android:attr/selectableItemBackground">

<org.tigase.messenger.phone.pro.omemo.FingerprintView
android:id="@+id/fingerprint_view"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="15dip"
android:layout_marginEnd="16dp"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/xml/account_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@

</PreferenceCategory>

<PreferenceCategory android:title="OMEMO">
<PreferenceCategory android:key="omemo_category" android:title="OMEMO">
<org.tigase.messenger.phone.pro.settings.FingerprintPreference android:key="omemo_fingerprint"
android:text="KKK" android:title="Key"/>
</PreferenceCategory>

<PreferenceCategory android:key="omemo_other" android:title="Other Devices with OMEMO" >
</PreferenceCategory>

<PreferenceCategory
android:title="Resource priority">
<SwitchPreference
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

buildscript {
repositories {
google()
mavenLocal()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.firebase:firebase-plugins:1.2.0'
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.firebase:firebase-plugins:2.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.google.gms:google-services:4.3.0'
}
}

allprojects {
repositories {
google()
mavenLocal()
google()
jcenter()
maven {url "http://maven-repo.tigase.org/repository/release/"}
maven {url "http://maven-repo.tigase.org/repository/snapshot/"}
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 27 14:11:27 CEST 2018
#Wed Aug 14 12:10:57 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 028cb4e

Please sign in to comment.