mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-20 21:39:44 +00:00
Merge pull request 'feat(ssh): Add support for ecdsa keys' (#64) from ecdsa-keys into master
Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api/pulls/64 Reviewed-by: NaiJi ✨ <naiji@noreply.git.selfprivacy.org>
This commit is contained in:
commit
2a03d3962f
3 changed files with 5 additions and 16 deletions
|
@ -49,19 +49,6 @@ def set_ssh_settings(
|
||||||
data["ssh"]["passwordAuthentication"] = password_authentication
|
data["ssh"]["passwordAuthentication"] = password_authentication
|
||||||
|
|
||||||
|
|
||||||
def add_root_ssh_key(public_key: str):
|
|
||||||
with WriteUserData() as data:
|
|
||||||
if "ssh" not in data:
|
|
||||||
data["ssh"] = {}
|
|
||||||
if "rootKeys" not in data["ssh"]:
|
|
||||||
data["ssh"]["rootKeys"] = []
|
|
||||||
# Return 409 if key already in array
|
|
||||||
for key in data["ssh"]["rootKeys"]:
|
|
||||||
if key == public_key:
|
|
||||||
raise KeyAlreadyExists()
|
|
||||||
data["ssh"]["rootKeys"].append(public_key)
|
|
||||||
|
|
||||||
|
|
||||||
class KeyAlreadyExists(Exception):
|
class KeyAlreadyExists(Exception):
|
||||||
"""Key already exists"""
|
"""Key already exists"""
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ class UsersMutations:
|
||||||
except InvalidPublicKey:
|
except InvalidPublicKey:
|
||||||
return UserMutationReturn(
|
return UserMutationReturn(
|
||||||
success=False,
|
success=False,
|
||||||
message="Invalid key type. Only ssh-ed25519 and ssh-rsa are supported",
|
message="Invalid key type. Only ssh-ed25519, ssh-rsa and ecdsa are supported",
|
||||||
code=400,
|
code=400,
|
||||||
)
|
)
|
||||||
except UserNotFound:
|
except UserNotFound:
|
||||||
|
|
|
@ -88,10 +88,12 @@ class ReadUserData(object):
|
||||||
|
|
||||||
|
|
||||||
def validate_ssh_public_key(key):
|
def validate_ssh_public_key(key):
|
||||||
"""Validate SSH public key. It may be ssh-ed25519 or ssh-rsa."""
|
"""Validate SSH public key.
|
||||||
|
It may be ssh-ed25519, ssh-rsa or ecdsa-sha2-nistp256."""
|
||||||
if not key.startswith("ssh-ed25519"):
|
if not key.startswith("ssh-ed25519"):
|
||||||
if not key.startswith("ssh-rsa"):
|
if not key.startswith("ssh-rsa"):
|
||||||
return False
|
if not key.startswith("ecdsa-sha2-nistp256"):
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue