Added workaround for S/MIME signed content in encrypted message (2)

This commit is contained in:
M66B 2022-09-19 17:20:40 +02:00
parent e241522132
commit 7f1b8cd60e
2 changed files with 23 additions and 18 deletions

View File

@ -127,6 +127,12 @@ public interface DaoAttachment {
" AND NOT (related IS :related)")
void setCid(long id, String cid, Boolean related);
@Query("UPDATE attachment" +
" SET encryption = :encryption" +
" WHERE id = :id" +
" AND NOT (encryption IS :encryption)")
void setEncryption(long id, Integer encryption);
@Query("UPDATE attachment" +
" SET media_uri = :media_uri" +
" WHERE id = :id" +

View File

@ -8187,7 +8187,7 @@ public class FragmentMessages extends FragmentBase
boolean download_plain = prefs.getBoolean("download_plain", false);
String html = parts.getHtml(context, download_plain);
if (html == null && (debug || BuildConfig.DEBUG)) {
if (html == null && debug) {
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
MessageHelper.getStructure(imessage, ssb, 0, textColorLink);
@ -8890,21 +8890,7 @@ public class FragmentMessages extends FragmentBase
boolean download_plain = prefs.getBoolean("download_plain", false);
String html = parts.getHtml(context, download_plain);
if (!parts.hasBody() && parts.getAttachmentParts().size() == 1)
try {
InputStream i = parts.getAttachmentParts().get(0).part.getInputStream();
CMSSignedData signedData = new CMSSignedData(i);
CMSTypedData sc = signedData.getSignedContent();
InputStream bis = new ByteArrayInputStream((byte[]) sc.getContent());
MimeMessage inner = new MimeMessage(isession, bis);
MessageHelper h = new MessageHelper(inner, context);
parts = h.getMessageParts();
html = parts.getHtml(context, download_plain);
} catch (Throwable ex) {
Log.w(ex);
}
if (html == null && (debug || BuildConfig.DEBUG)) {
if (html == null && debug) {
int textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
MessageHelper.getStructure(imessage, ssb, 0, textColorLink);
@ -8936,23 +8922,36 @@ public class FragmentMessages extends FragmentBase
});
// Add decrypted attachments
boolean signedData = false;
List<EntityAttachment> remotes = parts.getAttachments();
for (int index = 0; index < remotes.size(); index++) {
EntityAttachment remote = remotes.get(index);
remote.message = message.id;
remote.sequence = index + 1;
remote.id = db.attachment().insertAttachment(remote);
Log.i("s/mime attachment=" + remote);
try {
parts.downloadAttachment(context, index, remote);
} catch (Throwable ex) {
Log.e(ex);
}
Log.i("s/mime attachment=" + remote);
if (!parts.hasBody() && remotes.size() == 1)
try (FileInputStream fos = new FileInputStream(remote.getFile(context))) {
new CMSSignedData(fos).getSignedContent().getContent();
signedData = true;
remote.encryption = EntityAttachment.SMIME_SIGNED_DATA;
db.attachment().setEncryption(remote.id, remote.encryption);
} catch (Throwable ex) {
Log.w(ex);
}
}
checkPep(message, remotes, context);
db.message().setMessageEncrypt(message.id, parts.getEncryption());
db.message().setMessageEncrypt(message.id,
signedData ? EntityMessage.SMIME_SIGNONLY : parts.getEncryption());
db.message().setMessageStored(message.id, new Date().getTime());
db.message().setMessageFts(message.id, false);