Craziest… Bookmarklet… Ever.

What Is This?

This is a bookmarklet that will allow you to store private sites a bookmark manager like Google Browser Sync.

What Does That Mean?

Google Browser Sync is a way of sharing browser data, like bookmarks, across all of the computers you use. It's a Firefox browser extension, and it works like a charm. The data is encrypted when transferred, and according to Google, the data is stored in Google's data center in a way that even Google employees can't see it.

Unfortunately, the extension code is (mostly) compiled, which makes it extremely difficult to verify that your browser data is actually stored in a way such that only you can decrypt it. Of course, I like to trust Google (and I want to work there *HINT*), but the fact that I can't view the source code makes me nervous about using Browser Sync on my desktop machine, since I store URLs there that I don't want anyone seeing, such as private torrent tracker sites. Er, I mean, uh, legal torrent, um, sites, er, with Linux distributions and, uh, creative-commons music.

What tinfoil-hat-wearing lunatics like myself need is way of storing bookmarks to super-private urls in a way so that the bookmark stored doesn't give away the actual url.

How Does This Work?

The short version is that, instead of storing the url to a Super-Private Site, you store a javascript bookmarklet. This bookmarklet stores an encrypted version of the URL. It asks you for your decryption key, decrypts the encrypted version of the URL, then loads the address bar with the decrypted URL. The en/decryption algorithm being used in my implemention is the Tiny Encryption Algorithm.

Of course, the real tricky bit is that I actually need a bookmarklet that will GENERATE these bookmarklets for me. That's the bookmarklet I am providing.

Drag this link to your bookmarks:
[Encrypt-Bookmark This Page]

How Do I Use It?

Once you've dragged the above bookmark into your bookmarks, all you have to do is click it whenever you're at a page you want to bookmark in an encrypted way. It will prompt you for your encryption key. Provide one and hit okay. The page will be replaced by a page giving you A NEW BOOKMARKLET, which you can then drag to your bookmarks as well.

When you click THAT bookmarklet, you will be prompted for your decryption key. Provide the same key as before, and your secret site will load.

What Does The Code Look Like?

  1. /*
  2. TEA JavaScript Implementation Copyright Chris Veness:
  3. http://www.movable-type.co.uk/scripts/tea-block.html
  4. */
  5.  
  6. function TEAencrypt(plaintext, password)
  7. {
  8. if (plaintext.length == 0) return('');
  9. var asciitext = escape(plaintext).replace(/%20/g,' ');
  10. var v = strToLongs(asciitext);
  11. if (v.length <= 1) v[1] = 0;
  12. var k = strToLongs(password.slice(0,16));
  13. var n = v.length;
  14.  
  15. var z = v[n-1], y = v[0], delta = 0x9E3779B9;
  16. var mx, e, q = Math.floor(6 + 52/n), sum = 0;
  17.  
  18. while (q-- > 0) {
  19. sum += delta;
  20. e = sum>>>2 & 3;
  21. for (var p = 0; p < n; p++) {
  22. y = v[(p+1)%n];
  23. mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
  24. z = v[p] += mx;
  25. }
  26. }
  27.  
  28. var ciphertext = longsToStr(v);
  29.  
  30. return escCtrlCh(ciphertext);
  31. }
  32.  
  33. function TEAdecrypt(ciphertext, password)
  34. {
  35. if (ciphertext.length == 0) return('');
  36. var v = strToLongs(unescCtrlCh(ciphertext));
  37. var k = strToLongs(password.slice(0,16));
  38. var n = v.length;
  39.  
  40. var z = v[n-1], y = v[0], delta = 0x9E3779B9;
  41. var mx, e, q = Math.floor(6 + 52/n), sum = q*delta;
  42.  
  43. while (sum != 0) {
  44. e = sum>>>2 & 3;
  45. for (var p = n-1; p >= 0; p--) {
  46. z = v[p>0 ? p-1 : n-1];
  47. mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
  48. y = v[p] -= mx;
  49. }
  50. sum -= delta;
  51. }
  52.  
  53. var plaintext = longsToStr(v);
  54.  
  55. plaintext = plaintext.replace(/\0+$/,'');
  56.  
  57. return unescape(plaintext);
  58. }
  59.  
  60. function strToLongs(s) {
  61. var l = new Array(Math.ceil(s.length/4));
  62. for (var i=0; i<l.length; i++) {
  63. l[i] = s.charCodeAt(i*4) + (s.charCodeAt(i*4+1)<<8) +
  64. (s.charCodeAt(i*4+2)<<16) + (s.charCodeAt(i*4+3)<<24);
  65. }
  66. return l;
  67. }
  68.  
  69. function longsToStr(l) {
  70. var a = new Array(l.length);
  71. for (var i=0; i<l.length; i++) {
  72. a[i] = String.fromCharCode(l[i] & 0xFF, l[i]>>>8 & 0xFF,
  73. l[i]>>>16 & 0xFF, l[i]>>>24 & 0xFF);
  74. }
  75. return a.join('');
  76. }
  77.  
  78. function escCtrlCh(str) {
  79. return str.replace(/[\0\t\n\v\f\r\xa0'"!]/g, function(c) {
  80. return '!' + c.charCodeAt(0) + '!';
  81. });
  82. }
  83.  
  84. function unescCtrlCh(str) {
  85. return str.replace(/!\d\d?\d?!/g, function(c) {
  86. return String.fromCharCode(c.slice(1,-1));
  87. });
  88. }
  89.  
  90. input=window.location;
  91. key=prompt("Pick an encryption key (you must type this every time you load the bookmark)");
  92. sitename=window.document.title;
  93.  
  94. encrypted=TEAencrypt(input,key);
  95. the_code=TEAencrypt.toSource() + TEAdecrypt.toSource() + strToLongs.toSource() +
  96. longsToStr.toSource()+ escCtrlCh.toSource() + unescCtrlCh.toSource();
  97.  
  98. the_code=the_code.replace(/\"/g,"'");
  99.  
  100. document.write("Bookmark this link:<br/>[<a href=\"javascript:"+ the_code +
  101. "; key=prompt('What is your decryption key?'); decrypted=TEAdecrypt('"+
  102. encrypted+"', key); window.location=decrypted;\">"+sitename+"</a>]");

This was more of a pain in the ass to write than it looks, trust me. The fact that no syntax highlighter (including the one above) can comprehend the code well enough to even highlight it should illustrate why.

This Is Stupid. What Kind Of Crazy Person Is This Paranoid?

Me. I love the new trend toward social sharing on the internet, but some of the privacy issues make my neckhair stand on end. I love the convenience of things like del.icio.us and Google Browser Sync, but the fact that I'm storing stuff somewhere other than my own machine makes me nervous. It's an adjustment I'm still making, and until I'm fully adjusted I need to create crap like this to help me relax.

This bookmarklet is for everyone out there in the same boat.

Unleash This Post Upon Others:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg
  • Fark
  • YahooMyWeb
  • NewsVine
  • Ma.gnolia
  • blogmarks
  • co.mments
  • connotea
  • De.lirio.us
  • Furl
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank

One Comment

  1. Matt:

    This is pretty cool. Hang on there dude, you are not alone with your privacy concerns issues.
    BTW, try Kate, the KDE Advanced Text Editor. Highlights your code just fine.

Leave a comment