Browse Source

validation.py: add support for ECDSA keys

pull/1/head
Hidden Z 10 years ago
parent
commit
38a792c7c0
  1. 5
      pyi2phosts/lib/validation.py

5
pyi2phosts/lib/validation.py

@ -85,7 +85,7 @@ def validate_b64hash(data, check_uniq=True):
if length > 616: if length > 616:
raise ValidationError(_('Specified base64 hash is bigger than 616 bytes')) raise ValidationError(_('Specified base64 hash is bigger than 616 bytes'))
# keys with cert may ends with anything, so check is relaxed # keys with cert may ends with anything, so check is relaxed
if length > 516 and re.match(r'[a-zA-Z0-9\-~]+$', data) == None: if length > 516 and re.match(r'[a-zA-Z0-9\-~=]+$', data) == None:
raise ValidationError(_('Invalid characters in base64 hash')) raise ValidationError(_('Invalid characters in base64 hash'))
# base64-validity test # base64-validity test
if length > 516: if length > 516:
@ -104,6 +104,9 @@ def validate_b64hash(data, check_uniq=True):
# base64-i2p # base64-i2p
if length == 516 and re.match(r'[a-zA-Z0-9\-~]+AA$', data) == None: if length == 516 and re.match(r'[a-zA-Z0-9\-~]+AA$', data) == None:
raise ValidationError(_('Invalid base64 hash')) raise ValidationError(_('Invalid base64 hash'))
# check ECDSA validity
if length == 524 and re.match(r'[a-zA-Z0-9\-~]+AEAAEAAA==$', data) == None:
raise ValidationError(_('Invalid base64 ECDSA hash'))
if check_uniq == True: if check_uniq == True:
# Avoid adding non-unique hashes # Avoid adding non-unique hashes
qs = i2phost.objects.filter(b64hash=data) qs = i2phost.objects.filter(b64hash=data)

Loading…
Cancel
Save