| | 13 | |
|---|
| | 14 | /* LOCALIZATION STRINGS */ |
|---|
| | 15 | function get_prog_name() { return "Ten Thousand Zombies Crypto Injector"; } |
|---|
| | 16 | function get_error_no_pk_found() { return "skipped: public key not found"; /* FIXME: localize-ready this */ } |
|---|
| | 17 | function get_error_bad_pass_for_signing() { return "clearsign failed: bad passphrase"; /* FIXME: localize-ready this */ } |
|---|
| | 18 | function get_encrypted_message_note() { return "This is an encrypted message (wooo, scary!). To read it, enter your passphrase: "; } |
|---|
| | 19 | function get_signed_message_note() { return "This is a signed message (whoa, cool!). The signature was/was not valid FIXME: "; } |
|---|
| | 20 | function get_adverlink() { return "\n\nWondering what this mysterious gibberish is? Learn more here: \nhttp://codeswami.com/secure-mail-that-doesnt-suck/\n\n"; } |
|---|
| 478 | | if( document.getElementById('mb_0')) { |
|---|
| 479 | | var i = 0, mb; |
|---|
| 480 | | while( mb = document.getElementById( 'mb_' + i)) { |
|---|
| 481 | | // handle decrypting functionality |
|---|
| 482 | | var ct = mb.innerHTML; |
|---|
| 483 | | |
|---|
| 484 | | if( ct.indexOf( "-----BEGIN PGP MESSAGE-----") != -1) { /* FIXME: let const this */ |
|---|
| 485 | | log( "message body " + i + " contains encrypted PGP content"); |
|---|
| 486 | | |
|---|
| 487 | | // remove HTML from the message: |
|---|
| 488 | | ct = html_to_text( ct ); |
|---|
| 489 | | GM_log( "ct: " + ct ); |
|---|
| | 477 | if( ! document.getElementById('mb_0')) |
|---|
| | 478 | return; |
|---|
| | 479 | |
|---|
| | 480 | var i = 0, mb; |
|---|
| | 481 | while( mb = document.getElementById( 'mb_' + i)) { |
|---|
| | 482 | var ct = mb.innerHTML; |
|---|
| | 483 | var f = document.createElement("form"); |
|---|
| | 484 | f.setAttribute("style", "padding: 0.5em; background-color: #dddddd; border: 2px solid red; width: 95%; margin-bottom: 1.0em;"); |
|---|
| | 485 | f.setAttribute( "id", "jm3_status_pane" ); |
|---|
| | 486 | |
|---|
| | 487 | /* inject decrypt UI */ |
|---|
| | 488 | if( ct.indexOf( "-----BEGIN PGP MESSAGE-----") != -1) { /* FIXME: let const this */ |
|---|
| | 489 | log( "message body " + i + " contains encrypted PGP content"); |
|---|
| | 490 | |
|---|
| | 491 | /* remove HTML from the message: */ |
|---|
| | 492 | ct = html_to_text( ct ); |
|---|
| | 493 | |
|---|
| | 494 | var dec = document.createElement("button"); |
|---|
| | 495 | dec.setAttribute("style", "padding: 0pt 1em; width: 16ex;"); |
|---|
| | 496 | dec.setAttribute("type", "button"); |
|---|
| | 497 | dec.setAttribute("id", "jm3_decrypt"); |
|---|
| | 498 | dec.setAttribute("name", "jm3_decrypt"); |
|---|
| | 499 | dec.appendChild( document.createTextNode( "Decrypt" )); |
|---|
| | 500 | dec.addEventListener('click', function(event) { |
|---|
| 491 | | |
|---|
| 492 | | // inject a decrypt button: |
|---|
| 493 | | var dec = document.createElement("button"); |
|---|
| 494 | | dec.setAttribute("style", "padding: 0pt 1em; width: 16ex;"); |
|---|
| 495 | | dec.setAttribute("type", "button"); |
|---|
| 496 | | dec.setAttribute("id", "jm3_decrypt"); |
|---|
| 497 | | dec.setAttribute("name", "jm3_decrypt"); |
|---|
| 498 | | dec.appendChild( document.createTextNode( "Decrypt" )); |
|---|
| 499 | | dec.addEventListener('click', function(event) { |
|---|
| 500 | | log( "decrypt listener firing" ); |
|---|
| 501 | | decrypt_message(event, ct); |
|---|
| 502 | | }, true); |
|---|
| 503 | | |
|---|
| 504 | | var f = document.createElement("form"); |
|---|
| 505 | | f.setAttribute("style", "padding: 0.5em; background-color: #dddddd; border: 2px solid red; width: 95%; margin-bottom: 1.0em;"); |
|---|
| 506 | | f.setAttribute( "id", "jm3_status_pane" ); |
|---|
| 507 | | |
|---|
| 508 | | var p = get_passphrase_field(); |
|---|
| 509 | | p.setAttribute( "mode", "decrypt" ); |
|---|
| 510 | | p.addEventListener("keypress", function(event) { |
|---|
| 511 | | broker_remote_read(this, event); |
|---|
| 512 | | }, true); |
|---|
| 513 | | |
|---|
| 514 | | f.appendChild( document.createTextNode( "This is an encrypted message (wooo, scary!). To read it, enter your passphrase: ")); |
|---|
| 515 | | f.appendChild( p ); |
|---|
| 516 | | f.appendChild( dec ); |
|---|
| 517 | | |
|---|
| 518 | | mb.parentNode.insertBefore(f, mb); |
|---|
| 519 | | |
|---|
| 520 | | } else if( ct.indexOf( "-----BEGIN PGP SIGNED MESSAGE-----") != -1) { |
|---|
| 521 | | log( "message body " + i + " contains signed PGP content"); |
|---|
| 522 | | ct = html_to_text( ct ); |
|---|
| 523 | | log( "clean message body: " + i + " contains " + ct); |
|---|
| 524 | | } |
|---|
| 525 | | i++; |
|---|
| 526 | | } |
|---|
| 527 | | } |
|---|
| | 502 | log( "decrypt listener firing with ct: " + ct ); |
|---|
| | 503 | decrypt_message(event, ct); |
|---|
| | 504 | }, true); |
|---|
| | 505 | |
|---|
| | 506 | var pass = get_passphrase_field(); |
|---|
| | 507 | pass.setAttribute( "mode", "decrypt" ); |
|---|
| | 508 | pass.setAttribute( "mb", ct ); |
|---|
| | 509 | pass.addEventListener("keypress", function(event) { |
|---|
| | 510 | /* called whenever someone types in the password field */ |
|---|
| | 511 | handle_passphase_entry(this, event, this.getAttribute( "mb" )); |
|---|
| | 512 | }, true); |
|---|
| | 513 | |
|---|
| | 514 | f.appendChild( document.createTextNode( get_encrypted_message_note())); |
|---|
| | 515 | |
|---|
| | 516 | f.appendChild( pass ); |
|---|
| | 517 | f.appendChild( dec ); |
|---|
| | 518 | |
|---|
| | 519 | mb.parentNode.insertBefore(f, mb); |
|---|
| | 520 | |
|---|
| | 521 | } else if( ct.indexOf( "-----BEGIN PGP SIGNED MESSAGE-----") != -1) { |
|---|
| | 522 | |
|---|
| | 523 | /* inject verify UI */ |
|---|
| | 524 | |
|---|
| | 525 | mb.parentNode.insertBefore(f, mb); |
|---|
| | 526 | f.appendChild( document.createTextNode( get_signed_message_note())); |
|---|
| | 527 | |
|---|
| | 528 | log( "message body " + i + " contains signed PGP content"); |
|---|
| | 529 | ct = html_to_text( ct ); |
|---|
| | 530 | log( "clean message body: " + i + " contains " + ct); |
|---|
| | 531 | } |
|---|
| | 532 | i++; |
|---|
| | 533 | } |
|---|