Browse Source

P4TB-400: Improved manual key import. Part 2: Backend changes, also stricter error checking in adapter. Logging clean-up.

master
Jörg Knobloch 11 months ago
parent
commit
41e13b9511
6 changed files with 155 additions and 206 deletions
  1. +4
    -4
      addon/_locales/de/messages.json
  2. +4
    -4
      addon/_locales/en/messages.json
  3. +22
    -6
      addon/content/dialogs/options.js
  4. +5
    -7
      addon/content/importRNP.js
  5. +8
    -33
      addon/content/modules/pEp.js
  6. +112
    -152
      addon/content/modules/pEpAdapter.js

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

@ -212,9 +212,6 @@
"optionsCompatibilityHeaderImport": {
"message": "PGP Schlüsselimport"
},
"optionsCompatibilityDetailImport": {
"message": "Sie können einen privaten Schlüssel importieren."
},
"optionsASCFile": {
"message": "ASC Datei"
},
@ -285,7 +282,10 @@
"message": "PGP Schlüssel-Import"
},
"optionsImportError": {
"message": "Fehler. Kein Schlüssel wurde importiert."
"message": "Fehler beim Schlüssel-Import"
},
"optionsKeyUseError": {
"message": "Schlüssel kann nicht genutzt werden wie ausgewählt"
},
"optionsKeyImportNotPossibleDevGroup": {
"message": "Schlüssel-Import nicht möglich solange das Gerät Mitglied einer Gerätegruppe ist."


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

@ -212,9 +212,6 @@
"optionsCompatibilityHeaderImport": {
"message": "PGP Key import"
},
"optionsCompatibilityDetailImport": {
"message": "You can import a secret key."
},
"optionsASCFile": {
"message": "ASC File"
},
@ -285,7 +282,10 @@
"message": "PGP Key import"
},
"optionsImportError": {
"message": "Error occurred. No key imported."
"message": "Error importing key"
},
"optionsKeyUseError": {
"message": "Key cannot be used as selected"
},
"optionsKeyImportNotPossibleDevGroup": {
"message": "Key import not possible while the device is in a device group."


+ 22
- 6
addon/content/dialogs/options.js View File

@ -406,7 +406,9 @@ var pEpOptions = {
stream.close();
// Send to the engine.
pEpController.importKey(btoa(streamData)).then((result) => {
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.
@ -417,6 +419,7 @@ var pEpOptions = {
} 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();
@ -434,11 +437,24 @@ var pEpOptions = {
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
msg,
)) return;
for (let i = 0; i < result.length; i++) {
result[i].user_id = "pEp_own_userId";
pEpController.setOwnKey(result[i]);
// If it fails now, it's a key use error.
errorMsg = "optionsKeyUseError";
switch (usage) {
case "keep":
for (let i = 0; i < result.length; i++) {
result[i].user_id = "pEp_own_userId";
pEpController.set_own_key(result[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]));
break;
default:
}
// TODO: Check error.
msg = pEpOptions.getLocaleMessage("optionsImportSuccessPrivateKey");
}
Services.prompt.alert(
@ -451,7 +467,7 @@ var pEpOptions = {
Services.prompt.alert(
window,
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
pEpOptions.getLocaleMessage("optionsImportError"),
pEpOptions.getLocaleMessage(errorMsg),
);
});
},


+ 5
- 7
addon/content/importRNP.js View File

@ -59,7 +59,7 @@ var ImportRNP = {
if (key.secretAvailable) {
// eslint-disable-next-line prefer-template
let keyData = await RNP.backupSecretKeys(["0x" + key.fpr], "");
let result = await this.controller.importKey(btoa(keyData));
let result = await this.controller.import_key(btoa(keyData));
let keyUsed = false;
for (let identity of fixIterator(MailServices.accounts.allIdentities, Ci.nsIMsgIdentity)) {
let idKeyId = Services.prefs.getStringPref(`mail.identity.${identity.key}.openpgp_key_id`, "");
@ -71,7 +71,7 @@ var ImportRNP = {
result[0].address = identity.email;
result[0].username = identity.fullName;
result[0].user_id = "pEp_own_userId";
await this.controller.setOwnKey(result[0]);
await this.controller.set_own_key(result[0]);
keyUsed = true;
}
}
@ -81,14 +81,14 @@ var ImportRNP = {
for (let i = 0; i < result.length; i++) {
this.controller.log.info(`Private key with user "${result[i].username}" and address "${result[i].address}"`);
result[i].user_id = "pEp_own_userId";
await this.controller.setOwnKey(result[i]);
await this.controller.set_own_key(result[i]);
}
}
priv++;
} else {
// eslint-disable-next-line prefer-template
let keyData = await RNP.getPublicKey("0x" + key.fpr);
let result = await this.controller.importKey(btoa(keyData));
let result = await this.controller.import_key(btoa(keyData));
let acceptanceResult = {};
await PgpSqliteDb2.getFingerprintAcceptance(null, key.fpr, acceptanceResult);
if (!("fingerprintAcceptance" in acceptanceResult) ||
@ -112,9 +112,7 @@ var ImportRNP = {
this.controller.log.info(`Public key with user "${username}" and address "${email}"`);
let id = new pEp.Identity(email, "", username, "");
id = await this.controller.update_identity(id);
id.fpr = key.fpr;
await this.controller.set_identity(id);
await this.controller.set_comm_partner_key(id, key.fpr);
}
pub++;
}


+ 8
- 33
addon/content/modules/pEp.js View File

@ -76,7 +76,6 @@ class pEp {
*/
async serverVersion() {
this.log.info("pEp: serverVersion()");
return this.adapter.serverVersion();
}
@ -99,7 +98,7 @@ class pEp {
}
async getOutgoingRating(from, to = [], cc, bcc, preview = false) {
this.log.info("getOutgoingRating: ", from, to, cc, bcc, preview);
this.log.info("Entry: getOutgoingRating:", from, to, cc, bcc, preview);
if (to.length == 0 && (!cc || cc.length == 0)) return 0;
@ -117,7 +116,7 @@ class pEp {
}
async getOutgoingRatingWithPartnerInfo(from, to = [], cc) {
this.log.info("getOutgoingRatingWithPartnerInfo: ", from, to, cc);
this.log.info("Entry: getOutgoingRatingWithPartnerInfo:", from, to, cc);
if (to.length == 0 && (!cc || cc.length == 0)) return { rating: 0, onlyPEP: false };
@ -144,7 +143,6 @@ class pEp {
}
async myself(identity) {
this.log.info("pEp: myself()");
// Workaround for ENGINE-753.
// Code was: return this.adapter.myself(identity);
let username = identity.username;
@ -154,7 +152,6 @@ class pEp {
}
async identity_rating(identity) {
this.log.info("pEp: identity_rating()", identity);
return this.adapter.identity_rating(identity).then((rating) => {
identity.rating = rating;
return identity;
@ -168,7 +165,6 @@ class pEp {
language = Services.locale.appLocaleAsLangTag.replace(/-.*/, "");
if (!this.languageList.has(language)) language = "en";
}
this.log.info("pEp: get_trustwords()", identity1, identity2);
return this.adapter.get_trustwords(identity1, identity2, language, full);
}
@ -177,47 +173,38 @@ class pEp {
}
async update_identity(identity) {
this.log.info("pEp: update_identity()", identity);
return this.adapter.update_identity(identity);
}
async set_identity(identity) {
this.log.info("pEp: set_identity()", identity);
return this.adapter.set_identity(identity);
}
async key_reset_trust(identity) {
this.log.info("pEp: key_reset_trust()", identity);
return this.adapter.key_reset_trust(identity);
}
async key_reset_user(identity) {
this.log.info("pEp: key_reset_user()", identity);
return this.adapter.key_reset_user(identity);
}
async key_reset_identity(identity) {
this.log.info("pEp: key_reset_identity()", identity);
return this.adapter.key_reset_identity(identity);
}
async key_reset_all_own_keys() {
this.log.info("pEp: key_reset_all_own_keys()");
return this.adapter.key_reset_all_own_keys();
}
async trust_personal_key(identity) {
this.log.info("pEp: trust_personal_key()", identity);
return this.adapter.trust_personal_key(identity);
}
async key_mistrusted(identity) {
this.log.info("pEp: key_mistrusted()", identity);
return this.adapter.key_mistrusted(identity);
}
async is_pEp_user(identity) {
this.log.info("pEp: is_pEp_user()", identity);
return this.adapter.is_pEp_user(identity).then((is_pEp) => {
identity.is_pEp = is_pEp;
return identity;
@ -225,83 +212,71 @@ class pEp {
}
async enablePassiveMode() {
this.log.info("pEp: enablePassiveMode()");
return this.adapter.config_passive_mode(true);
}
async disablePassiveMode() {
this.log.info("pEp: disablePassiveMode()");
return this.adapter.config_passive_mode(false);
}
async enableprotectSubjects() {
this.log.info("pEp: enableprotectSubjects()");
return this.adapter.config_unencrypted_subject(false);
}
async disableprotectSubjects() {
this.log.info("pEp: disableprotectSubjects()");
return this.adapter.config_unencrypted_subject(true);
}
async importKey(keydata) {
this.log.info("pEp: importKey()");
async import_key(keydata) {
return this.adapter.import_key(keydata);
}
async setOwnKey(identity) {
this.log.info("pEp: setOwnKey()");
async set_own_key(identity) {
return this.adapter.set_own_key(identity);
}
async set_comm_partner_key(identity, fpr) {
return this.adapter.set_comm_partner_key(identity, fpr);
}
async reEvaluateMessageRating(message, keyList, oldRating) {
this.log.info("pEp: reEvaluateMessageRating()", message.from, keyList, oldRating);
return this.adapter.re_evaluate_message_rating(message, keyList, oldRating);
}
// Sync methods.
async deliverHandshakeResult(signal, identity) {
this.log.info("pEp: deliverHandshakeResult()");
return this.adapter.deliverHandshakeResult(signal, identity);
}
async enableIdentityForSync(identity) {
this.log.info("pEp: enableIdentityForSync()");
return this.adapter.enable_identity_for_sync(identity);
}
async disableIdentityForSync(identity) {
this.log.info("pEp: disableIdentityForSync()");
return this.adapter.disable_identity_for_sync(identity);
}
async disable_all_sync_channels() {
this.log.info("pEp: disable_all_sync_channels()");
return this.adapter.disable_all_sync_channels();
}
async leaveDeviceGroup() {
this.log.info("pEp: leaveDeviceGroup()");
return this.adapter.leave_device_group();
}
async startSync() {
this.log.info("pEp: startSync()");
return this.adapter.startSync();
}
async stopSync() {
this.log.info("pEp: stopSync()");
return this.adapter.stopSync();
}
async config_passphrase(passphrase) {
this.log.info("pEp: config_passphrase()");
return this.adapter.config_passphrase(passphrase);
}
async config_passphrase_for_new_keys(enable, passphrase) {
this.log.info("pEp: config_passphrase_for_new_keys()");
return this.adapter.config_passphrase_for_new_keys(enable, passphrase);
}
}


+ 112
- 152
addon/content/modules/pEpAdapter.js View File

@ -25,14 +25,15 @@ const API_METHOD_CONFIG_PASSIVE_MODE = "config_passive_mode";
const API_METHOD_CONFIG_UNENCRYPTED_SUBJECT = "config_unencrypted_subject";
const API_METHOD_CONFIG_PASSPHRASE = "config_passphrase";
const API_METHOD_CONFIG_PASSPHRASE_FOR_NEW_KEYS = "config_passphrase_for_new_keys";
const API_METHOD_GET_KEY_MISTRUSTED = "key_mistrusted";
const API_METHOD_GET_TRUST_PERSONAL_KEY = "trust_personal_key";
const API_METHOD_GET_KEY_RESET_TRUST = "key_reset_trust";
const API_METHOD_GET_KEY_RESET_USER = "key_reset_user";
const API_METHOD_GET_KEY_RESET_IDENTITY = "key_reset_identity";
const API_METHOD_GET_KEY_RESET_ALL_OWN_KEYS = "key_reset_all_own_keys";
const API_METHOD_GET_IMPORT_KEY = "import_key";
const API_METHOD_GET_SET_OWN_KEY = "set_own_key";
const API_METHOD_KEY_MISTRUSTED = "key_mistrusted";
const API_METHOD_TRUST_PERSONAL_KEY = "trust_personal_key";
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_SET_OWN_KEY = "set_own_key";
const API_METHOD_SET_COMM_PARTNER_KEY = "set_comm_partner_key";
const API_METHOD_ENABLE_IDENTITY_FOR_SYNC = "enable_identity_for_sync";
const API_METHOD_DISABLE_IDENTITY_FOR_SYNC = "disable_identity_for_sync";
@ -70,6 +71,13 @@ class pEpAdapter {
this.server = server;
}
checkError(funcName, response) {
this.log.debug(`pEpAdapter: ${funcName}. Return value:`, response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
throw new Error(`${funcName} returned status ${response.result.return.status}`);
}
}
async delegateCallPepAdapter(funcType, functionName, paramsArr) {
let response = await this.server.callPepAdapter(funcType, functionName, paramsArr);
@ -93,7 +101,7 @@ class pEpAdapter {
}
async serverVersion() {
this.log.info("pEpAdapter.js: serverVersion()");
this.log.info("pEpAdapter entry: serverVersion()");
const params = [];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -106,7 +114,7 @@ class pEpAdapter {
}
async config_passive_mode(enable) {
this.log.info("pEpAdapter.js: config_passive_mode()");
this.log.info("pEpAdapter entry: config_passive_mode()");
const params = [enable];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -119,7 +127,7 @@ class pEpAdapter {
}
async config_unencrypted_subject(enable) {
this.log.info("pEpAdapter.js: config_unencrypted_subject()");
this.log.info("pEpAdapter entry: config_unencrypted_subject()");
const params = [enable];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -132,7 +140,7 @@ class pEpAdapter {
}
async config_passphrase(passphrase) {
this.log.info("pEpAdapter.js: config_passphrase()");
this.log.info("pEpAdapter entry: config_passphrase()");
const params = [passphrase];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -145,7 +153,7 @@ class pEpAdapter {
}
async config_passphrase_for_new_keys(enable, passphrase) {
this.log.info("pEpAdapter.js: config_passphrase_for_new_keys()");
this.log.info("pEpAdapter entry: config_passphrase_for_new_keys()");
const params = [enable, passphrase];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -158,17 +166,14 @@ class pEpAdapter {
}
async outgoing_message_rating(message, preview) {
this.log.info("pEpAdapter.js: outgoing_message_rating()");
this.log.info("pEpAdapter entry: outgoing_message_rating()");
const params = [message, "OUT"];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
preview ? API_METHOD_OUTGOING_MESSAGE_RATING_PREVIEW : API_METHOD_OUTGOING_MESSAGE_RATING,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: outgoing_message_rating()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(preview ? API_METHOD_OUTGOING_MESSAGE_RATING_PREVIEW : API_METHOD_OUTGOING_MESSAGE_RATING, response);
return response.result.outParams[0].rating;
}).catch((err) => {
this.log.error(err.message);
@ -177,17 +182,14 @@ class pEpAdapter {
}
async outgoing_message_rating_with_partner_info(message) {
this.log.info("pEpAdapter.js: outgoing_message_rating_with_partner_info()");
this.log.info("pEpAdapter entry: outgoing_message_rating_with_partner_info()");
const params = [message, "OUT", "OUT"];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_OUTGOING_MESSAGE_RATING_WPI,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: outgoing_message_rating_with_partner_info()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_OUTGOING_MESSAGE_RATING_WPI, response);
return { rating: response.result.outParams[1].rating, onlyPEP: response.result.outParams[0] };
}).catch((err) => {
this.log.error(err.message);
@ -196,17 +198,14 @@ class pEpAdapter {
}
async re_evaluate_message_rating(message, keyList, oldRating) {
this.log.info("pEpAdapter.js: re_evaluate_message_rating()");
this.log.info("pEpAdapter entry: re_evaluate_message_rating()", message.from, keyList, oldRating);
const params = [message, keyList, { rating: oldRating }, "OUT"];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_RE_EVALUATE_MESSAGE_RATING,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: re_evaluate_message_rating()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_RE_EVALUATE_MESSAGE_RATING, response);
return response.result.outParams[0].rating;
}).catch((err) => {
this.log.error(err.message);
@ -215,17 +214,14 @@ class pEpAdapter {
}
async myself(identity) {
this.log.info("pEpAdapter.js: myself()", identity);
this.log.info("pEpAdapter entry: myself()", identity);
const params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_MYSELF,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: myself()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_MYSELF, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -234,17 +230,14 @@ class pEpAdapter {
}
async set_identity(identity) {
this.log.info("pEpAdapter.js: set_identity()", identity);
this.log.info("pEpAdapter entry: set_identity()", identity);
const params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_SET_IDENTITY,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: set_identity()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_SET_IDENTITY, response);
return null;
}).catch((err) => {
this.log.error(err.message);
@ -253,17 +246,14 @@ class pEpAdapter {
}
async update_identity(identity) {
this.log.info("pEpAdapter.js: update_identity()", identity);
this.log.info("pEpAdapter entry: update_identity()", identity);
const params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_UPDATE_IDENTITY,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: update_identity()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_UPDATE_IDENTITY, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -272,7 +262,7 @@ class pEpAdapter {
}
async get_trustwords(identity1, identity2, language, full) {
this.log.info("pEpAdapter.js: get_trustwords()", identity1, identity2);
this.log.info("pEpAdapter entry: get_trustwords()", identity1, identity2);
const params = [identity1, identity2, language, "OUT", "OUT", full];
return this.delegateCallPepAdapter(
@ -280,10 +270,7 @@ class pEpAdapter {
API_METHOD_GET_TRUSTWORDS,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: get_trustwords()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_GET_TRUSTWORDS, response);
return response.result.outParams[1];
}).catch((err) => {
// TODO Validate length (outParams[0]) with words (outParams[1])
@ -293,7 +280,7 @@ class pEpAdapter {
}
async get_languagelist() {
this.log.info("pEpAdapter.js: get_languagelist()");
this.log.info("pEpAdapter entry: get_languagelist()");
const params = ["OUT"];
return this.server.callPepAdapter(
@ -307,17 +294,14 @@ class pEpAdapter {
}
async trust_personal_key(identity) {
this.log.info("pEpAdapter.js: trust_personal_key()", identity);
this.log.info("pEpAdapter entry: trust_personal_key()", identity);
const params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_TRUST_PERSONAL_KEY,
API_METHOD_TRUST_PERSONAL_KEY,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: trust_personal_key()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_TRUST_PERSONAL_KEY, response);
return response.result.outParams;
}).catch((err) => {
this.log.error(err.message);
@ -326,17 +310,14 @@ class pEpAdapter {
}
async key_reset_trust(identity) {
this.log.info("pEpAdapter.js: key_reset_trust()", identity);
this.log.info("pEpAdapter entry: key_reset_trust()", identity);
const params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_KEY_RESET_TRUST,
API_METHOD_KEY_RESET_TRUST,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: key_reset_trust()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_KEY_RESET_TRUST, response);
return response.result.outParams;
}).catch((err) => {
this.log.error(err.message);
@ -345,17 +326,14 @@ class pEpAdapter {
}
async key_reset_user(identity) {
this.log.info("pEpAdapter.js: key_reset_user()", identity);
this.log.info("pEpAdapter entry: key_reset_user()", identity);
const params = [identity.user_id, identity.fpr];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_KEY_RESET_USER,
API_METHOD_KEY_RESET_USER,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: key_reset_user()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_KEY_RESET_USER, response);
return response.result.outParams;
}).catch((err) => {
this.log.error(err.message);
@ -364,17 +342,14 @@ class pEpAdapter {
}
async key_reset_identity(identity) {
this.log.info("pEpAdapter.js: key_reset_identity()", identity);
this.log.info("pEpAdapter entry: key_reset_identity()", identity);
const params = [identity, identity.fpr];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_KEY_RESET_IDENTITY,
API_METHOD_KEY_RESET_IDENTITY,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: key_reset_identity()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_KEY_RESET_IDENTITY, response);
return response.result.outParams;
}).catch((err) => {
this.log.error(err.message);
@ -383,17 +358,14 @@ class pEpAdapter {
}
async key_reset_all_own_keys() {
this.log.info("pEpAdapter.js: key_reset_all_own_keys()");
this.log.info("pEpAdapter entry: key_reset_all_own_keys()");
const params = [];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_KEY_RESET_ALL_OWN_KEYS,
API_METHOD_KEY_RESET_ALL_OWN_KEYS,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: key_reset_all_own_keys()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_KEY_RESET_ALL_OWN_KEYS, response);
return response.result.outParams;
}).catch((err) => {
this.log.error(err.message);
@ -402,17 +374,14 @@ class pEpAdapter {
}
async key_mistrusted(identity) {
this.log.info("pEpAdapter.js: key_mistrusted()", identity);
this.log.info("pEpAdapter entry: key_mistrusted()", identity);
const params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_KEY_MISTRUSTED,
API_METHOD_KEY_MISTRUSTED,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: key_mistrusted()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_KEY_MISTRUSTED, response);
return response.result.outParams;
}).catch((err) => {
this.log.error(err.message);
@ -421,11 +390,11 @@ class pEpAdapter {
}
async import_key(keydata) {
this.log.info("pEpAdapter.js: import_key()", keydata);
this.log.info("pEpAdapter entry: import_key()", keydata);
const params = [keydata, keydata.length, ["OP"]];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_IMPORT_KEY,
API_METHOD_IMPORT_KEY,
params,
).then((response) => {
if ((typeof (response) === "object") && response.hasOwnProperty("error")) {
@ -435,12 +404,11 @@ class pEpAdapter {
if (response.result.return.hasOwnProperty("status")) {
switch (response.result.return.status) {
case PEP_KEY_IMPORTED:
this.log.debug("callPepAdapter: 'import_key' returned with success: ", response);
this.log.debug("import_key returned with success: ", response);
return response.result.outParams[0];
default:
this.log.debug("callPepAdapter: 'import_key' returned with error: ", response);
throw new Error(`import key error ${response.result.return.status}`);
this.checkError(API_METHOD_IMPORT_KEY, response);
}
}
// Hmm, no error and no result?
@ -452,17 +420,30 @@ class pEpAdapter {
}
async set_own_key(identity) {
this.log.info("pEpAdapter.js: set_own_key()", identity);
this.log.info("pEpAdapter entry: set_own_key()", identity);
const params = [identity, identity.fpr];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_GET_SET_OWN_KEY,
API_METHOD_SET_OWN_KEY,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: set_own_key()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_SET_OWN_KEY, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
throw err;
});
}
async set_comm_partner_key(identity, fpr) {
this.log.info("pEpAdapter entry: set_comm_partner_key()", identity, fpr);
const params = [identity, fpr];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_SET_COMM_PARTNER_KEY,
params,
).then((response) => {
this.checkError(API_METHOD_SET_COMM_PARTNER_KEY, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -471,17 +452,14 @@ class pEpAdapter {
}
async is_pEp_user(identity) {
this.log.info("pEpAdapter.js: is_pEp_user()", identity);
this.log.info("pEpAdapter entry: is_pEp_user()", identity);
const params = [identity, true];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_IS_PEP_USER,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: is_pEp_user()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_IS_PEP_USER, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -490,17 +468,14 @@ class pEpAdapter {
}
async cache_mime_decode_message(message, size) {
this.log.info("pEpAdapter.js: cache_mime_decode_message()");
this.log.info("pEpAdapter entry: cache_mime_decode_message()");
const params = [message, size, ["OP"]];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_CACHE_MIME_DECODE_MESSAGE,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: cache_mime_decode_message()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_CACHE_MIME_DECODE_MESSAGE, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -509,7 +484,7 @@ class pEpAdapter {
}
async cache_mime_encode_message(srcDst, message, omit_fields) {
this.log.info("pEpAdapter.js: cache_mime_encode_message()");
this.log.info("pEpAdapter entry: cache_mime_encode_message()");
const params = [srcDst, message, omit_fields, ["OP"]];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -519,10 +494,7 @@ class pEpAdapter {
if ((typeof (response) === "object") && response.hasOwnProperty("error")) {
throw new Error(response.error.message);
}
this.log.debug("pEpAdapter.js: cache_mime_encode_message()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_CACHE_MIME_ENCODE_MESSAGE, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -531,7 +503,7 @@ class pEpAdapter {
}
async cache_release(msgID) {
this.log.info("pEpAdapter.js: cache_release()");
this.log.info("pEpAdapter entry: cache_release()");
const params = [msgID];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -544,7 +516,7 @@ class pEpAdapter {
}
async cache_decrypt_message(message) {
this.log.info("pEpAdapter.js: cache_decrypt_message()", message);
this.log.info("pEpAdapter entry: cache_decrypt_message()", message);
const params = [
message, // message input
["OP"], // message output
@ -573,7 +545,7 @@ class pEpAdapter {
decryptedMessage.rating = response.result.outParams[1].rating;
decryptedMessage.enc_format = ENC_FORMAT_DECRYPTED; // Sucessfully decrypted.
this.log.debug("callPepAdapter: 'cache_decrypt_message' returned with success: ", response);
this.log.debug("cache_decrypt_message returned with success:", response);
break;
// Workaround for https://pep.foundation/jira/browse/ENGINE-756.
@ -583,13 +555,13 @@ class pEpAdapter {
decryptedMessage.rating = response.result.outParams[1].rating;
decryptedMessage.enc_format = ENC_FORMAT_DECRYPTED; // Sucessfully decrypted.
this.log.debug(
"callPepAdapter: 'cache_decrypt_message' returned with PEP_VERIFY_SIGNER_KEY_REVOKED (decrypted): ", response,
"cache_decrypt_message returned with PEP_VERIFY_SIGNER_KEY_REVOKED (decrypted):", response,
);
} else {
decryptedMessage = response.result.outParams[4];
decryptedMessage.rating = response.result.outParams[1].rating;
this.log.debug(
"callPepAdapter: 'cache_decrypt_message' returned with PEP_VERIFY_SIGNER_KEY_REVOKED (NOT decrypted) status: ",
"cache_decrypt_message returned with PEP_VERIFY_SIGNER_KEY_REVOKED (NOT decrypted) status:",
response,
);
}
@ -601,15 +573,14 @@ class pEpAdapter {
decryptedMessage.rating = response.result.outParams[1].rating;
decryptedMessage.enc_format = ENC_FORMAT_DECRYPTED; // Sucessfully decrypted.
this.log.debug(
"callPepAdapter: 'cache_decrypt_message' returned with PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH (decrypted): ",
"cache_decrypt_message returned with PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH (decrypted):",
response,
);
} else {
decryptedMessage = response.result.outParams[4];
decryptedMessage.rating = response.result.outParams[1].rating;
this.log.debug(
// eslint-disable-next-line max-len
"callPepAdapter: 'cache_decrypt_message' returned with PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH (NOT decrypted) status: ",
"cache_decrypt_message returned with PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH (NOT decrypted) status:",
response,
);
}
@ -619,18 +590,17 @@ class pEpAdapter {
decryptedMessage = response.result.outParams[4];
decryptedMessage.rating = response.result.outParams[1].rating;
decryptedMessage.enc_format = ENC_FORMAT_NONE; // This wasn't encrypted to start with.
this.log.debug("callPepAdapter: 'cache_decrypt_message' returned with UNENCRYPTED status: ", response);
this.log.debug("cache_decrypt_message returned with UNENCRYPTED status:", response);
break;
case PEP_DECRYPT_NO_KEY:
decryptedMessage = response.result.outParams[4];
decryptedMessage.rating = response.result.outParams[1].rating;
this.log.debug("callPepAdapter: 'cache_decrypt_message' returned with DECRYPT_NO_KEY status: ", response);
this.log.debug("cache_decrypt_message returned with DECRYPT_NO_KEY status:", response);
break;
default:
this.log.debug("callPepAdapter: 'cache_decrypt_message' returned with error: ", response);
throw new Error(`decrypt error ${response.result.return.status}`);
this.checkError(API_METHOD_CACHE_DECRYPT_MESSAGE, response);
}
}
@ -650,7 +620,7 @@ class pEpAdapter {
encFormat, // Encoding Format
0, // Flags
]);
this.log.info("pEpAdapter.js: cache_encrypt_message()", message);
this.log.info("pEpAdapter entry: cache_encrypt_message()", message);
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
isDraftOrTemplate ? API_METHOD_CACHE_ENCRYPT_MESSAGE_FOR_SELF : API_METHOD_CACHE_ENCRYPT_MESSAGE,
@ -666,7 +636,7 @@ class pEpAdapter {
switch (response.result.return.status) {
case PEP_STATUS_OK:
encryptedMessage = response.result.outParams[0];
this.log.debug("callPepAdapter: 'cache_encrypt_message' returned with success: ", response);
this.log.debug("cache_encrypt_message returned with success:", response);
break;
// It's unclear whether anything except `PEP_UNENCRYPTED` will be returned here.
@ -677,12 +647,14 @@ class pEpAdapter {
case PEP_KEY_HAS_AMBIG_NAME:
encryptedMessage = response.result.outParams[1];
encryptedMessage.enc_format = ENC_FORMAT_NONE; // We couldn't encrypt, so this is unencrypted.
this.log.debug("callPepAdapter: 'cache_encrypt_message' returned with UNENCRYPTED status: ", response);
this.log.debug("cache_encrypt_message returned with UNENCRYPTED status:", response);
break;
default:
this.log.debug("callPepAdapter: 'cache_encrypt_message' returned with error: ", response);
throw new Error(`encrypt error ${response.result.return.status}`);
this.checkError(
isDraftOrTemplate ? API_METHOD_CACHE_ENCRYPT_MESSAGE_FOR_SELF : API_METHOD_CACHE_ENCRYPT_MESSAGE,
response,
);
}
}
@ -694,17 +666,14 @@ class pEpAdapter {
}
async identity_rating(identity) {
this.log.info("pEpAdapter.js: identity_rating()");
this.log.info("pEpAdapter entry: identity_rating()", identity);
const params = [identity, ["OP"]];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_IDENTITY_RATING,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: identity_rating()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_IDENTITY_RATING, response);
return response.result.outParams[0].rating;
}).catch((err) => {
this.log.error(err.message);
@ -713,17 +682,14 @@ class pEpAdapter {
}
async enable_identity_for_sync(identity) {
this.log.info("pEpAdapter.js: enable_identity_for_sync()", identity);
this.log.info("pEpAdapter entry: enable_identity_for_sync()", identity);
let params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_ENABLE_IDENTITY_FOR_SYNC,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: enable_identity_for_sync()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_ENABLE_IDENTITY_FOR_SYNC, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -732,17 +698,14 @@ class pEpAdapter {
}
async disable_identity_for_sync(identity) {
this.log.info("pEpAdapter.js: disable_identity_for_sync()", identity);
this.log.info("pEpAdapter entry: disable_identity_for_sync()", identity);
let params = [identity];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_DISABLE_IDENTITY_FOR_SYNC,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: disable_identity_for_sync()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_DISABLE_IDENTITY_FOR_SYNC, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -751,7 +714,7 @@ class pEpAdapter {
}
async disable_all_sync_channels() {
this.log.info("pEpAdapter.js: disable_all_sync_channels()");
this.log.info("pEpAdapter entry: disable_all_sync_channels()");
let params = [];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -764,17 +727,14 @@ class pEpAdapter {
}
async leave_device_group(identity) {
this.log.info("pEpAdapter.js: leave_device_group()");
this.log.info("pEpAdapter entry: leave_device_group()");
let params = [];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
API_METHOD_LEAVE_DEVICE_GROUP,
params,
).then((response) => {
this.log.debug("pEpAdapter.js: leave_device_group()", response);
if (response.result.return.hasOwnProperty("status") && response.result.return.status != PEP_STATUS_OK) {
this.log.error(`returned status ${response.result.return.status}`);
}
this.checkError(API_METHOD_LEAVE_DEVICE_GROUP, response);
return response.result.outParams[0];
}).catch((err) => {
this.log.error(err.message);
@ -783,7 +743,7 @@ class pEpAdapter {
}
async deliverHandshakeResult(signal, identity) {
this.log.info("pEpAdapter.js: deliverHandshakeResult()");
this.log.info("pEpAdapter entry: deliverHandshakeResult()");
let params = [signal, [identity]];
return this.delegateCallPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -803,7 +763,7 @@ class pEpAdapter {
}
async startSync() {
this.log.info("pEpAdapter.js: startSync()");
this.log.info("pEpAdapter entry: startSync()");
let params = [];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,
@ -816,7 +776,7 @@ class pEpAdapter {
}
async stopSync() {
this.log.info("pEpAdapter.js: stopSync()");
this.log.info("pEpAdapter entry: stopSync()");
let params = [];
return this.server.callPepAdapter(
SERVER_TYPE_CALL_FUNC,


Loading…
Cancel
Save