Skip to content

Commit 0f9f429

Browse files
committed
Validate crypto key lengths independently for each cauth version
Since different versions have different requirements on crypto key length, we should also check it individually and not just assume the user did it right.
1 parent 23f1c69 commit 0f9f429

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pgweb/account/admin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ def clean_cryptkey(self):
3434
def clean(self):
3535
d = super().clean()
3636

37+
if 'cryptkey' in self.cleaned_data:
38+
key = base64.b64decode(self.cleaned_data['cryptkey'])
39+
if self.cleaned_data['version'] == 2:
40+
keylen = 32
41+
elif self.cleaned_data['version'] == 3:
42+
keylen = 64
43+
elif self.cleaned_data['version'] == 4:
44+
keylen = 32
45+
else:
46+
self.add_error('version', 'Unknown version')
47+
keylen = 0
48+
if len(key) != keylen:
49+
self.add_error('cryptkey', 'For version {}, crypto keys muyst be {} bytes'.format(self.cleaned_data['version'], keylen))
50+
3751
if d.get('push_changes', False) and not d.get('apiurl', ''):
3852
self.add_error('push_changes', 'API url must be specified to enable push changes!')
3953

0 commit comments

Comments
 (0)