Many more changes for #89

This commit is contained in:
the-djmaze 2022-01-20 16:38:27 +01:00
parent 3cc3a76b23
commit a7eeeb4f55
18 changed files with 310 additions and 236 deletions

View file

@ -1192,7 +1192,7 @@ class Actions
$aResult[] = Enumerations\Capa::OPEN_PGP;
}
if (\SnappyMail\PGP\GnuPG::isSupported()) {
$aResult[] = Enumerations\Capa::GNUGP;
$aResult[] = Enumerations\Capa::GNUPG;
}
if ($bAdmin || ($oAccount && $oAccount->Domain()->UseSieve())) {

View file

@ -16,50 +16,48 @@ trait Pgp
return \SnappyMail\PGP\GnuPG::getInstance($pgp_dir);
}
public function DoGnupgGetKeysEmails() : array
public function DoGnupgGetKeys() : array
{
$GPG = $this->GnuPG();
if ($GPG) {
$keys = [];
/**
* PECL GnuPG can't list private
*
* gpg --list-secret-keys
* gpg --list-public-keys
*/
foreach ($GPG->keyInfo('') as $info) {
if (!$info['disabled'] && !$info['expired'] && !$info['revoked']) {
$info['can_verify'] = $info['can_sign'];
$info['can_sign'] = $info['can_decrypt'] = false;
foreach ($info['subkeys'] as $key) {
$hasKey = $GPG->hasPrivateKey($key['keygrip']);
$info['can_sign'] = $info['can_sign'] || ($info['can_verify'] && $hasKey);
$info['can_decrypt'] = $info['can_decrypt'] || ($info['can_encrypt'] && $hasKey);
}
foreach ($info['uids'] as $uid) {
$id = $uid['email'];
if (isset($keys[$id])) {
$keys[$id]['can_sign'] = $keys[$id]['can_sign'] || $info['can_sign'];
// Public Key tasks
$keys[$id]['can_verify'] = $keys[$id]['can_verify'] || $info['can_verify'];
$keys[$id]['can_encrypt'] = $keys[$id]['can_encrypt'] || $info['can_encrypt'];
// Private Key tasks
$keys[$id]['can_sign'] = $keys[$id]['can_sign'] || $info['can_sign'];
$keys[$id]['can_decrypt'] = $keys[$id]['can_decrypt'] || $info['can_decrypt'];
} else {
$keys[$id] = [
'name' => $uid['name'],
'email' => $uid['email'],
// Public Key tasks
'can_verify' => $info['can_sign'],
'can_encrypt' => $info['can_encrypt'],
// Private Key tasks
'can_sign' => $info['can_sign'],
'can_encrypt' => $info['can_encrypt']
'can_decrypt' => $info['can_decrypt']
];
}
}
/*
foreach ($info['subkeys'] as $key) {
$key['can_authenticate'] = true
$key['can_certify'] = true
$key['can_encrypt'] = true
$key['can_sign'] = true
$key['disabled'] = false
$key['expired'] = false
$key['expires'] = 0
$key['fingerprint'] = "99BBB6F2FDDE9E20CD78B98DC85B364A5A6CCF52"
$key['invalid'] = false
$key['is_cardkey'] = false
$key['is_de_vs'] = true
$key['is_qualified'] = false
$key['is_secret'] = false
$key['keygrip'] = "CBCCF45D4F6D300417F044A08E08F8F14522BABE"
$key['keyid'] = "C85B364A5A6CCF52"
$key['length'] = 4096
$key['pubkey_algo'] = 1
$key['revoked'] = false
$key['timestamp'] = 1428449321
}
*/
}
}
return $this->DefaultResponse(__FUNCTION__, $keys);
@ -67,13 +65,13 @@ trait Pgp
return $this->FalseResponse(__FUNCTION__);
}
public function DoPgpImportKey() : array
public function DoGnupgImportKey() : array
{
$sKey = $this->GetActionParam('Key', '');
$sKeyId = $this->GetActionParam('KeyId', '');
$sPublicKey = $this->GetActionParam('PublicKey', '');
$sEmail = $this->GetActionParam('Email', '');
if (!$sPublicKey) {
if (!$sKey) {
try {
if (!$sKeyId) {
if (\preg_match('/[^\\s<>]+@[^\\s<>]+/', $sEmail, $aMatch)) {
@ -97,16 +95,16 @@ trait Pgp
}
}
if ($sKeyId) {
$sPublicKey = \SnappyMail\PGP\Keyservers::get($sKeyId);
$sKey = \SnappyMail\PGP\Keyservers::get($sKeyId);
}
} catch (\Throwable $e) {
// ignore
}
}
$GPG = $sPublicKey ? $this->GnuPG() : null;
$GPG = $sKey ? $this->GnuPG() : null;
return $GPG
? $this->DefaultResponse(__FUNCTION__, $GPG->import($sPublicKey))
? $this->DefaultResponse(__FUNCTION__, $GPG->import($sKey))
: $this->FalseResponse(__FUNCTION__);
}
}

View file

@ -254,7 +254,7 @@ trait Response
$mResult['Plain'] = $mResponse->Plain();
// $this->GetCapa(false, Capa::OPEN_PGP) || $this->GetCapa(false, Capa::GNUGP)
// $this->GetCapa(false, Capa::OPEN_PGP) || $this->GetCapa(false, Capa::GNUPG)
$mResult['isPgpEncrypted'] = $mResponse->isPgpEncrypted();
$mResult['PgpSigned'] = $mResponse->PgpSigned();

View file

@ -4,7 +4,7 @@ namespace RainLoop\Enumerations;
class Capa
{
const GNUGP = 'GNUGP';
const GNUPG = 'GNUPG';
const OPEN_PGP = 'OPEN_PGP';
const PREFETCH = 'PREFETCH';
const THEMES = 'THEMES';

View file

@ -374,6 +374,17 @@ class GnuPG
return false;
}
/**
* Returns an array with information about all keys that matches the given pattern
*/
public function hasPrivateKey(string $keygrip) : bool
{
if ($this->GnuPG || $this->Crypt_GPG) {
return \is_file("{$this->homedir}/private-keys-v1.d/{$keygrip}.key");
}
return false;
}
/**
* Toggle armored output
* When true the output is ASCII

View file

@ -8,6 +8,22 @@
<div class="control-group" data-bind="css: {'error': keyError}">
<textarea class="inputKey input-xxlarge" rows="14" autofocus="" autocomplete="off" data-bind="value: key"></textarea>
</div>
<div class="control-group">
<div data-bind="visible: canGnuPG, component: {
name: 'Checkbox',
params: {
label: 'Store in GnuPG',
value: saveGnuPG
}
}"></div>
<div data-bind="visible: canOpenPGP, component: {
name: 'Checkbox',
params: {
label: 'Store in OpenPGP.js',
value: saveOpenPGP
}
}"></div>
</div>
</div>
</div>
<footer>

View file

@ -9,9 +9,7 @@
</div>
<div class="control-group" data-bind="css: {'error': emailError}">
<label data-i18n="GLOBAL/EMAIL"></label>
<input type="email" class="input-xlarge"
autofocus="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
data-bind="value: email" />
<select class="input-xlarge" data-bind="value: email, options: identities, optionsText: 'email', optionsValue: 'email'"></select>
</div>
<div class="control-group">
<label data-i18n="GLOBAL/NAME"></label>

View file

@ -3,6 +3,7 @@
<i class="icon-list-add"></i>
<span data-i18n="SETTINGS_OPEN_PGP/BUTTON_ADD_OPEN_PGP_KEY"></span>
</button>
<!-- ko if: canOpenPGP -->
&nbsp;&nbsp;
<div style="display: inline-block" data-i18n="[title]SETTINGS_OPEN_PGP/GENERATE_ONLY_HTTPS">
<button class="btn" data-bind="click: generateOpenPgpKey">
@ -10,6 +11,8 @@
<span data-i18n="SETTINGS_OPEN_PGP/BUTTON_GENERATE_OPEN_PGP_KEYS"></span>
</button>
</div>
<!-- /ko -->
<br />
<br />
<div class="control-group">
@ -22,8 +25,27 @@
}"></div>
</div>
<br />
<table class="table table-hover list-table" data-bind="i18nUpdate: openpgpkeys">
<tbody data-bind="foreach: openpgpkeysPrivate">
<h1>GnuPG</h1>
<table class="table table-hover list-table">
<tbody data-bind="foreach: gnupgkeys, i18nUpdate: gnupgkeys">
<tr class="open-pgp-key-item">
<td>
<span data-bind="visible: can_sign" class="fontastic" data-i18n="[title]SETTINGS_OPEN_PGP/TITLE_PRIVATE">✍/🔓</span>
<td>
<td>
<span data-bind="visible: can_encrypt" class="fontastic" data-i18n="[title]SETTINGS_OPEN_PGP/TITLE_PUBLIC">🔒</span>
</td>
<td>
<!-- ko text: email --><!-- /ko -->
</td>
</tr>
</tbody>
</table>
<h1>OpenPGP.js</h1>
<table class="table table-hover list-table">
<tbody data-bind="foreach: openpgpkeysPrivate, i18nUpdate: openpgpkeysPrivate">
<tr class="open-pgp-key-item">
<td>
<span class="open-pgp-key-img fontastic" data-i18n="[title]SETTINGS_OPEN_PGP/TITLE_PRIVATE">🔒</span>
@ -40,7 +62,7 @@
</td>
<td class="view-open-pgp-key fontastic" data-bind="click: function (openPgpKey) { $root.viewOpenPgpKey(openPgpKey); }">👁</td>
</tr>
</tbody><tbody data-bind="foreach: openpgpkeysPublic">
</tbody><tbody data-bind="foreach: openpgpkeysPublic, i18nUpdate: openpgpkeysPublic">
<tr class="open-pgp-key-item">
<td>
<span class="open-pgp-key-img fontastic" data-i18n="[title]SETTINGS_OPEN_PGP/TITLE_PUBLIC">🔑</span>