Validate syntax of custom bridges

This commit is contained in:
Miguel Jacq 2018-01-14 20:12:24 +11:00
parent ed8c4c8302
commit bf01fcaa6e
No known key found for this signature in database
GPG Key ID: 5418373DFF79BA19
2 changed files with 14 additions and 4 deletions

View File

@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt5 import QtCore, QtWidgets, QtGui
import sys, platform, datetime
import sys, platform, datetime, re
from onionshare import strings, common
from onionshare.settings import Settings
@ -688,11 +688,20 @@ class SettingsDialog(QtWidgets.QDialog):
# provided from https://bridges.torproject.org
new_bridges = []
bridges = self.tor_bridges_use_custom_textbox.toPlainText().split('\n')
bridges_valid = False
for bridge in bridges:
if bridge != '':
new_bridges.append(''.join(['Bridge ', bridge, '\n']))
new_bridges = ''.join(new_bridges)
settings.set('tor_bridges_use_custom_bridges', new_bridges)
# Check the syntax of the custom bridge to make sure it looks legitimate
pattern = re.compile("[0-9.]+:[0-9]+\s[A-Z0-9]+$")
if pattern.match(bridge):
new_bridges.append(''.join(['Bridge ', bridge, '\n']))
bridges_valid = True
if bridges_valid:
new_bridges = ''.join(new_bridges)
settings.set('tor_bridges_use_custom_bridges', new_bridges)
else:
Alert(strings._('gui_settings_tor_bridges_invalid', True))
settings.set('no_bridges', True)
return settings

View File

@ -95,6 +95,7 @@
"gui_settings_tor_bridges_obfs4_radio_option": "Use obfs4 pluggable transports",
"gui_settings_tor_bridges_custom_radio_option": "Use custom bridges",
"gui_settings_tor_bridges_custom_label": "You can get bridges from <a href=\"https://bridges.torproject.org/bridges\">https://bridges.torproject.org</a>",
"gui_settings_tor_bridges_invalid": "None of the bridges you supplied seem to be valid, so they've been ignored.\nPlease try again with valid bridges.",
"gui_settings_button_save": "Save",
"gui_settings_button_cancel": "Cancel",
"gui_settings_button_help": "Help",