mirror of https://github.com/M66B/FairEmail.git
Store Autocrypt header
This commit is contained in:
parent
b4465c388d
commit
b26892a3c4
File diff suppressed because it is too large
Load Diff
|
@ -32,7 +32,6 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -67,7 +66,6 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -99,7 +97,6 @@ import javax.mail.FolderNotFoundException;
|
|||
import javax.mail.Message;
|
||||
import javax.mail.MessageRemovedException;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.UIDFolder;
|
||||
|
@ -2084,6 +2081,7 @@ class Core {
|
|||
message.reply = helper.getReply();
|
||||
message.list_post = helper.getListPost();
|
||||
message.unsubscribe = helper.getListUnsubscribe();
|
||||
message.autocrypt = helper.getAutocrypt();
|
||||
message.subject = helper.getSubject();
|
||||
message.size = parts.getBodySize();
|
||||
message.total = helper.getSize();
|
||||
|
@ -2146,35 +2144,6 @@ class Core {
|
|||
Log.i(folder.name + " added id=" + message.id + " uid=" + message.uid);
|
||||
|
||||
int sequence = 1;
|
||||
|
||||
String autocrypt = helper.getAutocrypt();
|
||||
if (autocrypt != null) {
|
||||
EntityAttachment attachment = new EntityAttachment();
|
||||
attachment.message = message.id;
|
||||
attachment.sequence = sequence++;
|
||||
attachment.name = "pubkey.pem";
|
||||
attachment.type = "application/pgp-keys";
|
||||
attachment.disposition = Part.INLINE;
|
||||
attachment.id = db.attachment().insertAttachment(attachment);
|
||||
|
||||
try {
|
||||
byte[] b = Base64.decode(autocrypt, Base64.DEFAULT);
|
||||
|
||||
File file = attachment.getFile(context);
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
writer.write("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n\r\n");
|
||||
writer.write(Base64.encodeToString(b, Base64.CRLF));
|
||||
writer.write("-----END PGP PUBLIC KEY BLOCK-----\r\n");
|
||||
}
|
||||
|
||||
db.attachment().setDownloaded(attachment.id, file.length());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Log.w(ex);
|
||||
db.attachment().setDownloaded(attachment.id, 0L);
|
||||
db.attachment().setError(attachment.id, Log.formatThrowable(ex, false));
|
||||
}
|
||||
}
|
||||
|
||||
List<EntityAttachment> attachments = parts.getAttachments();
|
||||
for (EntityAttachment attachment : attachments) {
|
||||
Log.i(folder.name + " attachment seq=" + sequence + " " + attachment);
|
||||
|
|
|
@ -56,7 +56,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 125,
|
||||
version = 126,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -1217,6 +1217,13 @@ public abstract class DB extends RoomDatabase {
|
|||
}
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(125, 126) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `autocrypt` TEXT");
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ public class EntityMessage implements Serializable {
|
|||
public Address[] reply;
|
||||
public Address[] list_post;
|
||||
public String unsubscribe;
|
||||
public String autocrypt;
|
||||
public String headers;
|
||||
public Boolean raw;
|
||||
public String subject;
|
||||
|
|
|
@ -4280,7 +4280,25 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
return null;
|
||||
else
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));
|
||||
/*
|
||||
if (message.from != null && message.from.length > 0 &&
|
||||
message.autocrypt != null &&
|
||||
OpenPgpApi.ACTION_DECRYPT_VERIFY.equals(data.getAction())) {
|
||||
int k = message.autocrypt.indexOf("keydata=");
|
||||
if (k >= 0)
|
||||
try {
|
||||
String keydata = message.autocrypt.substring(k + 8);
|
||||
AutocryptPeerUpdate update = AutocryptPeerUpdate.createAutocryptPeerUpdate(
|
||||
Base64.decode(keydata, Base64.DEFAULT),
|
||||
new Date(message.received));
|
||||
|
||||
data.putExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_ID, ((InternetAddress) message.from[0]).getAddress());
|
||||
data.putExtra(OpenPgpApi.EXTRA_AUTOCRYPT_PEER_UPDATE, update);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Intent result;
|
||||
try {
|
||||
// Decrypt message
|
||||
|
|
|
@ -232,15 +232,28 @@ public class MessageHelper {
|
|||
for (EntityAttachment attachment : attachments)
|
||||
if (EntityAttachment.PGP_KEY.equals(attachment.encryption)) {
|
||||
InternetAddress from = (InternetAddress) message.from[0];
|
||||
File file = attachment.getFile(context);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
File file = attachment.getFile(context);
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
if (!line.startsWith("-----") && !line.endsWith("-----"))
|
||||
sb.append(line);
|
||||
String line = br.readLine();
|
||||
while (line != null) {
|
||||
String data = null;
|
||||
if (line.length() > 0 &&
|
||||
!line.startsWith("-----BEGIN ") &&
|
||||
!line.startsWith("-----END "))
|
||||
data = line;
|
||||
|
||||
line = br.readLine();
|
||||
|
||||
// https://www.w3.org/Protocols/rfc822/3_Lexical.html#z0
|
||||
if (data != null &&
|
||||
line != null && !line.startsWith("-----END "))
|
||||
sb.append("\r\n ").append(data);
|
||||
}
|
||||
}
|
||||
|
||||
// https://autocrypt.org/level1.html#the-autocrypt-header
|
||||
imessage.addHeader("Autocrypt",
|
||||
"addr=" + from.getAddress() + ";" +
|
||||
" prefer-encrypt=mutual;" +
|
||||
|
@ -881,13 +894,7 @@ public class MessageHelper {
|
|||
if (autocrypt == null)
|
||||
return null;
|
||||
|
||||
autocrypt = MimeUtility.unfold(autocrypt);
|
||||
|
||||
int k = autocrypt.indexOf("keydata=");
|
||||
if (k < 0)
|
||||
return null;
|
||||
|
||||
return autocrypt.substring(k + 8);
|
||||
return MimeUtility.unfold(autocrypt);
|
||||
}
|
||||
|
||||
String getSubject() throws MessagingException {
|
||||
|
|
Loading…
Reference in New Issue