# HG changeset patch # User Mads Kiilerich # Date 2019-12-29 15:11:13 # Node ID 3cab6bc45cc39a7a622b2a1e662e233279e9c579 # Parent 01dbd21d206c724952cba54063bc5835981b356f ssh: use fingerprint when deleting public keys Avoid relying on a database index of the full public key string. diff --git a/kallithea/controllers/admin/my_account.py b/kallithea/controllers/admin/my_account.py --- a/kallithea/controllers/admin/my_account.py +++ b/kallithea/controllers/admin/my_account.py @@ -285,9 +285,9 @@ class MyAccountController(BaseController @IfSshEnabled def my_account_ssh_keys_delete(self): - public_key = request.POST.get('del_public_key') + fingerprint = request.POST.get('del_public_key_fingerprint') try: - SshKeyModel().delete(public_key, request.authuser.user_id) + SshKeyModel().delete(fingerprint, request.authuser.user_id) Session().commit() SshKeyModel().write_authorized_keys() h.flash(_("SSH key successfully deleted"), category='success') diff --git a/kallithea/controllers/admin/users.py b/kallithea/controllers/admin/users.py --- a/kallithea/controllers/admin/users.py +++ b/kallithea/controllers/admin/users.py @@ -462,9 +462,9 @@ class UsersController(BaseController): def ssh_keys_delete(self, id): c.user = self._get_user_or_raise_if_default(id) - public_key = request.POST.get('del_public_key') + fingerprint = request.POST.get('del_public_key_fingerprint') try: - SshKeyModel().delete(public_key, c.user.user_id) + SshKeyModel().delete(fingerprint, c.user.user_id) Session().commit() SshKeyModel().write_authorized_keys() h.flash(_("SSH key successfully deleted"), category='success') diff --git a/kallithea/model/ssh_key.py b/kallithea/model/ssh_key.py --- a/kallithea/model/ssh_key.py +++ b/kallithea/model/ssh_key.py @@ -72,13 +72,13 @@ class SshKeyModel(object): return new_ssh_key - def delete(self, public_key, user=None): + def delete(self, fingerprint, user=None): """ - Deletes given public_key, if user is set it also filters the object for - deletion by given user. + Deletes ssh key with given fingerprint. If user is set, it also filters + the object for deletion by given user. Will raise SshKeyModelException on errors """ - ssh_key = UserSshKeys.query().filter(UserSshKeys._public_key == public_key) + ssh_key = UserSshKeys.query().filter(UserSshKeys.fingerprint == fingerprint) if user: user = User.guess_instance(user) @@ -86,7 +86,7 @@ class SshKeyModel(object): ssh_key = ssh_key.scalar() if ssh_key is None: - raise SshKeyModelException(_('SSH key %r not found') % safe_str(public_key)) + raise SshKeyModelException(_('SSH key with fingerprint %r found') % safe_str(fingerprint)) Session().delete(ssh_key) def get_ssh_keys(self, user): diff --git a/kallithea/templates/admin/my_account/my_account_ssh_keys.html b/kallithea/templates/admin/my_account/my_account_ssh_keys.html --- a/kallithea/templates/admin/my_account/my_account_ssh_keys.html +++ b/kallithea/templates/admin/my_account/my_account_ssh_keys.html @@ -23,7 +23,7 @@ ${h.form(url('my_account_ssh_keys_delete'))} - ${h.hidden('del_public_key', ssh_key.public_key)} + ${h.hidden('del_public_key_fingerprint', ssh_key.fingerprint)}