Skip to content
Snippets Groups Projects
Commit 1dc27c58 authored by Niall Sheridan's avatar Niall Sheridan
Browse files

Updated agent lib accepts *ed25519.PrivateKey

parent bbbe873e
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ func generateED25519Key(bits int) (key, ssh.PublicKey, error) { ...@@ -31,7 +31,7 @@ func generateED25519Key(bits int) (key, ssh.PublicKey, error) {
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
return k, pub, nil return &k, pub, nil
} }
func generateRSAKey(bits int) (key, ssh.PublicKey, error) { func generateRSAKey(bits int) (key, ssh.PublicKey, error) {
......
...@@ -536,7 +536,7 @@ type ed25519CertMsg struct { ...@@ -536,7 +536,7 @@ type ed25519CertMsg struct {
Constraints []byte `ssh:"rest"` Constraints []byte `ssh:"rest"`
} }
// Insert adds a private key to the agent. If a certificate is given, // Add 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 {
var constraints []byte var constraints []byte
...@@ -594,12 +594,12 @@ func (c *client) insertCert(s interface{}, cert *ssh.Certificate, comment string ...@@ -594,12 +594,12 @@ func (c *client) insertCert(s interface{}, cert *ssh.Certificate, comment string
Comments: comment, Comments: comment,
Constraints: constraints, Constraints: constraints,
}) })
case ed25519.PrivateKey: case *ed25519.PrivateKey:
req = ssh.Marshal(ed25519CertMsg{ req = ssh.Marshal(ed25519CertMsg{
Type: cert.Type(), Type: cert.Type(),
CertBytes: cert.Marshal(), CertBytes: cert.Marshal(),
Pub: []byte(k)[32:], Pub: []byte(*k)[32:],
Priv: []byte(k), Priv: []byte(*k),
Comments: comment, Comments: comment,
Constraints: constraints, Constraints: constraints,
}) })
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"log" "log"
"math/big" "math/big"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
) )
...@@ -175,6 +176,15 @@ func parseRSAKey(req []byte) (*AddedKey, error) { ...@@ -175,6 +176,15 @@ func parseRSAKey(req []byte) (*AddedKey, error) {
return &AddedKey{PrivateKey: priv, Comment: k.Comments}, nil return &AddedKey{PrivateKey: priv, Comment: k.Comments}, nil
} }
func parseEd25519Key(req []byte) (*AddedKey, error) {
var k ed25519KeyMsg
if err := ssh.Unmarshal(req, &k); err != nil {
return nil, err
}
priv := ed25519.PrivateKey(k.Priv)
return &AddedKey{PrivateKey: &priv, Comment: k.Comments}, nil
}
func parseDSAKey(req []byte) (*AddedKey, error) { func parseDSAKey(req []byte) (*AddedKey, error) {
var k dsaKeyMsg var k dsaKeyMsg
if err := ssh.Unmarshal(req, &k); err != nil { if err := ssh.Unmarshal(req, &k); err != nil {
...@@ -219,6 +229,23 @@ func unmarshalECDSA(curveName string, keyBytes []byte, privScalar *big.Int) (pri ...@@ -219,6 +229,23 @@ func unmarshalECDSA(curveName string, keyBytes []byte, privScalar *big.Int) (pri
return priv, nil return priv, nil
} }
func parseEd25519Cert(req []byte) (*AddedKey, error) {
var k ed25519CertMsg
if err := ssh.Unmarshal(req, &k); err != nil {
return nil, err
}
pubKey, err := ssh.ParsePublicKey(k.CertBytes)
if err != nil {
return nil, err
}
priv := ed25519.PrivateKey(k.Priv)
cert, ok := pubKey.(*ssh.Certificate)
if !ok {
return nil, errors.New("agent: bad ED25519 certificate")
}
return &AddedKey{PrivateKey: &priv, Certificate: cert, Comment: k.Comments}, nil
}
func parseECDSAKey(req []byte) (*AddedKey, error) { func parseECDSAKey(req []byte) (*AddedKey, error) {
var k ecdsaKeyMsg var k ecdsaKeyMsg
if err := ssh.Unmarshal(req, &k); err != nil { if err := ssh.Unmarshal(req, &k); err != nil {
...@@ -367,12 +394,16 @@ func (s *server) insertIdentity(req []byte) error { ...@@ -367,12 +394,16 @@ func (s *server) insertIdentity(req []byte) error {
addedKey, err = parseDSAKey(req) addedKey, err = parseDSAKey(req)
case ssh.KeyAlgoECDSA256, ssh.KeyAlgoECDSA384, ssh.KeyAlgoECDSA521: case ssh.KeyAlgoECDSA256, ssh.KeyAlgoECDSA384, ssh.KeyAlgoECDSA521:
addedKey, err = parseECDSACert(req) addedKey, err = parseECDSACert(req)
case ssh.KeyAlgoED25519:
addedKey, err = parseEd25519Key(req)
case ssh.CertAlgoRSAv01: case ssh.CertAlgoRSAv01:
addedKey, err = parseRSACert(req) addedKey, err = parseRSACert(req)
case ssh.CertAlgoDSAv01: case ssh.CertAlgoDSAv01:
addedKey, err = parseDSACert(req) addedKey, err = parseDSACert(req)
case ssh.CertAlgoECDSA256v01, ssh.CertAlgoECDSA384v01, ssh.CertAlgoECDSA521v01: case ssh.CertAlgoECDSA256v01, ssh.CertAlgoECDSA384v01, ssh.CertAlgoECDSA521v01:
addedKey, err = parseECDSACert(req) addedKey, err = parseECDSACert(req)
case ssh.CertAlgoED25519v01:
addedKey, err = parseEd25519Cert(req)
default: default:
return fmt.Errorf("agent: not implemented: %q", record.Type) return fmt.Errorf("agent: not implemented: %q", record.Type)
} }
......
...@@ -364,14 +364,14 @@ ...@@ -364,14 +364,14 @@
{ {
"checksumSHA1": "3dxfePz1LkJB7x0nIiTI88o/fFY=", "checksumSHA1": "3dxfePz1LkJB7x0nIiTI88o/fFY=",
"path": "golang.org/x/crypto/ssh", "path": "golang.org/x/crypto/ssh",
"revision": "5bcd134fee4dd1475da17714aac19c0aa0142e2f", "revision": "811831de4c4dd03a0b8737233af3b36852386373",
"revisionTime": "2016-05-16T23:05:56Z" "revisionTime": "2016-06-21T01:10:02Z"
}, },
{ {
"checksumSHA1": "EcKMEjHXZnW85PGnmiVGLknf8HU=", "checksumSHA1": "pSECJ5r90CMX5V05qPZnJhi2zso=",
"path": "golang.org/x/crypto/ssh/agent", "path": "golang.org/x/crypto/ssh/agent",
"revision": "89d9e62992539701a49a19c52ebb33e84cbbe80f", "revision": "811831de4c4dd03a0b8737233af3b36852386373",
"revisionTime": "2016-06-03T20:06:38Z" "revisionTime": "2016-06-21T01:10:02Z"
}, },
{ {
"checksumSHA1": "9jjO5GjLa0XF/nfWihF02RoH4qc=", "checksumSHA1": "9jjO5GjLa0XF/nfWihF02RoH4qc=",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment