S/MIME decrypt

pull/168/head
M66B 5 years ago
parent 0e4e96ef69
commit cb0db5de3e

@ -1501,6 +1501,7 @@ class Core {
message.size = parts.getBodySize();
message.total = helper.getSize();
message.content = false;
message.encrypt = parts.getEncryption();
message.received = helper.getReceived();
message.sent = helper.getSent();
message.seen = false;
@ -2084,6 +2085,7 @@ class Core {
message.size = parts.getBodySize();
message.total = helper.getSize();
message.content = false;
message.encrypt = parts.getEncryption();
message.received = (account.use_date ? (sent == null ? 0 : sent) : helper.getReceived());
message.sent = sent;
message.seen = seen;
@ -2147,15 +2149,6 @@ class Core {
attachment.message = message.id;
attachment.sequence = sequence++;
attachment.id = db.attachment().insertAttachment(attachment);
if (EntityAttachment.PGP_SIGNATURE.equals(attachment.encryption))
db.message().setMessageEncrypt(message.id, EntityMessage.PGP_SIGNONLY);
else if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption))
db.message().setMessageEncrypt(message.id, EntityMessage.PGP_SIGNENCRYPT);
else if (EntityAttachment.SMIME_SIGNATURE.equals(attachment.encryption))
db.message().setMessageEncrypt(message.id, EntityMessage.SMIME_SIGNONLY);
else if (EntityAttachment.SMIME_MESSAGE.equals(attachment.encryption))
db.message().setMessageEncrypt(message.id, EntityMessage.SMIME_SIGNENCRYPT);
}
runRules(context, imessage, message, rules);

@ -4270,6 +4270,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
}
}
db.message().setMessageEncrypt(message.id, parts.getEncryption());
db.message().setMessageStored(message.id, new Date().getTime());
db.setTransactionSuccessful();
@ -4372,16 +4373,46 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Collection<RecipientInformation> recipients = envelopedData.getRecipientInfos().getRecipients();
KeyTransRecipientInformation recipientInfo = (KeyTransRecipientInformation) recipients.iterator().next();
JceKeyTransRecipient recipient = new JceKeyTransEnvelopedRecipient(pk);
InputStream is = recipientInfo.getContentStream(recipient).getContentStream();
byte[] result = recipientInfo.getContent(recipient);
File output = EntityMessage.getFile(context, id);
try (OutputStream os = new FileOutputStream(output)) {
os.write("<pre>\r\n".getBytes());
os.write(result);
os.write("</pre>\r\n".getBytes());
}
// Decode message
Properties props = MessageHelper.getSessionProperties();
Session isession = Session.getInstance(props, null);
MimeMessage imessage = new MimeMessage(isession, is);
MessageHelper helper = new MessageHelper(imessage);
MessageHelper.MessageParts parts = helper.getMessageParts(context);
try {
db.beginTransaction();
// Write decrypted body
String html = parts.getHtml(context);
Helper.writeText(EntityMessage.getFile(context, id), html);
db.message().setMessageStored(id, new Date().getTime());
// Remove existing attachments
db.attachment().deleteAttachments(id);
// Add decrypted attachments
List<EntityAttachment> remotes = parts.getAttachments();
for (int index = 0; index < remotes.size(); index++) {
EntityAttachment remote = remotes.get(index);
remote.message = id;
remote.sequence = index + 1;
remote.id = db.attachment().insertAttachment(remote);
try {
parts.downloadAttachment(context, index, remote);
} catch (Throwable ex) {
Log.e(ex);
}
}
db.message().setMessageEncrypt(id, parts.getEncryption());
db.message().setMessageStored(id, new Date().getTime());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return true;
}

@ -1089,6 +1089,19 @@ public class MessageHelper {
return result;
}
Integer getEncryption() {
for (AttachmentPart apart : attachments)
if (EntityAttachment.PGP_SIGNATURE.equals(apart.attachment.encryption))
return EntityMessage.PGP_SIGNONLY;
else if (EntityAttachment.PGP_MESSAGE.equals(apart.attachment.encryption))
return EntityMessage.PGP_SIGNENCRYPT;
else if (EntityAttachment.SMIME_SIGNATURE.equals(apart.attachment.encryption))
return EntityMessage.SMIME_SIGNONLY;
else if (EntityAttachment.SMIME_MESSAGE.equals(apart.attachment.encryption))
return EntityMessage.SMIME_SIGNENCRYPT;
return null;
}
void downloadAttachment(Context context, EntityAttachment local) throws IOException, MessagingException {
List<EntityAttachment> remotes = getAttachments();

Loading…
Cancel
Save