Skip to content

Commit

Permalink
Support simultaneous encryption and signing
Browse files Browse the repository at this point in the history
  • Loading branch information
bogde committed Jul 22, 2013
1 parent 8c31148 commit 705eb77
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions js/rc_openpgpjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,48 @@ if(window.rcmail) {
return true;
}

// Encrypt and sign
if($("#openpgpjs_encrypt").is(":checked") && $("#openpgpjs_sign").is(":checked")) {
console.log('encrypt and sign');
// get the private key
if(this.passphrase === "" && getPrivkeyCount() > 0) {
this.sendmail = true; // Global var to notify set_passphrase
$("#openpgpjs_key_select").dialog("open");
return false;
}

if(!getPrivkeyCount()) {
alert(rcmail.gettext("no_keys", "rc_openpgpjs"));
return false;
}

var passobj = JSON.parse(this.passphrase);
var privkey = getPrivkeyObj(passobj.id);

if(!privkey[0].decryptSecretMPIs(passobj.passphrase)) {
alert(rcmail.gettext("incorrect_pass", "rc_openpgpjs"));
}

var priv_key = openpgp.read_privateKey(getPrivkeyArmored(passobj.id));
// we now have the private key (for signing)

// get the public key
var pubkeys = fetchRecipientPubkeys();
if(pubkeys.length === 0) {
return false;
}
// done public keys

var text = $("textarea#composebody").val();
var encrypted = encrypt(pubkeys, text, 1, priv_key, passobj.passphrase);

if(encrypted) {
$("textarea#composebody").val(encrypted);
this.finished_treating = 1;
return true;
}
}

// Encrypt only
if($("#openpgpjs_encrypt").is(":checked") &&
!$("#openpgpjs_sign").is(":checked")) {
Expand Down

2 comments on commit 705eb77

@niklasfemerstrand
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some constructive criticism:

  • You break the indent beginning on row 303, and the rest is inconsistent
  • You are putting OpenPGP.js specific code into rc_openpgp.js. This is wrong, it should be in rc_openpgpjs.crypto.js for Turn OpenPGP.js into driver niklasfemerstrand/rc_openpgpjs#73
  • You didn't change test/index.htm, so there's no quick way of making sure that this works with the full chain

Please fix these problems before I merge it :-)

@bogde
Copy link
Owner Author

@bogde bogde commented on 705eb77 Jul 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your comments. i'm very new to working on open source projects.
can recommend what editor to use (maybe let me know what you're using) and what the indentation settings should be (if there are any guidelines let me know where i can find it).

i'll try to make the other required changes today.

Please sign in to comment.