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

Don't break command channel initialization on socket.ErrNotSupported #368

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion tpm/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,15 @@
return nil
}

// initializeCommandChannel initializes the TPM's command channel based on
// configuration provided when creating the TPM instance. The method is
// primarily used to be able to use a TPM simulator in lieu of a real TPM
// being available or when the real TPM should not be used. There's a special
// case for a TPM exposed using a UNIX socket, which also is used primarily
// for interacting with a TPM simulator.
func (t *TPM) initializeCommandChannel() error {
// return early with the complete `attestConfig` set if
// command channel was provided before.
if t.commandChannel != nil {
t.attestConfig = &attest.OpenConfig{
TPMVersion: t.options.attestConfig.TPMVersion,
Expand All @@ -222,16 +230,25 @@
t.commandChannel = t.options.commandChannel
}

// finally, check if the device name points to a UNIX socket, and use that
// as the command channel, if available.
if t.commandChannel == nil {
if socketCommandChannel, err := trySocketCommandChannel(t.deviceName); err != nil {
if !errors.Is(err, socket.ErrNotAvailable) {
switch {
case errors.Is(err, socket.ErrNotSupported):

Check warning on line 238 in tpm/tpm.go

View check run for this annotation

Codecov / codecov/patch

tpm/tpm.go#L237-L238

Added lines #L237 - L238 were not covered by tests
// don't try to use socket command channel if not supported. No need to return
// an error, because the code should still rely on the default TPM command channel.
case !errors.Is(err, socket.ErrNotAvailable):

Check warning on line 241 in tpm/tpm.go

View check run for this annotation

Codecov / codecov/patch

tpm/tpm.go#L241

Added line #L241 was not covered by tests
return err
}
} else {
t.commandChannel = socketCommandChannel
}
}

// update `attestConfig` with the command channel, so that it is used whenever
// attestation operations are being performed. Note that the command channel can
// still be nil. It simply won't be used (wrapped) by `go-attestation` in that case.
t.attestConfig = &attest.OpenConfig{
TPMVersion: t.options.attestConfig.TPMVersion,
CommandChannel: t.commandChannel,
Expand Down