|
|
|
@ -8,6 +8,8 @@ var { pEpUtils } = ChromeUtils.import("chrome://pEp4Tb/content/modules/utils.js"
|
|
|
|
|
var { pEp } = ChromeUtils.import("chrome://pEp4Tb/content/modules/pEp.js");
|
|
|
|
|
var { pEpController } = ChromeUtils.import("chrome://pEp4Tb/content/pEpController.js");
|
|
|
|
|
|
|
|
|
|
var gImportResult;
|
|
|
|
|
|
|
|
|
|
var pEpOptions = {
|
|
|
|
|
openLink(url) {
|
|
|
|
|
Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).launchExternalURL(url);
|
|
|
|
@ -369,7 +371,7 @@ var pEpOptions = {
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
importKey() {
|
|
|
|
|
async importKey() {
|
|
|
|
|
// Workaround for ENGINE-808.
|
|
|
|
|
if (Services.prefs.getBoolPref("extensions.pEp.grouped", false)) {
|
|
|
|
|
Services.prompt.alert(
|
|
|
|
@ -405,71 +407,114 @@ var pEpOptions = {
|
|
|
|
|
}
|
|
|
|
|
stream.close();
|
|
|
|
|
|
|
|
|
|
// TODO: Check for multiple public keys.
|
|
|
|
|
|
|
|
|
|
// Send to the engine.
|
|
|
|
|
let errorMsg = "optionsImportError";
|
|
|
|
|
pEpController.import_key(btoa(streamData)).then((result) => {
|
|
|
|
|
const usage = Services.prefs.getStringPref("extensions.pEp.keyUse", "other");
|
|
|
|
|
let msg;
|
|
|
|
|
// If we get identites returned, we imported a private key,
|
|
|
|
|
// if we get empty identities, we imported a public key.
|
|
|
|
|
// Anything else is an error.
|
|
|
|
|
if (!result) {
|
|
|
|
|
pEpController.log.error("Key import error: result is null");
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportError");
|
|
|
|
|
} else if (result.length == 0) {
|
|
|
|
|
pEpController.log.info("Public key import");
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportSuccessPublicKey");
|
|
|
|
|
// if (usage == "public") pEpController.set_comm_partner_key( some id, some fpr);
|
|
|
|
|
} else {
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportFingerprint");
|
|
|
|
|
const fpr = result[0].fpr.replace(/(....)/g, "$1 ").trim();
|
|
|
|
|
msg += `\n${fpr}`;
|
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
|
const username = result[i].username;
|
|
|
|
|
const [delim, delim2] = username ? [" <", ">"] : ["", ""];
|
|
|
|
|
// eslint-disable-next-line prefer-template
|
|
|
|
|
msg += `\n${username}${delim}${result[i].address}${delim2}`;
|
|
|
|
|
}
|
|
|
|
|
let result;
|
|
|
|
|
try {
|
|
|
|
|
result = await pEpController.import_key(btoa(streamData));
|
|
|
|
|
} catch (err) {
|
|
|
|
|
pEpController.log.error(`Key import error: ${err.message}`);
|
|
|
|
|
Services.prompt.alert(
|
|
|
|
|
window,
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsImportError"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let msg;
|
|
|
|
|
// If we get identites returned, we imported a private key,
|
|
|
|
|
// if we get empty identities, we imported a public key.
|
|
|
|
|
// Anything else is an error.
|
|
|
|
|
if (!result) {
|
|
|
|
|
pEpController.log.error("Key import error: result is null");
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportError");
|
|
|
|
|
} else if (result.length == 0) {
|
|
|
|
|
pEpController.log.info("Public key import");
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportSuccessPublicKey");
|
|
|
|
|
|
|
|
|
|
let importResult = document.getElementById("importResult");
|
|
|
|
|
importResult.textContent = msg;
|
|
|
|
|
importResult.removeAttribute("hidden");
|
|
|
|
|
|
|
|
|
|
// E-Mail entry missing here.
|
|
|
|
|
|
|
|
|
|
let button1 = document.getElementById("useForAddress");
|
|
|
|
|
button1.removeAttribute("hidden");
|
|
|
|
|
let button2 = document.getElementById("cancelKey");
|
|
|
|
|
button2.removeAttribute("hidden");
|
|
|
|
|
} else {
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportFingerprint");
|
|
|
|
|
const fpr = result[0].fpr.replace(/(....)/g, "$1 ").trim();
|
|
|
|
|
msg += `\n${fpr}`;
|
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
|
const username = result[i].username;
|
|
|
|
|
const [delim, delim2] = username ? [" <", ">"] : ["", ""];
|
|
|
|
|
// eslint-disable-next-line prefer-template
|
|
|
|
|
msg += "\n\n" + pEpOptions.getLocaleMessage("optionsImportUseKey");
|
|
|
|
|
if (!Services.prompt.confirm(
|
|
|
|
|
null,
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
|
|
|
|
|
msg,
|
|
|
|
|
)) return;
|
|
|
|
|
msg += `\n${username}${delim}${result[i].address}${delim2}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let importResult = document.getElementById("importResult");
|
|
|
|
|
importResult.textContent = msg;
|
|
|
|
|
importResult.removeAttribute("hidden");
|
|
|
|
|
|
|
|
|
|
// If it fails now, it's a key use error.
|
|
|
|
|
errorMsg = "optionsKeyUseError";
|
|
|
|
|
switch (usage) {
|
|
|
|
|
let importOptions = document.getElementById("importOptions");
|
|
|
|
|
importOptions.removeAttribute("hidden");
|
|
|
|
|
let button1 = document.getElementById("useKey");
|
|
|
|
|
button1.removeAttribute("hidden");
|
|
|
|
|
let button2 = document.getElementById("cancelKey");
|
|
|
|
|
button2.removeAttribute("hidden");
|
|
|
|
|
}
|
|
|
|
|
gImportResult = result;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
cancelKey() {
|
|
|
|
|
let importResult = document.getElementById("importResult");
|
|
|
|
|
importResult.textContent = "";
|
|
|
|
|
importResult.setAttribute("hidden", "hidden");
|
|
|
|
|
|
|
|
|
|
let importOptions = document.getElementById("importOptions");
|
|
|
|
|
importOptions.setAttribute("hidden", "true");
|
|
|
|
|
let button1 = document.getElementById("useKey");
|
|
|
|
|
button1.setAttribute("hidden", "true");
|
|
|
|
|
let button2 = document.getElementById("useForAddress");
|
|
|
|
|
button2.setAttribute("hidden", "true");
|
|
|
|
|
let button3 = document.getElementById("cancelKey");
|
|
|
|
|
button3.setAttribute("hidden", "true");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
useKey() {
|
|
|
|
|
if (gImportResult.length > 0) {
|
|
|
|
|
let keyUse = Services.prefs.getStringPref("extensions.pEp.keyUse", "other");
|
|
|
|
|
try {
|
|
|
|
|
switch (keyUse) {
|
|
|
|
|
case "keep":
|
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
|
result[i].user_id = "pEp_own_userId";
|
|
|
|
|
pEpController.set_own_key(result[i]);
|
|
|
|
|
for (let i = 0; i < gImportResult.length; i++) {
|
|
|
|
|
gImportResult[i].user_id = "pEp_own_userId";
|
|
|
|
|
pEpController.set_own_key(gImportResult[i]);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "switch":
|
|
|
|
|
// Only run on the first identity.
|
|
|
|
|
result[0].user_id = "pEp_own_userId";
|
|
|
|
|
pEpController.synchronise(pEpController.set_own_key(result[0]));
|
|
|
|
|
pEpController.synchronise(pEpController.key_reset_identity(result[0]));
|
|
|
|
|
gImportResult[0].user_id = "pEp_own_userId";
|
|
|
|
|
pEpController.synchronise(pEpController.set_own_key(gImportResult[0]));
|
|
|
|
|
pEpController.synchronise(pEpController.key_reset_identity(gImportResult[0]));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
msg = pEpOptions.getLocaleMessage("optionsImportSuccessPrivateKey");
|
|
|
|
|
} catch (err) {
|
|
|
|
|
pEpController.log.error(`Key use error: ${err.message}`);
|
|
|
|
|
Services.prompt.alert(
|
|
|
|
|
window,
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsKeyUseError"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Services.prompt.alert(
|
|
|
|
|
window,
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
|
|
|
|
|
msg,
|
|
|
|
|
);
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
pEpController.log.error(`Key import error: ${err.message}`);
|
|
|
|
|
Services.prompt.alert(
|
|
|
|
|
window,
|
|
|
|
|
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
|
|
|
|
|
pEpOptions.getLocaleMessage(errorMsg),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// TODO: pEpController.set_comm_partner_key( some id, some fpr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.cancelKey();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updateGloda() {
|
|
|
|
|