Properly load keyrings of Mailvelope, OpenPGP.js and GnuPG

This commit is contained in:
the-djmaze 2022-01-19 20:14:21 +01:00
parent 9f0b872839
commit c2e162b01b
8 changed files with 98 additions and 46 deletions

View file

@ -1191,6 +1191,9 @@ class Actions
if ($oConfig->Get('security', 'openpgp', false)) {
$aResult[] = Enumerations\Capa::OPEN_PGP;
}
if (\SnappyMail\PGP\GnuPG::isSupported()) {
$aResult[] = Enumerations\Capa::GNUGP;
}
if ($bAdmin || ($oAccount && $oAccount->Domain()->UseSieve())) {
$aResult[] = Enumerations\Capa::SIEVE;

View file

@ -9,39 +9,60 @@ trait Pgp
*/
public function GnuPG() : ?\SnappyMail\PGP\GnuPG
{
$pgp_dir = $this->StorageProvider()->GenerateFilePath(
$pgp_dir = \dirname($this->StorageProvider()->GenerateFilePath(
$this->getAccountFromToken(),
\RainLoop\Providers\Storage\Enumerations\StorageType::PGP
);
));
return \SnappyMail\PGP\GnuPG::getInstance($pgp_dir);
}
public function DoPgpGetKeysEmails() : array
public function DoGnupgGetKeysEmails() : array
{
$GPG = $this->GnuPG();
if ($GPG) {
$sign = $encrypt = $keys = [];
$keys = [];
foreach ($GPG->keyInfo('') as $info) {
if (!$info['disabled'] && !$info['expired'] && !$info['revoked']) {
if ($info['can_sign']) {
foreach ($info['uids'] as $uid) {
$private[] = $info['email'];
foreach ($info['uids'] as $uid) {
$id = $uid['email'];
if (isset($keys[$id])) {
$keys[$id]['can_sign'] = $keys[$id]['can_sign'] || $info['can_sign'];
$keys[$id]['can_encrypt'] = $keys[$id]['can_encrypt'] || $info['can_encrypt'];
} else {
$keys[$id] = [
'name' => $uid['name'],
'email' => $uid['email'],
'can_sign' => $info['can_sign'],
'can_encrypt' => $info['can_encrypt']
];
}
}
if ($info['can_encrypt']) {
foreach ($info['uids'] as $uid) {
$public[] = $info['email'];
}
/*
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
}
*/
}
$keys[] = $info;
}
return $this->DefaultResponse(__FUNCTION__, [
'sign' => $sign,
'encrypt' => $encrypt,
'keys' => $keys,
'info' => $GPG->getEngineInfo()
]);
return $this->DefaultResponse(__FUNCTION__, $keys);
}
return $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::OPEN_PGP) || $this->GetCapa(false, Capa::GNUGP)
$mResult['isPgpEncrypted'] = $mResponse->isPgpEncrypted();
$mResult['PgpSigned'] = $mResponse->PgpSigned();

View file

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

View file

@ -11,10 +11,16 @@ class GnuPG
// Instance of PEAR Crypt_GPG
$Crypt_GPG;
public static function getInstance(string $home) : ?self
public static function isSupported() : bool
{
return \class_exists('gnupg')
|| \stream_resolve_include_path('Crypt/GPG.php');
}
public static function getInstance(string $base_dir) : ?self
{
$self = null;
$home .= '/.gnupg';
$home = $base_dir . '/.gnupg';
if (\class_exists('gnupg')) {
$self = new self;
$self->GnuPG = new \gnupg([