1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var { EnigmailFuncs } = ChromeUtils.import(
"chrome://openpgp/content/modules/funcs.jsm"
);
var EnigmailKeyRing = ChromeUtils.import(
"chrome://openpgp/content/modules/keyRing.jsm"
).EnigmailKeyRing;
var { EnigmailWindows } = ChromeUtils.import(
"chrome://openpgp/content/modules/windows.jsm"
);
var { EnigmailDialog } = ChromeUtils.import(
"chrome://openpgp/content/modules/dialog.jsm"
);
var { EnigmailKey } = ChromeUtils.import(
"chrome://openpgp/content/modules/key.jsm"
);
var KeyLookupHelper = ChromeUtils.import(
"chrome://openpgp/content/modules/keyLookupHelper.jsm"
).KeyLookupHelper;
const { PgpSqliteDb2 } = ChromeUtils.import(
"chrome://openpgp/content/modules/sqliteDb.jsm"
);
var gListBox;
var gViewButton;
var gAddr;
var gRowToKey = [];
async function setListEntries(keys = null) {
let index = 0;
// Temporary code for debugging/development, should be removed when
// a final patch for bug 1627956 lands.
console.log(await EnigmailKeyRing.getEncryptionKeyMeta(gAddr));
if (!keys) {
keys = await EnigmailKeyRing.getMultValidKeysForOneRecipient(gAddr, true);
}
for (let keyObj of keys) {
let listitem = document.createXULElement("richlistitem");
let keyId = document.createXULElement("label");
keyId.setAttribute("value", "0x" + keyObj.keyId);
keyId.setAttribute("crop", "end");
keyId.setAttribute("style", "width: var(--keyWidth)");
listitem.appendChild(keyId);
let acceptanceText;
// Further above, we called getMultValidKeysForOneRecipient
// and asked to ignore if a key is expired.
// If the following check fails, the key must be expired.
if (!EnigmailKeyRing.isValidForEncryption(keyObj)) {
acceptanceText = "openpgp-key-expired";
} else if (keyObj.secretAvailable) {
if (await PgpSqliteDb2.isAcceptedAsPersonalKey(keyObj.fpr)) {
acceptanceText = "openpgp-key-own";
} else {
acceptanceText = "openpgp-key-secret-not-personal";
}
} else {
if (!("acceptance" in keyObj)) {
throw new Error(
"expected getMultValidKeysForOneRecipient to set acceptance"
);
}
switch (keyObj.acceptance) {
case "rejected":
acceptanceText = "openpgp-key-rejected";
break;
case "unverified":
acceptanceText = "openpgp-key-unverified";
break;
case "verified":
acceptanceText = "openpgp-key-verified";
break;
case "undecided":
acceptanceText = "openpgp-key-undecided";
break;
default:
throw new Error("unexpected acceptance value: " + keyObj.acceptance);
}
}
let status = document.createXULElement("label");
document.l10n.setAttributes(status, acceptanceText);
status.setAttribute("crop", "end");
status.setAttribute("style", "width: var(--statusWidth)");
listitem.appendChild(status);
let issued = document.createXULElement("label");
issued.setAttribute("value", keyObj.created);
issued.setAttribute("crop", "end");
issued.setAttribute("style", "width: var(--issuedWidth)");
listitem.appendChild(issued);
let expire = document.createXULElement("label");
expire.setAttribute("value", keyObj.expiry);
expire.setAttribute("crop", "end");
expire.setAttribute("style", "width: var(--expireWidth)");
listitem.appendChild(expire);
gListBox.appendChild(listitem);
gRowToKey[index] = keyObj.keyId;
index++;
}
}
async function onLoad() {
let params = window.arguments[0];
if (!params) {
return;
}
gListBox = document.getElementById("infolist");
gViewButton = document.getElementById("detailsButton");
gAddr = params.email;
document.l10n.setAttributes(
document.getElementById("intro"),
"openpgp-intro",
{ key: gAddr }
);
await setListEntries(params.keys);
}
async function reloadAndSelect(selIndex = -1) {
while (true) {
let child = gListBox.lastChild;
// keep first child, which is the header
if (child == gListBox.firstChild) {
break;
}
gListBox.removeChild(child);
}
gRowToKey = [];
await setListEntries();
gListBox.selectedIndex = selIndex;
}
function onSelectionChange(event) {
let haveSelection = gListBox.selectedItems.length;
gViewButton.disabled = !haveSelection;
}
function viewSelectedKey() {
let selIndex = gListBox.selectedIndex;
if (gViewButton.disabled || selIndex == -1) {
return;
}
EnigmailWindows.openKeyDetails(window, gRowToKey[selIndex], false);
reloadAndSelect(selIndex);
}
async function discoverKey() {
let keyIds = gRowToKey;
let foundNewData = await KeyLookupHelper.fullOnlineDiscovery(
"interactive-import",
window,
gAddr,
keyIds
);
if (foundNewData) {
reloadAndSelect();
} else {
let value = await document.l10n.formatValue("no-key-found2");
EnigmailDialog.alert(window, value);
}
}
|