use writeTmpKeyFile in calcFingerprint (#1828)

this makes calcFingerprint use SSH.KeyTestpath instead of os temp dir.
This commit is contained in:
Timo Myyrä 2017-05-29 14:51:16 +03:00 committed by Lunny Xiao
parent b93568cce4
commit 2525195749
1 changed files with 2 additions and 10 deletions

View File

@ -13,7 +13,6 @@ import (
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
@ -373,15 +372,8 @@ func checkKeyFingerprint(e Engine, fingerprint string) error {
func calcFingerprint(publicKeyContent string) (string, error) { func calcFingerprint(publicKeyContent string) (string, error) {
// Calculate fingerprint. // Calculate fingerprint.
tmpPath := strings.Replace(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()), tmpPath, err := writeTmpKeyFile(publicKeyContent)
"id_rsa.pub"), "\\", "/", -1) if err != nil {
dir := path.Dir(tmpPath)
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return "", fmt.Errorf("Failed to create dir %s: %v", dir, err)
}
if err := ioutil.WriteFile(tmpPath, []byte(publicKeyContent), 0644); err != nil {
return "", err return "", err
} }
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath) stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)