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

TPM Simulator reporting unrecognised command over socket #348

Open
iolivergithub opened this issue Nov 25, 2023 · 0 comments
Open

TPM Simulator reporting unrecognised command over socket #348

iolivergithub opened this issue Nov 25, 2023 · 0 comments

Comments

@iolivergithub
Copy link

NB: I am still using the tpm2 legacy commands

IBM Software TPM: tpm_server is v1682

On startup, it listens on port 2321, tpm2_startup -c is sent to start the TPM from the command line. Trace.txt contains the following messages at that point. No other information is recorded. Other commands, eg: tpm2_pcrread all work with the appropriate flag.

Output from tpm_server:

tpmsim/src$ ./tpm_server -v 
LIBRARY_COMPATIBILITY_CHECK is ON
Starting ACT thread...
TPM command server listening on port 2321
Platform server listening on port 2322
Command IPv4 client accepted
Unrecognized TPM interface command 80010000
TPM command server listening on port 2321

tpm_server trace.txt

$ tail -f trace.txt
                Command Code 0000017e
TPM2_PCR_Read:
                Command Code 0000017e
TPM2_PCR_Read:
                Command Code 0000017e
TPM2_PCR_Read:
                Command Code 0000017e
TPM2_PCR_Read:
                Command Code 00000144
TPM2_Startup:

Command to start TPM

$ tpm2_startup -c -T mssim:host=localhost,port=2321

The Go code contains the following. The import contains: "github.com/google/go-tpm/legacy/tpm2". I wrote a wrapper around OpenTPM to allow use on Unix and Windows (and support the use of socket + devices on the former).

       rwc, err := OpenTPM(tpm2device)
	if err != nil {
		rtn := tpm2taErrorReturn{fmt.Sprintf("no TPM %w", err.Error())}
		return c.JSON(http.StatusInternalServerError, rtn)
	}
	defer rwc.Close()

	banks := make(map[string]pcrValue)

	for _, b := range pcrbanks {
		pcrvs := make(map[int]string)

		for i := 0; i <= 23; i++ {
			pcrv, pcre := tpm2.ReadPCR(rwc, i, b)
			if pcre == nil {
				pcrvs[i] = hex.EncodeToString(pcrv)
			}
		}
		banks[bankNames[b]] = pcrvs
	}

OpenTPM is as follows:

var TPMDEVICES = []string{ "/dev/tpm0", "/dev/tpmrm0", "/dev/tpm1", "/dev/tpmrm1", }

func OpenTPM(path string) (io.ReadWriteCloser,error) {
	
	if slices.Contains(TPMDEVICES,path) {
		return tpm2.OpenTPM(path)
	} else {
		return net.Dial("tcp",path)
	}
}

The parameter to OpenTPM being passed is "0.0.0.0:2321"

tpm_simulator (as above) reports

Command IPv4 client accepted
Unrecognized TPM interface command 80010000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant