Browse Source

merge default into P4TB-73-disable-accounts

1.1.101
francesco 2 years ago
parent
commit
ab6b45519f
8 changed files with 320 additions and 22 deletions
  1. +0
    -0
      chrome/background.js
  2. +7
    -2
      chrome/content/p4tb.js
  3. +12
    -0
      chrome/content/pEp.css
  4. +10
    -1
      chrome/content/pEpMimeEncrypt.js
  5. +21
    -11
      chrome/content/pepmessengercompose.js
  6. +2
    -0
      chrome/content/prefsFactory.js
  7. +12
    -0
      chrome/manifest.json
  8. +256
    -8
      tests/features/encrypt_feature_spec.js

+ 0
- 0
chrome/background.js View File


+ 7
- 2
chrome/content/p4tb.js View File

@ -93,15 +93,20 @@ let adapter = new pEpAdapter(logger, server);
let pEpController = new pEp(env, logger, adapter, files, os);
pEpController.privacyStatusToTextClass = (privacyStatus) => {
pEpController.privacyStatusToTextClass = (privacyStatus, protectionDisabled = false) => {
let privacyText = "Unknown";
switch (privacyStatus) {
case "red":
privacyText = "Mistrusted";
case "green":
privacyText = "Secure & Trusted";
privacyText = "Secure and Trusted";
if(protectionDisabled) privacyStatus = "green-disabled";
break;
case "yellow":
privacyText = "Secure";
if(protectionDisabled) privacyStatus = "yellow-disabled";
break;
default:
privacyStatus = "no-color";


+ 12
- 0
chrome/content/pEp.css View File

@ -19,6 +19,18 @@ tabbox {
border-color: #c35855;
}
.green-disabled {
background: url('chrome://p4t/content/green-shield.png') #ffffff;
border: 1px solid #468f41;
color: black;
}
.yellow-disabled {
background: url('chrome://p4t/content/yellow-shield.png') #ffffff;
border: 1px solid #c7b729;
color: black;
}
.no-color {
background: url('chrome://p4t/content/no-color-shield-white.png') #dddddd;
border-color: #959595;


+ 10
- 1
chrome/content/pEpMimeEncrypt.js View File

@ -12,6 +12,10 @@ const maxBufferLen = 102400;
const MIME_SIGNED = 1;
const MIME_ENCRYPTED = 2;
const ENC_FORMAT_NONE = 0;
const ENC_FORMAT_PGP_MIME = 3;
const ENC_FORMAT_PEP = 4;
let gDebugLogLevel = 0;
function isMessageUriInPgpMime() {
@ -304,6 +308,11 @@ PgpMimeEncrypt.prototype = {
let sendFlags = 0;
this.outQueue = "";
let enc_format = ENC_FORMAT_PGP_MIME;
if(this.msgIdentity.getBoolAttribute("protectionDisabled")) {
enc_format = ENC_FORMAT_NONE;
}
this.sendFlags = SEND_ENCRYPTED; // BECAUSE TESTING
if (!this.isDraft) {
@ -346,7 +355,7 @@ PgpMimeEncrypt.prototype = {
return this.pEpController.disclaimerStep(pEpMessage);
}).then((pEpMessage) => {
this.pEpController.encryptMailWithMessage(pEpMessage).then((result) => {
this.pEpController.encryptMailWithMessage(pEpMessage, enc_format).then((result) => {
resultObj = result;
// unblock the waiting lock in finishCryptoEncapsulation


+ 21
- 11
chrome/content/pepmessengercompose.js View File

@ -10,7 +10,6 @@ const { prefsFactory } = ChromeUtils.import("chrome://p4t/content/prefsFactory.
var TbAbstraction = {
getCurrentIdentity: () => {
/* global gCurrentIdentity: false */
console.log("CURRENT IDENTITY:", gCurrentIdentity);
return gCurrentIdentity;
}
};
@ -52,9 +51,9 @@ var removeNode = (nodeId) => {
}
};
var createPrivacyNode = (privacyStatus) => {
var createPrivacyNode = (privacyStatus, protectionDisabled = false) => {
let privacyTextClass = pEpController.privacyStatusToTextClass(privacyStatus);
let privacyTextClass = pEpController.privacyStatusToTextClass(privacyStatus, protectionDisabled);
let privacyNodeId = "pEp-compose-privacy-bar";
@ -101,6 +100,7 @@ var pEpComposer = {
// sent. A race condition is unlikely yet possible.
pEpController.setPrefs(this.prefs);
TbAbstraction.getCurrentIdentity().setIntAttribute("encryptionpolicy", 2);
TbAbstraction.getCurrentIdentity().setBoolAttribute("protectionDisabled", false);
},
initPrivacyWarning() {
@ -146,19 +146,16 @@ var pEpComposer = {
let cc = (msgCompFields.cc) ? _parseAddress(msgCompFields.cc) : undefined;
let bcc = (msgCompFields.bcc) ? _parseAddress(msgCompFields.bcc) : undefined;
let ratingProm;
if (helper.disabledForAccount(gCurrentIdentity)) {
ratingProm = Promise.resolve(-2);
} else {
ratingProm = pEpController.getOngoingRating(from, to, cc, bcc);
}
ratingProm.then((rating) => {
pEpController.getOngoingRating(from, to, cc, bcc).then((rating) => {
let protectionDisabled = TbAbstraction.getCurrentIdentity().getBoolAttribute("protectionDisabled");
pEpController.getOngoingRating(from, to, cc, bcc).then((rating) => {
console.log("ONGOING RATING: ", rating);
if (typeof rating === "undefined") rating = -2;
updateMsgIdentity(rating);
pEpController.getPrivacyColorFromRating(rating).then((color) => {
createPrivacyNode(color);
createPrivacyNode(color, protectionDisabled);
});
}).catch(() => {
pEpController.getPrivacyColorFromRating(-2).then((color) => {
@ -187,6 +184,8 @@ var pEpComposer = {
};
getMsgCompose().RegisterStateListener(stateListener);
document.getElementById("p4tb_pep_security-composeAction-toolbarbutton").addEventListener("click", this.toggleDisableProtectionButtonAction);
},
fromChangedListener: function (event) {
@ -274,6 +273,16 @@ var pEpComposer = {
}
);
},
toggleDisableProtectionButtonAction: function() {
//Placeholder
//TODO To be implemented
let previousValue = TbAbstraction.getCurrentIdentity().getBoolAttribute("protectionDisabled");
TbAbstraction.getCurrentIdentity().setBoolAttribute("protectionDisabled", !previousValue);
this.addressPopupListener();
}
};
@ -281,4 +290,5 @@ window.addEventListener("compose-window-init", pEpComposer.initListener.bind(pEp
window.addEventListener("compose-from-changed", pEpComposer.fromChangedListener.bind(pEpComposer), true);
window.addEventListener('compose-send-message', pEpComposer.sendMessageListener.bind(pEpComposer), true);
pEpComposer.init(window);

+ 2
- 0
chrome/content/prefsFactory.js View File

@ -1,4 +1,6 @@
let { Services } = ChromeUtils.import('resource://gre/modules/Services.jsm');
function prefsFactory() {
const prefs = Services.prefs.getBranch('extensions.p4tb.');


+ 12
- 0
chrome/manifest.json View File

@ -19,6 +19,18 @@
"32": "content/logo.png",
"64": "content/logo.png"
},
"background": {
"scripts": ["background.js"]
},
"compose_action": {
"default_area": "formattoolbar",
"default_title": "Disable Protection",
"default_icon": "content/logo.png"
},
"default_locale": "en",
"legacy": {
"type": "bootstrap",


+ 256
- 8
tests/features/encrypt_feature_spec.js View File

@ -15,7 +15,15 @@ describe('pEp Encrypt Feature', () => {
before(() => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[null],"return":{"status":1024,"hex":"0x400 \"PEP_UNENCRYPTED\""},"errorstack":["(1 elements cleared)"]}});
queue.respondWith({
"jsonrpc": "2.0",
"id": 1,
"result": {
"outParams": [null],
"return": {"status": 1024, "hex": "0x400 \"PEP_UNENCRYPTED\""},
"errorstack": ["(1 elements cleared)"]
}
});
from = "cfg@pep.security";
to = "to@test.com";
@ -29,7 +37,25 @@ describe('pEp Encrypt Feature', () => {
});
it('returns an unencrypted message', () => {
queue.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"encrypt_message","params":[{"id":"pEp-0","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security","fpr":""},"to":[{"user_id":"","username":"anonymous","address":"to@test.com","fpr":""}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[],"cc":[]},[],["OP"],3,0],"id":1,"jsonrpc":"2.0"});
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""},
"to": [{"user_id": "", "username": "anonymous", "address": "to@test.com", "fpr": ""}],
"dir": 1,
"enc_format": 3,
"attachments": [],
"opt_fields": [],
"cc": []
}, [], ["OP"], 3, 0],
"id": 1,
"jsonrpc": "2.0"
});
result.should.eventually.have.property('enc_format', 0);
message = new pEp.Message("pEp-0", subject, body, from, to);
@ -47,7 +73,44 @@ describe('pEp Encrypt Feature', () => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({"jsonrpc":"2.0","id":2,"result":{"outParams":[{"dir":1,"id":"pEp.PXRZLM.16E95EA7JPDTS.BEFBAEC0-94DC-4AA2-A239-FE24BAA73911@pep.security","shortmsg":"p≡p","longmsg":"this message was encrypted with p≡p https://pEp-project.org","attachments":[{"value":"VmVyc2lvbjogMQ==","size":10,"mime_type":"application/pgp-encrypted"},{"value":"mockvalue","size":3681,"mime_type":"application/octet-stream","filename":"file://msg.asc"}],"from":{"address":"cfg@pep.security","fpr":"B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5","user_id":"pEp_own_userId","username":"anonymous","comm_type":255},"to":[{"address":"cfg@pep.security","fpr":"B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5","user_id":"pEp_own_userId","username":"anonymous","comm_type":255}],"opt_fields":[{"key":"X-pEp-Version","value":"2.1"}],"enc_format":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
queue.respondWith({
"jsonrpc": "2.0",
"id": 2,
"result": {
"outParams": [{
"dir": 1,
"id": "pEp.PXRZLM.16E95EA7JPDTS.BEFBAEC0-94DC-4AA2-A239-FE24BAA73911@pep.security",
"shortmsg": "p≡p",
"longmsg": "this message was encrypted with p≡p https://pEp-project.org",
"attachments": [{
"value": "VmVyc2lvbjogMQ==",
"size": 10,
"mime_type": "application/pgp-encrypted"
}, {
"value": "mockvalue",
"size": 3681,
"mime_type": "application/octet-stream",
"filename": "file://msg.asc"
}],
"from": {
"address": "cfg@pep.security",
"fpr": "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
},
"to": [{
"address": "cfg@pep.security",
"fpr": "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
}],
"opt_fields": [{"key": "X-pEp-Version", "value": "2.1"}],
"enc_format": 3
}], "return": {"status": 0, "hex": "0 \"PEP_STATUS_OK\""}, "errorstack": ["(1 elements cleared)"]
}
});
from = "cfg@pep.security";
to = "cfg@pep.security";
@ -61,7 +124,25 @@ describe('pEp Encrypt Feature', () => {
});
it('sends as expected', () => {
queue.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"encrypt_message","params":[{"id":"pEp-0","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","from":{"user_id":"","username":"anonymous","address":"cfg@pep.security","fpr":""},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security","fpr":""}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[],"cc":[]},[],["OP"],3,0],"id":1,"jsonrpc":"2.0"});
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""},
"to": [{"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""}],
"dir": 1,
"enc_format": 3,
"attachments": [],
"opt_fields": [],
"cc": []
}, [], ["OP"], 3, 0],
"id": 1,
"jsonrpc": "2.0"
});
});
it('should resolve into an encrypted mail', () => {
@ -136,7 +217,55 @@ describe('pEp Encrypt Feature', () => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({"jsonrpc":"2.0","id":1,"result":{"outParams":[{"dir":1,"id":"pEp-0","shortmsg":"p≡p","longmsg":"this message was encrypted with p≡p https://pEp-project.org","attachments":[{"value":"VmVyc2lvbjogMQ==","size":10,"mime_type":"application/pgp-encrypted"},{"value":"mocked value","size":5071,"mime_type":"application/octet-stream","filename":"file://msg.asc"}],"from":{"address":"fo@pep.security","fpr":"B0E03850E2033BCBBF22F7087D45E0D0A78160AC","user_id":"pEp_own_userId","username":"anonymous","comm_type":255},"to":[{"address":"cfg@pep.security","fpr":"B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5","user_id":"pEp_own_userId","username":"anonymous","comm_type":255},{"address":"rg@pep.security","fpr":"14120CA823EA419E6A297EEDE37AADE4CCFDFBAD","user_id":"TOFU_rg@pep.security","username":"anonymous","comm_type":56}],"cc":[{"address":"kinga@pep-security.net","fpr":"B49167205B22B4891CD69580A1D55C3A106407CF","user_id":"TOFU_kinga@pep-security.net","username":"anonymous","comm_type":56}],"opt_fields":[{"key":"X-pEp-Version","value":"2.1"}],"enc_format":3}],"return":{"status":0,"hex":"0 \"PEP_STATUS_OK\""},"errorstack":["(1 elements cleared)"]}});
queue.respondWith({
"jsonrpc": "2.0", "id": 1, "result": {
"outParams": [{
"dir": 1,
"id": "pEp-0",
"shortmsg": "p≡p",
"longmsg": "this message was encrypted with p≡p https://pEp-project.org",
"attachments": [{
"value": "VmVyc2lvbjogMQ==",
"size": 10,
"mime_type": "application/pgp-encrypted"
}, {
"value": "mocked value",
"size": 5071,
"mime_type": "application/octet-stream",
"filename": "file://msg.asc"
}],
"from": {
"address": "fo@pep.security",
"fpr": "B0E03850E2033BCBBF22F7087D45E0D0A78160AC",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
},
"to": [{
"address": "cfg@pep.security",
"fpr": "B5313A3FBF6720F2A421F8B3B8C7ED6CD7FF61B5",
"user_id": "pEp_own_userId",
"username": "anonymous",
"comm_type": 255
}, {
"address": "rg@pep.security",
"fpr": "14120CA823EA419E6A297EEDE37AADE4CCFDFBAD",
"user_id": "TOFU_rg@pep.security",
"username": "anonymous",
"comm_type": 56
}],
"cc": [{
"address": "kinga@pep-security.net",
"fpr": "B49167205B22B4891CD69580A1D55C3A106407CF",
"user_id": "TOFU_kinga@pep-security.net",
"username": "anonymous",
"comm_type": 56
}],
"opt_fields": [{"key": "X-pEp-Version", "value": "2.1"}],
"enc_format": 3
}], "return": {"status": 0, "hex": "0 \"PEP_STATUS_OK\""}, "errorstack": ["(1 elements cleared)"]
}
});
from = "fo@pep.security";
to = ["cfg@pep.security", "rg@pep.security"];
@ -152,7 +281,30 @@ describe('pEp Encrypt Feature', () => {
});
it('sends as expected', () => {
queue.expectSent({"security_token":"0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW","method":"encrypt_message","params":[{"id":"pEp-0","shortmsg":"subject","longmsg":"Not Encrypted Message","longmsg_formatted":"","from":{"user_id":"","username":"anonymous","address":"fo@pep.security","fpr":""},"to":[{"user_id":"","username":"anonymous","address":"cfg@pep.security","fpr":""},{"user_id":"","username":"anonymous","address":"rg@pep.security","fpr":""}],"dir":1,"enc_format":3,"attachments":[],"opt_fields":[],"cc":[{"user_id":"","username":"anonymous","address":"kinga@pep-security.net","fpr":""}]},[],["OP"],3,0],"id":1,"jsonrpc":"2.0"});
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "fo@pep.security", "fpr": ""},
"to": [{
"user_id": "",
"username": "anonymous",
"address": "cfg@pep.security",
"fpr": ""
}, {"user_id": "", "username": "anonymous", "address": "rg@pep.security", "fpr": ""}],
"dir": 1,
"enc_format": 3,
"attachments": [],
"opt_fields": [],
"cc": [{"user_id": "", "username": "anonymous", "address": "kinga@pep-security.net", "fpr": ""}]
}, [], ["OP"], 3, 0],
"id": 1,
"jsonrpc": "2.0"
});
});
it('should resolve into an encrypted mail', () => {
@ -171,7 +323,7 @@ describe('pEp Encrypt Feature', () => {
});
});
it("should return sender fingerprints", () => {
it("should return original sender info", () => {
return result.should.eventually.have.property("from").then((sender) => {
sender.should.be.deep.equal({
"address": "fo@pep.security",
@ -183,7 +335,7 @@ describe('pEp Encrypt Feature', () => {
});
});
it("should return to fingerprints", () => {
it("should return original receivers info", () => {
return result.should.eventually.have.property("to").then((receivers) => {
return receivers.should.be.deep.equal([{
"address": "cfg@pep.security",
@ -240,4 +392,100 @@ describe('pEp Encrypt Feature', () => {
});
});
});
describe('Encryption None scenario', () => {
let from, to, subject, body, message;
before(() => {
queue = getQueue();
pEpController = getController(queue);
queue.respondWith({
"jsonrpc": "2.0",
"id": 2,
"result": {
"outParams": [null], "return": {"status": 1024, "hex": "0x400 \"PEP_UNENCRYPTED\""}, "errorstack": ["(1 elements cleared)"]
}
});
from = "cfg@pep.security";
to = "cfg@pep.security";
subject = "subject";
body = "Not Encrypted Message";
result = pEpController.encryptMail(subject, body, "", from, to, undefined, undefined, 0);
});
after(() => {
queue.after();
pEpController.after();
});
it('sends as expected', () => {
queue.expectSent({
"security_token": "0847cqi9WqqE5ZcVtA8_mDIgEmYMv14xlNAvSZW",
"method": "encrypt_message",
"params": [{
"id": "pEp-0",
"shortmsg": "subject",
"longmsg": "Not Encrypted Message",
"longmsg_formatted": "",
"from": {"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""},
"to": [{"user_id": "", "username": "anonymous", "address": "cfg@pep.security", "fpr": ""}],
"dir": 1,
"enc_format": 0,
"attachments": [],
"opt_fields": [],
"cc": []
}, [], ["OP"], 0, 0],
"id": 1,
"jsonrpc": "2.0"
});
});
it('should resolve into an encrypted mail', () => {
return result.should.be.fulfilled;
});
it("should return an outgoing message", () => {
return result.should.eventually.have.property("dir").then((dir) => {
dir.should.be.equal(1);
});
});
it("should return formated with enc_format default", () => {
return result.should.eventually.have.property("enc_format").then((enc_format) => {
enc_format.should.be.equal(0);
});
});
it("should return sender fingerprints", () => {
return result.should.eventually.have.property("from").then((sender) => {
sender.address.should.be.equal(from);
sender.fpr.should.be.equal("");
sender.user_id.should.be.equal("");
sender.username.should.be.equal("anonymous");
});
});
it("should return receiver fingerprints", () => {
return result.should.eventually.have.property("to").then((receivers) => {
receivers.length.should.be.gte(1);
receivers[0].address.should.be.equal(to);
receivers[0].fpr.should.be.equal("");
receivers[0].user_id.should.be.equal("");
receivers[0].username.should.be.equal("anonymous");
});
});
it("should have original subject", () => {
return result.should.eventually.have.property("shortmsg").then((shortmsg) => {
shortmsg.should.be.equal("subject");
});
});
it('should have original body', () => {
return result.should.eventually.have.property("longmsg").then((longmsg) => {
longmsg.should.be.equal("Not Encrypted Message");
});
});
});
});

Loading…
Cancel
Save