aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-08-20 20:21:43 +0100
committerNiall Sheridan <nsheridan@gmail.com>2016-08-20 20:21:43 +0100
commitf375ecdce3586627c81665307b8f959abfddb769 (patch)
tree099a5bbd27084f6573b95d6a299fdc005d4a130d
parent121e65912fcc2627cc46d3641f3611bed5523d33 (diff)
Add key expiry time to the comment
-rw-r--r--cmd/cashier/client_test.go9
-rw-r--r--cmd/cashier/main.go8
2 files changed, 14 insertions, 3 deletions
diff --git a/cmd/cashier/client_test.go b/cmd/cashier/client_test.go
index b82d78f..dcf674b 100644
--- a/cmd/cashier/client_test.go
+++ b/cmd/cashier/client_test.go
@@ -9,6 +9,7 @@ import (
"net/http"
"net/http/httptest"
"testing"
+ "time"
"github.com/nsheridan/cashier/lib"
"github.com/nsheridan/cashier/testdata"
@@ -22,6 +23,7 @@ func TestLoadCert(t *testing.T) {
key := priv.(*rsa.PrivateKey)
pub, _ := ssh.NewPublicKey(&key.PublicKey)
c := &ssh.Certificate{
+ KeyId: "test_key_12345",
Key: pub,
CertType: ssh.UserCert,
ValidBefore: ssh.CertTimeInfinity,
@@ -46,6 +48,13 @@ func TestLoadCert(t *testing.T) {
if !bytes.Equal(listedKeys[0].Marshal(), c.Marshal()) {
t.Fatal("Certs not equal")
}
+ for _, k := range listedKeys {
+ exp := time.Unix(int64(c.ValidBefore), 0).String()
+ want := fmt.Sprintf("%s [Expires %s]", c.KeyId, exp)
+ if k.Comment != want {
+ t.Errorf("key comment:\nwanted:%s\ngot: %s", want, k.Comment)
+ }
+ }
}
func TestSignGood(t *testing.T) {
diff --git a/cmd/cashier/main.go b/cmd/cashier/main.go
index 047c13e..72355e3 100644
--- a/cmd/cashier/main.go
+++ b/cmd/cashier/main.go
@@ -32,11 +32,13 @@ var (
)
func installCert(a agent.Agent, cert *ssh.Certificate, key key) error {
- lifetime := time.Unix(int64(cert.ValidBefore), 0).Sub(time.Now()).Seconds()
+ t := time.Unix(int64(cert.ValidBefore), 0)
+ lifetime := t.Sub(time.Now()).Seconds()
+ comment := fmt.Sprintf("%s [Expires %s]", cert.KeyId, t)
pubcert := agent.AddedKey{
PrivateKey: key,
Certificate: cert,
- Comment: cert.KeyId,
+ Comment: comment,
LifetimeSecs: uint32(lifetime),
}
if err := a.Add(pubcert); err != nil {
@@ -44,7 +46,7 @@ func installCert(a agent.Agent, cert *ssh.Certificate, key key) error {
}
privkey := agent.AddedKey{
PrivateKey: key,
- Comment: cert.KeyId,
+ Comment: comment,
LifetimeSecs: uint32(lifetime),
}
if err := a.Add(privkey); err != nil {