From 71db4b333396c8c18504c198d066e29ed8b474d4 Mon Sep 17 00:00:00 2001 From: forest Date: Wed, 12 May 2021 11:48:55 -0500 Subject: [PATCH] allow colons in ssh key comments and adjust ssh key whitespace handling --- capsulflask/console.py | 6 +++--- capsulflask/shell_scripts/create.sh | 4 ++-- capsulflask/spoke_model.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/capsulflask/console.py b/capsulflask/console.py index a6f7283..cff81f0 100644 --- a/capsulflask/console.py +++ b/capsulflask/console.py @@ -320,9 +320,9 @@ def ssh_public_keys(): if not content or len(content.strip()) < 1: errors.append("Content is required") else: - content = content.replace("\r", "").replace("\n", "") - if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$", content): - errors.append("Content must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$\"") + content = content.replace("\r", " ").replace("\n", " ").strip() + if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$", content): + errors.append("Content must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$\"") if get_model().ssh_public_key_name_exists(session["account"], name): errors.append("A key with that name already exists") diff --git a/capsulflask/shell_scripts/create.sh b/capsulflask/shell_scripts/create.sh index 2a7760f..142180f 100755 --- a/capsulflask/shell_scripts/create.sh +++ b/capsulflask/shell_scripts/create.sh @@ -32,8 +32,8 @@ if echo "$memory" | grep -vqE "^[0-9]+$"; then fi echo "$pubkeys" | while IFS= read -r line; do - if echo "$line" | grep -vqE "^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$"; then - echo "pubkey \"$line\" must match "'"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$"' + if echo "$line" | grep -vqE '^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$'; then + echo "pubkey \"$line\" must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$\"" exit 1 fi done diff --git a/capsulflask/spoke_model.py b/capsulflask/spoke_model.py index ae69119..a8ad013 100644 --- a/capsulflask/spoke_model.py +++ b/capsulflask/spoke_model.py @@ -136,8 +136,8 @@ class ShellScriptSpoke(VirtualizationInterface): raise ValueError(f"template_image_file_name \"{template_image_file_name}\" must match \"^[a-zA-Z0-9/_.-]+$\"") for ssh_authorized_key in ssh_authorized_keys: - if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$", ssh_authorized_key): - raise ValueError(f"ssh_authorized_key \"{ssh_authorized_key}\" must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$\"") + if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$", ssh_authorized_key): + raise ValueError(f"ssh_authorized_key \"{ssh_authorized_key}\" must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@:. -]+$\"") if vcpus < 1 or vcpus > 8: raise ValueError(f"vcpus \"{vcpus}\" must match 1 <= vcpus <= 8")