Skip to content

Commit 2525195

Browse files
Timo Myyrälunny
Timo Myyrä
authored andcommitted
use writeTmpKeyFile in calcFingerprint (#1828)
this makes calcFingerprint use SSH.KeyTestpath instead of os temp dir.
1 parent b93568c commit 2525195

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

models/ssh_key.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"io/ioutil"
1414
"math/big"
1515
"os"
16-
"path"
1716
"path/filepath"
1817
"strings"
1918
"sync"
@@ -373,15 +372,8 @@ func checkKeyFingerprint(e Engine, fingerprint string) error {
373372

374373
func calcFingerprint(publicKeyContent string) (string, error) {
375374
// Calculate fingerprint.
376-
tmpPath := strings.Replace(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
377-
"id_rsa.pub"), "\\", "/", -1)
378-
dir := path.Dir(tmpPath)
379-
380-
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
381-
return "", fmt.Errorf("Failed to create dir %s: %v", dir, err)
382-
}
383-
384-
if err := ioutil.WriteFile(tmpPath, []byte(publicKeyContent), 0644); err != nil {
375+
tmpPath, err := writeTmpKeyFile(publicKeyContent)
376+
if err != nil {
385377
return "", err
386378
}
387379
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)

0 commit comments

Comments
 (0)