Skip to content

Commit

Permalink
fix slog formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jtagcat committed Oct 14, 2023
1 parent 3d70fda commit f1338eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (

var ErrOperationUnsupported = errors.New("operation unsupported")

var (
SSH_TPM_AGENT_ADD = "tpm-add-key"
)
var SSH_TPM_AGENT_ADD = "tpm-add-key"

type Agent struct {
mu sync.Mutex
Expand All @@ -45,7 +43,7 @@ func (a *Agent) Extension(extensionType string, contents []byte) ([]byte, error)
slog.Debug("called extensions")
switch extensionType {
case SSH_TPM_AGENT_ADD:
slog.Debug("runnning %s", extensionType)
slog.Debug("runnning extension", slog.String("type", extensionType))
return a.AddTPMKey(contents)
}
return nil, agent.ErrExtensionUnsupported
Expand Down Expand Up @@ -78,7 +76,7 @@ func (a *Agent) signers() ([]ssh.Signer, error) {
for _, agent := range a.agents {
l, err := agent.Signers()
if err != nil {
slog.Info("failed getting Signers from agent: %f", err)
slog.Info("failed getting Signers from agent", slog.String("error", err.Error()))
continue
}
signers = append(signers, l...)
Expand Down Expand Up @@ -111,7 +109,7 @@ func (a *Agent) List() ([]*agent.Key, error) {
for _, agent := range a.agents {
l, err := agent.List()
if err != nil {
slog.Info("failed getting list from agent: %v", err)
slog.Info("failed getting list from agent", slog.String("error", err.Error()))
continue
}
agentKeys = append(agentKeys, l...)
Expand Down Expand Up @@ -160,7 +158,7 @@ func (a *Agent) SignWithFlags(key ssh.PublicKey, data []byte, flags agent.Signat
for _, agent := range a.agents {
signers, err := agent.Signers()
if err != nil {
slog.Info("failed getting signers from agent: %v", err)
slog.Info("failed getting signers from agent", slog.String("error", err.Error()))
continue
}
for _, s := range signers {
Expand All @@ -181,7 +179,7 @@ func (a *Agent) Sign(key ssh.PublicKey, data []byte) (*ssh.Signature, error) {

func (a *Agent) serveConn(c net.Conn) {
if err := agent.ServeAgent(a, c); err != io.EOF {
slog.Info("Agent client connection ended with error:", err)
slog.Info("Agent client connection ended unsuccessfully", slog.String("error", err.Error()))
}
}

Expand All @@ -202,17 +200,18 @@ func (a *Agent) serve() {
if err != nil {
type temporary interface {
Temporary() bool
Error() string
}
if err, ok := err.(temporary); ok && err.Temporary() {
slog.Info("Temporary Accept error, sleeping 1s:", err)
slog.Info("Temporary Accept failure, sleeping 1s", slog.String("error", err.Error()))
time.Sleep(1 * time.Second)
continue
}
select {
case <-a.quit:
return
default:
slog.Error("Failed to accept connections:", err)
slog.Error("Failed to accept connections", slog.String("error", err.Error()))
}
}
a.wg.Add(1)
Expand Down Expand Up @@ -252,14 +251,17 @@ func (a *Agent) Remove(key ssh.PublicKey) error {
slog.Debug("called remove")
return ErrOperationUnsupported
}

func (a *Agent) RemoveAll() error {
slog.Debug("called removeall")
return a.Close()
}

func (a *Agent) Lock(passphrase []byte) error {
slog.Debug("called lock")
return ErrOperationUnsupported
}

func (a *Agent) Unlock(passphrase []byte) error {
slog.Debug("called unlock")
return ErrOperationUnsupported
Expand All @@ -284,7 +286,7 @@ func LoadKeys(keyDir string) (map[string]*key.Key, error) {
}
k, err := key.DecodeKey(f)
if err != nil {
slog.Debug("%s not a TPM sealed key: %v\n", path, err)
slog.Debug("not a TPM-sealed key", slog.String("key_path", path), slog.String("error", err.Error()))
return nil
}
keys[k.Fingerprint()] = k
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssh-tpm-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func main() {
os.Exit(1)
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
slog.Info("Warning: %s is a symbolic link; will not follow it", keyDir)
slog.Info("Not following symbolic link", slog.String("key_directory", keyDir))
}

if term.IsTerminal(int(os.Stdin.Fd())) {
Expand Down Expand Up @@ -220,7 +220,7 @@ func main() {
slog.Error("Failed to listen on UNIX socket:", err)
os.Exit(1)
}
slog.Info(fmt.Sprintf("Listening on %v", socketPath))
slog.Info(fmt.Sprintf("Listening on socket", slog.String("path", socketPath)))
}

a := agent.NewAgent(listener,
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssh-tpm-keygen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func main() {
continue
}

slog.Info(fmt.Sprintf("Generating new %s host key\n", strings.ToUpper(n)))
slog.Info("Generating new host key", slog.String("algorithm", strings.ToUpper(n)))

k, err := key.CreateKey(tpm, t, []byte(""), []byte(defaultComment))
if err != nil {
Expand All @@ -169,7 +169,7 @@ func main() {
log.Fatal(err)
}

slog.Info(fmt.Sprintf("Wrote %s\n", privatekeyFilename))
slog.Info("Wrote private key", slog.String("filename", privatekeyFilename))
}
os.Exit(0)
}
Expand Down

0 comments on commit f1338eb

Please sign in to comment.