|
|
|
@ -53,9 +53,7 @@ class pEpAdapter {
|
|
|
|
|
this.requestId++;
|
|
|
|
|
let msgId = PEP_PREFIX + this.requestId;
|
|
|
|
|
|
|
|
|
|
subject = "pEp"; // CHECK
|
|
|
|
|
|
|
|
|
|
let message = new pEpAdapter.pEpMessage(msgId, subject, null, sender, to, DIR_INCOMING);
|
|
|
|
|
let message = new pEpAdapter.pEpMessage(msgId, subject, body, sender, to, DIR_INCOMING);
|
|
|
|
|
|
|
|
|
|
if (cc) {
|
|
|
|
|
message.cc = cc;
|
|
|
|
@ -74,41 +72,57 @@ class pEpAdapter {
|
|
|
|
|
0 // flags output
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
console.debug(params);
|
|
|
|
|
console.debug(params[0].attachments);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return await this.server.callPepAdapter(
|
|
|
|
|
SERVER_TYPE_CALL_FUNC,
|
|
|
|
|
API_METHOD_DECRYPT,
|
|
|
|
|
params,
|
|
|
|
|
|
|
|
|
|
response => {
|
|
|
|
|
let result = response.result.outParams;
|
|
|
|
|
this.log("pEpAdapter.js: decrypt() success: ", result);
|
|
|
|
|
const pEp_message = result[3];
|
|
|
|
|
return {
|
|
|
|
|
longmsg: pEp_message.longmsg,
|
|
|
|
|
shortmsg: pEp_message.shortmsg,
|
|
|
|
|
persons: {
|
|
|
|
|
from: pEp_message.from,
|
|
|
|
|
to: pEp_message.to,
|
|
|
|
|
cc: pEp_message.cc,
|
|
|
|
|
reply_to: pEp_message.reply_to
|
|
|
|
|
},
|
|
|
|
|
rating: result[1].rating,
|
|
|
|
|
fpr: result[2]
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
err => {
|
|
|
|
|
this.log("this is an error", err);
|
|
|
|
|
return null;
|
|
|
|
|
return await this.server.callPepAdapter(
|
|
|
|
|
SERVER_TYPE_CALL_FUNC,
|
|
|
|
|
API_METHOD_DECRYPT,
|
|
|
|
|
params
|
|
|
|
|
).then((response) => {
|
|
|
|
|
this.log("pEpAdapter.js: decrypt() success: ", response);
|
|
|
|
|
|
|
|
|
|
if ((typeof(response) === "object") && response.hasOwnProperty("error")) {
|
|
|
|
|
switch (response.error.code) {
|
|
|
|
|
case PEP_WRONG_SEC_TOKEN_CODE:
|
|
|
|
|
throw new Error({code: "PEP-ERROR", message: "Invalid Security Token", response});
|
|
|
|
|
break;
|
|
|
|
|
case -32603:
|
|
|
|
|
console.log("2222", response.error.data.params[0].to);
|
|
|
|
|
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.log("pEpAdapter.js: decrypt() error: ", e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(typeof response === "object" &&
|
|
|
|
|
response.hasOwnProperty("result") &&
|
|
|
|
|
response.result.hasOwnProperty("return"))) {
|
|
|
|
|
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let decryptedMessage = {};
|
|
|
|
|
|
|
|
|
|
if (response.result.return.hasOwnProperty("status")) {
|
|
|
|
|
switch (response.result.return.status) {
|
|
|
|
|
case(PEP_RESPONSE_OK):
|
|
|
|
|
case(PEP_RESPONSE_DECRYPTED):
|
|
|
|
|
console.log(response.result.outParams);
|
|
|
|
|
decryptedMessage = response.result.outParams[4];
|
|
|
|
|
this.log("callPepAdapter: '" + "decrypt" + "' returned with success: ", response);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case(PEP_RESPONSE_UNENCRYPTED):
|
|
|
|
|
decryptedMessage = message;
|
|
|
|
|
this.log("callPepAdapter: '" + "decrypt" + "' returned with UNENCRYPTED status: ", response);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
this.log("callPepAdapter: '" + "decrypt" + "' returned with error: ", response);
|
|
|
|
|
throw new Error({code: "PEP-ERROR", message: response.error.message, response});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decryptedMessage;
|
|
|
|
|
}).catch( (err) => {
|
|
|
|
|
this.log(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async encrypt(subject, body, from, to = [], stringlist = [], encodingFormat = ENC_FORMAT_PEP) {
|
|
|
|
@ -153,12 +167,12 @@ class pEpAdapter {
|
|
|
|
|
case(PEP_RESPONSE_OK):
|
|
|
|
|
case(PEP_RESPONSE_DECRYPTED):
|
|
|
|
|
encryptedMessage = response.result.outParams[0];
|
|
|
|
|
this.log("callPepAdapter: '" + "encrypt" + "' returned with success: ", response, response);
|
|
|
|
|
this.log("callPepAdapter: '" + "encrypt" + "' returned with success: ", response);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case(PEP_RESPONSE_UNENCRYPTED):
|
|
|
|
|
encryptedMessage = message;
|
|
|
|
|
this.log("callPepAdapter: '" + "encrypt" + "' returned with UNENCRYPTED status: ", response, response);
|
|
|
|
|
this.log("callPepAdapter: '" + "encrypt" + "' returned with UNENCRYPTED status: ", response);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|