mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
#89 Use OpenPGP.js v5.1.0 (still in progress)
This commit is contained in:
parent
dfd255545a
commit
ff7e41ad08
130 changed files with 1871 additions and 44411 deletions
|
|
@ -67,16 +67,6 @@ export const
|
|||
*/
|
||||
staticLink = path => VERSION_PREFIX + 'static/' + path,
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
openPgpJs = () => staticLink('js/min/openpgp.min.js'),
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
openPgpWorkerJs = () => staticLink('js/min/openpgp.worker.min.js'),
|
||||
|
||||
/**
|
||||
* @param {string} theme
|
||||
* @returns {string}
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ export class MessageModel extends AbstractModel {
|
|||
hasExternals: false,
|
||||
|
||||
pgpSigned: null,
|
||||
pgpEncrypted: null,
|
||||
isPgpEncrypted: false,
|
||||
pgpSignedVerifyStatus: SignedVerifyStatus.None,
|
||||
pgpSignedVerifyUser: '',
|
||||
|
|
@ -181,6 +182,7 @@ export class MessageModel extends AbstractModel {
|
|||
this.attachments(new AttachmentCollectionModel);
|
||||
|
||||
this.pgpSigned(null);
|
||||
this.pgpEncrypted(null);
|
||||
this.isPgpEncrypted(false);
|
||||
this.pgpSignedVerifyStatus(SignedVerifyStatus.None);
|
||||
this.pgpSignedVerifyUser('');
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import Remote from 'Remote/User/Fetch';
|
|||
|
||||
import { showScreenPopup } from 'Knoin/Knoin';
|
||||
|
||||
import { AddOpenPgpKeyPopupView } from 'View/Popup/AddOpenPgpKey';
|
||||
import { NewOpenPgpKeyPopupView } from 'View/Popup/NewOpenPgpKey';
|
||||
import { OpenPgpImportPopupView } from 'View/Popup/OpenPgpImport';
|
||||
import { OpenPgpGeneratePopupView } from 'View/Popup/OpenPgpGenerate';
|
||||
import { ViewOpenPgpKeyPopupView } from 'View/Popup/ViewOpenPgpKey';
|
||||
|
||||
import { Capa } from 'Common/Enums';
|
||||
|
|
@ -22,9 +22,7 @@ export class OpenPgpUserSettings /*extends AbstractViewSettings*/ {
|
|||
this.openpgpkeysPrivate = PgpUserStore.openpgpPrivateKeys;
|
||||
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
|
||||
// this.canOpenPGP = !!PgpUserStore.openpgpKeyring;
|
||||
this.canOpenPGP = Settings.capa(Capa.OpenPGP);
|
||||
// this.canGnuPG = !!PgpUserStore.gnupgKeyring;
|
||||
this.canGnuPG = Settings.capa(Capa.GnuPG);
|
||||
this.canMailvelope = !!window.mailvelope;
|
||||
|
||||
|
|
@ -34,11 +32,11 @@ export class OpenPgpUserSettings /*extends AbstractViewSettings*/ {
|
|||
}
|
||||
|
||||
addOpenPgpKey() {
|
||||
showScreenPopup(AddOpenPgpKeyPopupView);
|
||||
showScreenPopup(OpenPgpImportPopupView);
|
||||
}
|
||||
|
||||
generateOpenPgpKey() {
|
||||
showScreenPopup(NewOpenPgpKeyPopupView);
|
||||
showScreenPopup(OpenPgpGeneratePopupView);
|
||||
}
|
||||
|
||||
viewOpenPgpKey(openPgpKey) {
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ import ko from 'ko';
|
|||
|
||||
import { Capa } from 'Common/Enums';
|
||||
import { doc, createElement, Settings } from 'Common/Globals';
|
||||
import { openPgpJs, openPgpWorkerJs } from 'Common/Links';
|
||||
import { staticLink } from 'Common/Links';
|
||||
import { isArray, arrayLength } from 'Common/Utils';
|
||||
import { delegateRunOnDestroy } from 'Common/UtilsUser';
|
||||
|
||||
import { showScreenPopup } from 'Knoin/Knoin';
|
||||
//import { showScreenPopup } from 'Knoin/Knoin';
|
||||
|
||||
import { MessageOpenPgpPopupView } from 'View/Popup/MessageOpenPgp';
|
||||
//import { MessageOpenPgpPopupView } from 'View/Popup/MessageOpenPgp';
|
||||
|
||||
import { EmailModel } from 'Model/Email';
|
||||
import { OpenPgpKeyModel } from 'Model/OpenPgpKey';
|
||||
//import { EmailModel } from 'Model/Email';
|
||||
//import { OpenPgpKeyModel } from 'Model/OpenPgpKey';
|
||||
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
|
|
@ -19,6 +19,60 @@ const
|
|||
findKeyByHex = (keys, hash) =>
|
||||
keys.find(item => item && (hash === item.id || item.ids.includes(hash)));
|
||||
|
||||
/**
|
||||
* OpenPGP.js v5 removed the localStorage (keyring)
|
||||
* This should be compatible with the old OpenPGP.js v2
|
||||
*/
|
||||
const
|
||||
publicKeysItem = 'openpgp-public-keys',
|
||||
privateKeysItem = 'openpgp-private-keys',
|
||||
storage = window.localStorage,
|
||||
loadOpenPgpKeys = async itemname => {
|
||||
let keys = [], key,
|
||||
armoredKeys = JSON.parse(storage.getItem(itemname)),
|
||||
i = arrayLength(armoredKeys);
|
||||
if (i) {
|
||||
while (i--) {
|
||||
key = await openpgp.readKey({armoredKey:armoredKeys[i]});
|
||||
if (!key.err) {
|
||||
const aEmails = [];
|
||||
if (key.users) {
|
||||
key.users.forEach(user => {
|
||||
if (user.userID.email) {
|
||||
aEmails.push(user.userID.email);
|
||||
}
|
||||
});
|
||||
}
|
||||
keys.push({
|
||||
id: key.getKeyID().toHex(),
|
||||
fingerprint: key.getFingerprint(),
|
||||
can_encrypt: !!key.getEncryptionKey(),
|
||||
can_sign: !!key.getSigningKey(),
|
||||
emails: aEmails,
|
||||
armor: armoredKeys[i],
|
||||
deleteAccess: ko.observable(false)
|
||||
});
|
||||
// key.getUserIDs()
|
||||
// key.getPrimaryUser()
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
/*
|
||||
},
|
||||
storeKeys = async (itemname, keys) => {
|
||||
let armoredKeys = [], i = arrayLength(keys);
|
||||
if (i) {
|
||||
while (i--) {
|
||||
armoredKeys.push(await keys[i].armor());
|
||||
}
|
||||
storage.setItem(itemname, JSON.stringify(armoredKeys));
|
||||
} else {
|
||||
storage.removeItem(itemname);
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
export const PgpUserStore = new class {
|
||||
constructor() {
|
||||
/**
|
||||
|
|
@ -29,7 +83,6 @@ export const PgpUserStore = new class {
|
|||
this.gnupgKeys = ko.observableArray();
|
||||
|
||||
// OpenPGP.js
|
||||
this.openpgpKeyring = null;
|
||||
this.openpgpPublicKeys = ko.observableArray();
|
||||
this.openpgpPrivateKeys = ko.observableArray();
|
||||
|
||||
|
|
@ -39,21 +92,12 @@ export const PgpUserStore = new class {
|
|||
|
||||
init() {
|
||||
if (Settings.capa(Capa.OpenPGP) && window.crypto && crypto.getRandomValues) {
|
||||
const script = createElement('script', {src:openPgpJs()});
|
||||
script.onload = () => {
|
||||
if (window.Worker) {
|
||||
try {
|
||||
openpgp.initWorker({ path: openPgpWorkerJs() });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
this.loadKeyrings();
|
||||
};
|
||||
const script = createElement('script', {src:staticLink('js/min/openpgp.min.js')});
|
||||
script.onload = () => this.loadKeyrings();
|
||||
script.onerror = () => {
|
||||
this.loadKeyrings();
|
||||
console.error(script.src);
|
||||
}
|
||||
};
|
||||
doc.head.append(script);
|
||||
} else {
|
||||
this.loadKeyrings();
|
||||
|
|
@ -82,8 +126,14 @@ export const PgpUserStore = new class {
|
|||
}
|
||||
|
||||
if (openpgp) {
|
||||
this.openpgpKeyring = new openpgp.Keyring();
|
||||
this.reloadOpenPgpKeys();
|
||||
loadOpenPgpKeys(publicKeysItem).then(keys => {
|
||||
this.openpgpPublicKeys(keys || []);
|
||||
console.log('openpgp.js public keys loaded');
|
||||
});
|
||||
loadOpenPgpKeys(privateKeysItem).then(keys => {
|
||||
this.openpgpPrivateKeys(keys || [])
|
||||
console.log('openpgp.js private keys loaded');
|
||||
});
|
||||
}
|
||||
|
||||
if (Settings.capa(Capa.GnuPG)) {
|
||||
|
|
@ -101,69 +151,6 @@ export const PgpUserStore = new class {
|
|||
}
|
||||
}
|
||||
|
||||
reloadOpenPgpKeys() {
|
||||
if (this.openpgpKeyring) {
|
||||
const publicKeys = [],
|
||||
privateKeys = [],
|
||||
email = new EmailModel();
|
||||
|
||||
this.openpgpKeyring.getAllKeys().forEach(oItem => {
|
||||
if (oItem && oItem.primaryKey) {
|
||||
const aEmails = [],
|
||||
aUsers = [],
|
||||
primaryUser = oItem.getPrimaryUser(),
|
||||
user =
|
||||
primaryUser && primaryUser.user
|
||||
? primaryUser.user.userId.userid
|
||||
: oItem.users && oItem.users[0]
|
||||
? oItem.users[0].userId.userid
|
||||
: '';
|
||||
|
||||
if (oItem.users) {
|
||||
oItem.users.forEach(item => {
|
||||
if (item.userId) {
|
||||
email.clear();
|
||||
email.parse(item.userId.userid);
|
||||
if (email.validate()) {
|
||||
aEmails.push(email.email);
|
||||
aUsers.push(item.userId.userid);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (aEmails.length) {
|
||||
(oItem.isPrivate() ? privateKeys : publicKeys).push(
|
||||
new OpenPgpKeyModel(
|
||||
oItem.primaryKey.getFingerprint(),
|
||||
oItem.primaryKey
|
||||
.getKeyId()
|
||||
.toHex()
|
||||
.toLowerCase(),
|
||||
oItem.getKeyIds()
|
||||
.map(item => (item && item.toHex ? item.toHex() : null))
|
||||
.validUnique(),
|
||||
aUsers,
|
||||
aEmails,
|
||||
oItem.isPrivate(),
|
||||
oItem.armor(),
|
||||
user
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
delegateRunOnDestroy(this.openpgpPublicKeys());
|
||||
this.openpgpPublicKeys(publicKeys);
|
||||
|
||||
delegateRunOnDestroy(this.openpgpPrivateKeys());
|
||||
this.openpgpPrivateKeys(privateKeys);
|
||||
|
||||
console.log('openpgp.js ready');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
|
@ -186,6 +173,29 @@ export const PgpUserStore = new class {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
keyPair.privateKey
|
||||
keyPair.publicKey
|
||||
keyPair.revocationCertificate
|
||||
keyPair.onServer
|
||||
keyPair.inGnuPG
|
||||
keyPair.uid.name
|
||||
keyPair.uid.email
|
||||
*/
|
||||
storeKeyPair(keyPair, callback) {
|
||||
// if (Settings.capa(Capa.GnuPG)) {
|
||||
Remote.request('PgpStoreKeyPair',
|
||||
(iError, oData) => {
|
||||
if (oData && oData.Result) {
|
||||
// this.gnupgKeyring = oData.Result;
|
||||
}
|
||||
callback && callback(iError, oData);
|
||||
}, keyPair
|
||||
);
|
||||
// storeKeys(publicKeysItem);
|
||||
// storeKeys(privateKeysItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if verifying/encrypting a message is possible with given email addresses.
|
||||
* Returns the first library that can.
|
||||
|
|
@ -199,8 +209,8 @@ export const PgpUserStore = new class {
|
|||
return 'gnupg';
|
||||
}
|
||||
|
||||
length = this.openpgpKeyring && recipients.filter(email =>
|
||||
this.openpgpKeyring.publicKeys.getForAddress(email).length
|
||||
length = recipients.filter(email =>
|
||||
this.openpgpPublicKeys().find(key => key.emails.includes(email))
|
||||
).length;
|
||||
if (openpgp && (!all || openpgp === count)) {
|
||||
return 'openpgp';
|
||||
|
|
@ -218,19 +228,29 @@ export const PgpUserStore = new class {
|
|||
return false;
|
||||
}
|
||||
|
||||
getGnuPGPrivateKeyFor(email, sign) {
|
||||
let key = this.gnupgKeyring && this.gnupgKeyring[email];
|
||||
if (key && key[sign?'can_sign':'can_decrypt']) {
|
||||
return ['gnupg', key];
|
||||
}
|
||||
}
|
||||
|
||||
getOpenPGPPrivateKeyFor(email/*, sign*/) {
|
||||
let key = this.openpgpPrivateKeys().find(key => key.emails.includes(email));
|
||||
if (key && key.length) {
|
||||
return ['openpgp', key[0]];
|
||||
}
|
||||
}
|
||||
|
||||
getOpenPGPPublicKeyFor(email/*, sign*/) {
|
||||
return this.gnupgKeyring && this.openpgpKeyring.publicKeys.getForAddress(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if signing a message is possible with given email address.
|
||||
* Returns the first library that can.
|
||||
*/
|
||||
async hasPrivateKeyFor(email, sign) {
|
||||
if (this.gnupgKeyring && this.gnupgKeyring[email] && this.gnupgKeyring[email][sign?'can_sign':'can_decrypt']) {
|
||||
return 'gnupg';
|
||||
}
|
||||
|
||||
if (this.openpgpKeyring && this.openpgpKeyring.privateKeys.getForAddress(email).length) {
|
||||
return 'openpgp';
|
||||
}
|
||||
|
||||
async getMailvelopePrivateKeyFor(email/*, sign*/) {
|
||||
let keyring = this.mailvelopeKeyring;
|
||||
if (keyring) {
|
||||
/**
|
||||
|
|
@ -238,7 +258,7 @@ export const PgpUserStore = new class {
|
|||
*/
|
||||
let keys = await keyring.validKeyForAddress([email]);
|
||||
if (keys && keys[email] && await keyring.hasPrivateKey(keys[email].keys[0].fingerprint)) {
|
||||
return 'mailvelope';
|
||||
return ['mailvelope', keys[email].keys[0].fingerprint];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,16 +269,20 @@ export const PgpUserStore = new class {
|
|||
* Checks if signing a message is possible with given email address.
|
||||
* Returns the first library that can.
|
||||
*/
|
||||
async hasKeyForSigning(email) {
|
||||
return await this.hasPrivateKeyFor(email, 1);
|
||||
async getKeyForSigning(email) {
|
||||
return this.getGnuPGPrivateKeyFor(email, 1)
|
||||
|| this.getOpenPGPPrivateKeyFor(email, 1)
|
||||
|| await this.getMailvelopePrivateKeyFor(email, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if decrypting a message is possible with given email address.
|
||||
* Returns the first library that can.
|
||||
*/
|
||||
async hasKeyForDecrypting(email) {
|
||||
return await this.hasPrivateKeyFor(email, 0);
|
||||
async getKeyForDecrypting(email) {
|
||||
return await this.getMailvelopePrivateKeyFor(email)
|
||||
|| this.getGnuPGPrivateKeyFor(email)
|
||||
|| this.getOpenPGPPrivateKeyFor(email);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -289,10 +313,10 @@ export const PgpUserStore = new class {
|
|||
if (items[0] || items[1]) {
|
||||
openpgpKeyring.store();
|
||||
}
|
||||
// this.reloadOpenPgpKeys();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
decryptMessage(message, recipients, fCallback) {
|
||||
if (message && message.getEncryptionKeyIds) {
|
||||
// findPrivateKeysByEncryptionKeyIds
|
||||
|
|
@ -352,6 +376,7 @@ export const PgpUserStore = new class {
|
|||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
verifyMessage(message, fCallback) {
|
||||
if (message && message.getSigningKeyIds) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#V-PopupsViewOpenPgpKey, #V-PopupsNewOpenPgpKey {
|
||||
#V-PopupsViewOpenPgpKey, #V-PopupsOpenPgpGenerate {
|
||||
max-width: 570px;
|
||||
}
|
||||
|
||||
|
|
@ -9,124 +9,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
#V-PopupsComposeOpenPgp {
|
||||
max-width: 800px;
|
||||
|
||||
.key-list {
|
||||
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 5px;
|
||||
padding: 10px 15px;
|
||||
|
||||
&-wrp {
|
||||
|
||||
&:hover {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
&:hover .key-list__item-name {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
&.empty {
|
||||
text-align: center;
|
||||
padding-top: 10px;
|
||||
color: #aaa;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
&__item {
|
||||
|
||||
color: #333;
|
||||
white-space: nowrap;
|
||||
padding-bottom: 4px;
|
||||
display: flex;
|
||||
|
||||
&:last-child {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
&-delete {
|
||||
cursor: pointer;
|
||||
|
||||
&.disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
&-names {
|
||||
color: #333;
|
||||
width: 80%;
|
||||
|
||||
&.empty {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
|
||||
&-name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
&-error {
|
||||
color: red;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
&-hash {
|
||||
color: #aaa;
|
||||
width: 20%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.key-actions {
|
||||
margin-top: 10px;
|
||||
min-height: 40px;
|
||||
|
||||
select option:nth-child(even) {
|
||||
background-color: rgba(128, 128, 128, 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#V-PopupsMessageOpenPgp {
|
||||
max-width: 700px;
|
||||
|
||||
.key-list {
|
||||
|
||||
margin-top: 5px;
|
||||
overflow: hidden;
|
||||
|
||||
&__item {
|
||||
|
||||
color: #555;
|
||||
cursor: pointer;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
&__radio {
|
||||
padding: 3px 5px 0 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
&__name {
|
||||
border-bottom: 1px solid transparent;
|
||||
}
|
||||
|
||||
&__names {
|
||||
display: inline-block;
|
||||
|
||||
&:hover .key-list__item__name {
|
||||
border-bottom: 1px dashed #555;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#V-PopupsAddOpenPgpKey {
|
||||
#V-PopupsOpenPgpImport {
|
||||
max-width: 645px;
|
||||
|
||||
.inputKey {
|
||||
|
|
|
|||
|
|
@ -1,40 +1,18 @@
|
|||
|
||||
V-Settings-OpenPgp {
|
||||
#V-Settings-OpenPgp {
|
||||
|
||||
td * {
|
||||
cursor: pointer;
|
||||
}
|
||||
td + td {
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
table {
|
||||
|
||||
.open-pgp-key-img {
|
||||
margin-right: 10px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.open-pgp-key-id, .open-pgp-key-user {
|
||||
display: inline-block;
|
||||
word-break: break-all;
|
||||
box-sizing: border-box;
|
||||
line-height: 22px;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.open-pgp-key-user-address:first-child {
|
||||
line-height: 30px;
|
||||
margin-bottom: -4px;
|
||||
}
|
||||
.open-pgp-key-user {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.open-pgp-key-item {
|
||||
|
||||
.delete-open-pgp-key, .view-open-pgp-key {
|
||||
cursor: pointer;
|
||||
opacity: 0.7;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
.delete-open-pgp-key:not(:hover) {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -279,9 +279,9 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
|
||||
currentIdentity: value => {
|
||||
this.canPgpSign(false);
|
||||
value && PgpUserStore.hasKeyForSigning(value.email()).then(result => {
|
||||
value && PgpUserStore.getKeyForSigning(value.email()).then(result => {
|
||||
console.log({canPgpSign:result});
|
||||
this.canPgpSign(result)
|
||||
this.canPgpSign(!!result)
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -458,11 +458,10 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
if ('openpgp' == sign) {
|
||||
let privateKey;
|
||||
try {
|
||||
const keys = PgpUserStore.openpgpKeyring.privateKeys.getForAddress(this.currentIdentity().email());
|
||||
const keys = PgpUserStore.getOpenPGPPrivateKeyFor(this.currentIdentity().email());
|
||||
if (keys[0]) {
|
||||
keys[0].decrypt(window.prompt('Password', ''));
|
||||
privateKey = keys[0];
|
||||
cfg.privateKeys = [privateKey];
|
||||
cfg.privateKey = privateKey = keys[0];
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
@ -478,7 +477,7 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
// error 'sign and encrypt must be same engine';
|
||||
} else if ('openpgp' == encrypt) {
|
||||
this.allRecipients().forEach(recEmail => {
|
||||
cfg.publicKeys = cfg.publicKeys.concat(PgpUserStore.openpgpKeyring.publicKeys.getForAddress(recEmail));
|
||||
cfg.publicKeys = cfg.publicKeys.concat(PgpUserStore.getOpenPGPPublicKeyFor(recEmail));
|
||||
});
|
||||
pgpPromise = openpgp.encrypt(cfg);
|
||||
} else if ('openpgp' == sign) {
|
||||
|
|
@ -1502,7 +1501,8 @@ class ComposePopupView extends AbstractViewPopup {
|
|||
allRecipients() {
|
||||
const email = new EmailModel();
|
||||
return [
|
||||
// this.currentIdentity.email(),
|
||||
// From/sender is also recipient (Sent mailbox)
|
||||
this.currentIdentity().email(),
|
||||
this.to(),
|
||||
this.cc(),
|
||||
this.bcc()
|
||||
|
|
|
|||
|
|
@ -1,121 +0,0 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { pString } from 'Common/Utils';
|
||||
import { Scope } from 'Common/Enums';
|
||||
|
||||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||
|
||||
class MessageOpenPgpPopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('MessageOpenPgp');
|
||||
|
||||
this.addObservables({
|
||||
notification: '',
|
||||
selectedKey: null,
|
||||
password: '',
|
||||
submitRequest: false
|
||||
});
|
||||
this.privateKeys = ko.observableArray();
|
||||
|
||||
this.resultCallback = null;
|
||||
|
||||
decorateKoCommands(this, {
|
||||
doCommand: self => !self.submitRequest()
|
||||
});
|
||||
}
|
||||
|
||||
doCommand() {
|
||||
this.submitRequest(true);
|
||||
|
||||
setTimeout(() => {
|
||||
let privateKey = null;
|
||||
|
||||
try {
|
||||
if (this.resultCallback && this.selectedKey()) {
|
||||
const privateKeys = this.selectedKey().getNativeKeys();
|
||||
privateKey = privateKeys && privateKeys[0] ? privateKeys[0] : null;
|
||||
|
||||
if (privateKey) {
|
||||
try {
|
||||
if (!privateKey.decrypt(pString(this.password()))) {
|
||||
console.log('Error: Private key cannot be decrypted');
|
||||
privateKey = null;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
privateKey = null;
|
||||
}
|
||||
} else {
|
||||
console.log('Error: Private key cannot be found');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
privateKey = null;
|
||||
}
|
||||
|
||||
this.submitRequest(false);
|
||||
|
||||
this.cancelCommand();
|
||||
this.resultCallback(privateKey);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
clearPopup() {
|
||||
this.notification('');
|
||||
|
||||
this.password('');
|
||||
|
||||
this.selectedKey(false);
|
||||
this.submitRequest(false);
|
||||
|
||||
this.resultCallback = null;
|
||||
this.privateKeys([]);
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
// shortcuts.add('tab', 'shift', Scope.MessageOpenPgp, () => {
|
||||
shortcuts.add('tab', '', Scope.MessageOpenPgp, () => {
|
||||
let btn = this.querySelector('.inputPassword');
|
||||
if (btn.matches(':focus')) {
|
||||
btn = this.querySelector('.buttonDo');
|
||||
}
|
||||
btn.focus();
|
||||
return false;
|
||||
});
|
||||
|
||||
const self = this;
|
||||
|
||||
oDom.addEventListener('click', event => {
|
||||
const el = event.target.closestWithin('.key-list__item', oDom);
|
||||
if (el) {
|
||||
oDom.querySelectorAll('.key-list__item .key-list__item__radio').forEach(node =>
|
||||
node.textContent = el === node ? '⦿' : '○'
|
||||
);
|
||||
|
||||
self.selectedKey(ko.dataFor(el));
|
||||
|
||||
// this.querySelector('.inputPassword').focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onHideWithDelay() {
|
||||
this.clearPopup();
|
||||
}
|
||||
|
||||
onShow(fCallback, privateKeys) {
|
||||
this.clearPopup();
|
||||
|
||||
this.resultCallback = fCallback;
|
||||
this.privateKeys(privateKeys);
|
||||
|
||||
if (this.viewModelDom) {
|
||||
const el = this.querySelector('.key-list__item');
|
||||
el && el.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { MessageOpenPgpPopupView, MessageOpenPgpPopupView as default };
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
import { pInt } from 'Common/Utils';
|
||||
|
||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||
import { IdentityUserStore } from 'Stores/User/Identity';
|
||||
|
||||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||
|
||||
class NewOpenPgpKeyPopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('NewOpenPgpKey');
|
||||
|
||||
this.identities = IdentityUserStore;
|
||||
|
||||
this.addObservables({
|
||||
email: '',
|
||||
emailError: false,
|
||||
|
||||
name: '',
|
||||
password: '',
|
||||
keyBitLength: 4096,
|
||||
|
||||
submitRequest: false,
|
||||
submitError: ''
|
||||
});
|
||||
|
||||
this.email.subscribe(() => this.emailError(false));
|
||||
|
||||
decorateKoCommands(this, {
|
||||
generateOpenPgpKeyCommand: 1
|
||||
});
|
||||
}
|
||||
|
||||
generateOpenPgpKeyCommand() {
|
||||
const userId = {},
|
||||
openpgpKeyring = PgpUserStore.openpgpKeyring;
|
||||
|
||||
this.emailError(!this.email().trim());
|
||||
if (!openpgpKeyring || this.emailError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
userId.email = this.email();
|
||||
if (this.name()) {
|
||||
userId.name = this.name();
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
this.submitError('');
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
openpgp
|
||||
.generateKey({
|
||||
userIds: [userId],
|
||||
numBits: pInt(this.keyBitLength()),
|
||||
passphrase: this.password().trim()
|
||||
})
|
||||
.then((keyPair) => {
|
||||
this.submitRequest(false);
|
||||
|
||||
if (keyPair && keyPair.privateKeyArmored) {
|
||||
openpgpKeyring.privateKeys.importKey(keyPair.privateKeyArmored);
|
||||
openpgpKeyring.publicKeys.importKey(keyPair.publicKeyArmored);
|
||||
|
||||
openpgpKeyring.store();
|
||||
|
||||
PgpUserStore.reloadOpenPgpKeys();
|
||||
|
||||
PgpUserStore.gnupgImportKey(keyPair.privateKeyArmored);
|
||||
|
||||
this.cancelCommand();
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
this.submitRequest(false);
|
||||
this.showError(e);
|
||||
});
|
||||
} catch (e) {
|
||||
this.submitRequest(false);
|
||||
this.showError(e);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
showError(e) {
|
||||
console.log(e);
|
||||
if (e && e.message) {
|
||||
this.submitError(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.name(IdentityUserStore()[0].name());
|
||||
this.password('');
|
||||
this.email(IdentityUserStore()[0].email());
|
||||
this.emailError(false);
|
||||
this.keyBitLength(4096);
|
||||
this.submitError('');
|
||||
}
|
||||
}
|
||||
|
||||
export { NewOpenPgpKeyPopupView, NewOpenPgpKeyPopupView as default };
|
||||
102
dev/View/Popup/OpenPgpGenerate.js
Normal file
102
dev/View/Popup/OpenPgpGenerate.js
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
//import { pInt } from 'Common/Utils';
|
||||
|
||||
import { PgpUserStore } from 'Stores/User/Pgp';
|
||||
import { IdentityUserStore } from 'Stores/User/Identity';
|
||||
|
||||
import { decorateKoCommands } from 'Knoin/Knoin';
|
||||
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
||||
|
||||
import { Capa } from 'Common/Enums';
|
||||
import { Settings } from 'Common/Globals';
|
||||
|
||||
export class OpenPgpGeneratePopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('OpenPgpGenerate');
|
||||
|
||||
this.identities = IdentityUserStore;
|
||||
|
||||
this.addObservables({
|
||||
email: '',
|
||||
emailError: false,
|
||||
|
||||
name: '',
|
||||
password: '',
|
||||
keyType: 'ECC',
|
||||
|
||||
submitRequest: false,
|
||||
submitError: '',
|
||||
|
||||
saveGnuPG: true,
|
||||
saveServer: true
|
||||
});
|
||||
|
||||
this.canGnuPG = Settings.capa(Capa.GnuPG);
|
||||
|
||||
this.email.subscribe(() => this.emailError(false));
|
||||
|
||||
decorateKoCommands(this, {
|
||||
generateOpenPgpKeyCommand: 1
|
||||
});
|
||||
}
|
||||
|
||||
generateOpenPgpKeyCommand() {
|
||||
const type = this.keyType().toLowerCase(),
|
||||
userId = {
|
||||
name: this.name(),
|
||||
email: this.email()
|
||||
},
|
||||
cfg = {
|
||||
type: type,
|
||||
userIDs: [userId],
|
||||
passphrase: this.password().trim()
|
||||
// format: 'armored' // output key format, defaults to 'armored' (other options: 'binary' or 'object')
|
||||
}
|
||||
/*
|
||||
if ('ecc' === type) {
|
||||
cfg.curve = 'curve25519';
|
||||
} else {
|
||||
cfg.rsaBits = pInt(this.keyBitLength());
|
||||
}
|
||||
*/
|
||||
this.emailError(!this.email().trim());
|
||||
if (this.emailError()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.submitRequest(true);
|
||||
this.submitError('');
|
||||
|
||||
openpgp.generateKey(cfg).then(keyPair => {
|
||||
if (keyPair) {
|
||||
keyPair.onServer = !!this.saveServer();
|
||||
keyPair.inGnuPG = !!this.saveGnuPG();
|
||||
keyPair.uid = userId;
|
||||
PgpUserStore.storeKeyPair(keyPair, ()=>{
|
||||
this.submitRequest(false);
|
||||
this.cancelCommand();
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
this.submitRequest(false);
|
||||
this.showError(e);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
showError(e) {
|
||||
console.log(e);
|
||||
if (e && e.message) {
|
||||
this.submitError(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
onShow() {
|
||||
this.name(''/*IdentityUserStore()[0].name()*/);
|
||||
this.password('');
|
||||
this.email(''/*IdentityUserStore()[0].email()*/);
|
||||
this.emailError(false);
|
||||
this.submitError('');
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@ import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|||
import { Capa } from 'Common/Enums';
|
||||
import { Settings } from 'Common/Globals';
|
||||
|
||||
class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
||||
export class OpenPgpImportPopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('AddOpenPgpKey');
|
||||
super('OpenPgpImport');
|
||||
|
||||
this.addObservables({
|
||||
key: '',
|
||||
|
|
@ -16,11 +16,10 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
keyErrorMessage: '',
|
||||
|
||||
saveGnuPG: true,
|
||||
saveOpenPGP: true
|
||||
saveServer: true
|
||||
});
|
||||
|
||||
this.canGnuPG = Settings.capa(Capa.GnuPG);
|
||||
this.canOpenPGP = Settings.capa(Capa.OpenPGP);
|
||||
|
||||
this.key.subscribe(() => {
|
||||
this.keyError(false);
|
||||
|
|
@ -50,8 +49,7 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
count = 30,
|
||||
done = false;
|
||||
// eslint-disable-next-line max-len
|
||||
const reg = /[-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}[\s\S]+?[-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}/gi,
|
||||
keyring = PgpUserStore.openpgpKeyring;
|
||||
const reg = /[-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}[\s\S]+?[-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}/gi;
|
||||
|
||||
do {
|
||||
match = reg.exec(keyTrimmed);
|
||||
|
|
@ -61,14 +59,15 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
if (this.saveGnuPG()) {
|
||||
PgpUserStore.gnupgImportKey(this.key());
|
||||
}
|
||||
/*
|
||||
if (this.canOpenPGP && this.saveOpenPGP()) {
|
||||
if ('PRIVATE' === match[1]) {
|
||||
err = keyring.privateKeys.importKey(match[0]);
|
||||
err = PgpUserStore.openpgpKeyring.privateKeys.importKey(match[0]);
|
||||
} else if ('PUBLIC' === match[1]) {
|
||||
err = keyring.publicKeys.importKey(match[0]);
|
||||
err = PgpUserStore.openpgpKeyring.publicKeys.importKey(match[0]);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
if (err) {
|
||||
this.keyError(true);
|
||||
this.keyErrorMessage(err && err[0] ? '' + err[0] : '');
|
||||
|
|
@ -83,12 +82,6 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
}
|
||||
} while (!done);
|
||||
|
||||
if (this.canOpenPGP && this.saveOpenPGP()) {
|
||||
keyring.store();
|
||||
}
|
||||
|
||||
// PgpUserStore.reloadOpenPgpKeys();
|
||||
|
||||
if (this.keyError()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -103,5 +96,3 @@ class AddOpenPgpKeyPopupView extends AbstractViewPopup {
|
|||
this.keyErrorMessage('');
|
||||
}
|
||||
}
|
||||
|
||||
export { AddOpenPgpKeyPopupView, AddOpenPgpKeyPopupView as default };
|
||||
|
|
@ -182,7 +182,7 @@ export class MailMessageView extends AbstractViewRight {
|
|||
|
||||
pgpSigned: () => currentMessage() && !!currentMessage().pgpSigned(),
|
||||
pgpEncrypted: () => currentMessage()
|
||||
&& currentMessage().isPgpEncrypted(),
|
||||
&& !!(currentMessage().pgpEncrypted() || currentMessage().isPgpEncrypted()),
|
||||
pgpSupported: () => currentMessage() && PgpUserStore.isSupported(),
|
||||
|
||||
messageListOrViewLoading:
|
||||
|
|
@ -625,7 +625,8 @@ export class MailMessageView extends AbstractViewRight {
|
|||
}
|
||||
|
||||
pgpDecrypt(self) {
|
||||
if (self.pgpEncrypted()) {
|
||||
const pgpInfo = self.pgpEncrypted();
|
||||
if (pgpInfo) {
|
||||
const message = self.message();
|
||||
if (window.mailvelope) {
|
||||
/**
|
||||
|
|
@ -657,10 +658,37 @@ export class MailMessageView extends AbstractViewRight {
|
|||
});
|
||||
}
|
||||
/*
|
||||
else {
|
||||
// TODO: which key to decrypt, use pgpInfo.KeyIds
|
||||
|
||||
PgpUserStore.getKeyForDecrypting(message.email()).then(result => {
|
||||
console.log({canPgpSign:result});
|
||||
this.canPgpSign(!!result)
|
||||
});
|
||||
|
||||
else if (window.openpgp) {
|
||||
decryptMessage(message, recipients, fCallback)
|
||||
}
|
||||
else if (Settings.capa(Capa.GnuPG)) {
|
||||
message.
|
||||
|
||||
let params = {
|
||||
Folder: message.folder,
|
||||
Uid: message.uid,
|
||||
PartId: message.pgpEncrypted().PartId,
|
||||
KeyId: '',
|
||||
Passphrase: prompt("Passphrase", ''),
|
||||
Data: '' // optional
|
||||
}
|
||||
rl.app.Remote.post('GnupgDecrypt', null, params)
|
||||
.then(data => {
|
||||
// TODO
|
||||
console.dir(data);
|
||||
})
|
||||
.catch(error => {
|
||||
// TODO
|
||||
console.dir(error);
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue