diff options
author | mathieui <mathieui@mathieui.net> | 2016-08-19 01:04:43 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2016-08-19 01:04:43 +0200 |
commit | 0c21af12b0578a0147f7b686954e7e121f959990 (patch) | |
tree | 1949fecf97018d073395ff39d83caba745691a15 | |
parent | 82d00d495b816c237cbefac3ff2387907a7f8843 (diff) | |
download | poezio-0c21af12b0578a0147f7b686954e7e121f959990.tar.gz poezio-0c21af12b0578a0147f7b686954e7e121f959990.tar.bz2 poezio-0c21af12b0578a0147f7b686954e7e121f959990.tar.xz poezio-0c21af12b0578a0147f7b686954e7e121f959990.zip |
Use the confirmtab for TLS cert validation
And wipe the YesNoInput from the codebase
-rw-r--r-- | poezio/core/handlers.py | 41 | ||||
-rw-r--r-- | poezio/tabs/rostertab.py | 6 | ||||
-rw-r--r-- | poezio/windows/__init__.py | 2 | ||||
-rw-r--r-- | poezio/windows/input_placeholders.py | 40 |
4 files changed, 26 insertions, 63 deletions
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index 98674fdd..ea605b2a 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -1204,30 +1204,39 @@ class HandlerCore: config.set_and_save('certificate', sha2_found_cert) return elif sha2_found_cert == cert: - log.debug('Cert %s OK', sha2_found_cert) return else: - saved_input = self.core.current_tab().input - log.debug('\nWARNING: CERTIFICATE CHANGED old: %s, new: %s\n', cert, sha2_found_cert) - self.core.information('New certificate found (sha-2 hash:' - ' %s)\nPlease validate or abort' % sha2_found_cert, - 'Warning') - def check_input(): - self.core.current_tab().input = saved_input - if input.value: - self.core.information('Setting new certificate: old: %s, new: %s' % (cert, sha2_found_cert), 'Info') + def cb(result): + if result: + self.core.information('New certificate accepted.', 'Info') log.debug('Setting certificate to %s', sha2_found_cert) if not config.silent_set('certificate', sha2_found_cert): - self.core.information('Unable to write in the config file', 'Error') + self.core.information( + 'Unable to write in the config file', + 'Error') else: - self.core.information('You refused to validate the certificate. You are now disconnected', 'Info') + self.core.information('You refused to validate the certificate. You are now disconnected.', 'Info') self.core.disconnect() new_loop.stop() asyncio.set_event_loop(old_loop) - input = windows.YesNoInput(text="WARNING! Server certificate has changed, accept? (y/n)", callback=check_input) - self.core.current_tab().input = input - input.resize(1, self.core.current_tab().width, self.core.current_tab().height-1, 0) - input.refresh() + confirm_tab = tabs.ConfirmTab( + self.core, + 'Certificate check required', + """ +WARNING: CERTIFICATE FOR %s CHANGED + +This can be part of a normal renewal process, but can also mean that \ +an attacker is performing a man-in-the-middle attack on your connection. +When in doubt, check with your administrator using another channel. + +SHA-512 of the old certificate: %s + +SHA-512 of the new certificate: %s +""" % (self.core.xmpp.boundjid.domain, cert, sha2_found_cert), + 'You need to accept or reject the certificate', + cb, + critical=True) + self.core.add_tab(confirm_tab, True) self.core.doupdate() old_loop = asyncio.get_event_loop() new_loop = asyncio.new_event_loop() diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index b9b0c228..f8b3e906 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -1018,8 +1018,6 @@ class RosterInfoTab(Tab): """ '/' is pressed, we enter "input mode" """ - if isinstance(self.input, windows.YesNoInput): - return curses.curs_set(1) self.input = windows.CommandInput("", self.reset_help_message, self.execute_slash_command) self.input.resize(1, self.width, self.height-1, 0) @@ -1195,8 +1193,6 @@ class RosterInfoTab(Tab): Start the search. The input should appear with a short instruction in it. """ - if isinstance(self.input, windows.YesNoInput): - return curses.curs_set(1) self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter) self.input.resize(1, self.width, self.height-1, 0) @@ -1207,8 +1203,6 @@ class RosterInfoTab(Tab): @refresh_wrapper.always def start_search_slow(self): - if isinstance(self.input, windows.YesNoInput): - return curses.curs_set(1) self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter_slow) self.input.resize(1, self.width, self.height-1, 0) diff --git a/poezio/windows/__init__.py b/poezio/windows/__init__.py index 06200a41..4b52d803 100644 --- a/poezio/windows/__init__.py +++ b/poezio/windows/__init__.py @@ -11,7 +11,7 @@ from poezio.windows.info_bar import GlobalInfoBar, VerticalGlobalInfoBar from poezio.windows.info_wins import InfoWin, XMLInfoWin, PrivateInfoWin, MucListInfoWin, \ ConversationInfoWin, DynamicConversationInfoWin, MucInfoWin, \ ConversationStatusMessageWin, BookmarksInfoWin, ConfirmStatusWin -from poezio.windows.input_placeholders import HelpText, YesNoInput +from poezio.windows.input_placeholders import HelpText from poezio.windows.inputs import Input, HistoryInput, MessageInput, CommandInput from poezio.windows.list import ListWin, ColumnHeaderWin from poezio.windows.misc import VerticalSeparator diff --git a/poezio/windows/input_placeholders.py b/poezio/windows/input_placeholders.py index dd7468a7..3ac478fd 100644 --- a/poezio/windows/input_placeholders.py +++ b/poezio/windows/input_placeholders.py @@ -35,43 +35,3 @@ class HelpText(Win): def on_delete(self): return - -class YesNoInput(Win): - """ - A Window just displaying a Yes/No input - Used to ask a confirmation - """ - def __init__(self, text='', callback=None): - Win.__init__(self) - self.key_func = { - 'y' : self.on_yes, - 'n' : self.on_no, - } - self.txt = text - self.value = None - self.callback = callback - - def on_yes(self): - self.value = True - - def on_no(self): - self.value = False - - def refresh(self, txt=None): - log.debug('Refresh: %s', self.__class__.__name__) - if txt: - self.txt = txt - self._win.erase() - self.addstr(0, 0, self.txt[:self.width-1], to_curses_attr(get_theme().COLOR_WARNING_PROMPT)) - self.finish_line(get_theme().COLOR_WARNING_PROMPT) - self._refresh() - - def do_command(self, key, raw=False): - if key.lower() in self.key_func: - self.key_func[key]() - if self.value is not None and self.callback is not None: - return self.callback() - - def on_delete(self): - return - |