Skip to content

Commit

Permalink
Improved and bugfix handling of GnuPG for #89
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Jan 24, 2022
1 parent 51fedab commit 1d3673f
Show file tree
Hide file tree
Showing 3 changed files with 450 additions and 295 deletions.
53 changes: 6 additions & 47 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Pgp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function GnuPG() : ?\SnappyMail\PGP\GnuPG
*/
if (80 < \strlen($homedir)) {
// First try a symbolic link
$link = \sys_get_temp_dir() . '/snappymail';
if (\is_dir($link) || \mkdir($link, 0700, true)) {
$tmpdir = \sys_get_temp_dir() . '/snappymail';
if (\is_dir($tmpdir) || \mkdir($tmpdir, 0700, true)) {
$link = $tmpdir . '/' . \md5($homedir);
if (\is_link($homedir) || \symlink($homedir, $link)) {
if (\is_link($link) || \symlink($homedir, $link)) {
$homedir = $link;
}
}
Expand All @@ -49,50 +49,9 @@ public function GnuPG() : ?\SnappyMail\PGP\GnuPG
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])) {
// 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_decrypt' => $info['can_decrypt']
];
}
}
}
}
return $this->DefaultResponse(__FUNCTION__, $keys);
}
return $this->FalseResponse(__FUNCTION__);
return $GPG
? $this->DefaultResponse(__FUNCTION__, $GPG->keyInfo(''))
: $this->FalseResponse(__FUNCTION__);
}

public function DoGnupgImportKey() : array
Expand Down
Loading

0 comments on commit 1d3673f

Please sign in to comment.