Skip to content
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

Merged
merged 7 commits into from Jun 26, 2023

Conversation

hslatman
Copy link
Member

@hslatman hslatman commented Jun 21, 2023

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 or simulator.Simulator directly, these will take precedence over the UNIX socket path.

Connecting to a TPM using a UNIX socket is not supported on Windows.

@hslatman hslatman requested a review from maraino June 23, 2023 13:40
maraino
maraino previously approved these changes Jun 26, 2023
Copy link
Contributor

@maraino maraino left a 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")
Copy link
Contributor

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.

Comment on lines +276 to +285
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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

tpm/tpm.go Outdated Show resolved Hide resolved
Co-authored-by: Mariano Cano <mariano.cano@gmail.com>
@hslatman hslatman enabled auto-merge June 26, 2023 19:04
@hslatman hslatman requested a review from maraino June 26, 2023 19:04
@hslatman hslatman merged commit daa0581 into master Jun 26, 2023
11 of 13 checks passed
@hslatman hslatman deleted the herman/tpm-initialization-options branch June 26, 2023 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants