x/crypto/ssh: set constraints when adding certs to the agent
Fixes golang/go#15953 Change-Id: Ia36b5422bef14609d512c3f5055a3bffad18ce0f Reviewed-on: https://go-review.googlesource.com/23752 Reviewed-by: Han-Wen Nienhuys <hanwen@google.com> Run-TryBot: Han-Wen Nienhuys <hanwen@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Han-Wen Nienhuys
parent
5bcd134fee
commit
89d9e62992
+16
-13
@@ -580,25 +580,28 @@ func (c *client) insertCert(s interface{}, cert *ssh.Certificate, comment string
|
|||||||
})
|
})
|
||||||
case *dsa.PrivateKey:
|
case *dsa.PrivateKey:
|
||||||
req = ssh.Marshal(dsaCertMsg{
|
req = ssh.Marshal(dsaCertMsg{
|
||||||
Type: cert.Type(),
|
Type: cert.Type(),
|
||||||
CertBytes: cert.Marshal(),
|
CertBytes: cert.Marshal(),
|
||||||
X: k.X,
|
X: k.X,
|
||||||
Comments: comment,
|
Comments: comment,
|
||||||
|
Constraints: constraints,
|
||||||
})
|
})
|
||||||
case *ecdsa.PrivateKey:
|
case *ecdsa.PrivateKey:
|
||||||
req = ssh.Marshal(ecdsaCertMsg{
|
req = ssh.Marshal(ecdsaCertMsg{
|
||||||
Type: cert.Type(),
|
Type: cert.Type(),
|
||||||
CertBytes: cert.Marshal(),
|
CertBytes: cert.Marshal(),
|
||||||
D: k.D,
|
D: k.D,
|
||||||
Comments: comment,
|
Comments: comment,
|
||||||
|
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,
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("agent: unsupported key type %T", s)
|
return fmt.Errorf("agent: unsupported key type %T", s)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
@@ -285,3 +286,42 @@ func testLockAgent(agent Agent, t *testing.T) {
|
|||||||
t.Errorf("Want 1 keys, got %v", keys)
|
t.Errorf("Want 1 keys, got %v", keys)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAgentLifetime(t *testing.T) {
|
||||||
|
agent, _, cleanup := startAgent(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
for _, keyType := range []string{"rsa", "dsa", "ecdsa"} {
|
||||||
|
// Add private keys to the agent.
|
||||||
|
err := agent.Add(AddedKey{
|
||||||
|
PrivateKey: testPrivateKeys[keyType],
|
||||||
|
Comment: "comment",
|
||||||
|
LifetimeSecs: 1,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("add: %v", err)
|
||||||
|
}
|
||||||
|
// Add certs to the agent.
|
||||||
|
cert := &ssh.Certificate{
|
||||||
|
Key: testPublicKeys[keyType],
|
||||||
|
ValidBefore: ssh.CertTimeInfinity,
|
||||||
|
CertType: ssh.UserCert,
|
||||||
|
}
|
||||||
|
cert.SignCert(rand.Reader, testSigners[keyType])
|
||||||
|
err = agent.Add(AddedKey{
|
||||||
|
PrivateKey: testPrivateKeys[keyType],
|
||||||
|
Certificate: cert,
|
||||||
|
Comment: "comment",
|
||||||
|
LifetimeSecs: 1,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("add: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
time.Sleep(1100 * time.Millisecond)
|
||||||
|
if keys, err := agent.List(); err != nil {
|
||||||
|
t.Errorf("List: %v", err)
|
||||||
|
} else if len(keys) != 0 {
|
||||||
|
t.Errorf("Want 0 keys, got %v", len(keys))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user