From 9f1790a6019bfeed61e0aabff6f6e7fecff77778 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 19 Feb 2020 01:57:56 -0600 Subject: [PATCH] Added mail message padding support --- src/onionrcommands/daemonlaunch/quotes.py | 2 +- static-data/www/mail/index.html | 4 ++-- static-data/www/mail/loadsettings.js | 3 +++ static-data/www/mail/mail.js | 15 +++++++++++++ static-data/www/mail/sendmail.js | 27 +++++++++++++++++++++-- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/onionrcommands/daemonlaunch/quotes.py b/src/onionrcommands/daemonlaunch/quotes.py index 5cdf547f..50e3f2b3 100644 --- a/src/onionrcommands/daemonlaunch/quotes.py +++ b/src/onionrcommands/daemonlaunch/quotes.py @@ -18,7 +18,7 @@ QUOTES = [ "James Bamford"), ("Freedom of the press is guaranteed only to those who own one", "A. J. Liebling"), - ("We kill people based on metadata", + ("\"Probably better than nothing\"", "") ] shuffle(QUOTES) diff --git a/static-data/www/mail/index.html b/static-data/www/mail/index.html index e154c49e..2d58e42e 100755 --- a/static-data/www/mail/index.html +++ b/static-data/www/mail/index.html @@ -160,9 +160,9 @@
- - +
diff --git a/static-data/www/mail/loadsettings.js b/static-data/www/mail/loadsettings.js index 36189b1a..ef8fa4de 100644 --- a/static-data/www/mail/loadsettings.js +++ b/static-data/www/mail/loadsettings.js @@ -11,4 +11,7 @@ fetch('/config/get/mail', { if (mailSettings.default_forward_secrecy === false){ document.getElementById('forwardSecrecySetting').checked = false } + if (mailSettings.use_padding === false){ + document.getElementById('messagePaddingSetting').checked = false + } }) \ No newline at end of file diff --git a/static-data/www/mail/mail.js b/static-data/www/mail/mail.js index 85f76a0c..32c86a2d 100755 --- a/static-data/www/mail/mail.js +++ b/static-data/www/mail/mail.js @@ -88,6 +88,21 @@ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){ document.getElementById('fromUser').value = sender || 'Anonymous' document.getElementById('fromUser').value = pubkey || '' document.getElementById('subjectView').innerText = subjectLine + + resp = resp.split("") + let zeroCount = 0 + for (x = resp.length - 1; x != 0; x--){ + if (resp[x] == "0"){ + zeroCount += 1 + } + else{ + break + } + } + resp.splice(resp.length - zeroCount, zeroCount) + resp = resp.join("") + + messageDisplay.innerText = resp var sigEl = document.getElementById('sigValid') var sigMsg = 'signature' diff --git a/static-data/www/mail/sendmail.js b/static-data/www/mail/sendmail.js index 3c2b5ca4..1d9db870 100755 --- a/static-data/www/mail/sendmail.js +++ b/static-data/www/mail/sendmail.js @@ -23,12 +23,35 @@ to = document.getElementById('draftID') subject = document.getElementById('draftSubject') friendPicker = document.getElementById('friendSelect') -function sendMail(toData, message, subject){ +function utf8Length(s) { + var size = encodeURIComponent(s).match(/%[89ABab]/g); + return s.length + (size ? size.length : 0); + } - postData = {'message': message, 'to': toData, 'type': 'pm', 'encrypt': true, 'meta': JSON.stringify({'subject': subject})} +function padString(string_data, round_nearest_byte_exponent = 3){ + if (utf8Length(string_data) === 0){ + string_data += '0' + } + let round_size = 10 ** round_nearest_byte_exponent + while (utf8Length(string_data) % round_size > 0){ + string_data += '0' + } + return string_data +} + +function sendMail(toData, message, subject){ + let meta = {'subject': subject} + + if (document.getElementById('messagePaddingSetting').checked){ + message = padString(message) + } + + + postData = {'message': message, 'to': toData, 'type': 'pm', 'encrypt': true, 'meta': JSON.stringify(meta)} postData.forward = document.getElementById('forwardSecrecySetting').checked postData = JSON.stringify(postData) sendForm.style.display = 'none' + fetch('/insertblock', { method: 'POST', body: postData,