stricter regex of IPv4 as well as IPv6 IPs in custom bridges

This commit is contained in:
Miguel Jacq 2018-01-22 16:24:26 +11:00
parent 16bd3291e3
commit 9a3bcb9834
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6

View File

@ -734,8 +734,9 @@ class SettingsDialog(QtWidgets.QDialog):
for bridge in bridges: for bridge in bridges:
if bridge != '': if bridge != '':
# Check the syntax of the custom bridge to make sure it looks legitimate # Check the syntax of the custom bridge to make sure it looks legitimate
pattern = re.compile("(obfs4\s)?[0-9.]+:[0-9]+\s[A-Z0-9]+(.+)?$") ipv4_pattern = re.compile("(obfs4\s)?(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]+\s[A-Z0-9]+(.+)?$")
if pattern.match(bridge): ipv6_pattern = re.compile("(obfs4\s)?\[(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\]:[0-9]+\s[A-Z0-9]+(.+)?$")
if ipv4_pattern.match(bridge) or ipv6_pattern.match(bridge):
new_bridges.append(''.join(['Bridge ', bridge, '\n'])) new_bridges.append(''.join(['Bridge ', bridge, '\n']))
bridges_valid = True bridges_valid = True
if bridges_valid: if bridges_valid: