ssh: allow adding ed25519 keys to the agent
Fixes golang/go#15701 Change-Id: I561701e38b9d434ef44448bdbcfab203f3c31d99 Reviewed-on: https://go-review.googlesource.com/23141 Reviewed-by: Han-Wen Nienhuys <hanwen@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
0a4e4d451b
commit
5bcd134fee
@@ -25,6 +25,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ed25519"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -423,6 +424,14 @@ type ecdsaKeyMsg struct {
|
|||||||
Constraints []byte `ssh:"rest"`
|
Constraints []byte `ssh:"rest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ed25519KeyMsg struct {
|
||||||
|
Type string `sshtype:"17|25"`
|
||||||
|
Pub []byte
|
||||||
|
Priv []byte
|
||||||
|
Comments string
|
||||||
|
Constraints []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
// Insert adds a private key to the agent.
|
// Insert adds a private key to the agent.
|
||||||
func (c *client) insertKey(s interface{}, comment string, constraints []byte) error {
|
func (c *client) insertKey(s interface{}, comment string, constraints []byte) error {
|
||||||
var req []byte
|
var req []byte
|
||||||
@@ -464,6 +473,14 @@ func (c *client) insertKey(s interface{}, comment string, constraints []byte) er
|
|||||||
Comments: comment,
|
Comments: comment,
|
||||||
Constraints: constraints,
|
Constraints: constraints,
|
||||||
})
|
})
|
||||||
|
case *ed25519.PrivateKey:
|
||||||
|
req = ssh.Marshal(ed25519KeyMsg{
|
||||||
|
Type: ssh.KeyAlgoED25519,
|
||||||
|
Pub: []byte(*k)[32:],
|
||||||
|
Priv: []byte(*k),
|
||||||
|
Comments: comment,
|
||||||
|
Constraints: constraints,
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("agent: unsupported key type %T", s)
|
return fmt.Errorf("agent: unsupported key type %T", s)
|
||||||
}
|
}
|
||||||
@@ -510,6 +527,15 @@ type ecdsaCertMsg struct {
|
|||||||
Constraints []byte `ssh:"rest"`
|
Constraints []byte `ssh:"rest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ed25519CertMsg struct {
|
||||||
|
Type string `sshtype:"17|25"`
|
||||||
|
CertBytes []byte
|
||||||
|
Pub []byte
|
||||||
|
Priv []byte
|
||||||
|
Comments string
|
||||||
|
Constraints []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
// Insert adds a private key to the agent. If a certificate is given,
|
// Insert adds a private key to the agent. If a certificate is given,
|
||||||
// that certificate is added instead as public key.
|
// that certificate is added instead as public key.
|
||||||
func (c *client) Add(key AddedKey) error {
|
func (c *client) Add(key AddedKey) error {
|
||||||
@@ -566,6 +592,14 @@ func (c *client) insertCert(s interface{}, cert *ssh.Certificate, comment string
|
|||||||
D: k.D,
|
D: k.D,
|
||||||
Comments: comment,
|
Comments: comment,
|
||||||
})
|
})
|
||||||
|
case ed25519.PrivateKey:
|
||||||
|
req = ssh.Marshal(ed25519CertMsg{
|
||||||
|
Type: cert.Type(),
|
||||||
|
CertBytes: cert.Marshal(),
|
||||||
|
Pub: []byte(k)[32:],
|
||||||
|
Priv: []byte(k),
|
||||||
|
Comments: comment,
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("agent: unsupported key type %T", s)
|
return fmt.Errorf("agent: unsupported key type %T", s)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ func testAgentInterface(t *testing.T, agent Agent, key interface{}, cert *ssh.Ce
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAgent(t *testing.T) {
|
func TestAgent(t *testing.T) {
|
||||||
for _, keyType := range []string{"rsa", "dsa", "ecdsa"} {
|
for _, keyType := range []string{"rsa", "dsa", "ecdsa", "ed25519"} {
|
||||||
testAgent(t, testPrivateKeys[keyType], nil, 0)
|
testAgent(t, testPrivateKeys[keyType], nil, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user