|
|
|
|
@ -32,7 +32,9 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
|
|
|
|
|
priv, err := rsa.GenerateKey(rand.Reader, 2014)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state.Put("error", fmt.Errorf("Error creating temporary SSH key: %s", err))
|
|
|
|
|
err = fmt.Errorf("Error creating temporary SSH key: %s", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -50,7 +52,9 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
// Marshal the public key into SSH compatible format
|
|
|
|
|
pub, err := ssh.NewPublicKey(&priv.PublicKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state.Put("error", fmt.Errorf("Error marshaling temporary SSH public key: %s", err))
|
|
|
|
|
err = fmt.Errorf("Error marshaling temporary SSH public key: %s", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -62,21 +66,27 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
|
|
|
|
|
f, err := os.Create(s.DebugKeyPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
|
|
|
|
|
err = fmt.Errorf("Error saving debug key: %s", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
// Write the key out
|
|
|
|
|
if _, err := f.Write(pem.EncodeToMemory(&privBlk)); err != nil {
|
|
|
|
|
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
|
|
|
|
|
err = fmt.Errorf("Error saving debug key: %s", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Chmod it so that it is SSH ready
|
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
|
if err := f.Chmod(0600); err != nil {
|
|
|
|
|
state.Put("error", fmt.Errorf("Error setting permissions of debug key: %s", err))
|
|
|
|
|
err = fmt.Errorf("Error setting permissions of debug key: %s", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|