mirror of https://github.com/M66B/FairEmail.git
Small improvements
This commit is contained in:
parent
032b1f14c1
commit
886ad067e4
|
@ -972,9 +972,11 @@ public class FragmentCompose extends FragmentBase {
|
||||||
menu.findItem(R.id.menu_media).setChecked(media);
|
menu.findItem(R.id.menu_media).setChecked(media);
|
||||||
menu.findItem(R.id.menu_compact).setChecked(compact);
|
menu.findItem(R.id.menu_compact).setChecked(compact);
|
||||||
|
|
||||||
if (EntityMessage.PGP_SIGNONLY.equals(encrypt))
|
if (EntityMessage.PGP_SIGNONLY.equals(encrypt) ||
|
||||||
|
EntityMessage.SMIME_SIGNONLY.equals(encrypt))
|
||||||
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_sign);
|
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_sign);
|
||||||
else if (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt))
|
else if (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt) ||
|
||||||
|
EntityMessage.SMIME_SIGNENCRYPT.equals(encrypt))
|
||||||
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_encrypt);
|
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_encrypt);
|
||||||
else
|
else
|
||||||
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_send);
|
bottom_navigation.getMenu().findItem(R.id.action_send).setTitle(R.string.title_send);
|
||||||
|
@ -1908,7 +1910,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
if (alias == null)
|
if (alias == null)
|
||||||
throw new IllegalArgumentException("Key alias missing");
|
throw new IllegalArgumentException("Key alias missing");
|
||||||
|
|
||||||
// Get key
|
// Get private key
|
||||||
PrivateKey privkey = KeyChain.getPrivateKey(context, alias);
|
PrivateKey privkey = KeyChain.getPrivateKey(context, alias);
|
||||||
if (privkey == null)
|
if (privkey == null)
|
||||||
throw new IllegalArgumentException("Private key missing");
|
throw new IllegalArgumentException("Private key missing");
|
||||||
|
@ -1933,7 +1935,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
db.attachment().setDownloaded(cattachment.id, content.length());
|
db.attachment().setDownloaded(cattachment.id, content.length());
|
||||||
|
|
||||||
// Build signature
|
// Sign
|
||||||
Store store = new JcaCertStore(Arrays.asList(chain[0]));
|
Store store = new JcaCertStore(Arrays.asList(chain[0]));
|
||||||
CMSSignedDataGenerator cmsGenerator = new CMSSignedDataGenerator();
|
CMSSignedDataGenerator cmsGenerator = new CMSSignedDataGenerator();
|
||||||
cmsGenerator.addCertificates(store);
|
cmsGenerator.addCertificates(store);
|
||||||
|
@ -1969,11 +1971,12 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
db.attachment().setDownloaded(sattachment.id, file.length());
|
db.attachment().setDownloaded(sattachment.id, file.length());
|
||||||
} else if (EntityMessage.SMIME_SIGNENCRYPT.equals(draft.encrypt)) {
|
} else if (EntityMessage.SMIME_SIGNENCRYPT.equals(draft.encrypt)) {
|
||||||
// TODO: sign
|
// Get recipient
|
||||||
if (draft.to == null || draft.to.length != 1)
|
if (draft.to == null || draft.to.length != 1)
|
||||||
throw new IllegalArgumentException(getString(R.string.title_to_missing));
|
throw new IllegalArgumentException(getString(R.string.title_to_missing));
|
||||||
|
|
||||||
String to = ((InternetAddress) draft.to[0]).getAddress();
|
String to = ((InternetAddress) draft.to[0]).getAddress();
|
||||||
|
|
||||||
|
// Get public key
|
||||||
List<EntityCertificate> c = db.certificate().getCertificateByEmail(to);
|
List<EntityCertificate> c = db.certificate().getCertificateByEmail(to);
|
||||||
if (c == null || c.size() == 0)
|
if (c == null || c.size() == 0)
|
||||||
throw new IllegalArgumentException("Certificate not found");
|
throw new IllegalArgumentException("Certificate not found");
|
||||||
|
@ -1982,6 +1985,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509")
|
X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509")
|
||||||
.generateCertificate(new ByteArrayInputStream(encoded));
|
.generateCertificate(new ByteArrayInputStream(encoded));
|
||||||
|
|
||||||
|
// Encrypt
|
||||||
CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
|
CMSEnvelopedDataGenerator cmsEnvelopedDataGenerator = new CMSEnvelopedDataGenerator();
|
||||||
RecipientInfoGenerator gen = new JceKeyTransRecipientInfoGenerator(cert);
|
RecipientInfoGenerator gen = new JceKeyTransRecipientInfoGenerator(cert);
|
||||||
cmsEnvelopedDataGenerator.addRecipientInfoGenerator(gen);
|
cmsEnvelopedDataGenerator.addRecipientInfoGenerator(gen);
|
||||||
|
@ -1995,8 +1999,6 @@ public class FragmentCompose extends FragmentBase {
|
||||||
CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator
|
CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator
|
||||||
.generate(msg, encryptor);
|
.generate(msg, encryptor);
|
||||||
|
|
||||||
byte[] encryptedData = cmsEnvelopedData/*.toASN1Structure()*/.getEncoded();
|
|
||||||
|
|
||||||
EntityAttachment attachment = new EntityAttachment();
|
EntityAttachment attachment = new EntityAttachment();
|
||||||
attachment.message = draft.id;
|
attachment.message = draft.id;
|
||||||
attachment.sequence = db.attachment().getAttachmentSequence(draft.id) + 1;
|
attachment.sequence = db.attachment().getAttachmentSequence(draft.id) + 1;
|
||||||
|
@ -2008,7 +2010,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
File file = attachment.getFile(context);
|
File file = attachment.getFile(context);
|
||||||
try (OutputStream os = new FileOutputStream(file)) {
|
try (OutputStream os = new FileOutputStream(file)) {
|
||||||
os.write(encryptedData);
|
cmsEnvelopedData.toASN1Structure().encodeTo(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.attachment().setDownloaded(attachment.id, file.length());
|
db.attachment().setDownloaded(attachment.id, file.length());
|
||||||
|
|
|
@ -382,6 +382,7 @@ public class MessageHelper {
|
||||||
// Build message
|
// Build message
|
||||||
imessage.setDisposition(Part.ATTACHMENT);
|
imessage.setDisposition(Part.ATTACHMENT);
|
||||||
imessage.setFileName(attachment.name);
|
imessage.setFileName(attachment.name);
|
||||||
|
imessage.setDescription("S/MIME Encrypted Message");
|
||||||
|
|
||||||
ContentType ct = new ContentType("application/pkcs7-mime");
|
ContentType ct = new ContentType("application/pkcs7-mime");
|
||||||
ct.setParameter("name", attachment.name);
|
ct.setParameter("name", attachment.name);
|
||||||
|
|
Loading…
Reference in New Issue