summaryrefslogtreecommitdiffstats
path: root/models/ssh_key.go
diff options
context:
space:
mode:
authorTimo Myyrä <timo.myyra@iki.fi>2017-05-29 14:51:16 +0300
committerLunny Xiao <xiaolunwen@gmail.com>2017-05-29 19:51:16 +0800
commit2525195749a1c343a9e9ff1f2f328acf7678c28a (patch)
treedc8b03d68d71f17046ad4df3811f5d3d1ad4754a /models/ssh_key.go
parentb93568cce4717abd97f1f92341ce9fdf331a7e98 (diff)
downloadgitea-2525195749a1c343a9e9ff1f2f328acf7678c28a.tar.gz
gitea-2525195749a1c343a9e9ff1f2f328acf7678c28a.zip
use writeTmpKeyFile in calcFingerprint (#1828)
this makes calcFingerprint use SSH.KeyTestpath instead of os temp dir.
Diffstat (limited to 'models/ssh_key.go')
-rw-r--r--models/ssh_key.go12
1 files changed, 2 insertions, 10 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go
index 653889e488..fa33cd4c15 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -13,7 +13,6 @@ import (
"io/ioutil"
"math/big"
"os"
- "path"
"path/filepath"
"strings"
"sync"
@@ -373,15 +372,8 @@ func checkKeyFingerprint(e Engine, fingerprint string) error {
func calcFingerprint(publicKeyContent string) (string, error) {
// Calculate fingerprint.
- tmpPath := strings.Replace(path.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
- "id_rsa.pub"), "\\", "/", -1)
- 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 {
+ tmpPath, err := writeTmpKeyFile(publicKeyContent)
+ if err != nil {
return "", err
}
stdout, stderr, err := process.GetManager().Exec("AddPublicKey", "ssh-keygen", "-lf", tmpPath)