1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-11-27 04:49:28 +01:00

Add message verify with openkeychain

This commit is contained in:
世界 2020-07-20 09:44:19 +08:00
parent b1a9d29a1a
commit 410e2490ca
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
5 changed files with 71 additions and 8 deletions

View File

@ -20,6 +20,7 @@
-keep class org.telegram.tgnet.QuickAckDelegate { *; }
-keep class org.telegram.tgnet.WriteToSocketDelegate { *; }
-keep class com.v2ray.ang.dto.** { *; }
-keep class org.openintents.openpgp.** { *; }
# -keep class io.github.trojan_gfw.** { *; }

View File

@ -18,11 +18,13 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
@ -57,6 +59,7 @@ import android.text.style.CharacterStyle;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.LongSparseArray;
import android.util.Property;
import android.util.SparseArray;
@ -96,6 +99,9 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import org.openintents.openpgp.OpenPgpDecryptionResult;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
@ -207,6 +213,7 @@ import org.telegram.ui.Components.URLSpanUserMention;
import org.telegram.ui.Components.UndoView;
import org.telegram.ui.Components.voip.VoIPHelper;
import cn.hutool.core.io.IoUtil;
import tw.nekomimi.nekogram.JalaliCalendar;
import tw.nekomimi.nekogram.MessageDetailsActivity;
import tw.nekomimi.nekogram.MessageHelper;
@ -214,6 +221,7 @@ import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.settings.NekoGeneralSettingsActivity;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
@ -235,6 +243,7 @@ import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.parts.MessageTransKt;
import tw.nekomimi.nekogram.transtale.Translator;
import tw.nekomimi.nekogram.utils.AlertUtil;
import tw.nekomimi.nekogram.utils.PGPUtil;
@SuppressWarnings("unchecked")
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate, LocationActivity.LocationActivityDelegate, ChatAttachAlertDocumentLayout.DocumentSelectActivityDelegate {
@ -15023,6 +15032,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
options.add(88);
icons.add(R.drawable.ic_translate);
}
if (StrUtil.isNotBlank(selectedObject.messageOwner.message) && StrUtil.isNotBlank(NekoConfig.openPGPApp) && selectedObject.messageOwner.message.contains("-----BEGIN PGP")) {
items.add(LocaleController.getString("DecryptVerify", R.string.DecryptVerify));
options.add(200);
icons.add(R.drawable.baseline_vpn_key_24);
}
}
if (NekoConfig.showMessageDetails) {
items.add(LocaleController.getString("MessageDetails", R.string.MessageDetails));
@ -16217,6 +16231,39 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}, null);
break;
}
case 200: {
Intent open = new Intent(Intent.ACTION_SEND);
open.setType("application/pgp-message");
open.putExtra(Intent.EXTRA_TEXT, selectedObject.messageOwner.message);
open.setClassName(NekoConfig.openPGPApp,NekoConfig.openPGPApp + ".ui.DecryptActivity");
try {
getParentActivity().startActivity(open);
} catch (Exception e) {
AlertUtil.showToast(e);
}
// ByteArrayInputStream is = IoUtil.toUtf8Stream(selectedObject.messageOwner.message);
//
// PGPUtil.post(() -> PGPUtil.api.executeApiAsync(new Intent(OpenPgpApi.ACTION_DECRYPT_VERIFY), is, null, new OpenPgpApi.IOpenPgpCallback() {
//
// @Override
// public void onReturn(Intent result) {
//
//
// OpenPgpSignatureResult s = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
//
// }
//
// }));
break;
}
}
selectedObject = null;
selectedObjectGroup = null;

View File

@ -3113,13 +3113,18 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
((LaunchActivity) parentActivity).callbacks.put(115, result -> {
long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0L);
if (signKeyId < 1L) NekoConfig.setOpenPGPKeyId(keyId);
long keyId = signKeyId;
if (signKeyId == 0L || signKeyId == 1L) {
keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0L);
if (signKeyId == 0L) NekoConfig.setOpenPGPKeyId(keyId);
}
signComment(keyId);
return Unit.INSTANCE;
});
}
@ -3149,8 +3154,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
try {
parentActivity.startIntentSenderFromChild(parentActivity, pi.getIntentSender(),
115, null, 0, 0, 0);
parentActivity.startIntentSenderFromChild(parentActivity, pi.getIntentSender(), 115, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(OpenPgpApi.TAG, "SendIntentException", e);
}

View File

@ -115,11 +115,13 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import kotlin.Unit;
import kotlin.reflect.KFunction;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.NekoXSettingActivity;
@ -2893,7 +2895,14 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
return rightActionBarLayout;
}
public HashMap<Integer, Function<Intent, Unit>> callbacks = new HashMap<>();
@FunctionalInterface
public interface Callback {
void invoke(Intent data);
}
public HashMap<Integer, Callback> callbacks = new HashMap<>();
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -2908,7 +2917,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
if (callbacks.containsKey(requestCode)) {
callbacks.remove(requestCode).apply(data);
callbacks.remove(requestCode).invoke(data);
return;

View File

@ -227,4 +227,6 @@
<string name="None">None</string>
<string name="Sign">Sign</string>
<string name="DecryptVerify">Decrypt / Verify</string>
</resources>