Changeset 46

Show
Ignore:
Timestamp:
07/26/06 13:21:28 (2 years ago)
Author:
jm3
Message:

minor cleanup in the process of debugging decryption
added vim tags file for jumping to functions

Files:

Legend:

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

    r45 r46  
    4242        return "skipped: public key not found"; /* FIXME: localize-ready this */ 
    4343} 
     44 
    4445function get_error_bad_pass_for_signing() { 
    4546        return "clearsign failed: bad passphrase"; /* FIXME: localize-ready this */ 
     
    8889 
    8990function decrypt_message( event, m) { 
    90         log( "text for decryption: \n" + m ); 
     91        log( "decrypt_message(): text for decryption: \n" + m ); 
    9192         
    9293        var d = document.getElementById( "jm3_decrypt" ); 
    9394         
    94         /* FIXME: implement: wtf was this? a loader? a thank you? */ 
    95         //d.parentNode.insertBefore( document.createTextNode( "hi"), d ); 
    96  
    9795        event.preventDefault(); 
    9896} 
     
    107105                p.setAttribute( "size", "50" ); 
    108106                p.setAttribute( "ct", source ); 
    109                 p.setAttribute( "mb", "mb_" + i ); 
     107                p.setAttribute( "mb", "mb_" + 0 ); /* FIXME: "i" should be passed in when looping over messagebodies */ 
    110108        } 
    111109        return p; 
     
    192190                link_button.setAttribute( "href", "#" );  
    193191                link_button.addEventListener("click", function(event) { 
     192                        log( "XXX sign_message(): listener firing" ); 
    194193                        handle_enter(document.getElementById( "passphrase" ), "manual"); 
    195194                }, true); 
     
    251250                                                for( var i = 0; i < errors.length; i++ ) { 
    252251                                                        if( errors[i].textContent.indexOf( get_error_no_pk_found() )) { 
    253                                                                 return bail( "no pk found - sign it instead and signal an error if possible" ); 
     252                                                                return bail( "no pk found - sign it instead and signal an error if possible: " + errors[i].textContent ); 
    254253                                                        } 
    255254                                                } 
     
    475474} 
    476475 
    477 /* --- END FUNCTION DEFS --- */ 
    478  
    479 // search for message bodies containing PGP/GPG-encrypted text and inject decrypt buttons 
    480 // nb. currently this only works for single-message threads 
    481 if( document.getElementById('mb_0')) { 
    482         var i = 0, mb; 
    483         while( mb = document.getElementById( 'mb_' + i)) { 
    484                 // handle decrypting functionality 
    485                 var ct = mb.innerHTML; 
    486  
    487                 if( ct.indexOf( "-----BEGIN PGP MESSAGE-----") != -1) { /* FIXME: let const this */ 
    488                         log( "message body " + i + " contains encrypted PGP content"); 
    489  
    490                         // remove HTML from the message: 
    491                         ct = html_to_text( ct ); 
    492                         /* FIXME: we need to cache this on the passphrase field so that we can grab it later */ 
    493  
    494                         // inject a decrypt button: 
    495                         var dec = document.createElement("button");  
    496                         dec.setAttribute("style","padding: 0pt 1em; width: 16ex;");                      
    497                         dec.setAttribute("type","button"); 
    498                         dec.setAttribute("id","jm3_decrypt"); 
    499                         dec.setAttribute("name","jm3_decrypt"); 
    500                         dec.appendChild( document.createTextNode( "Decrypt" )); 
    501                         dec.addEventListener('click', function(event) { 
    502                                 decrypt_message(event, ct); 
    503                         }, true); 
     476/* 
     477        find message bodies containing PGP/GPG-encrypted text and inject 
     478        decrypt buttons Nb. currently this only works for single-message 
     479        threads 
     480 */ 
     481 
     482function inject_decrypt_or_verify_ui() { 
     483        if( document.getElementById('mb_0')) { 
     484                var i = 0, mb; 
     485                while( mb = document.getElementById( 'mb_' + i)) { 
     486                        // handle decrypting functionality 
     487                        var ct = mb.innerHTML; 
     488 
     489                        if( ct.indexOf( "-----BEGIN PGP MESSAGE-----") != -1) { /* FIXME: let const this */ 
     490                                log( "message body " + i + " contains encrypted PGP content"); 
     491 
     492                                // remove HTML from the message: 
     493                                ct = html_to_text( ct ); 
     494                                GM_log( "ct: " + ct ); 
     495                                /* FIXME: we need to cache this on the passphrase field so that we can grab it later */ 
     496 
     497                                // inject a decrypt button: 
     498                                var dec = document.createElement("button");  
     499                                dec.setAttribute("style", "padding: 0pt 1em; width: 16ex;");                     
     500                                dec.setAttribute("type",  "button"); 
     501                                dec.setAttribute("id",    "jm3_decrypt"); 
     502                                dec.setAttribute("name",  "jm3_decrypt"); 
     503                                dec.appendChild( document.createTextNode( "Decrypt" )); 
     504                                dec.addEventListener('click', function(event) { 
     505                                        log( "XXX decrypt listener firing" ); 
     506                                        decrypt_message(event, ct); 
     507                                }, true); 
     508                                 
     509                                var f = document.createElement("form"); 
     510                                f.setAttribute("style", "padding: 0.5em; background-color: #dddddd; border: 2px solid red; margin-bottom: 1.0em;");                      
     511                                f.setAttribute( "id",   "jm3_status_pane" ); 
     512 
     513                                var p = get_passphrase_field(); 
     514                                p.setAttribute( "mode", "decrypt" );  
     515                                p.addEventListener("keypress", function(event) { 
     516                                        handle_enter(this, event); 
     517                                }, true); 
     518                                 
     519                                f.appendChild( document.createTextNode( "This is a secret message (woo, scary!). To read it, enter your passphrase: ")); 
     520                                f.appendChild( p ); 
     521                                f.appendChild( dec ); 
     522                                 
     523                                mb.parentNode.insertBefore(f, mb); 
     524                                 
     525                        } else if( ct.indexOf( "-----BEGIN PGP SIGNED MESSAGE-----") != -1) { 
     526                                log( "message body " + i + " contains signed PGP content"); 
     527                                ct = html_to_text( ct ); 
     528                                log( "clean message body: " + i + " contains " + ct); 
     529                        }  
     530                        i++; 
     531                } 
     532        }  
     533
     534 
     535function inject_encrypt_sign_ui() { 
     536        var buttons = document.getElementsByTagName('button'); 
     537        for (var i=0; i<buttons.length; i++)    { 
     538 
     539                var injection_point = buttons[i]; 
     540 
     541                /* look for the "Discard" to insertBefore -- inserting before Send does odd things */ 
     542                if (injection_point.getAttribute('id')=='x') { 
     543 
     544                        get_keys( get_crypto_url() + "/get-secret-keys.jm3" ); 
     545 
     546                        var send_signed = document.createElement("button");  
     547 
     548                        send_signed.setAttribute("type",     "button"); 
     549                        send_signed.setAttribute("id",       "jm3_send_signed"); 
     550                        send_signed.setAttribute("name",     "send_signed"); 
     551                        send_signed.setAttribute("style",    "padding: 0pt 1em; width: 16ex;"); 
     552                        send_signed.setAttribute("tabindex", "1"); 
     553 
     554                        send_signed.addEventListener("click", sign_message, true); 
     555                        send_signed.appendChild( document.createTextNode( "Sign" )); 
     556 
     557                        var send_encrypted = document.createElement("button");  
     558 
     559                        send_encrypted.setAttribute("type",     "button"); 
     560                        send_encrypted.setAttribute("id",       "jm3_send_encrypted"); 
     561                        send_encrypted.setAttribute("name",     "send_encrypted"); 
     562                        send_encrypted.setAttribute("style",    "padding: 0pt 1em; width: 16ex;"); 
     563                        send_encrypted.setAttribute("tabindex", "1"); 
     564 
     565                        send_encrypted.addEventListener("click", encrypt_message, true); 
     566                        send_encrypted.appendChild( document.createTextNode( "Encrypt" )); 
     567 
     568                        var p = injection_point.parentNode; 
     569                        p.insertBefore(send_signed, injection_point); 
     570                        p.insertBefore(send_encrypted, injection_point); 
    504571                         
    505                         var f = document.createElement("form"); 
    506                         f.setAttribute("style","padding: 0.5em; background-color: #dddddd; border: 2px solid red; margin-bottom: 1.0em;");                       
    507                         f.setAttribute( "id", "jm3_status_pane" ); 
    508  
    509                         var p = get_passphrase_field(); 
    510                         p.setAttribute( "mode", "decrypt" );  
    511                         p.addEventListener("keypress", function(event) { 
    512                                 handle_enter(this, event); 
    513                         }, true); 
    514                          
    515                         f.appendChild( document.createTextNode( "This is a secret message (woo, scary!). To read it, enter your passphrase: ")); 
    516                         f.appendChild( p ); 
    517                         f.appendChild( dec ); 
    518                          
    519                         mb.parentNode.insertBefore(f, mb); 
    520                          
    521                 } else if( ct.indexOf( "-----BEGIN PGP SIGNED MESSAGE-----") != -1) { 
    522                         log( "message body " + i + " contains signed PGP content"); 
    523                         ct = html_to_text( ct ); 
    524                         log( "clean message body: " + i + " contains " + ct); 
    525                 }  
    526                 i++; 
    527         } 
    528 }  
    529  
    530 var buttons = document.getElementsByTagName('button'); 
    531 for (var i=0; i<buttons.length; i++)    { 
    532         var injection_point = buttons[i]; 
    533  
    534         // look for the "Discard" to insertBefore -- inserting before Send does odd things 
    535         if (injection_point.getAttribute('id')=='x') { 
    536  
    537  
    538                 get_keys( get_crypto_url() + "/get-secret-keys.jm3" ); 
    539  
    540                 var send_signed = document.createElement("button");  
    541  
    542                 send_signed.setAttribute("type","button"); 
    543                 send_signed.setAttribute("id","jm3_send_signed"); 
    544                 send_signed.setAttribute("name","send_signed"); 
    545                 send_signed.setAttribute("style","padding: 0pt 1em; width: 16ex;"); 
    546                 send_signed.setAttribute("tabindex","1"); 
    547  
    548                 send_signed.addEventListener("click", sign_message, true); 
    549                 send_signed.appendChild( document.createTextNode( "Sign" )); 
    550  
    551                 var send_encrypted = document.createElement("button");  
    552  
    553                 send_encrypted.setAttribute("type","button"); 
    554                 send_encrypted.setAttribute("id","jm3_send_encrypted"); 
    555                 send_encrypted.setAttribute("name","send_encrypted"); 
    556                 send_encrypted.setAttribute("style","padding: 0pt 1em; width: 16ex;"); 
    557                 send_encrypted.setAttribute("tabindex","1"); 
    558  
    559                 send_encrypted.addEventListener("click", encrypt_message, true); 
    560                 send_encrypted.appendChild( document.createTextNode( "Encrypt" )); 
    561  
    562                 var p = injection_point.parentNode; 
    563                 p.insertBefore(send_signed, injection_point); 
    564                 p.insertBefore(send_encrypted, injection_point); 
    565                  
    566                 var master = document.createElement("a");  
    567                 master.setAttribute("href", "javascript:alert('hi');"); 
    568                 master.appendChild( document.createTextNode( "Master" )); 
    569                 /* FIXME: need some kind of callback so we can invoke a gmail Send from this button or from an element named "snd" with an event type of keydown: */ 
    570                 //master.setAttribute("onkeydown", "alert( 'foo' ); return top.js._CM_OnSendButtonKeyDown(window,this,event)"); 
    571                 //master.addEventListener("keydown", master_send, true); 
    572  
    573                 /* FIXME: dont inject until we have the above working: */ 
    574                 //p.insertBefore(master, injection_point); 
    575  
    576                 break; 
    577         } 
    578 
     572                        /* FIXME:  
     573                        need some kind of callback so we can invoke a gmail 
     574                        Send from this button or from an element named "snd" 
     575                        with an event type of keydown:  
     576                        */ 
     577 
     578                        break; 
     579                } 
     580        } 
     581
     582 
     583function inject_10kz_ui() { 
     584        inject_decrypt_or_verify_ui(); 
     585        inject_encrypt_sign_ui(); 
     586
     587 
     588inject_10kz_ui(); 
    579589 
    580590/* --- END SCRIPT --- */