Browse Source

P4TB-400: Improved manual key import. Part 4: Use import_key_with_fpr_return(), public key import partly done.

master
Jörg Knobloch 11 months ago
parent
commit
5496ade4ab
6 changed files with 52 additions and 14 deletions
  1. +1
    -1
      addon/_locales/de/messages.json
  2. +1
    -1
      addon/_locales/en/messages.json
  3. +29
    -2
      addon/content/dialogs/options.js
  4. +11
    -1
      addon/content/dialogs/options.xhtml
  5. +2
    -2
      addon/content/modules/pEp.js
  6. +8
    -7
      addon/content/modules/pEpAdapter.js

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

@ -288,7 +288,7 @@
"message": "Schlüssel-Import nicht möglich solange das Gerät Mitglied einer Gerätegruppe ist."
},
"optionsImportSuccessPublicKey": {
"message": "Öffentlicher Schlüssel erfolgreich importiert. Bitten geben Sie die E-Mail-Adresse des Kommunikationspartners an:"
"message": "Öffentlicher Schlüssel erfolgreich importiert. Der Fingerabdruck des ausgewählten Schlüssel ist:{0}Bitten geben Sie die E-Mail-Adresse des Kommunikationspartners an:"
},
"optionsImportFingerprint": {
"message": "Privater Schlüssel erfolgreich importiert. Der Fingerabdruck des ausgewählten Schlüssel ist:"


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

@ -288,7 +288,7 @@
"message": "Key import not possible while the device is in a device group."
},
"optionsImportSuccessPublicKey": {
"message": "Public key successfully imported. Please specify communication partner's email address:"
"message": "Public key successfully imported. The fingerprint of the selected key is:{0}Please specify communication partner's email address:"
},
"optionsImportFingerprint": {
"message": "Private key successfully imported. The fingerprint of the selected key is:"


+ 29
- 2
addon/content/dialogs/options.js View File

@ -372,6 +372,8 @@ var pEpOptions = {
},
async importKey() {
this.cancelKey();
// Workaround for ENGINE-808.
if (Services.prefs.getBoolPref("extensions.pEp.grouped", false)) {
Services.prompt.alert(
@ -411,8 +413,9 @@ var pEpOptions = {
// Send to the engine.
let result;
let fprs;
try {
result = await pEpController.import_key(btoa(streamData));
[result, fprs] = await pEpController.import_key_with_fpr_return(btoa(streamData));
} catch (err) {
pEpController.log.error(`Key import error: ${err.message}`);
Services.prompt.alert(
@ -433,11 +436,15 @@ var pEpOptions = {
pEpController.log.info("Public key import");
msg = pEpOptions.getLocaleMessage("optionsImportSuccessPublicKey");
const fpr = fprs[0].replace(/(....)/g, "$1 ").trim();
msg = msg.replace("{0}", `\n${fpr}\n`);
let importResult = document.getElementById("importResult");
importResult.textContent = msg;
importResult.removeAttribute("hidden");
// E-Mail entry missing here.
let commPartnerAddress = document.getElementById("commPartnerAddress");
commPartnerAddress.removeAttribute("hidden");
let button1 = document.getElementById("useForAddress");
button1.removeAttribute("hidden");
@ -468,11 +475,31 @@ var pEpOptions = {
gImportResult = result;
},
commPartnerKeyPress(event, element) {
if (event.key != "Enter" && event.key != "Tab") {
return;
}
let email = element.value;
if (!email.includes("@", 1) || email.endsWith("@")) {
// Invalid.
event.preventDefault();
return;
}
// Make Enter move to the next UI element as Tab already does.
if (event.key == "Enter") {
let button = document.getElementById("useForAddress");
button.focus();
}
},
cancelKey() {
let importResult = document.getElementById("importResult");
importResult.textContent = "";
importResult.setAttribute("hidden", "hidden");
let commPartnerAddress = document.getElementById("commPartnerAddress");
commPartnerAddress.setAttribute("hidden", "hidden");
let importOptions = document.getElementById("importOptions");
importOptions.setAttribute("hidden", "true");
let button1 = document.getElementById("useKey");


+ 11
- 1
addon/content/dialogs/options.xhtml View File

@ -155,7 +155,17 @@
<radio value="group" label-localekey="optionsPrivateGroup"/>
<radio value="other" label-localekey="optionsOther"/>
</radiogroup>
<!-- E-mail entry box for pub key missing here -->
<html:input is="autocomplete-input" id="commPartnerAddress"
hidden="hidden"
autocompletesearch="addrbook"
autocompletesearchparam="{}"
timeout="300"
maxrows="4"
completedefaultindex="true"
forcecomplete="true"
completeselectedindex="true"
minresultsforpopup="3"
onkeypress="pEpOptions.commPartnerKeyPress(event, this);"/>
<hbox class="button-group">
<html:button id="useKey"
hidden="true"


+ 2
- 2
addon/content/modules/pEp.js View File

@ -227,8 +227,8 @@ class pEp {
return this.adapter.config_unencrypted_subject(true);
}
async import_key(keydata) {
return this.adapter.import_key(keydata);
async import_key_with_fpr_return(keydata) {
return this.adapter.import_key_with_fpr_return(keydata);
}
async set_own_key(identity) {


+ 8
- 7
addon/content/modules/pEpAdapter.js View File

@ -31,7 +31,7 @@ const API_METHOD_KEY_RESET_TRUST = "key_reset_trust";
const API_METHOD_KEY_RESET_USER = "key_reset_user";
const API_METHOD_KEY_RESET_IDENTITY = "key_reset_identity";
const API_METHOD_KEY_RESET_ALL_OWN_KEYS = "key_reset_all_own_keys";
const API_METHOD_IMPORT_KEY = "import_key";
const API_METHOD_IMPORT_KEY_WITH_FPR_RETURN = "import_key_with_fpr_return";
const API_METHOD_SET_OWN_KEY = "set_own_key";
const API_METHOD_SET_COMM_PARTNER_KEY = "set_comm_partner_key";
@ -389,12 +389,12 @@ class pEpAdapter {
});
}
async import_key(keydata) {
async import_key_with_fpr_return(keydata) {
this.log.info("pEpAdapter entry: import_key()", keydata);
const params = [keydata, keydata.length, ["OP"]];
const params = [keydata, keydata.length, ["OP"], ["OP"], 0];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_IMPORT_KEY,
API_METHOD_IMPORT_KEY_WITH_FPR_RETURN,
params,
).then((response) => {
if ((typeof (response) === "object") && response.hasOwnProperty("error")) {
@ -404,11 +404,12 @@ class pEpAdapter {
if (response.result.return.hasOwnProperty("status")) {
switch (response.result.return.status) {
case PEP_KEY_IMPORTED:
this.log.debug("import_key returned with success: ", response);
return response.result.outParams[0];
this.log.debug("import_key_with_fpr_return returned with success:", response);
// Identities for privated keys, FPRs.
return [response.result.outParams[2], response.result.outParams[1]];
default:
this.checkError(API_METHOD_IMPORT_KEY, response);
this.checkError(API_METHOD_IMPORT_KEY_WITH_FPR_RETURN, response);
}
}
// Hmm, no error and no result?


Loading…
Cancel
Save