From 2a1b51e39c5aa4b9e5ea925881d01af766f73fcc Mon Sep 17 00:00:00 2001 From: Magnus Lindvall Date: Wed, 31 May 2017 16:40:05 +0200 Subject: [PATCH 1/5] Delete public key tmp file after calculating fingerprint Signed-off-by: Magnus Lindvall --- models/ssh_key.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/ssh_key.go b/models/ssh_key.go index fa33cd4c15310..c221887d81059 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -373,6 +373,7 @@ func checkKeyFingerprint(e Engine, fingerprint string) error { func calcFingerprint(publicKeyContent string) (string, error) { // Calculate fingerprint. tmpPath, err := writeTmpKeyFile(publicKeyContent) + defer os.Remove(tmpPath) if err != nil { return "", err } From 0d0f6e4673adb37b97acc7e288d658504f86de77 Mon Sep 17 00:00:00 2001 From: Magnus Lindvall Date: Mon, 5 Jun 2017 14:16:42 +0200 Subject: [PATCH 2/5] Move line Signed-off-by: Magnus Lindvall --- models/ssh_key.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/ssh_key.go b/models/ssh_key.go index c221887d81059..25b3e53b90bb1 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -373,7 +373,6 @@ func checkKeyFingerprint(e Engine, fingerprint string) error { func calcFingerprint(publicKeyContent string) (string, error) { // Calculate fingerprint. tmpPath, err := writeTmpKeyFile(publicKeyContent) - defer os.Remove(tmpPath) if err != nil { return "", err } @@ -383,6 +382,7 @@ func calcFingerprint(publicKeyContent string) (string, error) { } else if len(stdout) < 2 { return "", errors.New("not enough output for calculating fingerprint: " + stdout) } + defer os.Remove(tmpPath) return strings.Split(stdout, " ")[1], nil } From 0cecf3ed2991333483ca55d2e772be7e4f2ffd3c Mon Sep 17 00:00:00 2001 From: Magnus Lindvall Date: Mon, 5 Jun 2017 14:23:15 +0200 Subject: [PATCH 3/5] Remove defer statement Signed-off-by: Magnus Lindvall --- models/ssh_key.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/ssh_key.go b/models/ssh_key.go index 25b3e53b90bb1..11e26a28209cf 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -382,7 +382,7 @@ func calcFingerprint(publicKeyContent string) (string, error) { } else if len(stdout) < 2 { return "", errors.New("not enough output for calculating fingerprint: " + stdout) } - defer os.Remove(tmpPath) + os.Remove(tmpPath) return strings.Split(stdout, " ")[1], nil } From f84bc0637c0bd3e1c5e3f8f1b44b516dd1442811 Mon Sep 17 00:00:00 2001 From: Magnus Lindvall Date: Wed, 7 Jun 2017 09:54:12 +0200 Subject: [PATCH 4/5] Readd defer statement and move remove Signed-off-by: Magnus Lindvall --- models/ssh_key.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/ssh_key.go b/models/ssh_key.go index 11e26a28209cf..b2b568a11c5e5 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -376,13 +376,14 @@ func calcFingerprint(publicKeyContent string) (string, error) { if err != nil { return "", err } + defer os.Remove(tmpPath) + stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath) if err != nil { return "", fmt.Errorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr) } else if len(stdout) < 2 { return "", errors.New("not enough output for calculating fingerprint: " + stdout) } - os.Remove(tmpPath) return strings.Split(stdout, " ")[1], nil } From b03b20446de3461257c0e5835419a6b7618307c9 Mon Sep 17 00:00:00 2001 From: Magnus Lindvall Date: Wed, 7 Jun 2017 10:31:34 +0200 Subject: [PATCH 5/5] Delete space Signed-off-by: Magnus Lindvall --- models/ssh_key.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/ssh_key.go b/models/ssh_key.go index b2b568a11c5e5..38b172d2ed498 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -377,7 +377,6 @@ func calcFingerprint(publicKeyContent string) (string, error) { return "", err } defer os.Remove(tmpPath) - stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath) if err != nil { return "", fmt.Errorf("'ssh-keygen -lf %s' failed with error '%s': %s", tmpPath, err, stderr)