[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Check that a networkstatus nickname matches tor-spec.
commit 1c96f4bbf504af86a4254078f0c0cbf01b7124d5
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Sat Nov 16 00:34:14 2013 +0000
Check that a networkstatus nickname matches tor-spec.
---
lib/bridgedb/parse/networkstatus.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/lib/bridgedb/parse/networkstatus.py b/lib/bridgedb/parse/networkstatus.py
index 9b1bb01..6e2c0d6 100644
--- a/lib/bridgedb/parse/networkstatus.py
+++ b/lib/bridgedb/parse/networkstatus.py
@@ -41,13 +41,32 @@ class InvalidNetworkstatusRouterIdentity(ValueError):
class InvalidNetworkstatusDescriptorDigest(ValueError):
"""Descriptor digest of a networkstatus document 'r'-line is invalid."""
+class InvalidRouterNickname(ValueError):
+ """Router nickname doesn't follow tor-spec."""
+
+
+ALPHANUMERIC = string.letters + string.digits
+
def isValidRouterNickname(nickname):
"""Determine if a router's given nickname meets the specification.
:param string nickname: An OR's nickname.
"""
-
+ try:
+ if not (1 <= len(nickname) <= 19):
+ raise InvalidRouterNickname(
+ "Nicknames must be between 1 and 19 characters: %r" % nickname)
+ for letter in nickname:
+ if not letter in ALPHANUMERIC:
+ raise InvalidRouterNickname(
+ "Nicknames must only use [A-Za-z0-9]: %r" % nickname)
+ except Exception as error:
+ logging.exception(error)
+ else:
+ return True
+
+ raise InvalidRouterNickname
def parseRLine(line):
"""Parse an 'r'-line from a networkstatus document.
@@ -90,6 +109,8 @@ def parseRLine(line):
try:
nickname, ID = fields[:2]
+ isValidRouterNickname(nickname)
+
if ID.endswith('='):
raise InvalidNetworkstatusRouterIdentity(
"Skipping networkstatus parsing for router with nickname %r:"\
@@ -109,6 +130,9 @@ def parseRLine(line):
except IndexError as error:
logging.error(error.message)
+ except InvalidRouterNickname as error:
+ logging.error(error.message)
+ nickname = None
except InvalidNetworkstatusRouterIdentity as error:
logging.error(error.message)
ID = None
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits