Browse Source

P4TB-400: Improved manual key import. Part 3: Reshuffle to show parts of the panel later.

master
Jörg Knobloch 11 months ago
parent
commit
50c4713078
5 changed files with 144 additions and 78 deletions
  1. +9
    -9
      addon/_locales/de/messages.json
  2. +9
    -9
      addon/_locales/en/messages.json
  3. +1
    -1
      addon/content/dialogs/options.css
  4. +99
    -54
      addon/content/dialogs/options.js
  5. +26
    -5
      addon/content/dialogs/options.xhtml

+ 9
- 9
addon/_locales/de/messages.json View File

@ -227,9 +227,6 @@
"optionsPrivateGroup": {
"message": "Nutzung als derzeitiger PGP-Schlüssel für Gruppen oder Listen"
},
"optionsPublic": {
"message": "Nutzung als derzeitiger Schlüssel für Kommunikationspartner"
},
"optionsOther": {
"message": "Andere Nutzung"
},
@ -291,16 +288,19 @@
"message": "Schlüssel-Import nicht möglich solange das Gerät Mitglied einer Gerätegruppe ist."
},
"optionsImportSuccessPublicKey": {
"message": "Öffentlicher Schlüssel erfolgreich importiert."
"message": "Öffentlicher Schlüssel erfolgreich importiert. Bitten geben Sie die E-Mail-Adresse des Kommunikationspartners an:"
},
"optionsImportFingerprint": {
"message": "Der Fingerabdruck des ausgewählten Schlüssel ist:"
"message": "Privater Schlüssel erfolgreich importiert. Der Fingerabdruck des ausgewählten Schlüssel ist:"
},
"optionsUseAsSelected": {
"message": "Benutzen wie gewählt"
},
"optionsImportUseKey": {
"message": "Schlüssel importieren und verwenden?"
"optionsUseForAddress": {
"message": "Benutzen für Adresse"
},
"optionsImportSuccessPrivateKey": {
"message": "Privater Schlüssel erfolgreich importiert."
"optionsCancel": {
"message": "Abbrechen"
},
"optionsClose": {
"message": "Schließen"


+ 9
- 9
addon/_locales/en/messages.json View File

@ -227,9 +227,6 @@
"optionsPrivateGroup": {
"message": "Use as current PGP key for group or list"
},
"optionsPublic": {
"message": "Use as current key for communication partner"
},
"optionsOther": {
"message": "Other use"
},
@ -291,16 +288,19 @@
"message": "Key import not possible while the device is in a device group."
},
"optionsImportSuccessPublicKey": {
"message": "Public key successfully imported."
"message": "Public key successfully imported. Please specify communication partner's email address:"
},
"optionsImportFingerprint": {
"message": "The fingerprint of the selected key is:"
"message": "Private key successfully imported. The fingerprint of the selected key is:"
},
"optionsUseAsSelected": {
"message": "Use as selected"
},
"optionsImportUseKey": {
"message": "Import and use this key?"
"optionsUseForAddress": {
"message": "Use for address"
},
"optionsImportSuccessPrivateKey": {
"message": "Private key successfully imported."
"optionsCancel": {
"message": "Cancel"
},
"optionsClose": {
"message": "Close"


+ 1
- 1
addon/content/dialogs/options.css View File

@ -98,7 +98,7 @@ label.donate {
background-color: #03AA4B;
}
#ImportOptions radio {
#importOptions radio {
margin-top: 0;
margin-bottom: 0;
padding-top: 0;


+ 99
- 54
addon/content/dialogs/options.js View File

@ -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() {


+ 26
- 5
addon/content/dialogs/options.xhtml View File

@ -141,18 +141,39 @@
onclick="pEpOptions.browseForKey();">
</html:button>
</hbox>
<radiogroup id="ImportOptions" orient="vertical" preference="extensions.pEp.keyUse">
<hbox class="button-group">
<html:button id="import"
data-localekey="optionsImport"
onclick="pEpOptions.importKey();">
</html:button>
</hbox>
<html:div id="importResult" hidden="hidden" style="white-space: pre;">
</html:div>
<radiogroup id="importOptions" hidden="true" orient="vertical" preference="extensions.pEp.keyUse">
<radio value="keep" label-localekey="optionsPrivateOwnKeep"/>
<radio value="switch" label-localekey="optionsPrivateOwnSwitch"/>
<radio value="group" label-localekey="optionsPrivateGroup"/>
<radio value="public" label-localekey="optionsPublic"/>
<radio value="other" label-localekey="optionsOther"/>
</radiogroup>
<!-- E-mail entry box for pub key missing here -->
<hbox class="button-group">
<html:button id="import"
data-localekey="optionsImport"
onclick="pEpOptions.importKey();">
<html:button id="useKey"
hidden="true"
data-localekey="optionsUseAsSelected"
onclick="pEpOptions.useKey();">
</html:button>
<html:button id="useForAddress"
hidden="true"
data-localekey="optionsUseForAddress"
onclick="pEpOptions.useKey();">
</html:button>
<html:button id="cancelKey"
hidden="true"
data-localekey="optionsCancel"
onclick="pEpOptions.cancelKey();">
</html:button>
</hbox>
<hbox class="button-group">
<html:button id="close"
data-localekey="optionsClose"
onclick="self.close()">


Loading…
Cancel
Save