From 7c4a938c8fd8a4639784bd1a2a577e9328f3eaec Mon Sep 17 00:00:00 2001 From: Tharre Date: Sun, 17 Feb 2019 23:26:57 +0100 Subject: [PATCH] Correctly handle newlines in SSH keys OpenSSH does not like carriage returns in it's key files and will reject the key: > Load key "/home/build/.ssh/id_ed25519": invalid format Fixes #189. --- buildsrht/blueprints/secrets.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/buildsrht/blueprints/secrets.py b/buildsrht/blueprints/secrets.py index 2fab67c..ae08c3a 100644 --- a/buildsrht/blueprints/secrets.py +++ b/buildsrht/blueprints/secrets.py @@ -42,14 +42,16 @@ def secrets_POST(): for f in ["secret", "file-file"]: valid.expect(bool(_secret) ^ bool(secret_file), "Either secret text or file have to be provided", field=f) + else: + _secret = valid.require("secret", friendly_name="Secret") + + if secret_type in (SecretType.plaintext_file, SecretType.ssh_key): if _secret: _secret = _secret.replace('\r\n', '\n') if not _secret.endswith('\n'): _secret += '\n' - else: + elif secret_type == SecretType.plaintext_file: _secret = secret_file - else: - _secret = valid.require("secret", friendly_name="Secret") if isinstance(_secret, str): _secret = _secret.encode() -- 2.38.5