New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UNIX socket TPM connection support #273
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a few comments.
|
||
var ( | ||
ErrNotAvailable = errors.New("socket not available") | ||
ErrNotSupported = errors.New("connecting to a TPM using a UNIX socket is not supported on Windows") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There is limited support for UNIX sockets on Windows, but the proper solution are named pipes using https://github.com/microsoft/go-winio, for example, step
connects to the agent using:
conn, err := winio.DialPipeContext(context.Background(), `\\.\\pipe\\openssh-ssh-agent`)
The same library can create a listener on a pipe using:
lis, err := winio.ListenPipe(`\\.\\pipe\\step-agent`, nil)
If the simulator in windows can use those, they will not be difficult to implement in a future PR.
defer func() { t.attestTPM = nil }() | ||
if err := closer.AttestTPM(t.attestTPM, t.attestConfig); err != nil { | ||
return fmt.Errorf("failed closing attest.TPM: %w", err) | ||
} | ||
} | ||
|
||
// clean up the go-tpm rwc | ||
if t.rwc != nil { | ||
err := t.rwc.Close() | ||
t.rwc = nil | ||
if err != nil { | ||
defer func() { t.rwc = nil }() | ||
if err := closer.RWC(t.rwc); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be ok, but it might be weird to set those to nil even if the close fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I kind of agree. But I think it's OK in this case, because no matter what happens, I want to have a new, clean io.RWC
on the next open
, and never start with an old one in a weird state.
Co-authored-by: Mariano Cano <mariano.cano@gmail.com>
On Linux and macOS a connection can now be made to a TPM that's exposed on a UNIX socket. This shouldn't be used for production purposes, but can be useful for development and testing with a TPM simulator. The tpmutil.EmulatorReadWriteCloser is used to create the connection with the simulated TPM.
A UNIX socket TPM will only be used when the TPM is initialized with a device name that contains the path to a UNIX socket. If the TPM instance is initialized with a
tpm.CommandChannel
orsimulator.Simulator
directly, these will take precedence over the UNIX socket path.Connecting to a TPM using a UNIX socket is not supported on Windows.