Documentation
¶
Overview ¶
Package nvcounter is a rollback counter on a TPM 2.0: a TPM_NT_COUNTER NV index (TCG TPM 2.0 Library Part 3, 31.8), created once, incremented by its own authValue and never reset, over go-tpm2/tpm2. It is the counter theca binds a container to; nothing in it is specific to theca.
Counter.Identity names the TPM the counter lives on (the digest inside the Name of its ECC P-256 endorsement key), so a caller can pin a counter to one TPM and refuse the same handle and Name on another.
Transports: the Linux kernel resource manager (/dev/tpmrm0), Windows TPM Base Services ("tbs:", the Windows default, go-tpm2/devtpm OpenTBS), and any raw TPM 2.0 stream the caller names as "unix:<socket>" (a software TPM started with swtpm --server type=unixio). macOS has no TPM and returns ErrUnsupported unless a device is named explicitly; "tbs:" off Windows is an error too.
A Counter holds no open connection. Each operation opens the device and closes it, so no lifetime has to be managed and the kernel resource manager releases everything between operations.
Index ¶
Constants ¶
const ( First uint32 = 0x01500000 Span uint32 = 0x1000 )
First and Span give the owner NV handles searched for a free one: the TCG registry assigns 0x01500000-0x01BFFFFF to the owner.
const DefaultLinuxDevice = devtpm.DefaultDevice
DefaultLinuxDevice is the kernel resource manager.
const IDSize = 32
IDSize is the size of an identity: a SHA-256 digest.
const TBSDevice = "tbs:"
TBSDevice names Windows TPM Base Services, the Windows default: one TBS context per operation, as for the other devices.
Variables ¶
var ( // ErrUnsupported: this platform has no TPM interface and no device was named. ErrUnsupported = errors.New("nvcounter: no TPM interface on this platform (name a device)") // ErrNotCounter: the NV index exists but is not a counter this package made. ErrNotCounter = errors.New("nvcounter: the NV index is not a rollback counter created by this package") // ErrNoCounter: the NV index is not defined on this TPM (it was undefined, // the TPM was cleared, or this is another TPM). ErrNoCounter = errors.New("nvcounter: the TPM has no NV index at the counter's handle") // ErrAuthTooLong: an authValue longer than a SHA-256 digest (Part 3 31.3.1). ErrAuthTooLong = errors.New("nvcounter: an authValue is at most 32 bytes") // ErrIdentity: the TPM could not name itself (no EK, a set endorsement // authValue) or answered with something that is not an EK Name. ErrIdentity = errors.New("nvcounter: cannot read this TPM's identity") // ErrNoFreeHandle: every handle in the search range is taken. ErrNoFreeHandle = errors.New("nvcounter: no free NV index handle in the owner range searched") )
Errors.
var ErrEndorsementAuth = errors.New("nvcounter: the TPM refused the endorsement hierarchy password")
ErrEndorsementAuth: the TPM refused the endorsement hierarchy password (TPM_RC_BAD_AUTH or TPM_RC_AUTH_FAIL). The authValue of a hierarchy is not DA protected, so the refusal does not count toward the lockout.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a TPM NV counter. It satisfies theca.Counter and theca.IdentifiedCounter.
func Create ¶
Create defines a new counter index and returns it. The index is not yet written: the first Increment writes it. If a later step fails, call Destroy.
func Open ¶
Open attaches to the existing counter o.Handle and reads its Name from the TPM. It refuses an index that is not a counter with the attributes Create sets. (The container pins the Name too: a different index fails there.)
func (*Counter) Destroy ¶
Destroy deletes the index under the owner password in the Options it was created with. Use it only to undo a Create.
func (*Counter) Identity ¶
Identity is the identity of THIS TPM, the SHA-256 digest inside the Name of its endorsement key (the EK Credential Profile ECC P-256 template, created transiently and flushed, never made persistent). The same TPM gives the same identity on every call, another TPM another one. Needs the endorsement hierarchy's authValue to be empty, the default, or EndorsementAuth to be the password; otherwise it fails (with ErrEndorsementAuth if the TPM refused the password).
It names the TPM, it does not prove the TPM answering is that one: whoever controls a software TPM can present any EK.
func (*Counter) Increment ¶
Increment adds one to the counter. It then reads the Name again: the first increment sets TPMA_NV_WRITTEN, which is part of the public area the Name is the digest of, so the Name of a counter that was just created changes once. (Measured on swtpm: a Name read before the first increment does not match the one read after it.)
type Options ¶
type Options struct {
// Device is a character device path, "unix:<socket>", or empty for the
// platform default (/dev/tpmrm0 on Linux).
Device string
// Handle is the NV index. Create picks a free one when it is 0; Open
// requires it.
Handle uint32
// OwnerAuth authorizes Create and Destroy (the owner hierarchy password;
// empty on a TPM with no owner password). Read from a file by the caller,
// never from argv or the environment.
OwnerAuth []byte
// Auth is the counter's own authValue, used to increment and read it.
Auth []byte
// EndorsementAuth authorizes the creation of the endorsement key that names
// the TPM (Identity): the endorsement hierarchy password, empty on a TPM
// with none. A wrong one is ErrEndorsementAuth.
EndorsementAuth []byte
}
Options select the TPM and the credentials.