Skip to content

Client Side Online Decryption of Text Files Using git instaweb

sebastianha edited this page Dec 9, 2012 · 1 revision

NOTE: This is a dirty hack only. It utilizes git-instaweb to show the sparkleshare git online in a browser and adds decrypting functionality for text files to it. Follow the tutorial on your own risk!

1) You need a encrypted sparkleshare share (here: test-crypto)

2) navigate to the share folder (here: /home/storage/test-crypto/)

3) start git-instaweb by typing:

root@box:/home/storage/test-crypto# git-instaweb -p 12345

4) go to /home/storage/test-crypto/.git/gitweb/ and add a file named "decrypt.js" with the following content:

        if(!decrypted || decrypted == "") {
                alert("Wrong password!");
                return(-1);
        }
 
        decrypted = decrypted.toString(CryptoJS.enc.Utf8);
 
        var splitted = decrypted.split("\n");
 
        var resulting = "";
        for(var i=0; i<splitted.length; i++) {
                resulting += "<div class=\"pre\"><a id=\"" + (i+1) + "\" href=\"#" + (i+1) + "\" class=\"linenr\">" + a(i+1, 4) + "</a> " + splitted[i] + "</div>"
        }
        document.getElementById("page_body").innerHTML = resulting;
 }
 
 function a(b, howmany) {
        b = "" + b;
        var r = ""
        for(var i=b.length; i< howmany; i++)
                r+=" ";
        return(r + b);
 }

5) apply the following patch to /home/storage/test-crypto/.git/gitweb/gitweb.cgi:

  <head>
 +
 +<script src="decrypt.js" type="text/javascript"></script>
 +<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/aes.js"></script>
 +
  <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
  <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
  <meta name="robots" content="index, nofollow"/>
 @@ -4338,8 +4334,7 @@
                       "<div class=\"title\">$hash</div>\n";
         }
         git_print_page_path($file_name, "blob", $hash_base);
 +       print "<div id=\"page_body\" class=\"page_body\">\n";
 +       my $blobcontent;
 -       print "<div class=\"page_body\">\n";
         if ($mimetype =~ m!^image/!) {
                 print qq!<img type="$mimetype"!;
                 if ($file_name) {
 @@ -4352,7 +4347,6 @@
         } else {
                 my $nr;
                 while (my $line = <$fd>) {
 +                       $blobcontent = $blobcontent . $line;
                         chomp $line;
                         $nr++;
                         $line = untabify($line);
 @@ -4362,7 +4356,7 @@
         }
         close $fd
                 or print "Reading blob failed.\n";
 +       printf "</div><button onclick=\"decrypt_blob('%s')\">decrypt</button>", $blobcontent;
 -       print "</div>";
         git_footer_html();
  }

6) You are done. Navigate your browser to http://your-ip:12345 and open the blob view of an encrypted text file and at the bottom there is a decrypt button. Use it to decrypt the text live in your browser.