-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5dd7a9
Add `options` for TPM initialization
hslatman 5e6c433
Add the basics for using a TPM simulator via a socket
hslatman 7f8e037
Add support for connecting to TPM via UNIX socket
hslatman fb5b6ea
Fix linter issues
hslatman de3c9d1
Add TPM availability check method
hslatman 8a4f670
Add support for seeding the TPM simulator
hslatman ca29d42
Update tpm/tpm.go
hslatman File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package available | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.step.sm/crypto/tpm" | ||
) | ||
|
||
func Check(opts ...tpm.NewTPMOption) error { | ||
t, err := tpm.New(opts...) | ||
if err != nil { | ||
return fmt.Errorf("failed creating TPM instance: %w", err) | ||
} | ||
return t.Available() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package closer | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/smallstep/go-attestation/attest" | ||
) | ||
|
||
func RWC(rwc io.ReadWriteCloser) error { | ||
return closeRWC(rwc) | ||
} | ||
|
||
func AttestTPM(t *attest.TPM, c *attest.OpenConfig) error { | ||
return attestTPM(t, c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package closer | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/google/go-tpm/tpmutil" | ||
"github.com/smallstep/go-attestation/attest" | ||
|
||
"go.step.sm/crypto/tpm/internal/socket" | ||
) | ||
|
||
func closeRWC(rwc io.ReadWriteCloser) error { | ||
if _, ok := rwc.(*tpmutil.EmulatorReadWriteCloser); ok { | ||
return nil // EmulatorReadWriteCloser automatically closes on every write/read cycle | ||
} | ||
return rwc.Close() | ||
} | ||
|
||
func attestTPM(t *attest.TPM, c *attest.OpenConfig) error { | ||
if _, ok := c.CommandChannel.(*socket.CommandChannelWithoutMeasurementLog); ok { | ||
return nil // backed by tpmutil.EmulatorReadWriteCloser; already closed | ||
} | ||
return t.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package closer | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/smallstep/go-attestation/attest" | ||
) | ||
|
||
func closeRWC(rwc io.ReadWriteCloser) error { | ||
return rwc.Close() | ||
} | ||
|
||
func attestTPM(t *attest.TPM, _ *attest.OpenConfig) error { | ||
return t.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package socket | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
) | ||
|
||
var ( | ||
ErrNotAvailable = errors.New("socket not available") | ||
ErrNotSupported = errors.New("connecting to a TPM using a UNIX socket is not supported on Windows") | ||
) | ||
|
||
func New(path string) (io.ReadWriteCloser, error) { | ||
return newSocket(path) | ||
} | ||
|
||
type CommandChannelWithoutMeasurementLog struct { | ||
io.ReadWriteCloser | ||
} | ||
|
||
func (c *CommandChannelWithoutMeasurementLog) MeasurementLog() ([]byte, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package socket | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/google/go-tpm/tpmutil" | ||
) | ||
|
||
func newSocket(path string) (io.ReadWriteCloser, error) { | ||
if path == "" { | ||
return nil, ErrNotAvailable | ||
} | ||
fi, err := os.Stat(path) | ||
if err != nil { // TODO(hs): handle specific errors here? | ||
return nil, err | ||
} | ||
if fi.Mode()&os.ModeSocket != 0 { | ||
return tpmutil.NewEmulatorReadWriteCloser(path), nil | ||
} | ||
return nil, ErrNotAvailable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package socket | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
func newSocket(_ string) (io.ReadWriteCloser, error) { | ||
return nil, ErrNotSupported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:The same library can create a listener on a pipe using:
If the simulator in windows can use those, they will not be difficult to implement in a future PR.