Mercurial > libervia-web
changeset 538:3317e5d0ac1d
browser_side (plugin OTR): put all the text messages into constants
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 07 Sep 2014 22:33:28 +0200 |
parents | cd492c18b366 |
children | 19b8af73e945 |
files | src/browser/sat_browser/plugin_sec_otr.py |
diffstat | 1 files changed, 73 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_sec_otr.py Sun Sep 07 19:28:27 2014 +0200 +++ b/src/browser/sat_browser/plugin_sec_otr.py Sun Sep 07 22:33:28 2014 +0200 @@ -37,14 +37,48 @@ PRIVATE_KEY = "PRIVATE KEY" MAIN_MENU = D_('OTR encryption') DIALOG_EOL = "<br />" -AUTH_INFO_TXT = D_("Authenticating a correspondent helps ensure that the person you are talking to is who he or she claims to be.{eol}{eol}").format(eol=DIALOG_EOL) -AUTH_FINGERPRINT_TXT = D_("<i>To verify the fingerprint, contact your correspondent via some other authenticated channel (i.e. not in this chat), such as the telephone or GPG-signed email. Each of you should tell your fingerprint to the other.</i>{eol}{eol}").format(eol=DIALOG_EOL) -AUTH_QUEST_DEF = D_("<i>To authenticate using a question, pick a question whose answer is known only to you and your correspondent. Enter this question and this answer, then wait for your correspondent to enter the answer too. If the answers don't match, then you may be talking to an imposter.</i>{eol}{eol}").format(eol=DIALOG_EOL) -AUTH_QUEST_ASK = D_("<i>Your correspondent is attempting to determine if he or she is really talking to you, or if it's someone pretending to be you. Your correspondent has asked a question, indicated below. To authenticate to your correspondent, enter the answer and click OK.</i>{eol}{eol}").format(eol=DIALOG_EOL) -AUTH_SECRET_TXT = D_("{eol}{eol}Enter secret answer here: (case sensitive){eol}").format(eol=DIALOG_EOL) -FEEDBACK_NOT_PRIVATE = D_("Your conversation with %s is not encrypted.") -DROP_TXT = D_("You private key is used to encrypt messages for your correspondent, nobody except you must know it, if you are in doubt, you should drop it!{eol}{eol}Are you sure you want to drop your private key?").format(eol=DIALOG_EOL) +AUTH_TRUSTED = D_("Verified") +AUTH_UNTRUSTED = D_("Unverified") +AUTH_OTHER_TITLE = D_("Authentication of {jid}") +AUTH_US_TITLE = D_("Authentication to {jid}") +AUTH_TRUST_NA_TITLE = D_("Authentication requirement") +AUTH_TRUST_NA_TXT = D_("You must start an OTR conversation before authenticating your correspondent.") +AUTH_INFO_TXT = D_("Authenticating a correspondent helps ensure that the person you are talking to is who he or she claims to be.{eol}{eol}") +AUTH_FINGERPRINT_YOURS = D_("Your fingerprint is:{eol}{fingerprint}{eol}{eol}Start an OTR conversation to have your correspondent one.") +AUTH_FINGERPRINT_TXT = D_("To verify the fingerprint, contact your correspondent via some other authenticated channel (i.e. not in this chat), such as the telephone or GPG-signed email. Each of you should tell your fingerprint to the other.{eol}{eol}") +AUTH_FINGERPRINT_VERIFY = D_("Fingerprint for you, {you}:{eol}{your_fp}{eol}{eol}Purported fingerprint for {other}:{eol}{other_fp}{eol}{eol}Did you verify that this is in fact the correct fingerprint for {other}?") +AUTH_QUEST_DEFINE_TXT = D_("To authenticate using a question, pick a question whose answer is known only to you and your correspondent. Enter this question and this answer, then wait for your correspondent to enter the answer too. If the answers don't match, then you may be talking to an imposter.{eol}{eol}") +AUTH_QUEST_DEFINE = D_("Enter question here:{eol}") +AUTH_QUEST_ANSWER_TXT = D_("Your correspondent is attempting to determine if he or she is really talking to you, or if it's someone pretending to be you. Your correspondent has asked a question, indicated below. To authenticate to your correspondent, enter the answer and click OK.{eol}{eol}") +AUTH_QUEST_ANSWER = D_("This is the question asked by your correspondent:{eol}{question}") +AUTH_SECRET_INPUT = D_("{eol}{eol}Enter secret answer here: (case sensitive){eol}") +AUTH_ABORTED_TXT = D_("Authentication aborted.") +AUTH_FAILED_TXT = D_("Authentication failed.") +AUTH_OTHER_OK = D_("Authentication successful.") +AUTH_US_OK = D_("Your correspondent has successfully authenticated you.") +AUTH_OTHER_TOO = D_("You may want to authenticate your correspondent as well by asking your own question.") +AUTH_STATUS = D_("The current conversation is now {state}.") + +FINISHED_CONTEXT_TITLE = D_('Finished OTR conversation with {jid}') +SEND_PLAIN_IN_FINISHED_CONTEXT = D_("Your message was not sent because your correspondent closed the OTR conversation on his/her side. Either close your own side, or refresh the session.") +RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT = D_("WARNING: received unencrypted data in a supposedly encrypted context!") + +QUERY_ENCRYPTED = D_('Attempting to refresh the OTR conversation with {jid}...') +QUERY_NOT_ENCRYPTED = D_('Attempting to start an OTR conversation with {jid}...') +AKE_ENCRYPTED = D_(" conversation with {jid} started. Your client is not logging this conversation.") +AKE_NOT_ENCRYPTED = D_("ERROR: successfully ake'd with {jid} but the conversation is not encrypted!") +END_ENCRYPTED = D_("ERROR: the OTR session ended but the context is still supposedly encrypted!") +END_PLAIN = D_("Your conversation with {jid} is no more or hasn't been encrypted.") +END_FINISHED = D_("{jid} has ended his or her private conversation with you; you should do the same.") + +KEY_TITLE = D_('Private key') +KEY_NA_TITLE = D_("No private key") +KEY_NA_TXT = D_("You don't have any private key yet.") +KEY_DROP_TITLE = D_('Drop your private key') +KEY_DROP_TXT = D_("You private key is used to encrypt messages for your correspondent, nobody except you must know it, if you are in doubt, you should drop it!{eol}{eol}Are you sure you want to drop your private key?") +KEY_DROPPED_TXT = D_("Your private key has been dropped.") + DEFAULT_POLICY_FLAGS = { 'ALLOW_V2': True, @@ -100,8 +134,7 @@ if not encrypted: if self.state == otr.context.STATE_ENCRYPTED: log.warning(u"Received unencrypted message in an encrypted context (from %(jid)s)" % {'jid': self.peer.full()}) - feedback = _(u"WARNING: received unencrypted data in a supposedly encrypted context"), - self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {}) + self.host.newMessageCb(self.peer, RECEIVE_PLAIN_IN_ENCRYPTED_CONTEXT, C.MESS_TYPE_INFO, self.host.whoami, {}) self.host.newMessageCb(self.peer, msg, "chat", self.host.whoami, {}) def sendMessageCb(self, msg, meta=None): @@ -127,47 +160,43 @@ trust = self.getCurrentTrust() if status == otr.context.STATUS_SEND_QUERY: - if msg_state == otr.context.STATE_ENCRYPTED: - feedback = _('Attempting to refresh the private conversation with %s...') - else: - feedback = _('Attempting to start a private conversation with %s...') + feedback = QUERY_ENCRYPTED if msg_state == otr.context.STATE_ENCRYPTED else QUERY_NOT_ENCRYPTED elif status == otr.context.STATUS_AKE_SUCCESS: - trusted_str = _(u"Verified") if trust else _(u"Unverified") - if msg_state == otr.context.STATE_ENCRYPTED: - feedback = trusted_str + (u" conversation with %s started. Your client is not logging this conversation.") - else: - feedback = _("Error: successfully ake'd with %s but the conversation is not private!") + trusted_str = AUTH_TRUSTED if trust else AUTH_UNTRUSTED + feedback = (trusted_str + AKE_ENCRYPTED) if msg_state == otr.context.STATE_ENCRYPTED else AKE_NOT_ENCRYPTED elif status == otr.context.STATUS_END_OTR: if msg_state == otr.context.STATE_PLAINTEXT: - feedback = FEEDBACK_NOT_PRIVATE + feedback = END_PLAIN elif msg_state == otr.context.STATE_ENCRYPTED: - log.error(_("OTR session ended but the context's state is still 'encrypted'!")) + log.error(END_ENCRYPTED) elif msg_state == otr.context.STATE_FINISHED: - feedback = _("%s has ended his/her private conversation with you; you should do the same.") + feedback = END_FINISHED - self.host.newMessageCb(self.peer, feedback % other_jid_s, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)}) + self.host.newMessageCb(self.peer, feedback.format(jid=other_jid_s), C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(msg_state, trust)}) def setCurrentTrust(self, new_trust='', act='asked', type_='trust'): log.debug("setCurrentTrust: trust={trust}, act={act}, type={type}".format(type=type_, trust=new_trust, act=act)) - title = (_("Authentication of {jid}") if act == "asked" else _("Authentication to {jid}")).format(jid=self.peer.full()) + title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer.full()) + old_trust = self.getCurrentTrust() if type_ == 'abort': - msg = _("Authentication aborted.") + msg = AUTH_ABORTED_TXT elif new_trust: if act == "asked": - msg = _("Authentication successful.") + msg = AUTH_OTHER_OK else: - msg = _("Your correspondent has successfully authenticated you. You may want to authenticate your correspondent as well by asking your own question.") + msg = AUTH_US_OK + if not old_trust: + msg += " " + AUTH_OTHER_TOO else: - msg = _("Authentication failed.") + msg = AUTH_FAILED_TXT dialog.InfoDialog(title, msg, AddStyleName="maxWidthLimit").show() if act != "asked": return - old_trust = self.getCurrentTrust() otr.context.Context.setCurrentTrust(self, new_trust) if old_trust != new_trust: - feedback = _("The privacy status of the current conversation is now: {state}").format(state='Private' if new_trust else 'Unverified') + feedback = AUTH_STATUS.format(state=(AUTH_TRUSTED if new_trust else AUTH_UNTRUSTED).lower()) self.host.newMessageCb(self.peer, feedback, C.MESS_TYPE_INFO, self.host.whoami, {'header_info': Context.getInfoText(self.state, new_trust)}) def fingerprintAuthCb(self): @@ -181,17 +210,15 @@ other_key = self.getCurrentKey() if other_key is None: # we have a private key, but not the fingerprint of our correspondent - msg = AUTH_INFO_TXT + ("Your fingerprint is:{eol}{fingerprint}{eol}{eol}Start an OTR conversation to have your correspondent one.").format(fingerprint=priv_key.fingerprint(), eol=DIALOG_EOL) + msg = (AUTH_INFO_TXT + AUTH_FINGERPRINT_YOURS).format(fingerprint=priv_key.fingerprint(), eol=DIALOG_EOL) dialog.InfoDialog(_("Fingerprint"), msg, AddStyleName="maxWidthLimit").show() return def setTrust(confirm): self.setCurrentTrust('fingerprint' if confirm else '') - text = AUTH_INFO_TXT + AUTH_FINGERPRINT_TXT + _("Fingerprint for you, {jid}:{eol}{fingerprint}{eol}{eol}").format(jid=self.host.whoami, fingerprint=priv_key.fingerprint(), eol=DIALOG_EOL) - text += _("Purported fingerprint for {jid}:{eol}{fingerprint}{eol}{eol}").format(jid=self.peer, fingerprint=other_key.fingerprint(), eol=DIALOG_EOL) - text += _("Did you verify that this is in fact the correct fingerprint for {jid}?").format(jid=self.peer) - title = _('Authentication of {jid}').format(jid=self.peer.full()) + text = (AUTH_INFO_TXT + "<i>" + AUTH_FINGERPRINT_TXT + "</i>" + AUTH_FINGERPRINT_VERIFY).format(you=self.host.whoami, your_fp=priv_key.fingerprint(), other=self.peer, other_fp=other_key.fingerprint(), eol=DIALOG_EOL) + title = AUTH_OTHER_TITLE.format(jid=self.peer.full()) dialog.ConfirmDialog(setTrust, text, title, AddStyleName="maxWidthLimit").show() def smpAuthCb(self, type_, data, act=None): @@ -216,23 +243,23 @@ # make us need the dirty self.smpAuthAbort. else: log.error("FIXME: unmanaged ambiguous 'act' value in Context.smpAuthCb!") - title = (_("Authentication of {jid}") if act == "asked" else _("Authentication to {jid}")).format(jid=self.peer.full()) + title = (AUTH_OTHER_TITLE if act == "asked" else AUTH_US_TITLE).format(jid=self.peer.full()) if type_ == 'question': if act == 'asked': def cb(question, answer=None): if question is False or not answer: # dialog cancelled or the answer is empty return self.smpAuthSecret(answer, question) - text = AUTH_INFO_TXT + AUTH_QUEST_DEF + _("Enter question here:{eol}").format(eol=DIALOG_EOL, question=data) - dialog.PromptDialog(cb, [text, AUTH_SECRET_TXT], title=title, AddStyleName="maxWidthLimit").show() + text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_DEFINE_TXT + "</i>" + AUTH_QUEST_DEFINE).format(eol=DIALOG_EOL) + dialog.PromptDialog(cb, [text, AUTH_SECRET_INPUT.format(eol=DIALOG_EOL)], title=title, AddStyleName="maxWidthLimit").show() else: def cb(answer): if not answer: # dialog cancelled or the answer is empty self.smpAuthAbort('answered') return self.smpAuthSecret(answer) - text = AUTH_INFO_TXT + AUTH_QUEST_ASK + _("This is the question asked by your correspondent:{eol}{question}").format(eol=DIALOG_EOL, question=data) - dialog.PromptDialog(cb, text + AUTH_SECRET_TXT, title=title, AddStyleName="maxWidthLimit").show() + text = (AUTH_INFO_TXT + "<i>" + AUTH_QUEST_ANSWER_TXT + "</i>" + AUTH_QUEST_ANSWER).format(eol=DIALOG_EOL, question=data) + dialog.PromptDialog(cb, text + AUTH_SECRET_INPUT.format(eol=DIALOG_EOL), title=title, AddStyleName="maxWidthLimit").show() elif type_ == 'trust': self.setCurrentTrust('smp' if data else '', act) elif type_ == 'abort': @@ -374,8 +401,8 @@ otrctx.sendMessage(msg) self.host.newMessageCb(self.host.whoami, msg, msg_type, jid, extra) else: - feedback = D_("Your message was not sent because your correspondent closed the encrypted conversation on his/her side. Either close your own side, or refresh the session.") - dialog.InfoDialog(_('Finished encrypted session'), feedback, AddStyleName="maxWidthLimit").show() + feedback = SEND_PLAIN_IN_FINISHED_CONTEXT + dialog.InfoDialog(FINISHED_CONTEXT_TITLE.format(jid=to_jid.full()), feedback, AddStyleName="maxWidthLimit").show() else: log.debug(u"sending message unencrypted") self.host.bridge.call('sendMessage', (None, self.host.sendError), to_jid.full(), msg, '', msg_type, extra) @@ -401,7 +428,7 @@ def cb(other_jid): def not_available(): if not finish: - self.host.newMessageCb(other_jid, FEEDBACK_NOT_PRIVATE % other_jid.full(), C.MESS_TYPE_INFO, self.host.whoami, {}) + self.host.newMessageCb(other_jid, END_PLAIN.format(jid=other_jid.full()), C.MESS_TYPE_INFO, self.host.whoami, {}) priv_key = self.context_manager.account.privkey if priv_key is None: @@ -456,7 +483,7 @@ @param profile: %(doc_profile)s """ def not_available(): - dialog.InfoDialog(_("No running session"), _("You must start a private conversation before authenticating your correspondent."), AddStyleName="maxWidthLimit").show() + dialog.InfoDialog(AUTH_TRUST_NA_TITLE, AUTH_TRUST_NA_TXT, AddStyleName="maxWidthLimit").show() priv_key = self.context_manager.account.privkey if priv_key is None: @@ -492,7 +519,7 @@ priv_key = self.context_manager.account.privkey if priv_key is None: # we have no private key yet - dialog.InfoDialog(_("No private key"), _("You don't have any private key yet."), AddStyleName="maxWidthLimit").show() + dialog.InfoDialog(KEY_NA_TITLE, KEY_NA_TXT, AddStyleName="maxWidthLimit").show() return def cb(to_jid): @@ -503,11 +530,9 @@ context.disconnect() self.context_manager.account.privkey = None self.context_manager.account.getPrivkey() # as account.privkey are None, getPrivkey will generate a new key, and save it - dialog.InfoDialog(_('Private key'), _("Your private key has been dropped."), AddStyleName="maxWidthLimit").show() + dialog.InfoDialog(KEY_TITLE, KEY_DROPPED_TXT, AddStyleName="maxWidthLimit").show() - text = _(DROP_TXT) - title = _('Drop your private key') - dialog.ConfirmDialog(dropKey, text, title, AddStyleName="maxWidthLimit").show() + dialog.ConfirmDialog(dropKey, KEY_DROP_TXT.format(eol=DIALOG_EOL), KEY_DROP_TITLE, AddStyleName="maxWidthLimit").show() try: to_jid = menu_data['jid']