Also allow backup PGP keys on server on import #89

This commit is contained in:
the-djmaze 2024-02-08 18:01:15 +01:00
parent 83aa65981b
commit 43cbbd51c1
4 changed files with 29 additions and 22 deletions

View file

@ -117,19 +117,6 @@ export const GnuPGUserStore = new class {
return SettingsCapa('GnuPG');
}
importKey(key, callback) {
Remote.request('GnupgImportKey',
(iError, oData) => {
if (oData?.Result/* && (oData.Result.imported || oData.Result.secretimported)*/) {
this.loadKeyrings();
}
callback?.(iError, oData);
}, {
key: key
}
);
}
/**
keyPair.privateKey
keyPair.publicKey

View file

@ -19,7 +19,7 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
keyErrorMessage: '',
saveGnuPG: true,
saveServer: false
saveServer: true
});
this.canGnuPG = GnuPGUserStore.isSupported();
@ -69,9 +69,22 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
match = reg.exec(keyTrimmed);
if (match && 0 < count) {
if (match[0] && match[1] && match[2] && match[1] === match[2]) {
this.saveGnuPG() && GnuPGUserStore.isSupported() && GnuPGUserStore.importKey(this.key(), (iError, oData) => {
iError && alert(oData.ErrorMessage);
});
const GnuPG = this.saveGnuPG() && GnuPGUserStore.isSupported(),
backup = this.saveServer();
if (GnuPG || backup()) {
Remote.request('PgpImportKey',
(iError, oData) => {
if (GnuPG && oData?.Result/* && (oData.Result.imported || oData.Result.secretimported)*/) {
GnuPGUserStore.loadKeyrings();
}
iError && alert(oData.ErrorMessage);
}, {
key: this.key(),
gnuPG: GnuPG,
backup: backup
}
);
}
OpenPGPUserStore.isSupported() && OpenPGPUserStore.importKey(this.key());
}

View file

@ -190,7 +190,7 @@ trait Pgp
return $this->DefaultResponse($GPG ? $GPG->deleteKey($sKeyId, $bPrivate) : false);
}
public function DoGnupgImportKey() : array
public function DoPgpImportKey() : array
{
$sKey = $this->GetActionParam('key', '');
$sKeyId = $this->GetActionParam('keyId', '');
@ -217,8 +217,17 @@ trait Pgp
}
}
$GPG = $sKey ? $this->GnuPG() : null;
return $this->DefaultResponse($GPG ? $GPG->import($sKey) : false);
$result = false;
if ($sKey) {
if ($this->GetActionParam('backup', '')) {
$result = $result || Backup::PGPKey($sKey);
}
if ($this->GetActionParam('gnuPG', '') && ($GPG = $this->GnuPG())) {
$result = $result || $GPG->import($sKey);
}
}
return $this->DefaultResponse($result);
}
/**

View file

@ -13,7 +13,6 @@
<textarea class="input-xxlarge" rows="14" autofocus="" autocomplete="off" data-bind="value: key" required=""></textarea>
</div>
<div class="control-group">
<!--
<div data-bind="component: {
name: 'Checkbox',
params: {
@ -22,7 +21,6 @@
}
}"></div>
<br>
-->
<div data-bind="visible: canGnuPG, component: {
name: 'Checkbox',
params: {