Ubuntu Pastebin

Paste from tvoss at Tue, 11 Apr 2017 19:56:14 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
diff --git a/overlord/devicestate/crypto.go b/overlord/devicestate/crypto.go
index 8fdbdfcdf..5cddd27b6 100644
--- a/overlord/devicestate/crypto.go
+++ b/overlord/devicestate/crypto.go
@@ -34,19 +34,13 @@ import (
 )
 
 func generateRSAKey(keyLength int) (*rsa.PrivateKey, error) {
-       sshKeyFile       := filepath.Join(dirs.SnapRunDir, "snapd.key.tmp")
-       sshPublicKeyFile := sshKeyFile + ".pub"
+       tempDir, _ := ioutil.TempDir(dirs.SnapRunDir, "tmp")
+       sshKeyFile := filepath.Join(tempDir, "snapd.key")
 
        defer func() {
-               os.Remove(sshKeyFile)
-               os.Remove(sshPublicKeyFile)
+               os.Remove(tempDir)
        }()
 
-       os.MkdirAll(dirs.SnapRunDir, 0755)
-
-       os.Remove(sshKeyFile)
-       os.Remove(sshPublicKeyFile)
-
        cmd := exec.Command("ssh-keygen", "-t", "rsa", "-b", strconv.Itoa(keyLength), "-N", "", "-f", sshKeyFile)
        out, err := cmd.CombinedOutput()
        if err != nil {
Download as text