Foxboron / ssh-tpm-agent

:computer: :key: ssh-agent for TPMs
MIT License
354 stars 20 forks source link

LoadKeys() use env + slog.Debug + refactor #24

Closed jtagcat closed 1 year ago

jtagcat commented 1 year ago

Continuing discussion from https://github.com/Foxboron/ssh-tpm-agent/pull/23:

Refactor: keep functions small[^vid], less nested, and exit early. Named it createListener (not listener, since it would result in variable shadowing). I ended up refactoring the bottom part, since there was a shadowed err in main() [^shadow].

My .ssh directory is a symlink. As there is no apparent reason for avoiding symlinks (neither is there precedent from ssh-agent, etc), I made it follow symlinks.

Turns out ssh-tpm-agent didn't use $SSH_AUTH_SOCK, as specified in the systemd unit, now it does.

The debug statements (and a small refactor in main()) are because it didn't give me any error before. Now I am staring at: ~~level=DEBUG msg="%s not a TPM sealed key: %v\n" /r/c/ssh/hh-8192_ecdsa.tpm="tpm-ssh: unsupported key type \"TPM EC PRIVATE KEY\" ~~ edit: fixed by regenerating keys with trunk, not 0.1.0

[^vid]: Pointing to https://www.youtube.com/watch?v=CFRhGnuXG-4 again makes me feel like a religious follower of CodeAesthetic, but I'm not. It happens the topics they have videos on matches, and are imo good explanations.

[^shadow]: Meaning a 2nd error check was checking an error from far above, not the assumed one.

jtagcat commented 1 year ago

Resolved conflicts + squashed the linter fix to first commit.

when it is not 5am, i might add context to commits as well :sunglasses: 'trying to get it working by understanding it and by understanding, changing it'