1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-22 04:24:15 +00:00

validation.py: add support for ECDSA keys

This commit is contained in:
Hidden Z 2014-12-22 19:03:35 +00:00
parent 1fbcdeb4bd
commit 38a792c7c0

View File

@ -85,7 +85,7 @@ def validate_b64hash(data, check_uniq=True):
if length > 616:
raise ValidationError(_('Specified base64 hash is bigger than 616 bytes'))
# 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'))
# base64-validity test
if length > 516:
@ -104,6 +104,9 @@ def validate_b64hash(data, check_uniq=True):
# base64-i2p
if length == 516 and re.match(r'[a-zA-Z0-9\-~]+AA$', data) == None:
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:
# Avoid adding non-unique hashes
qs = i2phost.objects.filter(b64hash=data)