mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Delete OpenPGP keys on the server when they are deleted in the browser
This commit is contained in:
parent
7eaa065d76
commit
c0348893af
3 changed files with 31 additions and 4 deletions
|
|
@ -13,7 +13,7 @@ import { OpenPgpKeyPopupView } from 'View/Popup/OpenPgpKey';
|
|||
|
||||
import { Passphrases } from 'Storage/Passphrases';
|
||||
|
||||
import { baseCollator } from 'Common/Translator';
|
||||
import { baseCollator, getNotification } from 'Common/Translator';
|
||||
|
||||
const
|
||||
loaded = () => !!window.openpgp,
|
||||
|
|
@ -120,6 +120,17 @@ class OpenPgpKeyModel {
|
|||
OpenPGPUserStore.publicKeys.remove(this);
|
||||
storeOpenPgpKeys(OpenPGPUserStore.publicKeys, publicKeysItem);
|
||||
}
|
||||
Remote.request('DeletePGPKey',
|
||||
(iError, oData) => {
|
||||
if (oData) {
|
||||
if (iError || oData.Result === false) {
|
||||
alert(oData.message || getNotification(iError));
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: this.armor
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -287,6 +287,14 @@ trait Pgp
|
|||
return $this->DefaultResponse(($key && $keyId && Backup::PGPKey($key, $keyId)));
|
||||
}
|
||||
|
||||
public function DoDeletePGPKey(): array
|
||||
{
|
||||
$key = $this->GetActionParam('key', '');
|
||||
$keyId = $this->GetActionParam('keyId', '');
|
||||
$success = $key && Backup::PGPKey($key, $keyId, true);
|
||||
return $this->DefaultResponse($success, ['code' => (int)!$success]);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://datatracker.ietf.org/doc/html/rfc3156#section-5
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace SnappyMail\PGP;
|
|||
|
||||
class Backup
|
||||
{
|
||||
public static function PGPKey(string $key, string $keyId = '') : bool
|
||||
public static function PGPKey(string $key, string $keyId = '', $doDelete = false) : bool
|
||||
{
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
$oAccount = $oActions->getMainAccountFromToken();
|
||||
|
|
@ -21,15 +21,23 @@ class Backup
|
|||
true
|
||||
);
|
||||
if (\str_contains($key, 'PGP PRIVATE KEY')) {
|
||||
$fileName = "{$dir}{$keyId}.key";
|
||||
if ($doDelete) {
|
||||
return !file_exists($fileName) || unlink($fileName);
|
||||
}
|
||||
$hash = $oAccount->CryptKey();
|
||||
$key = \SnappyMail\Crypt::Encrypt($key, $hash);
|
||||
$key[1] = \base64_encode($key[1]);
|
||||
$key[2] = \base64_encode($key[2]);
|
||||
$key[3] = \hash_hmac('sha1', $key[2], $hash);
|
||||
return !!\file_put_contents("{$dir}{$keyId}.key", \json_encode($key));
|
||||
return !!\file_put_contents($fileName, \json_encode($key));
|
||||
}
|
||||
if (\str_contains($key, 'PGP PUBLIC KEY')) {
|
||||
return !!\file_put_contents("{$dir}{$keyId}_public.asc", $key);
|
||||
$fileName = "{$dir}{$keyId}_public.asc";
|
||||
if ($doDelete) {
|
||||
return !file_exists($fileName) || unlink($fileName);
|
||||
}
|
||||
return !!\file_put_contents($fileName, $key);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue