From f3a79838e6646180d696632626d81a60510af5d5 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Sat, 16 Oct 2010 19:03:54 +0000 Subject: [PATCH] web/lib/validation.py: fix base64 validations according to zzz's explanation --- web/lib/validation.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/lib/validation.py b/web/lib/validation.py index c69f6c3..ddefae1 100644 --- a/web/lib/validation.py +++ b/web/lib/validation.py @@ -47,8 +47,11 @@ def validate_b64hash(data, check_uniq=True): # Minimum key length 516 bytes if len(data) < 516: raise forms.ValidationError('Specified base64 hash are less than 516 bytes') + # keys with cert may ends with anything, so check is relaxed + if len(data) > 516 and re.match(r'[a-zA-Z0-9\-~]+$', data) == None: + raise forms.ValidationError('Invalid characters in base64 hash') # base64-i2p - if re.match(r'[a-zA-Z0-9\-~]+AAAA$', data) == None: + if len(data) == 516 and re.match(r'[a-zA-Z0-9\-~]+AA$', data) == None: raise forms.ValidationError('Invalid base64 hash') if check_uniq == True: # Avoid adding non-unique hashes