Set S/MIME private key and certificate per identity #259

This commit is contained in:
the-djmaze 2024-02-18 17:18:47 +01:00
parent 33de51b2d5
commit 6fa4dff23b
6 changed files with 83 additions and 35 deletions

View file

@ -25,6 +25,9 @@ export class IdentityModel extends AbstractModel {
pgpSign: false, pgpSign: false,
pgpEncrypt: false, pgpEncrypt: false,
smimeKey: '',
smimeCertificate: '',
askDelete: false askDelete: false
}); });
} }

View file

@ -38,6 +38,20 @@ export class IdentityPopupView extends AbstractViewPopup {
) )
); );
this.defaultOptionsAfterRender = defaultOptionsAfterRender; this.defaultOptionsAfterRender = defaultOptionsAfterRender;
this.createSelfSigned = this.createSelfSigned.bind(this);
}
createSelfSigned() {
let identity = this.identity();
Remote.request('CreateSMimeCertificate', (iError, oData) => {
if (oData.Result.x509) {
identity.smimeKey(oData.Result.pkey);
identity.smimeCertificate(oData.Result.x509);
}
}, {
email: identity.email()
});
} }
submitForm(form) { submitForm(form) {

View file

@ -29,7 +29,7 @@ trait SMime
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT \RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
), '/') . '/.smime'; ), '/') . '/.smime';
*/ */
$sEmail = $this->GetActionParam('Email', '') ?: $oAccount->Email(); $sEmail = $this->GetActionParam('email', '') ?: $oAccount->Email();
$cert = new Certificate(); $cert = new Certificate();
$cert->distinguishedName['emailAddress'] = $sEmail; $cert->distinguishedName['emailAddress'] = $sEmail;

View file

@ -17,7 +17,7 @@ trait User
use Messages; use Messages;
use Attachments; use Attachments;
use Pgp; use Pgp;
// use SMime; use SMime;
private ?Suggestions $oSuggestionsProvider = null; private ?Suggestions $oSuggestionsProvider = null;

View file

@ -24,8 +24,11 @@ class Identity implements \JsonSerializable
private bool $bSignatureInsertBefore = false; private bool $bSignatureInsertBefore = false;
private bool $bPgpEncrypt = false; private bool $pgpEncrypt = false;
private bool $bPgpSign = false; private bool $pgpSign = false;
private string $SMimeKey = '';
private string $SMimeCertificate = '';
function __construct(string $sId = '', string $sEmail = '') function __construct(string $sId = '', string $sEmail = '')
{ {
@ -95,8 +98,10 @@ class Identity implements \JsonSerializable
$this->sSignature = !empty($aData['Signature']) ? $aData['Signature'] : ''; $this->sSignature = !empty($aData['Signature']) ? $aData['Signature'] : '';
$this->bSignatureInsertBefore = !empty($aData['SignatureInsertBefore']); $this->bSignatureInsertBefore = !empty($aData['SignatureInsertBefore']);
$this->sSentFolder = isset($aData['sentFolder']) ? $aData['sentFolder'] : ''; $this->sSentFolder = isset($aData['sentFolder']) ? $aData['sentFolder'] : '';
$this->bPgpEncrypt = !empty($aData['pgpEncrypt']); $this->pgpEncrypt = !empty($aData['pgpEncrypt']);
$this->bPgpSign = !empty($aData['pgpSign']); $this->pgpSign = !empty($aData['pgpSign']);
$this->SMimeKey = isset($aData['smimeKey']) ? $aData['smimeKey'] : '';
$this->SMimeCertificate = isset($aData['smimeCertificate']) ? $aData['smimeCertificate'] : '';
return true; return true;
} }
@ -116,8 +121,10 @@ class Identity implements \JsonSerializable
'Signature' => $this->sSignature, 'Signature' => $this->sSignature,
'SignatureInsertBefore' => $this->bSignatureInsertBefore, 'SignatureInsertBefore' => $this->bSignatureInsertBefore,
'sentFolder' => $this->sSentFolder, 'sentFolder' => $this->sSentFolder,
'pgpEncrypt' => $this->bPgpEncrypt, 'pgpEncrypt' => $this->pgpEncrypt,
'pgpSign' => $this->bPgpSign 'pgpSign' => $this->pgpSign,
'smimeKey' => $this->SMimeKey,
'smimeCertificate' => $this->SMimeCertificate
); );
} }
@ -135,8 +142,10 @@ class Identity implements \JsonSerializable
'signature' => $this->sSignature, 'signature' => $this->sSignature,
'signatureInsertBefore' => $this->bSignatureInsertBefore, 'signatureInsertBefore' => $this->bSignatureInsertBefore,
'sentFolder' => $this->sSentFolder, 'sentFolder' => $this->sSentFolder,
'pgpEncrypt' => $this->bPgpEncrypt, 'pgpEncrypt' => $this->pgpEncrypt,
'pgpSign' => $this->bPgpSign 'pgpSign' => $this->pgpSign,
'smimeKey' => $this->SMimeKey,
'smimeCertificate' => $this->SMimeCertificate
); );
} }

View file

@ -55,33 +55,55 @@
<input type="radio" name="identitytabs" id="tab-identity-crypto"> <input type="radio" name="identitytabs" id="tab-identity-crypto">
<label data-i18n="CONTACTS/TAB_CRYPTO" for="tab-identity-crypto" role="tab" aria-selected="false" aria-controls="panel3" tabindex="0"></label> <label data-i18n="CONTACTS/TAB_CRYPTO" for="tab-identity-crypto" role="tab" aria-selected="false" aria-controls="panel3" tabindex="0"></label>
<div class="form-horizontal tab-content" role="tabpanel" aria-hidden="false"> <div class="form-horizontal tab-content" role="tabpanel" aria-hidden="false">
<div data-bind="component: { <details>
name: 'Checkbox', <summary><strong>PGP</strong></summary>
params: { <div class="control-group">
label: 'OPENPGP/LABEL_SIGN', <div data-bind="component: {
value: pgpSign, name: 'Checkbox',
name: 'pgpSign' params: {
} label: 'OPENPGP/LABEL_SIGN',
}"></div> value: pgpSign,
<div data-bind="component: { name: 'pgpSign'
name: 'Checkbox', }
params: { }"></div>
label: 'OPENPGP/LABEL_ENCRYPT', </div>
value: pgpEncrypt, <div class="control-group">
name: 'pgpEncrypt' <div data-bind="component: {
} name: 'Checkbox',
}"></div> params: {
label: 'OPENPGP/LABEL_ENCRYPT',
value: pgpEncrypt,
name: 'pgpEncrypt'
}
}"></div>
</div>
<!-- <!--
<div class="control-group"> <div class="control-group">
<label data-i18n="OPENPGP/LABEL_ENCRYPT"></label> <label data-i18n="OPENPGP/LABEL_ENCRYPT"></label>
<select name="PgpEncrypt" data-bind="value: pgpEncrypt"> <select name="PgpEncrypt" data-bind="value: pgpEncrypt">
<option value="Ask" data-i18n="CONTACTS/ASK"></option> <option value="Ask" data-i18n="CONTACTS/ASK"></option>
<option value="Never" data-i18n="CONTACTS/NEVER"></option> <option value="Never" data-i18n="CONTACTS/NEVER"></option>
<option value="Always" data-i18n="CONTACTS/ALWAYS"></option> <option value="Always" data-i18n="CONTACTS/ALWAYS"></option>
<option value="IfPossible" data-i18n="CONTACTS/ALWAYS_IF_POSSIBLE"></option> <option value="IfPossible" data-i18n="CONTACTS/ALWAYS_IF_POSSIBLE"></option>
</select> </select>
</div> </div>
--> -->
</details>
<details>
<summary><strong>S/MIME</strong></summary>
<div class="control-group">
<label>Private key</label>
<textarea name="smimeKey" class="input-xxlarge" rows="14" autofocus="" autocomplete="off" data-bind="value: smimeKey"></textarea>
</div>
<div class="control-group">
<label>Certificate</label>
<textarea name="smimeCertificate" class="input-xxlarge" rows="14" autofocus="" autocomplete="off" data-bind="value: smimeCertificate"></textarea>
</div>
<div class="control-group" data-bind="hidden:smimeKey">
<label></label>
<button type="button" data-bind="click: $root.createSelfSigned">Create self-signed</button>
</div>
</details>
</div> </div>
<input type="radio" name="identitytabs" id="tab-identity-advanced"> <input type="radio" name="identitytabs" id="tab-identity-advanced">