Skip to content

Commit

Permalink
Added ability to select singing key for Sign and EncryptSign operatio…
Browse files Browse the repository at this point in the history
…ns; work towards issues #76 and #77
  • Loading branch information
kylehuff committed Apr 21, 2013
1 parent f08bce6 commit 9051c39
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 268 deletions.
4 changes: 2 additions & 2 deletions extension/XULContent/thunderbird/composeOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ webpg.thunderbird.compose = {
return true;
});
}
var status = webpg.plugin.gpgEncrypt(msg, recipients, (sign == true) ? 1 : 0);
var status = webpg.plugin.gpgEncrypt(msg, recipients, (sign == true) ? 1 : 0, []);
webpg.plugin.restoreGPGConfig();
if (!status.error)
webpg.thunderbird.compose.setEditorContents(status.data);
Expand All @@ -374,7 +374,7 @@ webpg.thunderbird.compose = {

symCryptMsg: function(msg) {
try {
var encryptStatus = webpg.plugin.gpgSymmetricEncrypt(msg, 0);
var encryptStatus = webpg.plugin.gpgSymmetricEncrypt(msg, 0, []);
if (!encryptStatus.error)
webpg.thunderbird.compose.setEditorContents(encryptStatus.data);
} catch (err) {
Expand Down
18 changes: 13 additions & 5 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ webpg.background = {

/* Check to make sure all of the enabled_keys are private keys
this would occur if the key was enabled and then the secret key was deleted. */
webpg.default_key = webpg.preferences.default_key.get();
webpg.secret_keys = webpg.plugin.getPrivateKeyList();
for (var sKey in webpg.secret_keys)
webpg.secret_keys[sKey].default = (sKey == webpg.default_key);
webpg.enabled_keys = webpg.preferences.enabled_keys.get();
var secret_keys = webpg.secret_keys;
var enabled_keys = webpg.enabled_keys;
Expand Down Expand Up @@ -210,8 +213,10 @@ webpg.background = {
break;

case 'sign':
var signing_key = webpg.preferences.default_key.get()
var sign_status = webpg.plugin.gpgSignText([signing_key],
var signers = (typeof(request.signers)!=undefined
&& request.signers != null
&& request.signers.length > 0) ? request.signers : [webpg.preferences.default_key.get()]
var sign_status = webpg.plugin.gpgSignText(signers,
request.selectionData.selectionText, 2);
response = sign_status;
if (!sign_status.error && sign_status.data.length > 0) {
Expand Down Expand Up @@ -343,10 +348,13 @@ webpg.background = {
case 'encrypt':
var sign = (typeof(request.sign)=='undefined'
|| request.sign == false) ? 0 : 1;
var signers = (typeof(request.signers)!=undefined
&& request.signers != null
&& request.signers.length > 0) ? request.signers : [];
if (request.recipients.length > 0) {
//console.log(request.data, request.recipients);
response = webpg.plugin.gpgEncrypt(request.data,
request.recipients, sign);
request.recipients, sign, signers);
} else {
response = "";
}
Expand All @@ -364,7 +372,7 @@ webpg.background = {
//console.log("encrypt requested");
if (request.recipients && request.recipients.length > 0) {
response = webpg.plugin.gpgEncrypt(request.data,
request.recipients, 1);
request.recipients, 1, request.signers);
} else {
response = "";
}
Expand All @@ -378,7 +386,7 @@ webpg.background = {

case 'symmetricEncrypt':
//console.log("symmetric encryption requested");
response = webpg.plugin.gpgSymmetricEncrypt(request.data, 0);
response = webpg.plugin.gpgSymmetricEncrypt(request.data, 0, []);
if (request.message_event == "context" || request.message_event == "editor")
webpg.utils.tabs.sendRequest(sender.tab, {
"msg": "insertEncryptedData",
Expand Down
5 changes: 5 additions & 0 deletions extension/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,18 @@ webpg.dialog = {
var post_selection = unescape(webpg.dialog.qs.post_selection) || "";

var iframe_id = window.name;

var signers = (webpg.dialog.qs.signers!=undefined
&& unescape(webpg.dialog.qs.signers)!=null) ?
[unescape(webpg.dialog.qs.signers)] : null;

webpg.utils.sendRequest({"msg": "encrypt",
"data": unescape(webpg.dialog.qs.encrypt_data),
"pre_selection": pre_selection,
"post_selection": post_selection,
"recipients": webpg.dialog.selectedKeys,
"sign": (webpg.dialog.qs.dialog_type == "encryptsign"),
"signers": signers,
"target_id": iframe_id,
"iframe_id": iframe_id});
}
Expand Down
183 changes: 120 additions & 63 deletions extension/gmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ webpg.gmail = {
navDiv - <obj> The navigation div from the gmail interface we will be working with
*/
setup: function(navDiv) {
if (navDiv.find("#webpg-action-menu").length < 1) {
if (navDiv.find(".webpg-action-menu").length < 1) {
// If we are running Mozilla, inject the CSS file
if (webpg.utils.detectedBrowser['vendor'] == "mozilla") {
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
Expand Down Expand Up @@ -208,6 +208,7 @@ webpg.gmail = {
return;
}
webpg.utils.sendRequest({'msg': 'sign',
'signers': webpg.gmail.signers,
'message_event': 'gmail',
'selectionData': {
'selectionText': webpg.utils.linkify(message)
Expand All @@ -219,6 +220,9 @@ webpg.gmail = {
response.result.data
);
webpg.gmail.emulateMouseClick(webpg.gmail.oSendBtn[0]);
} else {
var result = response.result;
webpg.gmail.handleFailure(result);
}
});
break;
Expand All @@ -244,6 +248,7 @@ webpg.gmail = {
webpg.utils.sendRequest({'msg': 'encryptSign',
'data': message,
'recipients': users,
'signers': webpg.gmail.signers,
'message_event': 'gmail'
}, function(response) {
if (!response.result.error && response.result.data) {
Expand Down Expand Up @@ -544,117 +549,169 @@ webpg.gmail = {
this.oSendBtn.hide();

var action_menu = '' +
'<span id="webpg-current-action">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + "skin/images/badges/32x32/webpg.png" + '" width="17" height="17"/>' +
'WebPG' +
'</span>' +
'&nbsp;' +
'<span class="webpg-action-list-icon">' +
'&nbsp;' +
'</span>';

var action_list = '' +
'<ul class="webpg-action-list webpg-gmail-compose-' + webpg.gmail.gmailComposeType + '">' +
'<li class="webpg-action-btn" id="webpg-crypt-btn">' +
'<a href="#">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/48x48/stock_encrypted.png" class="webpg-li-icon"/>' +
_('Encrypt') +
'</a>' +
'</li>' +
'<li class="webpg-action-btn" id="webpg-sign-btn">' +
'<a href="#">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/48x48/stock_signature-ok.png" class="webpg-li-icon"/>' +
_('Sign only') +
'</a>' +
'</li>' +
'<li class="webpg-action-btn" id="webpg-scrypt-btn">' +
'<a href="#">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/48x48/stock_encrypted_signed.png" class="webpg-li-icon"/>' +
_('Sign and Encrypt') +
'</a>' +
'</li>' +
'<li class="webpg-action-btn" id="webpg-symmetric-btn">' +
'<a href="#">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/48x48/stock_encrypted.png" class="webpg-li-icon"/>' +
_('Symmetric Encryption') +
'</a>' +
'</li>' +
'<li class="webpg-action-btn" id="webpg-none-btn">' +
'<a href="#">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/48x48/stock_decrypted-signature-bad.png" class="webpg-li-icon"/>' +
_('Do not use WebPG for this message') +
'</a>' +
'</li>' +
'</ul>';
'<span class="webpg-action-menu">' +
'<span class="webpg-current-action" style="line-height:24px;">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + "skin/images/badges/32x32/webpg.png" + '" width="17" height="17"/>' +
'WebPG' +
'</span>' +
'&nbsp;' +
'<span class="webpg-action-list-icon">' +
'&nbsp;' +
'</span>' +
'</span>';

var action_list = '' +
'<span style="z-index:4;">' +
'<ul class="webpg-action-list webpg-gmail-compose-' + webpg.gmail.gmailComposeType + '">' +
'<li class="webpg-action-btn">' +
'<a class="webpg-toolbar-encrypt">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/20x20/stock_encrypted.png" class="webpg-li-icon"/>' +
_('Encrypt') +
'</a>' +
'</li>' +
'<li class="webpg-action-btn">' +
'<a class="webpg-toolbar-sign" style="display:inline-block;">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/20x20/stock_signature-ok.png" class="webpg-li-icon"/>' +
_('Sign only') +
'</a>' +
'<ul class="webpg-toolbar-sign-callout" style="top:0;' +
'right:4px;width:20px;display:inline-block;' +
'position:absolute;padding:0;">' +
'<li class="webpg-subaction-btn">' +
'<span class="webpg-action-list-icon">' +
'&nbsp;' +
'</span>' +
'</li>' +
'</ul>' +
'<ul class="webpg-subaction-list">' +
webpg.inline.createSecretKeySubmenu('sign', 'sign') +
'</ul>' +
'</li>' +
'<li class="webpg-action-btn">' +
'<a class="webpg-toolbar-cryptsign">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/20x20/stock_encrypted_signed.png" class="webpg-li-icon"/>' +
_('Sign and Encrypt') +
'</a>' +
'<ul class="webpg-toolbar-sign-callout" style="top:0;right:4px;width:20px;display:inline-block;position:absolute;padding:0;">' +
'<li class="webpg-subaction-btn">' +
'<span class="webpg-action-list-icon">' +
'&nbsp;' +
'</span>' +
'</li>' +
'</ul>' +
'<ul class="webpg-subaction-list">' +
webpg.inline.createSecretKeySubmenu('sign', 'cryptsign') +
'</ul>' +
'</li>' +
'<li class="webpg-action-btn">' +
'<a class="webpg-toolbar-symcrypt">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/20x20/stock_encrypted.png" class="webpg-li-icon"/>' +
_('Symmetric Encryption') +
'</a>' +
'</li>' +
'<li class="webpg-action-btn webpg-none-btn">' +
'<a class="webpg-toolbar-btn-none">' +
'<img src="' + webpg.utils.escape(webpg.utils.resourcePath) + 'skin/images/badges/20x20/stock_decrypted-signature-bad.png" class="webpg-li-icon"/>' +
_('Do not use WebPG for this message') +
'</a>' +
'</li>' +
'</ul>' +
'</span>';

if (webpg.gmail.gmailComposeType == "inline") {
esBtn.html(action_menu);
var canvasFrame = webpg.gmail.getCanvasFrame();
var action_list_el = webpg.gmail.getCanvasFrameDocument().createElement("span");
webpg.jq(action_list_el).html(action_list);
if (webpg.gmail.getCanvasFrame().find(".Hp").length < 1) {
webpg.jq(action_list_el).html(action_list);
navDiv.context.ownerDocument.querySelector('.aDh').appendChild(action_list_el);
} else {
webpg.jq(action_list_el).html(action_list);
navDiv.context.ownerDocument.querySelector('div>.nH.nH .aaZ, div>.nH.nH .ip.adB').firstChild.appendChild(action_list_el);
}
webpg.gmail.action_list = webpg.jq(action_list_el).find('ul.webpg-action-list');
webpg.inline.createWebPGActionMenu(action_list_el, esBtn);
} else {
esBtn.html(action_menu + action_list);
webpg.gmail.action_list = esBtn.find('ul.webpg-action-list');
webpg.inline.createWebPGActionMenu(esBtn, esBtn);
}

esBtn.click(function(e) {
var list = webpg.jq(this).closest('.webpg-modified').find('.webpg-action-list');
list[0].style.display = (list[0].style.display == "inline") ? "none" : "inline";
}).bind('mouseleave', function(e) {
if (webpg.gmail.gmailComposeType != "inline") {
var list = webpg.jq(this).closest('.webpg-modified').find('.webpg-action-list');
if (list[0].style.display == "inline")
webpg.jq(this).click();
if (e.target.className != "webpg-subaction-btn"
&& e.target.parentElement.className != "webpg-subaction-btn") {
webpg.gmail.action_list.css({
'display': (webpg.gmail.action_list[0].style.display == 'inline') ? 'none' : 'inline'
});
webpg.gmail.action_list.find('.webpg-subaction-list').hide();
if (webpg.gmail.gmailComposeType == "inline") {
webpg.gmail.action_list.find('ul.webpg-subaction-list').css({'top': 'auto', 'bottom': '0'});
}
}
});

esBtn.closest('.webpg-modified').find(".webpg-action-btn").click(function(e) {
var newIcon = webpg.jq(this).find("img")[0];
var newText = webpg.jq(this).find("a").text();

webpg.gmail.action_list.bind('mouseleave', function(e) {
webpg.jq(this).hide();
});

webpg.gmail.action_list.find('a').click(function(e) {
var newIcon = (this.id.indexOf("0x") > -1) ?
webpg.jq(this).parent().parent().parent().find('a img')[0] :
webpg.jq(this).find("img")[0];
var newText = (this.id.indexOf("0x") > -1) ?
webpg.jq(this).parent().parent().parent().find('a').first().text() :
webpg.jq(this).text();

if (webpg.gmail.gmailComposeType == "inline") {
this.parentNode.style.display = "none";
newText = "WebPG";
esBtn.click();
}
webpg.jq(this).closest('.webpg-modified').find("#webpg-current-action")

webpg.jq(this).closest('.webpg-modified').find(".webpg-current-action")
.html("<img src='" + newIcon.src + "' height='17' " +
"width='17'/>" + webpg.utils.escape(newText));

var action = this.id.split("-")[1];
var action = this.className.split("-")[2];

switch (action) {

case "crypt":
case "encrypt":
webpg.gmail.removeStatusLine();
webpg.gmail.checkRecipients();
webpg.gmail.action = 1;
esBtn.attr('data-tooltip', _("Encrypt"));
break;

case "sign":
webpg.gmail.removeStatusLine();
webpg.gmail.action = 2;
esBtn.attr('data-tooltip', _("Sign Only"));
break;

case "scrypt":
case "cryptsign":
webpg.gmail.removeStatusLine();
webpg.gmail.checkRecipients();
webpg.gmail.action = 3;
esBtn.attr('data-tooltip', _("Sign and Encrypt"));
break;

case "symmetric":
case "symcrypt":
webpg.gmail.removeStatusLine();
webpg.gmail.action = 4;
esBtn.attr('data-tooltip', _("Symmetric Encryption"));
break;

default:
webpg.gmail.removeStatusLine();
webpg.gmail.action = 0;
esBtn.attr('data-tooltip', _("Do not use WebPG for this message"));
}

webpg.gmail.signers = (this.id.search("0x") == 0) ?
[e.currentTarget.id.substr(2)] : null;

if (this.id.search("0x") == 0) {
webpg.jq(this).parent().parent().find('a img').css({'opacity': '0'});
webpg.jq(this).find('img').css({'opacity': '1.0'});
}
});
},
Expand Down
Loading

0 comments on commit 9051c39

Please sign in to comment.