Small changes

This commit is contained in:
Paul Schaub 2020-07-13 23:28:11 +02:00
parent 98c5b7ba61
commit f4c4033686
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
9 changed files with 89 additions and 60 deletions

View file

@ -58,6 +58,19 @@ public class AccountDetailsFragment extends Fragment {
this.accountId = accountId;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_account_details, container, false);
ButterKnife.bind(this, view);
externalFingerprintRecyclerView.setAdapter(adapter);
observe();
return view;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
@ -94,17 +107,4 @@ public class AccountDetailsFragment extends Fragment {
});
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_account_details, container, false);
ButterKnife.bind(this, view);
externalFingerprintRecyclerView.setAdapter(adapter);
observe();
return view;
}
}

View file

@ -49,11 +49,62 @@
android:textAppearance="@style/TextAppearance.AppCompat.SearchResult.Title"
android:text="Encryption Keys" />
<include layout="@layout/view_fingerprint_card"
android:layout_height="wrap_content"
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"/>
android:layout_marginBottom="8dp"
app:cardCornerRadius="4dp"
app:cardElevation="4dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="12dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Local Fingerprint"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/local_fingerprint"
layout="@layout/view_fingerprint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title" />
<Button
android:id="@+id/btn_backup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_server_backup"
app:layout_constraintEnd_toStartOf="@+id/btn_share"
app:layout_constraintTop_toBottomOf="@+id/local_fingerprint" />
<Button
android:id="@+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="share"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/local_fingerprint" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<include layout="@layout/view_fingerprints_card_toggleable"
android:id="@+id/other_fingerprints_card"

View file

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph">
</navigation>

View file

@ -144,4 +144,5 @@
<string name="button_delete">Delete</string>
<string name="test_fingerprint">1357 B018 65B2 503C 1845\n3D20 8CAC 2A96 7854 8E35</string>
<string name="btn_server_backup">Create Server Backup</string>
</resources>

View file

@ -255,23 +255,6 @@ public class RxOpenPgpRepository implements OpenPgpRepository {
});
}
@Override
public Observable<List<OpenPgpV4Fingerprint>> observeRemoteFingerprintsOfAccount(UUID accountId) {
return accountRepository.getAccount(accountId).toSingle()
.flatMapObservable(account -> data.select(AnnouncedOpenPgpContactKey.class)
.where(AnnouncedOpenPgpContactKey.ACCOUNT_ID.eq(accountId)
.and(AnnouncedOpenPgpContactKey.OWNER.eq(account.getJid())))
.get().observableResult()
.map(ResultDelegate::toList)
.map(list -> {
ArrayList<OpenPgpV4Fingerprint> fingerprints = new ArrayList<>();
for (AnnouncedOpenPgpContactKey key : list) {
fingerprints.add(key.getFingerprint());
}
return fingerprints;
}));
}
@Override
public Observable<List<FingerprintViewItem>> observeFingerprints(UUID accountId, EntityBareJid owner) {
return data.select(AnnouncedOpenPgpContactKey.ACCOUNT_ID,
@ -293,6 +276,7 @@ public class RxOpenPgpRepository implements OpenPgpRepository {
.and(OpenPgpKeyTrust.FINGERPRINT.eq(AnnouncedOpenPgpContactKey.FINGERPRINT))))
.where(AnnouncedOpenPgpContactKey.ACCOUNT_ID.eq(accountId).and(AnnouncedOpenPgpContactKey.OWNER.eq(owner)))
.orderBy(AnnouncedOpenPgpContactKey.MODIFICATION_DATE.desc())
.get().observableResult()
.map(ResultDelegate::toList)

View file

@ -4,10 +4,8 @@ import org.bouncycastle.openpgp.PGPException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smack.roster.RosterEntry;
import org.jivesoftware.smackx.ox.OpenPgpContact;
import org.jivesoftware.smackx.ox.OpenPgpManager;
import org.jivesoftware.smackx.ox_im.OXInstantMessagingManager;
import org.jxmpp.jid.EntityBareJid;
@ -19,13 +17,8 @@ import org.mercury_im.messenger.core.exception.ContactAlreadyAddedException;
import org.mercury_im.messenger.core.xmpp.MercuryConnection;
import org.mercury_im.messenger.core.xmpp.MercuryConnectionManager;
import org.mercury_im.messenger.entity.contact.Peer;
import org.mercury_im.messenger.entity.message.Message;
import org.mercury_im.messenger.entity.message.MessageDeliveryState;
import org.mercury_im.messenger.entity.message.MessageDirection;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -34,7 +27,6 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Completable;
import io.reactivex.disposables.CompositeDisposable;
@Singleton
public class Messenger {
@ -46,8 +38,6 @@ public class Messenger {
private final Repositories repositories;
private final SchedulersFacade schedulers;
private CompositeDisposable disposable = new CompositeDisposable();
@Inject
public Messenger(Repositories repositories,
MercuryConnectionManager connectionManager,

View file

@ -61,19 +61,30 @@ public class MercuryOpenPgpManager {
OpenPgpManager oxManager = OpenPgpManager.getInstanceFor(connection.getConnection());
oxManager.setOpenPgpProvider(provider);
SecretKeyBackupHelper.setBackupCodeGenerator(
// TODO: REMOVE IN PRODUCTION!!!
() -> "71ZA-Y416-UA7A-7NCE-3SNM-88EF"
);
try {
boolean mustGenerate = false;
if (!oxManager.hasSecretKeysAvailable()) {
try {
oxManager.restoreSecretKeyServerBackup(
//() -> "RW8X-367S-A2C3-QYAL-VG6E-Z2IM");
//() -> "KISJ-5Z1T-FGDW-WMDK-SC2U-SQUA");
() -> "71ZA-Y416-UA7A-7NCE-3SNM-88EF");
LOGGER.log(Level.INFO, "Successfully restored secret key backup!");
} catch (NoBackupFoundException | PubSubException.NotALeafNodeException | InvalidBackupCodeException e) {
LOGGER.log(Level.INFO, "Error restoring secret key backup.", e);
oxManager.generateAndImportKeyPair(connection.getAccount().getJid());
mustGenerate = true;
if (OpenPgpManager.serverSupportsSecretKeyBackups(connection.getConnection())) {
try {
oxManager.restoreSecretKeyServerBackup(
//() -> "RW8X-367S-A2C3-QYAL-VG6E-Z2IM");
//() -> "KISJ-5Z1T-FGDW-WMDK-SC2U-SQUA");
() -> "71ZA-Y416-UA7A-7NCE-3SNM-88EF");
mustGenerate = false;
LOGGER.log(Level.INFO, "Successfully restored secret key backup!");
} catch (NoBackupFoundException | PubSubException.NotALeafNodeException | InvalidBackupCodeException e) {
LOGGER.log(Level.INFO, "Error restoring secret key backup.", e);
}
}
}
if (mustGenerate) {
oxManager.generateAndImportKeyPair(connection.getAccount().getJid());
if (OpenPgpManager.serverSupportsSecretKeyBackups(connection.getConnection())) {
oxManager.backupSecretKeyToServer(
backupCode -> LOGGER.log(Level.INFO, "OpenPGP Backup Code: " + backupCode),
availableSecretKeys -> availableSecretKeys);

View file

@ -55,7 +55,5 @@ public interface OpenPgpRepository {
Observable<Optional<OpenPgpV4Fingerprint>> observeLocalFingerprintOf(UUID accountId);
Observable<List<OpenPgpV4Fingerprint>> observeRemoteFingerprintsOfAccount(UUID accountId);
Observable<List<FingerprintViewItem>> observeFingerprints(UUID accountId, EntityBareJid owner);
}

View file

@ -5,7 +5,6 @@ import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smackx.carbons.CarbonManager;
import org.jivesoftware.smackx.iqversion.VersionManager;
import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.receipts.DeliveryReceiptManager;
import org.jivesoftware.smackx.sid.StableUniqueStanzaIdManager;