From 257a8502f95f6db30fecc547e1e8e63bb26211c5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Mar 2021 11:40:41 +0000 Subject: [PATCH 1/4] Comment --- notifications_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications_client.py b/notifications_client.py index b27fb0b21..3ad8587e4 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -373,7 +373,7 @@ def _notificationNewDM(session, toHandle: str, def _storeMessage(speakerJson: {}) -> None: - """Stores a message for later reading + """Stores a message in your home directory for later reading """ if not speakerJson.get('published'): return From f10b71a1320c0fecb786c497c07e5e6ee3399c20 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Mar 2021 11:43:32 +0000 Subject: [PATCH 2/4] Indicate unlocked message --- notifications_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notifications_client.py b/notifications_client.py index 3ad8587e4..e25fdd5df 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -549,6 +549,8 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str, if speakerJson.get('content'): if not encryptedMessage: content = speakerJson['content'] + else: + content = '🔓 ' + messageStr # say the speaker's name _sayCommand(nameStr, nameStr, screenreader, From 3b5dba87c3f2dab94e997ea42f9580c3ceff2d19 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Mar 2021 12:04:34 +0000 Subject: [PATCH 3/4] Tidying of encrypted message detection --- content.py | 20 ++++++++------------ notifications_client.py | 2 +- pgp.py | 20 ++------------------ speaker.py | 3 ++- tests.py | 4 ++-- utils.py | 18 ++++++++++++++++++ 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/content.py b/content.py index eb9615af3..cd10d9d73 100644 --- a/content.py +++ b/content.py @@ -16,6 +16,8 @@ from utils import loadJson from utils import fileLastModified from utils import getLinkPrefixes from utils import dangerousMarkup +from utils import isPGPEncrypted +from utils import containsPGPPublicKey from petnames import getPetName @@ -65,8 +67,7 @@ def _removeQuotesWithinQuotes(content: str) -> str: def htmlReplaceEmailQuote(content: str) -> str: """Replaces an email style quote "> Some quote" with html blockquote """ - if '--BEGIN PGP MESSAGE--' in content or \ - '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if isPGPEncrypted(content) or containsPGPPublicKey(content): return content # replace quote paragraph if '

"' in content: @@ -109,8 +110,7 @@ def htmlReplaceQuoteMarks(content: str) -> str: """Replaces quotes with html formatting "hello" becomes hello """ - if '--BEGIN PGP MESSAGE--' in content or \ - '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if isPGPEncrypted(content) or containsPGPPublicKey(content): return content if '"' not in content: if '"' not in content: @@ -203,8 +203,7 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool: def switchWords(baseDir: str, nickname: str, domain: str, content: str) -> str: """Performs word replacements. eg. Trump -> The Orange Menace """ - if '--BEGIN PGP MESSAGE--' in content or \ - '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if isPGPEncrypted(content) or containsPGPPublicKey(content): return content switchWordsFilename = baseDir + '/accounts/' + \ nickname + '@' + domain + '/replacewords.txt' @@ -591,8 +590,7 @@ def _addMention(wordStr: str, httpPrefix: str, following: str, petnames: str, def replaceContentDuplicates(content: str) -> str: """Replaces invalid duplicates within content """ - if '--BEGIN PGP MESSAGE--' in content or \ - '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if isPGPEncrypted(content) or containsPGPPublicKey(content): return content while '<<' in content: content = content.replace('<<', '<') @@ -605,8 +603,7 @@ def replaceContentDuplicates(content: str) -> str: def removeTextFormatting(content: str) -> str: """Removes markup for bold, italics, etc """ - if '--BEGIN PGP MESSAGE--' in content or \ - '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if isPGPEncrypted(content) or containsPGPPublicKey(content): return content if '<' not in content: return content @@ -625,8 +622,7 @@ def removeLongWords(content: str, maxWordLength: int, """Breaks up long words so that on mobile screens this doesn't disrupt the layout """ - if '--BEGIN PGP MESSAGE--' in content or \ - '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if isPGPEncrypted(content) or containsPGPPublicKey(content): return content content = replaceContentDuplicates(content) if ' ' not in content: diff --git a/notifications_client.py b/notifications_client.py index e25fdd5df..20b0381b8 100644 --- a/notifications_client.py +++ b/notifications_client.py @@ -17,6 +17,7 @@ from utils import saveJson from utils import getNicknameFromActor from utils import getDomainFromActor from utils import getFullDomain +from utils import isPGPEncrypted from session import createSession from speaker import getSpeakerFromServer from speaker import getSpeakerPitch @@ -31,7 +32,6 @@ from announce import sendAnnounceViaServer from pgp import pgpDecrypt from pgp import hasLocalPGPkey from pgp import pgpEncryptToActor -from pgp import isPGPEncrypted def _waitForKeypress(timeout: int, debug: bool) -> str: diff --git a/pgp.py b/pgp.py index c5c65209d..5724127a4 100644 --- a/pgp.py +++ b/pgp.py @@ -10,6 +10,8 @@ import os import subprocess from pathlib import Path from person import getActorJson +from utils import containsPGPPublicKey +from utils import isPGPEncrypted def getEmailAddress(actorJson: {}) -> str: @@ -369,24 +371,6 @@ def pgpEncryptToActor(content: str, toHandle: str) -> str: return _pgpEncrypt(content, recipientPubKey) -def isPGPEncrypted(content: str) -> bool: - """Returns true if the given content is PGP encrypted - """ - if '--BEGIN PGP MESSAGE--' in content: - if '--END PGP MESSAGE--' in content: - return True - return False - - -def containsPGPPublicKey(content: str) -> bool: - """Returns true if the given content contains a PGP public key - """ - if '--BEGIN PGP PUBLIC KEY BLOCK--' in content: - if '--END PGP PUBLIC KEY BLOCK--' in content: - return True - return False - - def pgpDecrypt(content: str, fromHandle: str) -> str: """ Encrypt using your default pgp key to the given recipient fromHandle can be a handle or actor url diff --git a/speaker.py b/speaker.py index e28b37466..2d158cc30 100644 --- a/speaker.py +++ b/speaker.py @@ -21,6 +21,7 @@ from utils import removeHtml from utils import loadJson from utils import saveJson from utils import getFullDomain +from utils import isPGPEncrypted from content import htmlReplaceQuoteMarks speakerRemoveChars = ('.\n', '. ', ',', ';', '?', '!') @@ -413,7 +414,7 @@ def _postToSpeakerJson(baseDir: str, httpPrefix: str, content = urllib.parse.unquote_plus(postJsonObject['object']['content']) content = html.unescape(content) content = content.replace('

', '').replace('

', ' ') - if '--BEGIN PGP MESSAGE--' not in content: + if not isPGPEncrypted(content): # replace some emoji before removing html if ' <3' in content: content = content.replace(' <3', ' ' + translate['heart']) diff --git a/tests.py b/tests.py index 00dc92605..a3ba76b63 100644 --- a/tests.py +++ b/tests.py @@ -52,6 +52,8 @@ from utils import getStatusNumber from utils import getFollowersOfPerson from utils import removeHtml from utils import dangerousMarkup +from pgp import extractPGPPublicKey +from utils import containsPGPPublicKey from follow import followerOfPerson from follow import unfollowAccount from follow import unfollowerOfAccount @@ -102,8 +104,6 @@ from mastoapiv1 import getNicknameFromMastoApiV1Id from webapp_post import prepareHtmlPostNickname from webapp_utils import markdownToHtml from speaker import speakerReplaceLinks -from pgp import extractPGPPublicKey -from pgp import containsPGPPublicKey testServerAliceRunning = False testServerBobRunning = False diff --git a/utils.py b/utils.py index 1a977d692..2d09cf0e0 100644 --- a/utils.py +++ b/utils.py @@ -2130,3 +2130,21 @@ def isReply(postJsonObject: {}, actor: str) -> bool: if actor in tag['href']: return True return False + + +def containsPGPPublicKey(content: str) -> bool: + """Returns true if the given content contains a PGP public key + """ + if '--BEGIN PGP PUBLIC KEY BLOCK--' in content: + if '--END PGP PUBLIC KEY BLOCK--' in content: + return True + return False + + +def isPGPEncrypted(content: str) -> bool: + """Returns true if the given content is PGP encrypted + """ + if '--BEGIN PGP MESSAGE--' in content: + if '--END PGP MESSAGE--' in content: + return True + return False From 77818c99ceafab8a5a194eb7c9e8b618f98677c8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Mar 2021 12:17:44 +0000 Subject: [PATCH 4/4] Don't show ciphertext in the web interface --- translations/ar.json | 3 ++- translations/ca.json | 3 ++- translations/cy.json | 3 ++- translations/de.json | 3 ++- translations/en.json | 3 ++- translations/es.json | 3 ++- translations/fr.json | 3 ++- translations/ga.json | 3 ++- translations/hi.json | 3 ++- translations/it.json | 3 ++- translations/ja.json | 3 ++- translations/ku.json | 3 ++- translations/oc.json | 3 ++- translations/pt.json | 3 ++- translations/ru.json | 3 ++- translations/zh.json | 3 ++- webapp_post.py | 24 ++++++++++++++---------- 17 files changed, 46 insertions(+), 26 deletions(-) diff --git a/translations/ar.json b/translations/ar.json index a692a6a57..0f9847479 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -400,5 +400,6 @@ "heart": "قلب", "counselor": "مستشار", "Counselors": "المستشارين", - "shocked": "صدمت" + "shocked": "صدمت", + "Encrypted": "مشفر" } diff --git a/translations/ca.json b/translations/ca.json index 238dd2388..b44f228fe 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -400,5 +400,6 @@ "heart": "cor", "counselor": "conseller", "Counselors": "Consellers", - "shocked": "sorprès" + "shocked": "sorprès", + "Encrypted": "Xifrat" } diff --git a/translations/cy.json b/translations/cy.json index c7f6571b3..0f8362073 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -400,5 +400,6 @@ "heart": "galon", "counselor": "cynghorydd", "Counselors": "Cynghorwyr", - "shocked": "sioc" + "shocked": "sioc", + "Encrypted": "Amgryptio" } diff --git a/translations/de.json b/translations/de.json index 86c95ae49..bf5189e6c 100644 --- a/translations/de.json +++ b/translations/de.json @@ -400,5 +400,6 @@ "heart": "herz", "counselor": "Beraterin", "Counselors": "Berater", - "shocked": "schockiert" + "shocked": "schockiert", + "Encrypted": "Verschlüsselt" } diff --git a/translations/en.json b/translations/en.json index c778ff142..6840c67f2 100644 --- a/translations/en.json +++ b/translations/en.json @@ -400,5 +400,6 @@ "heart": "heart", "counselor": "counselor", "Counselors": "Counselors", - "shocked": "shocked" + "shocked": "shocked", + "Encrypted": "Encrypted" } diff --git a/translations/es.json b/translations/es.json index bf7c27980..901f8b515 100644 --- a/translations/es.json +++ b/translations/es.json @@ -400,5 +400,6 @@ "heart": "corazón", "counselor": "Consejera", "Counselors": "Consejeras", - "shocked": "conmocionada" + "shocked": "conmocionada", + "Encrypted": "Cifrada" } diff --git a/translations/fr.json b/translations/fr.json index 9606d3656..6d25dbd97 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -400,5 +400,6 @@ "heart": "cœur", "counselor": "Conseillère", "Counselors": "Conseillères", - "shocked": "sous le choc" + "shocked": "sous le choc", + "Encrypted": "Crypté" } diff --git a/translations/ga.json b/translations/ga.json index 1d3c2f16b..a997cb359 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -400,5 +400,6 @@ "heart": "chroí", "counselor": "Comhairleoir", "Counselors": "Comhairleoirí", - "shocked": "ionadh" + "shocked": "ionadh", + "Encrypted": "Criptithe" } diff --git a/translations/hi.json b/translations/hi.json index b72bbd022..0bc6813a1 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -400,5 +400,6 @@ "heart": "दिल", "counselor": "काउंसलर", "Counselors": "सलाहकार", - "shocked": "हैरान" + "shocked": "हैरान", + "Encrypted": "को गोपित" } diff --git a/translations/it.json b/translations/it.json index bc58e8605..347d904e7 100644 --- a/translations/it.json +++ b/translations/it.json @@ -400,5 +400,6 @@ "heart": "cuore", "counselor": "Consulente", "Counselors": "Consiglieri", - "shocked": "scioccata" + "shocked": "scioccata", + "Encrypted": "Crittografato" } diff --git a/translations/ja.json b/translations/ja.json index 818558412..ba402b9b3 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -400,5 +400,6 @@ "heart": "ハート", "counselor": "カウンセラー", "Counselors": "カウンセラー", - "shocked": "ショックを受けた" + "shocked": "ショックを受けた", + "Encrypted": "暗号化" } diff --git a/translations/ku.json b/translations/ku.json index d69187b4a..5e74514b1 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -400,5 +400,6 @@ "heart": "dil", "counselor": "Pêşnîyarvan", "Counselors": "Selêwirmendan", - "shocked": "şok kirin" + "shocked": "şok kirin", + "Encrypted": "Encîfre kirin" } diff --git a/translations/oc.json b/translations/oc.json index 6ecbfdf50..f355a9485 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -396,5 +396,6 @@ "heart": "heart", "counselor": "Counselors", "Counselors": "Counselors", - "shocked": "shocked" + "shocked": "shocked", + "Encrypted": "Encrypted" } diff --git a/translations/pt.json b/translations/pt.json index 1ddc7dc65..b7b3206c8 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -400,5 +400,6 @@ "heart": "coração", "counselor": "Conselheira", "Counselors": "Conselheiras", - "shocked": "chocada" + "shocked": "chocada", + "Encrypted": "Criptografada" } diff --git a/translations/ru.json b/translations/ru.json index ae4081d8a..bdf9754f8 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -400,5 +400,6 @@ "heart": "сердце", "counselor": "Советник", "Counselors": "Советники", - "shocked": "потрясенный" + "shocked": "потрясенный", + "Encrypted": "Зашифрованный" } diff --git a/translations/zh.json b/translations/zh.json index a81c63693..7814ba6bd 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -400,5 +400,6 @@ "heart": "心", "counselor": "顾问", "Counselors": "辅导员", - "shocked": "震惊的" + "shocked": "震惊的", + "Encrypted": "加密的" } diff --git a/webapp_post.py b/webapp_post.py index 36aec0653..1cd2099b6 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -21,6 +21,7 @@ from posts import postIsMuted from posts import getPersonBox from posts import downloadAnnounce from posts import populateRepliesJson +from utils import isPGPEncrypted from utils import isDM from utils import rejectPostId from utils import isRecentPost @@ -1570,17 +1571,20 @@ def individualPostAsHtml(allowDownloads: bool, _logPostTiming(enableTimingLog, postStartTime, '16') - if not isPatch: - objectContent = \ - removeLongWords(postJsonObject['object']['content'], 40, []) - objectContent = removeTextFormatting(objectContent) - objectContent = \ - switchWords(baseDir, nickname, domain, objectContent) - objectContent = htmlReplaceEmailQuote(objectContent) - objectContent = htmlReplaceQuoteMarks(objectContent) + if not isPGPEncrypted(postJsonObject['object']['content']): + if not isPatch: + objectContent = \ + removeLongWords(postJsonObject['object']['content'], 40, []) + objectContent = removeTextFormatting(objectContent) + objectContent = \ + switchWords(baseDir, nickname, domain, objectContent) + objectContent = htmlReplaceEmailQuote(objectContent) + objectContent = htmlReplaceQuoteMarks(objectContent) + else: + objectContent = \ + postJsonObject['object']['content'] else: - objectContent = \ - postJsonObject['object']['content'] + objectContent = '🔒 ' + translate['Encrypted'] objectContent = '
' + objectContent + '
'