From 435e2dae0e9204afd7288c14748e88f680276969 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 11 Nov 2013 00:21:00 -0800 Subject: display encrypted text inline --- include/bbcode.php | 7 +++++-- js/crypto.js | 18 ++++++++++++++++-- version.inc | 2 +- view/tpl/jot-header.tpl | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index de71eb4e3..271cace73 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -121,7 +121,9 @@ function bb_parse_crypt($match) { if ($matches[1] != "") $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - $Text = '
' . t('Encrypted content') . '
'; + $x = random_string(); + + $Text = '
' . t('Encrypted content') . '

'; return $Text; @@ -496,7 +498,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { } if (strpos($Text,'[/crypt]') !== false) { - $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); + $x = random_string(); + $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } // Try to Oembed diff --git a/js/crypto.js b/js/crypto.js index bed1525cd..6970229ce 100644 --- a/js/crypto.js +++ b/js/crypto.js @@ -33,14 +33,23 @@ function red_encrypt(alg, elem,text) { var text = $(elem).val(); + // key and hint need to be localised + var enc_key = prompt('key'); + // If you don't provide a key you get rot13, which doesn't need a key + // but consequently isn't secure. + if(! enc_key) alg = 'rot13'; if((alg == 'rot13') || (alg == 'triple-rot13')) newdiv = "[crypt alg='rot13']" + str_rot13(text) + '[/crypt]'; else if(alg == 'aes256') { + + // This is the prompt we're going to use when the receiver tries to open it. + // Maybe "Grandma's maiden name" or "our secret place" or something. + var enc_hint = prompt('hint'); enc_text = CryptoJS.AES.encrypt(text,enc_key); @@ -66,7 +75,7 @@ function red_encrypt(alg, elem,text) { // } } -function red_decrypt(alg,hint,text) { +function red_decrypt(alg,hint,text,elem) { var enc_text = ''; @@ -78,8 +87,13 @@ function red_decrypt(alg,hint,text) { enc_text = CryptoJS.AES.decrypt(text,enc_key); } - alert(enc_text.toString(CryptoJS.enc.Utf8)); + // Not sure whether to drop this back in the conversation display. + // It probably needs a lightbox or popup window because any conversation + // updates could + // wipe out the text and make you re-enter the key if it was in the + // conversation. For now we do that so you can read it. + $(elem).html(b2h(enc_text.toString(CryptoJS.enc.Utf8))); } diff --git a/version.inc b/version.inc index ee9cd8d7a..e352254ae 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2013-11-10.493 +2013-11-11.494 diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index 05928bc32..4457a6d52 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -361,6 +361,42 @@ function enableOnUser(){ }; + function b2h(s) { + var y = s; + function rep(re, str) { + y = y.replace(re,str); + }; + + rep(/\n/gi,"
"); + rep(/\[b\]/gi,""); + rep(/\[\/b\]/gi,""); + rep(/\[i\]/gi,""); + rep(/\[\/i\]/gi,""); + rep(/\[u\]/gi,""); + rep(/\[\/u\]/gi,""); + rep(/\[hr\]/gi,"
"); + rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2"); + rep(/\[url\](.*?)\[\/url\]/gi,"$1"); + rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,""); + rep(/\[img\](.*?)\[\/img\]/gi,""); + + rep(/\[list\](.*?)\[\/list\]/gi, ''); + rep(/\[list=\](.*?)\[\/list\]/gi, ''); + rep(/\[list=1\](.*?)\[\/list\]/gi, ''); + rep(/\[list=i\](.*?)\[\/list\]/gi,''); + rep(/\[list=I\](.*?)\[\/list\]/gi, ''); + rep(/\[list=a\](.*?)\[\/list\]/gi, ''); + rep(/\[list=A\](.*?)\[\/list\]/gi, ''); + rep(/\[li\](.*?)\[\/li\]/gi, '
  • $1
  • '); + rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); + rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"$2"); + rep(/\[code\](.*?)\[\/code\]/gi,"$1"); + rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"
    $1
    "); + + return y; + }; + + {{$geotag}} -- cgit v1.2.3