mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
OpenPGP.js automatically import backup keys from server
This commit is contained in:
parent
4365892927
commit
b5dbd0cc7a
2 changed files with 25 additions and 14 deletions
|
|
@ -18,8 +18,6 @@ import { OpenPgpGeneratePopupView } from 'View/Popup/OpenPgpGenerate';
|
||||||
import { SMimeUserStore } from 'Stores/User/SMime';
|
import { SMimeUserStore } from 'Stores/User/SMime';
|
||||||
import { SMimeImportPopupView } from 'View/Popup/SMimeImport';
|
import { SMimeImportPopupView } from 'View/Popup/SMimeImport';
|
||||||
|
|
||||||
import Remote from 'Remote/User/Fetch';
|
|
||||||
|
|
||||||
export class UserSettingsSecurity extends AbstractViewSettings {
|
export class UserSettingsSecurity extends AbstractViewSettings {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
@ -62,9 +60,7 @@ export class UserSettingsSecurity extends AbstractViewSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
importToOpenPGP() {
|
importToOpenPGP() {
|
||||||
OpenPGPUserStore.isSupported() && Remote.request('GetPGPKeys',
|
OpenPGPUserStore.loadBackupKeys();
|
||||||
(iError, oData) => !iError && oData.Result && OpenPGPUserStore.importKeys(oData.Result)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
importToSMime() {
|
importToSMime() {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ import { Passphrases } from 'Storage/Passphrases';
|
||||||
import { baseCollator } from 'Common/Translator';
|
import { baseCollator } from 'Common/Translator';
|
||||||
|
|
||||||
const
|
const
|
||||||
|
loaded = () => !!window.openpgp,
|
||||||
|
|
||||||
findOpenPGPKey = (keys, query/*, sign*/) =>
|
findOpenPGPKey = (keys, query/*, sign*/) =>
|
||||||
keys.find(key =>
|
keys.find(key =>
|
||||||
key.for(query) || query == key.id || query == key.fingerprint
|
key.for(query) || query == key.id || query == key.fingerprint
|
||||||
|
|
@ -134,23 +136,36 @@ export const OpenPGPUserStore = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadKeyrings() {
|
loadKeyrings() {
|
||||||
if (window.openpgp) {
|
if (loaded()) {
|
||||||
loadOpenPgpKeys(publicKeysItem).then(keys => {
|
loadOpenPgpKeys(publicKeysItem)
|
||||||
|
.then(keys => {
|
||||||
this.publicKeys(dedup(keys));
|
this.publicKeys(dedup(keys));
|
||||||
console.log('openpgp.js public keys loaded');
|
console.log('openpgp.js public keys loaded');
|
||||||
});
|
})
|
||||||
loadOpenPgpKeys(privateKeysItem).then(keys => {
|
.finally(() => {
|
||||||
this.privateKeys(dedup(keys));
|
loadOpenPgpKeys(privateKeysItem)
|
||||||
console.log('openpgp.js private keys loaded');
|
.then(keys => {
|
||||||
|
this.privateKeys(dedup(keys));
|
||||||
|
console.log('openpgp.js private keys loaded');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
/*SettingsGet('loadBackupKeys') && */this.loadBackupKeys();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadBackupKeys() {
|
||||||
|
Remote.request('GetPGPKeys',
|
||||||
|
(iError, oData) => !iError && oData.Result && this.importKeys(oData.Result)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isSupported() {
|
isSupported() {
|
||||||
return !!window.openpgp;
|
return loaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
importKey(armoredKey) {
|
importKey(armoredKey) {
|
||||||
|
|
@ -158,7 +173,7 @@ export const OpenPGPUserStore = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
async importKeys(keys) {
|
async importKeys(keys) {
|
||||||
if (window.openpgp) {
|
if (loaded()) {
|
||||||
const privateKeys = this.privateKeys(),
|
const privateKeys = this.privateKeys(),
|
||||||
publicKeys = this.publicKeys();
|
publicKeys = this.publicKeys();
|
||||||
for (const armoredKey of keys) try {
|
for (const armoredKey of keys) try {
|
||||||
|
|
@ -185,7 +200,7 @@ export const OpenPGPUserStore = new class {
|
||||||
keyPair.revocationCertificate
|
keyPair.revocationCertificate
|
||||||
*/
|
*/
|
||||||
storeKeyPair(keyPair) {
|
storeKeyPair(keyPair) {
|
||||||
if (window.openpgp) {
|
if (loaded()) {
|
||||||
openpgp.readKey({armoredKey:keyPair.publicKey}).then(key => {
|
openpgp.readKey({armoredKey:keyPair.publicKey}).then(key => {
|
||||||
this.publicKeys.push(new OpenPgpKeyModel(keyPair.publicKey, key));
|
this.publicKeys.push(new OpenPgpKeyModel(keyPair.publicKey, key));
|
||||||
storeOpenPgpKeys(this.publicKeys, publicKeysItem);
|
storeOpenPgpKeys(this.publicKeys, publicKeysItem);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue