Skip to content

Commit

Permalink
Enable S/MIME encrypt #259
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 20, 2024
1 parent ca12655 commit e9a63b4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions dev/App/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { AccountUserStore } from 'Stores/User/Account';
import { ContactUserStore } from 'Stores/User/Contact';
import { FolderUserStore } from 'Stores/User/Folder';
import { PgpUserStore } from 'Stores/User/Pgp';
//import { SMimeUserStore } from 'Stores/User/SMime';
import { SMimeUserStore } from 'Stores/User/SMime';
import { MessagelistUserStore } from 'Stores/User/Messagelist';
import { ThemeStore, initThemes } from 'Stores/Theme';
import { LanguageStore } from 'Stores/Language';
Expand Down Expand Up @@ -217,8 +217,7 @@ export class AppUser extends AbstractApp {
setInterval(reloadTime, 60000);

PgpUserStore.init();
// TODO:
// SMimeUserStore.loadCertificates();
SMimeUserStore.loadCertificates();

setTimeout(() => mailToHelper(SettingsGet('mailToEmail')), 500);

Expand Down
8 changes: 7 additions & 1 deletion dev/Model/Identity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractModel } from 'Knoin/AbstractModel';
import { addObservablesTo } from 'External/ko';
import { addObservablesTo, addComputablesTo } from 'External/ko';

export class IdentityModel extends AbstractModel {
/**
Expand Down Expand Up @@ -30,6 +30,12 @@ export class IdentityModel extends AbstractModel {

askDelete: false
});

addComputablesTo(this, {
smimeKeyEncrypted: () => this.smimeKey().includes('-----BEGIN ENCRYPTED PRIVATE KEY-----')
// smimeKeyValid: () => this.smimeKeyEncrypted() | this.smimeKey().includes('-----BEGIN PRIVATE KEY-----')
// smimeCertificateValid: () => this.smimeKey().includes('-----BEGIN CERTIFICATE-----')
});
}

/**
Expand Down
3 changes: 2 additions & 1 deletion dev/View/Popup/Compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ export class ComposePopupView extends AbstractViewPopup {
|| SMimeUserStore.find(certificate => email == certificate.emailAddress && certificate.smimeencrypt)
).length : 0;
this.canSMimeEncrypt(length && length === count);
console.log({canSMimeEncrypt:this.canSMimeEncrypt()});
}

async getMessageRequestParams(sSaveFolder, draft)
Expand Down Expand Up @@ -1537,7 +1538,7 @@ export class ComposePopupView extends AbstractViewPopup {
} else if (this.canSMimeSign()) {
params.signCertificate = identity.smimeCertificate();
params.signPrivateKey = identity.smimeKey();
if (identity.smimeKey().includes('-----BEGIN ENCRYPTED PRIVATE KEY-----')) {
if (identity.smimeKeyEncrypted()) {
const pass = await AskPopupView.password('S/MIME private key', 'CRYPTO/SIGN');
params.signPassphrase = pass?.password;
}
Expand Down
12 changes: 2 additions & 10 deletions dev/View/User/MailBox/MessageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,6 @@ export class MailMessageView extends AbstractViewRight {
}

async smimeDecrypt() {
/*
$sCertificate = $this->GetActionParam('signCertificate', '');
$sPrivateKey = $this->GetActionParam('signPrivateKey', '');
$sPassphrase = $this->GetActionParam('passphrase', '');
// TODO: find private key and certificate to decrypt
const oMessage = currentMessage();
*/
const message = currentMessage();
let data = message.smimeEncrypted(); // { partId: "1" }
const addresses = message.from.concat(message.to, message.cc, message.bcc).map(item => item.email),
Expand All @@ -642,7 +634,7 @@ export class MailMessageView extends AbstractViewRight {
// data.bodyPart = data.bodyPart?.raw;
data.certificate = identity.smimeCertificate();
data.privateKey = identity.smimeKey();
if (identity.smimeKey().includes('-----BEGIN ENCRYPTED PRIVATE KEY-----')) {
if (identity.smimeKeyEncrypted()) {
const pass = await AskPopupView.password('S/MIME private key', 'CRYPTO/DECRYPT');
data.passphrase = pass?.password;
}
Expand Down Expand Up @@ -672,7 +664,7 @@ export class MailMessageView extends AbstractViewRight {
message.html() ? message.viewHtml() : message.viewPlain();
response.Result.body = null;
}
message.smimeVerified(response.Result);
message.smimeVerified(true);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
<div id="mailvelope-settings" style="height:40em" data-bind="visible: canMailvelope"></div>
</details>

<!-- TODO
<details>
<summary class="legend">S/MIME Certificates</summary>
<table class="table table-hover list-table">
Expand All @@ -138,15 +137,16 @@
<span data-i18n="CRYPTO/VALID_UNTIL"></span>:
<time data-time-format="FULL" data-bind="time:validTo_time_t"></time>
</td>
<!-- TODO
<td>
<a class="btn btn-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: remove"
data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td>
<td>
<span class="delete-key fontastic" data-bind="visible: !askDelete(), click: openForDeletion">🗑</span>
</td>
-->
</tr>
</tbody>
</table>
</details>
-->

0 comments on commit e9a63b4

Please sign in to comment.