Improvements
This commit is contained in:
parent
c0b8c564df
commit
1e9bbf4d5c
|
@ -220,7 +220,6 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
|
|
||||||
ECDH.uncryptMessage(BaseMainActivity.this, "", "Underground@toot.fedilab.app");
|
|
||||||
try {
|
try {
|
||||||
if (intent != null && intent.getComponent() != null) {
|
if (intent != null && intent.getComponent() != null) {
|
||||||
ActivityInfo ai = pm.getActivityInfo(intent.getComponent(), PackageManager.GET_META_DATA);
|
ActivityInfo ai = pm.getActivityInfo(intent.getComponent(), PackageManager.GET_META_DATA);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
|
||||||
import org.spongycastle.asn1.ASN1ObjectIdentifier;
|
import org.spongycastle.asn1.ASN1ObjectIdentifier;
|
||||||
import org.spongycastle.asn1.x9.ECNamedCurveTable;
|
import org.spongycastle.asn1.x9.ECNamedCurveTable;
|
||||||
import org.spongycastle.asn1.x9.X9ECParameters;
|
import org.spongycastle.asn1.x9.X9ECParameters;
|
||||||
|
@ -36,7 +37,9 @@ import org.spongycastle.jce.spec.ECPublicKeySpec;
|
||||||
import org.spongycastle.math.ec.ECCurve;
|
import org.spongycastle.math.ec.ECCurve;
|
||||||
import org.spongycastle.math.ec.ECPoint;
|
import org.spongycastle.math.ec.ECPoint;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
|
@ -47,11 +50,13 @@ import java.security.PublicKey;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.security.interfaces.ECPublicKey;
|
import java.security.interfaces.ECPublicKey;
|
||||||
import java.security.spec.ECGenParameterSpec;
|
import java.security.spec.ECGenParameterSpec;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.CipherInputStream;
|
||||||
import javax.crypto.KeyAgreement;
|
import javax.crypto.KeyAgreement;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
import app.fedilab.android.sqlite.AccountDAO;
|
import app.fedilab.android.sqlite.AccountDAO;
|
||||||
|
@ -198,26 +203,37 @@ public class ECDH {
|
||||||
|
|
||||||
|
|
||||||
public static String uncryptMessage(Context context, String cyphered, String slug) {
|
public static String uncryptMessage(Context context, String cyphered, String slug) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
||||||
String crypted_message_test = sharedpreferences.getString("CRYPTED_MESSAGE_TEST", null);
|
|
||||||
Log.v(Helper.TAG, "crypted_message_test: " + crypted_message_test);
|
|
||||||
getInstance();
|
getInstance();
|
||||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
String[] slugArray = slug.split("@");
|
String[] slugArray = slug.split("@");
|
||||||
Account account = new AccountDAO(context, db).getUniqAccountUsernameInstance(slugArray[0], slugArray[1]);
|
Account account = new AccountDAO(context, db).getUniqAccountUsernameInstance(slugArray[0], slugArray[1]);
|
||||||
|
|
||||||
String uncrypted = crypted_message_test;
|
byte[] privateKey = getSharedSecret(context, account);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PublicKey dddd = getServerKey(context, account);
|
Cipher outCipher = Cipher.getInstance("ECIES", "SC");
|
||||||
|
outCipher.init(Cipher.DECRYPT_MODE, readPrivateKey(privateKey));
|
||||||
|
|
||||||
|
CipherInputStream cipherInputStream = new CipherInputStream(
|
||||||
|
new ByteArrayInputStream(Base64.decode(cyphered, Base64.DEFAULT)), outCipher);
|
||||||
|
|
||||||
|
ArrayList<Byte> values = new ArrayList<>();
|
||||||
|
int nextByte;
|
||||||
|
while ((nextByte = cipherInputStream.read()) != -1) {
|
||||||
|
values.add((byte) nextByte);
|
||||||
|
}
|
||||||
|
byte[] bytes = new byte[values.size()];
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
bytes[i] = values.get(i).byteValue();
|
||||||
|
}
|
||||||
|
String finalText = new String(bytes, 0, bytes.length, StandardCharsets.UTF_8);
|
||||||
|
Log.v(Helper.TAG, "---> " + finalText);
|
||||||
|
return finalText;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
byte[] ddd = getSharedSecret(context, account);
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,6 +247,11 @@ public class ECDH {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static PrivateKey readPrivateKey(byte[] key) throws Exception {
|
||||||
|
SecretKeySpec signingKey = new SecretKeySpec(key, "ECIES");
|
||||||
|
return kf.generatePrivate(signingKey);
|
||||||
|
}
|
||||||
|
|
||||||
static synchronized PrivateKey readMyPrivateKey(Context context) throws Exception {
|
static synchronized PrivateKey readMyPrivateKey(Context context) throws Exception {
|
||||||
X9ECParameters x9 = ECNamedCurveTable.getByName("prime256v1");
|
X9ECParameters x9 = ECNamedCurveTable.getByName("prime256v1");
|
||||||
ASN1ObjectIdentifier oid = ECNamedCurveTable.getOID("prime256v1");
|
ASN1ObjectIdentifier oid = ECNamedCurveTable.getOID("prime256v1");
|
||||||
|
|
|
@ -24,7 +24,9 @@ import org.unifiedpush.android.connector.MessagingReceiver;
|
||||||
import org.unifiedpush.android.connector.MessagingReceiverHandler;
|
import org.unifiedpush.android.connector.MessagingReceiverHandler;
|
||||||
|
|
||||||
|
|
||||||
|
import app.fedilab.android.activities.BaseMainActivity;
|
||||||
import app.fedilab.android.client.Entities.Account;
|
import app.fedilab.android.client.Entities.Account;
|
||||||
|
import app.fedilab.android.helper.ECDH;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.helper.NotificationsHelper;
|
import app.fedilab.android.helper.NotificationsHelper;
|
||||||
import app.fedilab.android.helper.PushNotifications;
|
import app.fedilab.android.helper.PushNotifications;
|
||||||
|
@ -51,6 +53,7 @@ class handler implements MessagingReceiverHandler {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
String[] slugArray = slug.split("@");
|
String[] slugArray = slug.split("@");
|
||||||
|
//ECDH.uncryptMessage(context, s, slug);
|
||||||
Account account = new AccountDAO(context, db).getUniqAccountUsernameInstance(slugArray[0], slugArray[1]);
|
Account account = new AccountDAO(context, db).getUniqAccountUsernameInstance(slugArray[0], slugArray[1]);
|
||||||
NotificationsHelper.task(context, account);
|
NotificationsHelper.task(context, account);
|
||||||
}).start();
|
}).start();
|
||||||
|
|
Loading…
Reference in New Issue