Skip to content

Commit 9115478

Browse files
Fixed existing key usage
- keys will now use the correct parsing function - fixed key pair not being copied over for existing keys
1 parent 6edbb7f commit 9115478

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

driver/driver.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ func (d *Driver) PreCreateCheck() error {
144144
return err
145145
}
146146

147-
pubk, err := ssh.ParsePublicKey(buf)
147+
// Will also parse `ssh-rsa w309jwf0e39jf asdf` public keys
148+
pubk, _, _, _, err := ssh.ParseAuthorizedKey(buf)
149+
if err != nil {
150+
return err
151+
}
148152

149153
if key.Fingerprint != ssh.FingerprintLegacyMD5(pubk) &&
150154
key.Fingerprint != ssh.FingerprintSHA256(pubk) {
@@ -156,19 +160,19 @@ func (d *Driver) PreCreateCheck() error {
156160
}
157161

158162
func (d *Driver) Create() error {
159-
if d.KeyID == 0 {
160-
if d.originalKey != "" {
161-
log.Debugf("Copying SSH key...")
162-
if err := d.copySSHKeyPair(d.originalKey); err != nil {
163-
return err
164-
}
165-
} else {
166-
log.Debugf("Generating SSH key...")
167-
if err := mcnssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
168-
return err
169-
}
163+
if d.originalKey != "" {
164+
log.Debugf("Copying SSH key...")
165+
if err := d.copySSHKeyPair(d.originalKey); err != nil {
166+
return err
167+
}
168+
} else {
169+
log.Debugf("Generating SSH key...")
170+
if err := mcnssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
171+
return err
170172
}
173+
}
171174

175+
if d.KeyID == 0 {
172176
log.Infof("Creating SSH key...")
173177

174178
buf, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")

0 commit comments

Comments
 (0)