Changeset 48

Show
Ignore:
Timestamp:
07/26/06 18:01:31 (2 years ago)
Author:
jm3
Message:

fixed signing!
fixed encryption!
got decryption working - bug ticket:27!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 10kz/scripts/crypto-ui-injector.user.js

    r47 r48  
    11// ==UserScript== 
    2 // @name           Crypto UI Injector 
     2// @name           Ten Thousand Zombies Crypto Injector 
    33// @namespace      http://www.codeswami.com 
    44// @description    Secure Email in your Gmail 
     
    1111if( ! (document.getElementById('snd') || document.getElementById('mb_0'))) 
    1212        return; 
     13 
     14/* LOCALIZATION STRINGS */ 
     15function get_prog_name() {                  return "Ten Thousand Zombies Crypto Injector"; } 
     16function get_error_no_pk_found() {          return "skipped: public key not found"; /* FIXME: localize-ready this */ } 
     17function get_error_bad_pass_for_signing() { return "clearsign failed: bad passphrase"; /* FIXME: localize-ready this */ } 
     18function get_encrypted_message_note() {     return "This is an encrypted message (wooo, scary!). To read it, enter your passphrase: "; } 
     19function get_signed_message_note() {        return "This is a signed message (whoa, cool!). The signature was/was not valid FIXME: "; } 
     20function get_adverlink() {                  return "\n\nWondering what this mysterious gibberish is? Learn more here: \nhttp://codeswami.com/secure-mail-that-doesnt-suck/\n\n"; } 
    1321 
    1422/* --- FUNCTION DEFS --- */ 
     
    3341function get_crypto_url() { 
    3442        return "http://localhost:6667"; 
    35 } 
    36  
    37 function get_prog_name() { 
    38         return "Crypto UI Injector"; 
    39 } 
    40  
    41 function get_error_no_pk_found() { 
    42         return "skipped: public key not found"; /* FIXME: localize-ready this */ 
    43 } 
    44  
    45 function get_error_bad_pass_for_signing() { 
    46         return "clearsign failed: bad passphrase"; /* FIXME: localize-ready this */ 
    47 } 
    48  
    49 function get_adverlink() { 
    50         return "\n\nWondering what this mysterious gibberish is? Learn more here: \nhttp://codeswami.com/secure-mail-that-doesnt-suck/\n\n"; 
    5143} 
    5244 
     
    149141        cached_message = document.getElementById( "cached_message" ); 
    150142        cached_message.innerHTML = pt.value; // whew. this is messy 
    151         log( "cached_message body for later in hidden div: " + cached_message.innerHTML ); /* FIXME: destroy when done */ 
    152143 
    153144        var p = document.getElementById( "passphrase" );  
     
    157148                p.setAttribute( "mode", "sign" );  
    158149                p.setAttribute( "style", "background-color: #ffffff; color: #dd0000; font-weight: bold; width: 350px;" );  
     150                p.setAttribute( "mb", pt.value );  
    159151 
    160152                p.addEventListener("keypress", function(event) { 
    161                         broker_remote_read(this, event); 
     153                        handle_passphase_entry(this, event, p.getAttribute( "mb" )); 
    162154                }, true); 
    163155 
     
    186178                link_button.addEventListener("click", function(event) { 
    187179                        log( "sign_message(): listener firing" ); 
    188                         broker_remote_read( document.getElementById( "passphrase" ), "manual"); 
     180                        handle_passphase_entry( document.getElementById( "passphrase" ), "manual", p.getAttribute( "mb" )); 
    189181                }, true); 
    190182                var instruction = document.createTextNode( "  Sign " ); 
     
    341333} 
    342334 
    343 function broker_remote_read( myfield, e ) { 
     335function handle_passphase_entry( myfield, e, content ) { 
    344336        var mode = myfield.getAttribute( "mode" ) ? myfield.getAttribute( "mode" ) : "decrypt"; 
    345337 
     
    365357                                // HACK: FF javascript not correctly url-encoding pluses in textareas, so we do it ourselves... 
    366358                                var ct = myfield.getAttribute('ct'); 
     359                                ct = (ct && ct != "undefined") ? ct : content; /* HACK: this can come in two different ways */ 
     360 
    367361                                ct = ct.replace(/\+/g, "__PLUS__"); 
    368362                                 
     
    371365                                        var regex=/^.*<div style="direction: ltr;">/m; 
    372366                                        ct = ct.replace(regex,""); 
    373                                 } 
     367                                }   
    374368                                post_data += "&plaintext=" + escape( ct ); 
    375369                                 
     
    403397                                                var t = responseDetails.responseText.replace(regex,"<br>"); 
    404398 
    405                                                 var injection_point = document.getElementById( mb ); 
    406                                                 if( !injection_point || !mb ) { 
     399                                                var injection_point = document.getElementById( "mb" ); 
     400                                                if( !injection_point ) 
     401                                                        injection_point = document.getElementById( "mb_0" ); 
     402                                                if( !injection_point ) { 
    407403                                                        var body = document.getElementById('ta_compose'); 
    408404                                                        body = !body ? document.getElementById('ta_0') : body; /* for drafts... */ 
     
    414410                                                } 
    415411                                                 
    416                                                 injection_point.innerHTML = "<div style='direction:ltr;'>" + t + "</div>"; 
     412                                                if( injection_point ) 
     413                                                        injection_point.innerHTML = "<div style='direction:ltr;'>" + t + "</div>"; 
     414                                                else 
     415                                                        return log( "can't find injection point: 'id: mb'" ); 
    417416                                                 
    418417                                        }, 
     
    476475 
    477476function inject_decrypt_or_verify_ui() { 
    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) { 
    490501                                /* FIXME: we need to cache this on the passphrase field so that we can grab it later */ 
    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        } 
    528534} 
    529535